You are on page 1of 6

28 / 43

Virtual Machine: platform independent

A platform independent
Instruction Set is needed.

29 / 43
Java Bytecode: A platform independent Instruction Set

• Instruction Set:
Arithmetic,
Load and store,
Type conversion
Object creation and manipulation
Operand stack manipulation
Control transfer
Method invocation and return

• Arithmetic Instruction:
Operate on the values from the stack Who executes Java Bytecode?
Push the result back onto the stack
Instructions for int, long, float and double
No direct support for byte, short or char types
Handled by int operations and type conversion

30 / 43
• Java class file starts with a header,
Java Class File Format
containing a "magic number" (0xCAFEBABE)
and the version number.

• The constant pool is the text segment


of an executable program,
occupying ~60% of class file.

• The access rights of the class


are encoded by a bit mask.

• A list of interfaces
implemented by the class.

• Lists containing the class’


fields and methods,
occupying ~12% of class file.

• The user-defined class attributes,


e.g. the name of the source file.

31 / 43
java -classpath ${java_home}/rt.jar myapp

• Load the code from disk to memory.


• Resolve the related code.
• Verify their correctness.

32 / 43
• Loading:
Finding and importing the binary data for a type.

• Linking:
Performing verification, preparation,
and (optionally) resolution.
• Linking (Verification):
Ensuring the correctness of the imported type.
• Linking (Preparation):
Allocating memory for class variables,
and initializing the memory to default values.
• Linking (Resolution):
Transforming symbolic references
from the type into direct references.

• Initialization:
Invoking Java code that initializes class variables Java ClassLoader
to their proper starting values.
33 / 43

You might also like