PLP: Lecture 27
References
The Java Virtual Machine Reference
JVM
Easier to generate code for stack-based architecture vs. register-based
Class files
Defined as a stream of 8-bit bytes consisting of a single ClassFile structure.
ClassFile {
u4 magic; <- MAGIC := 0xCAFEBABE
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info
constant_pool[constant_pool_count-1] <- constants in the program
u2 access_flags;
u2 super_class;
...
u2 attributes_count;
attribute_info attributes[...]
}
Instructions
Loads and stores are between the stack and memory. Arithmetic operations get their operands from the stack, and leave their results on the stack! Instructions consist of a one-byte opcode specifying the operation to be performed, followed by operands supplying args or data used by the operation.
Variables in the JVM are typed. booleans are referred to as āZā. Strings are referred to as Ljava/lang/String;
, and so on.
Variables
static, non-static, and local variables
- static- instructions
getstatic
andputstatic
- non-static class members-
getfield
andputfield
- local variables- each method invocation causes the creation of a new frame. Frame contains operand stack where most of the work is done, array of local variables