Why use aload_0 in Jasmin HelloWorld?
Question
There is the start of official Jasmin HelloWorld example.
.class public NoJad.j
.super java/lang/Object
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 2
...
Why there is aload_0
instruction? What does local var 0 consists?
Solution
It is calling a constructor of a base class (Object
in this case):
this.super();
In non-static methods local variable under index 0
is always this
reference so aload_0
pushes this
reference at the top of the reference stack. Then invokenonvirtual
calls designated method (Object/<init>()
) on an object at the top of the stack (this
).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow