1

00:00:01,140  -->  00:00:05,610
So let's go ahead and look at the contents of a stack frame.

2

00:00:05,730  -->  00:00:08,820
Here's an illustration of the stack frame of a method.

3

00:00:09,210  -->  00:00:10,770
It contains three things.

4

00:00:10,770  -->  00:00:17,430
A local with Eberts array and Upperton stack and also a reference to that runtime constant of the class

5

00:00:17,490  -->  00:00:19,230
of the current method.

6

00:00:19,500  -->  00:00:26,640
Look already was array as you may guess is an array that stores all the local variables and method since

7

00:00:26,640  -->  00:00:28,830
Midhat parameters are also local variables.

8

00:00:28,830  -->  00:00:30,420
They also get stored here.

9

00:00:30,870  -->  00:00:33,680
In fact method barometers are stored before local variables.

10

00:00:33,750  -->  00:00:41,530
And the idea if this method is an instance method then the element in the zero next will be a reference

11

00:00:41,530  -->  00:00:41,890
.

12

00:00:42,150  -->  00:00:45,140
That is a reference to the current object on the heap.

13

00:00:45,600  -->  00:00:49,470
And this is needed for accessing any instance do from within them either.

14

00:00:49,980  -->  00:00:56,020
But if the method is a static method then the zero element would be the first method parameter as a

15

00:00:56,030  -->  00:01:00,290
method to some sort before local variables that are declared in the body.

16

00:01:00,430  -->  00:01:06,030
I pop from local variables data that I read will also include the return address which is nothing but

17

00:01:06,030  -->  00:01:10,570
the memory address of the next instruction and the calling method.

18

00:01:10,590  -->  00:01:16,870
So if this method completes its execution successfully without any errors then the program counter is

19

00:01:16,870  -->  00:01:19,320
updated with this return address.

20

00:01:19,320  -->  00:01:25,740
Then GBM execution engine will exit give the instruction at that memory address.

21

00:01:25,740  -->  00:01:27,530
Now it's coming to open in-stock.

22

00:01:27,600  -->  00:01:29,650
It is similar to general purpose registers.

23

00:01:29,700  -->  00:01:31,450
In native you.

24

00:01:32,070  -->  00:01:38,580
It is a central focus of JVM instruction set as values are generally pushed onto it before they are

25

00:01:38,580  -->  00:01:40,070
used.

26

00:01:40,210  -->  00:01:42,550
Note is that we are using the word push here.

27

00:01:42,930  -->  00:01:50,310
And that's because our patent stack is a stack most byte code instructions involved moving values to

28

00:01:50,310  -->  00:01:57,300
and fro between the local variables array and the output in stack are put in stack is also used to receive

29

00:01:57,390  -->  00:02:02,850
any values that are written by methods invoked from the current method.

30

00:02:03,810  -->  00:02:10,380
Here's an example to illustrate how operant stack is used on the left we have a simple code fragment

31

00:02:11,040  -->  00:02:18,420
which initializes variables Y and Z and then assigns some to the variable x on the right.

32

00:02:18,450  -->  00:02:21,530
We have the corresponding bytecode instructions.

33

00:02:21,630  -->  00:02:27,560
Let's not have you want this bytecode instructions mean the first two instructions are generated due

34

00:02:27,560  -->  00:02:31,120
to the first statement and y equals to 1.

35

00:02:31,350  -->  00:02:37,830
The first instruction I Konst underscore one simply pushes the constant value one on the top of the

36

00:02:37,830  -->  00:02:39,380
open in-stock.

37

00:02:39,660  -->  00:02:42,000
So the suffix one indicates a constant value.

38

00:02:42,000  -->  00:02:49,850
One second instruction I store underscore one BOP's the value on the top of the operand stuck here.

39

00:02:49,860  -->  00:02:54,810
I and I start indicates the value to be part of any data type.

40

00:02:54,960  -->  00:02:59,800
The bottom line is it's stored in the local variables array at the end it's position 1.

41

00:03:00,330  -->  00:03:05,140
So suffixed one indicates the next position and the local variables are in.

42

00:03:05,460  -->  00:03:11,160
Next the third and fourth instructions are similar to forestall instructions and the corresponding The

43

00:03:11,160  -->  00:03:14,620
second statement in is equal to three.

44

00:03:14,670  -->  00:03:20,910
So the third instruction I cost underscore three pushes constant three on the opera in-stock.

45

00:03:21,300  -->  00:03:27,180
When the fourth instruction I start underscore to boost the value on the top of the operand stack and

46

00:03:27,180  -->  00:03:31,340
store it in the local variables array at index position 2.

47

00:03:31,830  -->  00:03:34,380
At this point the all put in stack is empty.

48

00:03:34,410  -->  00:03:42,330
When the local variables array has values 1 and 3 No the third statement is X equals Y policy in order

49

00:03:42,330  -->  00:03:44,500
to perform this operation.

50

00:03:44,640  -->  00:03:49,840
Venia to transfer the values from the local variables are you on to the operand stack.

51

00:03:49,920  -->  00:03:52,480
So the next two instructions I Laura underscore one.

52

00:03:52,550  -->  00:03:54,170
And I Lord underskirt boo boo.

53

00:03:54,180  -->  00:04:00,570
Exactly that I should underscore one takes the value add and mix position 1 in the local variables array

54

00:04:01,220  -->  00:04:04,130
and pushes it onto the top of the operand stock.

55

00:04:04,530  -->  00:04:10,040
Similarly I Lorena's go too big to evaluate inexpertly shouldn't do in the local variables array and

56

00:04:10,050  -->  00:04:13,440
pushes it onto the top of the operand stack.

57

00:04:13,560  -->  00:04:21,240
Next the instruction I add Boster and values on top of the operand stack and adds them on pushes the

58

00:04:21,240  -->  00:04:24,640
result back onto the upper end stack.

59

00:04:24,660  -->  00:04:31,880
Once again I and I add refers to integrate R-Type that is a boo or loose on the operand stack or off

60

00:04:31,940  -->  00:04:36,660
and did type since the sum is assigned to the variable x.

61

00:04:36,870  -->  00:04:42,690
We have the instruction eyes toward underskirt 3 which we know pops up and right now on the top of the

62

00:04:42,690  -->  00:04:48,780
operand stack which basically is the sum unstarted at the end ex-politician 3 in the local variables

63

00:04:49,020  -->  00:04:49,470
.

64

00:04:50,070  -->  00:04:55,870
So store instruction is basically moving the value from the open and stack to the local variables array

65

00:04:55,920  -->  00:04:56,280
.

66

00:04:56,710  -->  00:05:00,150
Well the load instruction is doing the exact opposite.

67

00:05:00,870  -->  00:05:07,290
So with that the local variables are the highest of value corresponding to Y and position 1 the value

68

00:05:07,290  -->  00:05:09,060
of Z at index 2.

69

00:05:09,270  -->  00:05:16,220
And finally the value of x at index 3 no index zero in this guess is reserved for the method parameter

70

00:05:16,220  -->  00:05:16,960
.

71

00:05:17,040  -->  00:05:23,280
And that's because this particular code fragment was part of the main method which we know has only

72

00:05:23,280  -->  00:05:26,130
a single parameter which is a String Theory.

73

00:05:26,760  -->  00:05:32,430
So if the code was inside some other static method that did not have any method parameters then our

74

00:05:32,430  -->  00:05:40,230
variable values y z on X would have been stored in expositions 0 1 and 2 respectively.

75

00:05:40,830  -->  00:05:46,780
So as you can see GBM uses are put in stack just like the way a CPO uses registers.

76

00:05:47,160  -->  00:05:50,230
So everything is done via the open stack.

77

00:05:51,000  -->  00:05:52,470
That's about stack frame.

78

00:05:52,470  -->  00:05:58,690
And we could also review these few simple bytecode instructions next to a very simple example.

79

00:05:58,740  -->  00:06:02,340
We will also explore a few other important bytecode instructions
