Skip to content
Advertisement

Java Object Method Stack Frame Parameters

So in java, say you have a non-static method ‘bar()’ in an class ‘Foo’.

class Foo
{
    private int m_answer;

    public Foo()
    {
        m_answer = -1;
    }

    public void bar(int newAnswer)
    {
        m_answer = newAnswer;
    }
}

Say then that you call this method like so:

Foo myFoo = new Foo();
myFoo.bar(42);

Now the stack frame for the call includes the integer parameter, as well as a ‘this’ parameter to be used as an internal reference to the object.

What other interesting parameters are copied to the new stack frame, in addition to ‘this’ and the method parameters?

.

Advertisement

Answer

Usually a pointer to the calling instruction, so that the VM (in this case, the CPU in native apps) will know where to set the instruction pointer (or PC – Program Counter) so the stack will be unfolded correctly

Advertisement