Search code examples
javajvmthisbytecodesuper

When local variable stack gets created?


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?


Solution

  • 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.