Source code would be platform independent, but neither efficient nor compact; machine code would be efficient but not platform independent. So SUN defined a virtual machine, JVM. Java source code is translated to JVM code, which is then downloaded along with web pages. The web browser includes a JVM implementation, which either interprets the JVM or translates it into machine code on the fly (JIT: just-in-time compiler). Processor chips have also been developed which execute JVM code directly.
JVM is a stack machine; this makes it simple to generate JVM code, and makes the JVM code compact.
Jasmin is an assembler for JVM assembly language. The Jasmin home page contains extensive information about Jasmin and JVM.
D-Java is a disassembler, which takes a JVM machine language program (a .class file) and translates it into Jasmin assembly language.
(We will execute these using a DOS window; it is easier if you put all the bin directories on the DOS PATH.)
If we create a simple Java class (file mymath.java) with one
method, which adds two integers:
; Major: 45
; Minor: 3
.class public synchronized mymath
; >> METHOD 1 <<
.method public <init>()V
.limit stack 1
.limit locals 1
; >> METHOD 2 <<
.method public static sum(II)I ; takes two int args and returns an int result
.limit stack 2
.limit locals 2
iload_0 ; load integer arguments (passed as local
iload_1 ; variables 0 and 1) onto stack
iadd ; integer add, leaving result on stack
ireturn ; return integer on top of stack