JVM:  Objects

Honors Computer Systems Organization (Prof. Grishman)

Additional notes on array operations

Passing Objects as Arguments

The type for an object is            Lclassname;

If the object contains public fields, these can be accessed by

getfield   class/field   type
(which expects the object reference on top of the stack, and replaces it by the value of the field) and set by
putfield   class/field   type
(which expects the object reference as the second element on the stack and the value to store on top of the stack, and removes both from the stack).

Constructors

When a new object is constructed (by new in Java), an instance initialization method for that class is invoked.  This method has the name <init> and does not return a value (its return type is void, V).
The object is passed as the first argument to the method (in local variable 0).

The instance initialization method should call the <init> method for its superclass, using the invokespecial operation, so a typical <init> would look like

.class public Blah
.super java/lang/Object
.method public <init>()V
   aload   0
   invokespecial   java/lang/Object/<init>()V
   return
.end method
If fields need to be initialized, this is done just before the return.

Non-static methods

When a non-static method is invoked, the object is passed as the first argument (in local variable 0) and the other arguments in local variables 1, 2, ... .