1

00:00:01,110  -->  00:00:05,300
So let's go ahead and look at few other important bytecode instructions.

2

00:00:05,500  -->  00:00:12,720
One minute if you're doing water and instructions called in work special on Iraq which we'll just recap

3

00:00:12,720  -->  00:00:19,560
here like in the case of a real CPA you JVM that is an abstract computing machine also has an instruction

4

00:00:19,560  -->  00:00:20,610
set.

5

00:00:20,710  -->  00:00:28,140
We know that a method bytecode stream would act as instructions for the JVM and the bytecode instructions

6

00:00:28,230  -->  00:00:34,440
also have a similar representation as regular instructions office EPU each bytecode instruction basically

7

00:00:34,440  -->  00:00:40,230
involves a run byte opcode followed by 0 or more options.

8

00:00:40,230  -->  00:00:45,750
The awkward specifies the operation to be performed when the operands specific additional information

9

00:00:45,760  -->  00:00:47,010
.

10

00:00:47,010  -->  00:00:52,310
For example the I add instruction that we saw earlier was just were adding two values.

11

00:00:52,740  -->  00:00:59,160
In this case I add is the opcode and there were no options open and so actually implicit.

12

00:00:59,160  -->  00:01:05,430
The upward sort implies popping the end values at the top of the operand stack and performing the necessary

13

00:01:05,820  -->  00:01:07,490
operation.

14

00:01:07,530  -->  00:01:10,050
We also have that Iler instruction.

15

00:01:10,050  -->  00:01:13,780
One example was I load underscore one here the suffix one.

16

00:01:13,800  -->  00:01:21,330
So says the opera and that is the instruction is telling JVM to dig the value at index 1 in the local

17

00:01:21,360  -->  00:01:29,910
variables Ari on push it onto the top of the operands like like C.P. you DBMSs execution engine also

18

00:01:29,910  -->  00:01:31,880
follows fetch on execution lifecycle.

19

00:01:31,950  -->  00:01:38,490
And we know that that is GBM would fetch an upcourt on any trailing operands then it would execute the

20

00:01:38,490  -->  00:01:45,230
operation requested by that upcourt and then it fetches the next instruction and so on.

21

00:01:45,240  -->  00:01:50,490
Now let's use this simple program to review the bytecode instructions that it generates.

22

00:01:50,490  -->  00:01:53,580
You can also find the program in resource section.

23

00:01:53,580  -->  00:01:59,220
The program has a main method and one additional method called string which basically overrides the

24

00:01:59,430  -->  00:02:02,310
string method in the Object class.

25

00:02:02,310  -->  00:02:06,650
This method has a system that overprint Allen's statement underlines the string hello.

26

00:02:07,260  -->  00:02:12,780
The main one that creates an instance of this class and simply in with a string method on that new instance

27

00:02:14,090  -->  00:02:20,370
not to look at the bytecode we will use a jalopy too which is basically a bytecode disassembler that

28

00:02:20,370  -->  00:02:22,210
comes with it.

29

00:02:22,290  -->  00:02:24,970
We looked at it when discussing method binding.

30

00:02:25,170  -->  00:02:31,290
It can be used to disassemble one or more class once and it can also take multiple command line options

31

00:02:31,290  -->  00:02:32,350
.

32

00:02:32,400  -->  00:02:37,890
For example if you include the option hyphen C it would print the byte code for each of them methods

33

00:02:37,940  -->  00:02:38,950
in the class.

34

00:02:39,600  -->  00:02:45,210
But if you can grab the option hyphen we are hyphen bobos then it would still print the byte code of

35

00:02:45,300  -->  00:02:46,490
each of the methods.

36

00:02:46,710  -->  00:02:53,370
But in addition it would also provide the dark constant boune on some additional information in case

37

00:02:53,370  -->  00:02:55,630
you want to view all the possible options.

38

00:02:55,830  -->  00:02:58,330
You can use hyphen help.

39

00:02:58,500  -->  00:03:05,860
So let's go ahead and use hyphen VI option on the Hello class as shown here under the bytecode.

40

00:03:07,000  -->  00:03:07,280
OK.

41

00:03:07,290  -->  00:03:08,940
Now here is the Hello class.

42

00:03:09,030  -->  00:03:10,710
So you're not going to look at that.

43

00:03:10,980  -->  00:03:14,590
So I'm just going to compile this first and then.

44

00:03:15,030  -->  00:03:18,810
So I'm just going to run the jalopy down with the hyphen B option.

45

00:03:18,870  -->  00:03:19,330
OK.

46

00:03:19,350  -->  00:03:22,540
And it's going to be hello dark class here.

47

00:03:22,680  -->  00:03:27,290
OK so we are running or we are running it on the classified.

48

00:03:27,810  -->  00:03:30,510
Now here is a byte code.

49

00:03:31,350  -->  00:03:36,080
And we can see that this is the method called by a byte code Fard the two string mentored.

50

00:03:36,320  -->  00:03:41,030
And similarly we have the bytecode for Main method here.

51

00:03:42,510  -->  00:03:48,750
And this is the bytecode for the for the constructor for which is which is inserted automatically the

52

00:03:48,750  -->  00:03:50,370
default constructor.

53

00:03:50,640  -->  00:03:55,180
And we're going to analyze each of them separately the constructor and the two methods.

54

00:03:55,440  -->  00:03:58,450
And then look at the byte code generated by them.

55

00:03:58,520  -->  00:04:00,290
And here is the constant pool.

56

00:04:00,450  -->  00:04:02,960
OK so this is the constant pool that's generated.

57

00:04:03,000  -->  00:04:06,220
It's this constant pool and all of this is there.

58

00:04:07,020  -->  00:04:10,490
And this was generated because of the hyphen v option.

59

00:04:10,700  -->  00:04:11,310
OK.

60

00:04:11,340  -->  00:04:14,910
And that is summertime information too and that's about it.

61

00:04:14,910  -->  00:04:19,870
So let's just go ahead and review each of the methods under constructor.

62

00:04:20,970  -->  00:04:26,430
Let's begin with looking at the bytecode generated for the constructor which was inserted automatically

63

00:04:26,430  -->  00:04:27,760
by the compiler.

64

00:04:28,200  -->  00:04:33,960
Now if you recall compiler when it auto inserts of default constructor it also ought to insert a statement

65

00:04:34,080  -->  00:04:38,330
for invoking the superclasses default constructor.

66

00:04:38,340  -->  00:04:41,820
And we know it's due to the constructor chaining process.

67

00:04:41,820  -->  00:04:45,560
The first two byte code instructions that you see here correspond to that statement.

68

00:04:45,780  -->  00:04:53,050
And let's see what they signify the first instruction here is in order underscores zero earlier in the

69

00:04:53,040  -->  00:04:59,160
bit I load instruction the prefix in this gives indicates an object reference.

70

00:04:59,550  -->  00:05:05,020
Well in the case of I load the prefix i indicates an in data type.

71

00:05:05,280  -->  00:05:09,000
Other than the small difference the operation performed is identical.

72

00:05:09,000  -->  00:05:14,580
That is it tigs the element at the specified index in the local variables array and pushes it onto the

73

00:05:14,580  -->  00:05:18,890
top of the upper and stock index because the index is zero.

74

00:05:20,070  -->  00:05:27,380
Not index zero we have this reference and that's because Kunstler is like an instance method unreleased

75

00:05:27,440  -->  00:05:32,740
because that for instance Medders the zeroth element in the local variables will be a reference to the

76

00:05:32,740  -->  00:05:36,760
current object that is this reference.

77

00:05:36,750  -->  00:05:43,030
The reason why we have this reference is because it allows the code in the method or the constructor

78

00:05:43,120  -->  00:05:45,790
to access any instance variables.

79

00:05:45,790  -->  00:05:52,270
Similarly if the current method or constructor is invoking another method or constructor in the same

80

00:05:52,260  -->  00:05:58,830
class or in a superclass then the this reference will be set in the local variables array corresponding

81

00:05:58,840  -->  00:06:07,210
to that method or constructor next instruction is an expression and it has one operand which is hash

82

00:06:07,210  -->  00:06:14,110
one getting a constructor in the superclass which is the object us apart from constructor.

83

00:06:14,230  -->  00:06:21,010
Invoke special instruction will also be generated when we are in working either a private method or

84

00:06:21,000  -->  00:06:25,650
when we are in Woking as superclass method we are the supercooled.

85

00:06:25,690  -->  00:06:32,170
So you can try that out just are a private matter and then and look at the byte code and you should

86

00:06:32,170  -->  00:06:35,640
be able to see and invoke special instruction.

87

00:06:35,670  -->  00:06:41,920
Now here we are referring the constructor as instance initialization method and that's because of JVM

88

00:06:41,920  -->  00:06:43,580
to do it.

89

00:06:43,770  -->  00:06:49,980
In fact what we are seeing here in this particular snapshot is an instance initialization method and

90

00:06:49,990  -->  00:06:53,710
such a method is inserted for each constructor in that class.

91

00:06:53,880  -->  00:07:00,190
But in addition to constructor called this instance initialization method will also initialize all the

92

00:07:00,190  -->  00:07:06,550
instance variables which in the source code might have been initialized outside of the constructor.

93

00:07:06,550  -->  00:07:09,320
Let me actually show that to you in the code.

94

00:07:10,440  -->  00:07:15,060
So let me go ahead and I had an instance variable here.

95

00:07:15,100  -->  00:07:19,780
Should I use it to 3 so it's initialized outside the constructor.

96

00:07:19,770  -->  00:07:21,350
In fact there is no constructor here.

97

00:07:21,510  -->  00:07:28,950
So let's just go ahead and compile this and then do a java command.

98

00:07:29,380  -->  00:07:32,980
Now let's look at the construct of code.

99

00:07:35,050  -->  00:07:37,530
As you can see here in the constructor called.

100

00:07:37,750  -->  00:07:42,820
So we have these three bytecode instructions in order underscore zero icons to underscore three and

101

00:07:42,880  -->  00:07:43,970
put free.

102

00:07:44,350  -->  00:07:49,370
So this is the code that is initializing the instance variable.

103

00:07:49,940  -->  00:07:50,940
So that's the thing.

104

00:07:50,950  -->  00:07:56,280
So in addition to the constructor code itself which is in this case in working the superclass constructor

105

00:07:56,950  -->  00:08:00,250
it also initializes the instance variables.

106

00:08:00,500  -->  00:08:08,290
How in this instance initialization method is also referenced using a special name called in it which

107

00:08:08,290  -->  00:08:12,400
you can see here in the common the name here in the signature.

108

00:08:12,400  -->  00:08:17,520
It still has the class name but in the constant bool it really did it for instance in it and we will

109

00:08:17,520  -->  00:08:19,020
see that in a moment.

110

00:08:19,680  -->  00:08:25,870
No come into the operation hash run it is simply an offset into the runtime constant pull of the current

111

00:08:25,870  -->  00:08:27,160
class.

112

00:08:27,190  -->  00:08:33,870
So let's look at the relevant section of the constant pull period is the constant Paulas sequential

113

00:08:33,900  -->  00:08:36,790
number but to highlight only the relevant part.

114

00:08:37,090  -->  00:08:43,360
I extracted only the relevant lines from the constant pull index one is basically a symbolic reference

115

00:08:43,360  -->  00:08:44,300
to him either.

116

00:08:44,500  -->  00:08:51,010
And in this case it's a constructor index one is referencing two other indices mind and pointy and nicks

117

00:08:51,000  -->  00:08:57,330
nine is referencing in index 28 which is a symbolic reference to the object us.

118

00:08:57,340  -->  00:09:00,020
Similarly in next one p is intended for rinsing.

119

00:09:00,050  -->  00:09:07,520
And this has been an 11 word 10 gives the method name which as mentioned earlier is especially in that

120

00:09:08,740  -->  00:09:14,180
index Levan holds information about what is called does matter descriptor which includes the matter

121

00:09:14,230  -->  00:09:16,910
parameters under it and type.

122

00:09:17,620  -->  00:09:19,370
In this case there are no parameters.

123

00:09:19,380  -->  00:09:25,650
We only have an empty promises when the return type is void which is indicated by the letter B.

124

00:09:26,640  -->  00:09:27,700
Know at runtime.

125

00:09:27,750  -->  00:09:33,600
When GBM and contest this in Rook's special instruction it performs a few actions.

126

00:09:33,700  -->  00:09:39,120
First it performs method resolution which in this case is a resolution of the instance initialization

127

00:09:39,120  -->  00:09:40,560
method.

128

00:09:40,680  -->  00:09:46,580
We know that this would entail replacing symbolic reference with direct reference.

129

00:09:47,190  -->  00:09:53,430
Next JVM creates a new stack frame for the instance initialization method and pushes it onto the stack

130

00:09:53,550  -->  00:09:55,530
.

131

00:09:56,060  -->  00:10:02,920
Nexted pops this reference from the operand stack and started index 0 of the local variables array of

132

00:10:02,910  -->  00:10:04,610
the newly created stack.

133

00:10:05,110  -->  00:10:10,270
So the reason for having Elorde underscores zero was for storing this reference variable on the stack

134

00:10:10,720  -->  00:10:12,830
so that Iraq's Special can use it next.

135

00:10:13,950  -->  00:10:17,340
Know the instance initialization method is ready to be in work.

136

00:10:18,060  -->  00:10:23,470
And so the program counter will be set with the first instruction in the instance initialization method

137

00:10:23,560  -->  00:10:25,100
of the superclass.

138

00:10:25,420  -->  00:10:30,370
So the execution continues from the first instruction.

139

00:10:30,370  -->  00:10:31,940
So that was a constructor court.

140

00:10:32,010  -->  00:10:35,380
I need an artist to review the Invoke special instruction.

141

00:10:35,380  -->  00:10:38,360
Now let's look at the main method byte order.

142

00:10:38,500  -->  00:10:42,530
The first statement in the main method creates a new instance of Hello.

143

00:10:43,000  -->  00:10:47,610
Now this statement generates the first three bytecode instructions that you'll see here.

144

00:10:47,620  -->  00:10:49,930
So let's start to make sense of this mapping.

145

00:10:50,230  -->  00:10:56,290
The first bytecode instruction which includes a opcode new creates an instance of hello on pushes the

146

00:10:56,380  -->  00:10:59,100
object reference onto the operand stack.

147

00:10:59,770  -->  00:11:06,450
So at this point only the object is created but for it to be fully formed we need to also in the constructor

148

00:11:06,450  -->  00:11:06,930
code.

149

00:11:07,760  -->  00:11:13,580
For that we know that we need an in special instruction but that's the third instruction.

150

00:11:13,870  -->  00:11:16,120
And there is a second instruction.

151

00:11:16,120  -->  00:11:22,030
The second instruction is doop and it basically makes a copy of the item which is on the top of the

152

00:11:22,030  -->  00:11:26,420
operand stack and also stores it on the top of the opening stack.

153

00:11:26,420  -->  00:11:32,680
Now we need to make this copy as one of the things in walks Bishan does is to pop the top element from

154

00:11:32,680  -->  00:11:39,010
the operand stack and store it as the zero element and the local variables array off the new frame that

155

00:11:39,010  -->  00:11:40,380
it is going to create.

156

00:11:41,020  -->  00:11:46,660
But if we don't have the loop instruction then invoke special would Bob the only object reference that

157

00:11:46,660  -->  00:11:53,050
we have and with that we will not have a way to end with the string method which is the second statement

158

00:11:53,050  -->  00:11:54,380
of the main method.

159

00:11:54,790  -->  00:11:57,970
So we do need the instruction.

160

00:11:57,970  -->  00:12:03,960
Next the following three bytecode instructions correspond to the second statement the instruction A-story

161

00:12:03,980  -->  00:12:08,700
must go to one Bob's the hallowed reference from the operand stack unstarted at.

162

00:12:08,730  -->  00:12:11,320
And next one in the local variables at it.

163

00:12:11,680  -->  00:12:18,310
But if you are storing it index one at index 0 we have the only method parameter off the main method

164

00:12:18,850  -->  00:12:20,810
which is a reference to the string theory.

165

00:12:21,380  -->  00:12:24,010
Next a lot underscore one does the exact opposite.

166

00:12:24,010  -->  00:12:30,160
That is it moves the element back to the stack from the local variables adding finally in-work which

167

00:12:30,160  -->  00:12:32,860
will BOP's the hallowed reference from the stack.

168

00:12:33,070  -->  00:12:36,190
And it also in wig's that boosting method.

169

00:12:36,460  -->  00:12:42,160
Know if you recall we discussed in work which will indeed did in the method by adding lesson which was

170

00:12:42,160  -->  00:12:45,380
covered in the inheritance and polymorphism chapter.

171

00:12:45,720  -->  00:12:51,580
That lesson we said that for instance methods met that signature binding happens at compile time itself

172

00:12:52,540  -->  00:12:56,890
but the method implementation binding happens only at runtime.

173

00:12:56,950  -->  00:13:02,390
That's because with instance methods we do not know which method to work until runtime.

174

00:13:02,410  -->  00:13:05,660
That is it is dependent on the object in context.

175

00:13:05,680  -->  00:13:11,830
For example here you can see that at compile time method signature is bonded to the string method in

176

00:13:11,830  -->  00:13:13,130
that object class.

177

00:13:13,750  -->  00:13:20,470
But at runtime the string method in the Hello class will be executed just like in the case of in Woakes

178

00:13:20,470  -->  00:13:21,060
mission.

179

00:13:21,160  -->  00:13:27,670
Let's also review the steps performed when in which what is encountered also autoloader the pop instruction

180

00:13:27,760  -->  00:13:32,310
which is the next one simply pops the top element on the stack.

181

00:13:32,470  -->  00:13:35,250
It has a value returned by the spring mother.

182

00:13:35,530  -->  00:13:41,260
Finally the return instruction at the end simply implies right as written.

183

00:13:41,260  -->  00:13:48,190
When JVM encounters in-work what will it Fussball force method resolution which in our case is the resolution

184

00:13:48,190  -->  00:13:51,180
of the string method and the object us.

185

00:13:51,460  -->  00:13:58,430
This could simply mean pointing to an index in the metric table of the object class and the element

186

00:13:58,420  -->  00:14:02,300
there would point to the actual string method code.

187

00:14:02,970  -->  00:14:08,130
But the method to be executed is dependent on the actual object for that runtime.

188

00:14:08,260  -->  00:14:13,250
We know that the operand stack has a reference to this actual object.

189

00:14:13,690  -->  00:14:16,180
So JVM performs a lookup operation here.

190

00:14:16,630  -->  00:14:22,210
It starts with the reference on the operand stack and follows it to the object on heap and then into

191

00:14:22,210  -->  00:14:23,110
its method table.

192

00:14:23,140  -->  00:14:30,730
In the metro area the actual implementation will be in the metal table at the next phone doing the matter

193

00:14:30,730  -->  00:14:32,510
resolution step.

194

00:14:32,740  -->  00:14:38,710
So the index number found during method resolution step then applies here in them at the table corresponding

195

00:14:38,710  -->  00:14:40,570
to that Holocaust.

196

00:14:40,600  -->  00:14:45,940
We discussed this when discussing method tables and we said that we are able to use the same index member

197

00:14:46,270  -->  00:14:52,870
as a reference type of the variable is a class not an interface does not that using Mathare table in

198

00:14:52,870  -->  00:14:59,280
such a way for a method implementation binding is entirely up to JVM implementation.

199

00:14:59,320  -->  00:15:02,280
Some implementations might do it in a different way too.

200

00:15:02,890  -->  00:15:05,870
At this point we know the method to be executor.

201

00:15:06,940  -->  00:15:13,450
So the next three steps are identical to what we saw in works Bishan that is create a new stack frame

202

00:15:13,450  -->  00:15:16,750
for boosting that and push it onto the stack.

203

00:15:16,820  -->  00:15:23,110
But this reference from operand stack unstarted that index zero of the local variables array of the

204

00:15:23,170  -->  00:15:30,490
new stack frame find a decent program counter to the first instruction of the new method.

205

00:15:30,490  -->  00:15:35,470
Now here is a last snapshot which corresponds to a boosting method heading through quota system not

206

00:15:35,470  -->  00:15:38,620
all that Prindle and segment which prints a string hello.

207

00:15:38,620  -->  00:15:44,440
It also returns a string literal Hello no in the expression system that called We know that system is

208

00:15:44,440  -->  00:15:48,660
a class an out is a static variable defined in that class.

209

00:15:48,940  -->  00:15:55,510
The type of code really obvious but in stream from the Java dot or package sprint and method is invoked

210

00:15:55,510  -->  00:15:57,510
on the reference variable.

211

00:15:58,030  -->  00:16:05,170
So we need to forestall the old reference variable in the opening stack and this is done by get static

212

00:16:05,170  -->  00:16:06,980
instruction.

213

00:16:07,210  -->  00:16:15,400
So it basically pushes the value of all credible onto the open and stack next instruction LTC gets the

214

00:16:15,400  -->  00:16:21,140
reference to the string literal Hello from the runtime constant pull on pushes it onto the open and

215

00:16:21,140  -->  00:16:22,880
stack.

216

00:16:23,590  -->  00:16:24,970
Finally invoke what you want.

217

00:16:24,980  -->  00:16:28,290
BOP's both the string literal hello and the reference.

218

00:16:28,440  -->  00:16:30,500
And in walks the print method.

219

00:16:30,710  -->  00:16:34,050
Then the string literal hello as the argument.

220

00:16:34,830  -->  00:16:42,160
No the last two instructions correspond to retaining the string Hello Azmat that's output under instruction

221

00:16:42,170  -->  00:16:42,220
.

222

00:16:42,280  -->  00:16:47,080
Arrogance simply implies that we are returning an object reference.

223

00:16:47,110  -->  00:16:53,980
There are other variations we're primitive types like I've written for returning an end date type.

224

00:16:54,100  -->  00:16:55,430
So that's about it.

225

00:16:55,430  -->  00:17:01,270
They look at both in word spatial and in word what you're willing to put in was started in detail and

226

00:17:01,270  -->  00:17:02,520
method by adding lesson.

227

00:17:02,740  -->  00:17:05,520
And it is related to in working static methods.

228

00:17:05,710  -->  00:17:12,370
You can review that read you again if needed another instruction you know as in rock interface in our

229

00:17:12,370  -->  00:17:18,630
program the reference type is a class object and the actual type of the object was hello.

230

00:17:19,030  -->  00:17:24,610
But if the reference type was an interface then it would have generated and invoke interface instruction

231

00:17:24,620  -->  00:17:25,050
.

232

00:17:25,630  -->  00:17:32,950
So you can try it out by making the Hello class implement an interface Resorcin section includes a pointer

233

00:17:32,950  -->  00:17:40,390
to the JVM specification page that includes detail information about all the bytecode instructions.

234

00:17:40,390  -->  00:17:45,730
So if you want to get a more in-depth understanding of any of the instructions that recolored or if

235

00:17:45,730  -->  00:17:50,850
you want to learn about any new instruction then you can refer to this page.

236

00:17:51,010  -->  00:17:52,450
So that's about it.

237

00:17:52,450  -->  00:17:56,620
Thanks and I hope you'll enjoy learning about the bytecode instructions.
