There is currently no standard syntax for representing Java bytecodes in human-readable form. Sun's javap utility provides one representation, but its output is complicated by code offsets and constant pool index numbers. Thus, a simpler syntax of coding in Java bytecodes was created.
Note: This is documentation on the syntax only. To understand what the operands mean and their usage in programming, look at the Java Virtual Machine Specification. Most of the documentation is beta, meaning some of it is out-of-date. Look for the book by Tim Lindholm and Frank Yellin (to be available sometime this summer by Addison-Wesley) for the latest documentation. Excerpts are available at the above link.
Each Java Assembly file (usually suffixed by .jasm) should have the following
format:
The declaration of the class's fields should have the following format:
The declaration of the class's methods should have the following format:
An access specifer (used in field declarations
and method declarations) is one of the
following:
Code is one or more lines in one of the following formats:
An operation is in one of the following formats:
An exception table has the following format:
A line number table has the following format:
An local variable table has the following format:
A class name has the following format:
A field name has the following format:
A method name has the following format:
Constants are defined much like in Java:
A type has the following format:
aaload aastore aconst_null aload_0 aload_1 aload_2 aload_3 areturn
arraylength astore_0 astore_1 astore_2 astore_3 athrow baload bastore caload
castore d2f d2i d2l dadd daload dastore dcmpg dcmpl dconst_0 dconst_1
ddiv dload_0 dload_1 dload_2 dload_3 dmul dneg drem dreturn dstore_0
dstore_1 dstore_2 dstore_3 dsub dup dup_x1 dup_x2 dup2 dup2_x1 dup2_x2
f2d f2i f2l fadd faload fastore fcmpg fcmpl fconst_0 fconst_1 fdiv fload_0
fload_1 fload_2 fload_3 fmul fneg frem freturn fstore_0 fstore_1 fstore_2
fstore_3 fsub i2b i2c i2d i2f i2l i2s iadd iaload iand iastore iconst_0
iconst_1 iconst_2 iconst_3 iconst_4 iconst_5 iconst_m1 idiv iload_0 iload_1
iload_2 iload_3 imul ineg ior irem ireturn ishl ishr istore_0 istore_1
istore_2 istore_3 isub iushr ixor l2d l2f l2i ladd laload land lastore lcmp
lconst_0 lconst_1 ldiv lload_0 lload_1 lload_2 lload_3 lmul lneg lor lrem
lreturn lshl lshr lstore_0 lstore_1 lstore_2 lstore_3 lsub lushr lxor
monitorenter monitorexit nop pop pop2 return saload sastore swap wide
bipush ldc ldc_w ldc2_w sipush
getfield getstatic putfield putstatic
invokeinterface invokestatic invokenonvirtual invokevirtual
checkcast instanceof new
The Class File Format
[abstract] [final] [public] [interface] class classname
[extends superclassname]
[implements interfacename [interfacename [...] ] ]
{
[field_declarations]
[method_declarations]
[sourcefile sourcefilename]
}
Field Declarations
field [access_specifier] [static] [final] [transient] [volatile] fieldname [= constantvalue]
Method Declarations
method [access_specifier] [static] [abstract] [final] [native] [synchronized] returntype methodname ( [arg1 [, arg2 [, ...] ] ] )
[throws exceptionname [exceptionname [...] ] ]
max_stack value1
[max_locals value2]
{
[code]
[exceptiontable]
[linenumbertable]
[localvariabletable]
}
Access Specifier
private
private protected
protected
public
Code
[label] operation
or
[label] vartype localvarname
Operation
no_arg_operand
constant_arg_operand constantval
field_ref_operand fieldtype fieldname
method_ref_operand returntype methodname ( [arg1 [,arg2 [...]]] )
class_ref_operand classname
label_operand labelname
local_var_operand localvararg
anewarray anewarrayname
iinc localvararg incrementvalue
lookupswitch
default defaultlabel
{
value1 : gotolabel1
value2 : gotolabel2
...
}
multianewarray multianewarraytype dimensions
newarray newarraytype
tableswitch beginval to endval
default defaultlabel
{
gotolabel1
gotolabel2
...
}
Exception Table
exceptions
{
startpc1 endpc1 handlerpc1 catchtype1
startpc2 endpc2 handlerpc2 catchtype2
...
}
Line Number Table
linenumbertable
{
startpc1 linenumber1
startpc2 linenumber2
...
}
Local Variable Table
localvariabletable
{
startpc1 endpc1 type1 localvar1 slotnum1
startpc2 endpc2 type2 localvar2 slotnum2
...
}
Class Name
part1[.part2[.part3[...]]]
Field Name
[aclass].afield
Method Name
[aclass].amethod
Constant
Type
basetype[bracketpair[bracketpair[...]]]
No Arg Operand
The following are no arg operands:
Constant Arg Operand
The following are constant arg operands:
Field Ref Operand
The following are field ref operands:
Method Ref Operand
The following are method ref operands:
Class Ref Operand
The following are class ref operands: