如何在java字节码中引用“this”对象?

时间:2022-06-18 13:54:18

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.

我正在用Java字节码创建一个类。我需要知道如何在这个对象中引用字段。首先,我需要知道如何引用“this”对象,就好像我正在访问它一样。从类TestClass var1。我知道如何访问其他对象中的字段,但不知道如何从我正在执行的对象中访问。

1 个解决方案

#1


5  

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.

这个指针隐含在每个方法调用中,作为隐藏的第一个参数。在所有非静态方法中,您可以使用aload_0将其推到堆栈上。

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

更多细节,或者正如Holger指出的,在JVM规范本身中。

#1


5  

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.

这个指针隐含在每个方法调用中,作为隐藏的第一个参数。在所有非静态方法中,您可以使用aload_0将其推到堆栈上。

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

更多细节,或者正如Holger指出的,在JVM规范本身中。