Introduction to Assembler Tools Syntax
AsmTools introduce two formats of assembler syntax for the representation of class files: JASM and JCOD. While both formats represent a class file in it's entirety, each has strengths for representation of different facets of a class. This Chapter introduces the two formats.
A complete description of the JASM and JCOD formats can be found in Appendix A and Appendix B.
The Jasm format
The JASM format is well suited to represent semantics of byte-code instructions within the method of a class. The JASM format uses mnemonics descriptions for encoding instructions - the same mnemonic language described in Chapter 6 of the Java VM specification. The JASM format also uses a Java-like syntax for class/method/field descriptions, access_flag mask values (that are decoded into "public", "protected", etc modifiers), and indexes into the constant pool (that can optionally be replaced with the values).
For a complete description of the JASM format, see the JASM language description in Appendix A.
To illustrate the JASM format, consider a small, very familiar Java class, HelloWorld (HelloWorld.java):
Now let's consider the JASM encoding of this. First, you would have to compile this class into it's object form to generate the .class file:
When you open the JASM formatted disassembly (HelloWorld.jasm), you see the following:
In this listing, you can see how the syntax is a mixture of Java declarations (for describing member signatures), Strings (encoded in the format that constants are represented in the constant pool), and Java instruction mnemonics. This type of format lends itself well to create class files to test incorrect sequences of instructions.
The Jcod format
The JCOD format is well suited to represent the structure of a class file (more so than instruction sequences).
For a complete description of JCOD syntax, see Appendix B.
Let's reuse our HelloWorld example to generate a JCOD disassembly:
Again, you need to compile this class into it's object form to generate the .class file and disassemble the object:
When you open the JCOD formatted disassembly (HelloWorld.jcod), you see the following:
In this listing, you can see how the syntax more directly correlates to the structure of a class file, in the same order and manner which a class file is described in Chapter 4 of the VM specification. Instructions themselves are not decoded (as they are in the JASM format), and appear as raw byte strings. Also, notice how references to the constant pool are treated as indexes (instead of being encoded as strings). As well, the constant pool is layed-out in the beginning of the listing.