Joseph Havens
Joseph Havens

Reputation: 25

How to reference "this" object in java bytecode

I am making a class in Java bytecode. I need to know how to reference fields in this object. First I need to know how to reference the "this" object as if I were accessing this.var1 from class TestClass. I know how to access fields in other objects, but not from the same object that I am executing from.

Upvotes: 2

Views: 421

Answers (1)

Adrian Petrescu
Adrian Petrescu

Reputation: 18019

The this pointer is implicit in every method call, as a hidden first parameter. In all non-static methods, you can push it onto the stack with aload_0.

More details here, or as Holger points out, in the JVM spec itself.

Upvotes: 5

Related Questions