Archive for June, 2007

Eclipse on cacao/s390

June 27th, 2007 | Category: Cacao

Finally, eclipse is running on cacao/s390:

eclipse.png

eclipse_about.png

1 comment

Cacao internals

June 17th, 2007 | Category: Cacao

I’ll try to briefly explain what cacao does using the well known hello world program:

class xhello {
    public static void main(String[] args) {
        System.out.println("hello");
    }
}    

The main method is compiled the first time it is called (just-in-time). Cacao first transforms the corresponding bytecode into an intermediate representation very similar to java bytecode. This intermediate representation is processed in passes. One of the passes allocates stack slots to registers or memory locations:

The static member out of java.lang.System is placed on the top of
stack (mapped to r2).
        | 0:  GETSTATIC
              <field> java.lang.System.out Ljava/io/PrintStream;
              PUBLIC STATIC FINAL
              => Aa4( r2)
The constant "hello" is placed on the top of stack (mapped to r3).
        | 1:  ACONST
              0x0086b7f8 "hello"
              => Aa5( r3)
The virtual method java.io.PrintStream.println is called.
The object reference and the sole argument are poped from the stack
(mapped to r2 and r3).
        | 2:  INVOKEVIRTUAL
              Aa4( r2) Aa5( r3)
              java.io.PrintStream.println(Ljava/lang/String;)V
              PUBLIC
Return from function.
        | 3:  RETURN

In the final pass, machine code generation, the intermediate representation is transformed into machine executable code:

Prologue
        | ahi      %r13,-4092
Allocate stack frame
        | ahi      %r15,-16
Store return address
        | st       %r14,12(%r15)
Get java.lang.System.out into argument register #1
        | l        %r1,4052(%r13)
        | l        %r2,0(%r1)
Load "hello" into argument register #2
        | l        %r3,4048(%r13)
Load virtual function table pointer of java.lang.System.out
        | l        %r12,0(%r2)
Load method address from virtual function table
        | l        %r13,192(%r12)
Call method
        | basr     %r14,%r13
Restore procedure vector (literal pool pointer in s390 terminology)
        | basr     %r13,%r0
        | ahi      %r13,-4128
Load return address
        | l        %r14,12(%r15)
Remove stack frame
        | ahi      %r15,16
Return
        | br       %r14
NOP
        | bc       0,0

One interesting aspect of cacao is the way it checks for null pointers. In java, operations on objects have to check if the object reference is null. If so the runtime system has to throw a NullPointerException. A naive implementation of this requirement would do a null pointer check before each such operation. Cacao translates a GETFIELD operation into a simple load:

Load the member field mem of the instance (r11) of klass and place it on
top of stack (mapped to r3).
        | 4:  GETFIELD        La0(r11)  klass.mem I => Ai7( r3)
No null pointer check here
        | 0x773a2314:   58 30 b0 0c                      l    %r3,12(%r11)

If the object reference in %r11 is null a SIGSEGV is raised. The installed signal handler examines the machine code and registers that caused the signal. If they correspond to the usage of a null pointer, a NullPointerException is raised.

No comments

Swing apps on cacao/s390

June 12th, 2007 | Category: Cacao

Some screenshots of a simple swing application displaying system properties and the foxhunt game running on the s390 cacao port:

properties.png

foxhunt.png

No comments