I am learning internals of jvm and i read this article. While reading i got one doubt i.e When local variable stack get created ? If local variable stack created at run time will this, super keywords point real objects Or if local variable stack is created at compile time, how this, super keywords internally works?
-
Local variable are virtually created when you virtually call a method. However it's all virtual which can mean the method and even the local variables might not exist after the code has been optimised, it's entirely notional. – Peter Lawrey Sep 11 '15 at 19:31
-
3@RealSkeptic `this` is always the 0-th variable on the stack in byte code. `super` on the other hand is just `this` which has been cast to use method of the parent class. – Peter Lawrey Sep 11 '15 at 19:32
1 Answers
When local variable stack get created ?
The javac
allocates local variables to a stack in byte code. This allocation is notional and the actual allocation in a real machine could be very different.
After the JIT
has optimised the code,the local variables and the method itself could be inlined in which case, nothing happens in an ideal situation.
If local variable stack created at run time will this, super keywords point real objects
There is no super
at runtime. There is only the current objects available such as the one which represents this
and the methods you can call on them. When you use super
you are referring to methods in the parent class rather than the current one.
Or if local variable stack is created at compile time, how this, super keywords internally works?
super
changes which methods the compiler chooses to call. Once this choice has been made, the distinction between super
and this
is discarded.

- 525,659
- 79
- 751
- 1,130