JVM Tutorials - Herong's Tutorial Examples - v5.14, by Herong Yang
AsmTools/JCOD Assembly File Format
This section provides a quick introduction on AsmTools/JCOD assembly file format.
The AsmTools/COD assembly language is not really a programming language. It is a specification of file format which can be used to encode data elements of a JVM bytecode file.
AsmTools/COD specifies the following data encoding rules:
1. Follow JVM Bytecode Class Structure - AsmTools/COD files follow the JVM bytecode class structure. The table bellow lists the data elements and their order:
Bytecode AsmTools/JCOD Description
------------ ------------- -------------------
ClassFile { class Foo { Begin of class
u4 0xCAFEBABE; 4-byte magic number
u2 0; minor version
u2 55; major version: JVM 11
u2 [?] constant pool count
constants {...} constant list
u2 0x0001; access flags: ACC_PUBLIC
u2 #?; this_class: cons ref #
u2 #?; super_class: cons ref #
u2 [?] interfaces count
interfaces {...} interfaces list
u2 [?] fields count
fields {...} fields list
u2 [?] methods count
methods {...} method list
u2 [?] attributes count
attributes {...} attribute list
} } End of class
2. Use Java Comment Syntax - Comments are coded in Java style: // ... or /* ... */.
Use Byte, Integer and String Literals - Values are coded as Java byte, int or String literals. For example:
0xCAFEBABE; // byte literal Utf8 "Hello World!"; // string literal Method #2 #3; // int literals
3. Use [] {...} for Lists Code lists in Java array literal style. The elements count will be calculated by the compiler. For example:
[] { // constant pool
; // #0: empty element
String #2; // #1: String constant ref
Utf8 "Hello World!"; // #2: String literal
}
[] {} // Interfaces: empty list
[] { // Methods: list of structures
{...}; // method 1
{...}; // method 2
...
{...}; // last method
}
4. Follow JVM Bytecode Method Structure - Code methods by following the JVM bytecode method structure. The table bellow lists the data elements and their order:
Bytecode AsmTools/JCOD Description
------------ ---------------- -------------------
{ { Begin of method
u2 0x0009; access flags ACC_PUBLIC | ACC_STATIC
#ref #24; method name
#ref #25; method descriptor
u2 [?] attributes count
attributes { Begin of attribute list
#23 Attr(#23) { Begin of "Code" attribute
u2 2; stack limit
u2 1; local variable limit
u2 Bytes[?] bytecode count
bytecodes {...} bytecode list
u2 [?] exceptions count
exceptions {...} exception list
u2 [?] sub-attributes count
attributes {...} sub-attribute list
} End of "Code" attribute
} End of
} End of method
5. Use Byte Literals for Bytecodes (JVM instructions) - Code JVM instructions as Java byte literals. For example:
Bytes[] {
0xB20007; // getstatic #7
0x120D; // ldc #13
0xB6000F; // invokevirtual #15
0xB1; // return
}
As you can see from these syntax rules, the AsmTools/JCOD specification actually offers you a class and method information structure and a JVM instruction container. All JVM instructions must be entered as a byte sequence of opcodes and parameters.
Maybe we can design an XML schema for the JVM bytecode file, and use an XML file to encode the JVM class structure. It might be easier to use than this AsmTools/JCOD format.
Table of Contents
JVM (Java Virtual Machine) Specification
Java HotSpot VM - JVM by Oracle/Sun
java.lang.Runtime Class - The JVM Instance
java.lang.System Class - The Operating System
ClassLoader Class - Class Loaders
Class Class - Class Reflections
JVM Stack, Frame and Stack Overflow
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
Micro Benchmark Runner and JVM Options
Micro Benchmark Tests on "int" Operations
Micro Benchmark Tests on "long" Operations
Micro Benchmark Tests in JIT Compilation Mode
Micro Benchmark Tests on "float" and "double" Operations
JRockit JVM 28.2.7 by Oracle Corporation
JVM Bytecode and Instruction Set
►JVM Assembler/Disassembler Tools
Compare HelloWorld.j with "javap" Output
JASM Example - Calculator.jasm
AsmTools/JASM Assembly Statements
AsmTools/JASM Example - Calculator.jasm
AsmTools/JASM Disassembler: "jdis"
►AsmTools/JCOD Assembly File Format
AsmTools/JCOD Example - HelloWorld.jcod
AsmTools/JCOD Disassembler: "jdec"