Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction is one byte in length (hence the name), thus the number of bytecodes is limited to no more than 256. Not all 256 possible bytecode values are used, in fact Sun Microsystems, the original creators of the Java programming language, the Java virtual machine and other components of the Java Runtime Environment, have set aside a number of values to be permanently unimplemented. The bytecodes are given below.
A Java programmer does not need to be aware of or understand Java bytecode at all. However, as suggested in the IBM developerWorks journal, "Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the C or C++ programmer."[1]
It is possible to write Java bytecode in hand, however this method is never used in real life because nowadays the compilers are able to compile well performing code and no person is able to comprehend a piece of Java bytecode of considerable size. Originally only one compiler existed, the javac compiler from Sun Microsystems, which compiles Java source code to Java bytecode. But because all the specifications for Java bytecode are available other parties have supplied compilers that produce Java bytecode. E.g.:
- Jython, compiles from Python to Java bytecode
- JRuby, compiles from Ruby to Java bytecode
- Jikes, compiles from the Java programming language to Java bytecode
- Espresso, compiles from the Java programming language to Java bytecode, only Java 1.0
- Gnu Java Compiler, GCJ, compiles from the Java programming language to Java bytecode, is also able to compile to native machine code.
- Groovy programming language, A scripting language based on java
If executing Java bytecode in a Java virtual machine is not desirable, a developer can also compile Java source code or Java bytecode directly to native machine code with tools such as the GNU Compiler for Java.
The Java bytecodes
Please see Sun's Java Virtual Machine Specification for more detailed descriptions (link at bottom of page)
Mnemonic | Description | |
aaload | loads onto the stack a reference to an array | |
aastore | stores into a reference to an array | |
aconst_null | pushes a null reference onto the stack | |
aload | loads a reference onto the stack from a local variable | |
aload_0 | loads a reference from local variable 0 | |
aload_1 | loads a reference from local variable 1 | |
aload_2 | loads a reference from local variable 2 | |
aload_3 | loads a reference from local variable 3 | |
anewarray | creates a new array of references | |
areturn | returns a reference from a method | |
arraylength | gets the length of an array | |
astore | stores a reference into a local variable | |
astore_0 | stores a reference into local variable 0 | |
astore_1 | stores a reference into local variable 1 | |
astore_2 | stores a reference into local variable 2 | |
astore_3 | stores a reference into local variable 3 | |
athrow | throws an error or exception | |
baload | loads a byte or boolean value from an array | |
bastore | stores a byte or boolean value into an array | |
bipush | pushes a byte onto the stack | |
caload | loads a char from an array | |
castore | stores a char into an array | |
checkcast | checks whether an object is of a certain type | |
d2f | converts a double to a float | |
d2i | converts a double to an int | |
d2l | converts a double to a long | |
dadd | adds two doubles | |
daload | loads a double from an array | |
dastore | stores a double into an array | |
dcmpg | compares two doubles | |
dcmpl | compares two doubles | |
dconst_0 | pushes the constant 0.0 onto the stack | |
dconst_1 | pushes the constant 1.0 onto the stack | |
ddiv | divides two doubles | |
dload | loads a double from a local variable | |
dload_0 | loads a double from local variable 0 | |
dload_1 | loads a double from local variable 1 | |
dload_2 | loads a double from local variable 2 | |
dload_3 | loads a double from local variable 3 | |
dmul | multiplies two doubles | |
dneg | negates a double | |
drem | gets the remainder from a division between two doubles | |
dreturn | returns a double from a method | |
dstore | stores a double into a local variable | |
dstore_0 | stores a double into local variable 0 | |
dstore_1 | stores a double into local variable 1 | |
dstore_2 | stores a double into local variable 2 | |
dstore_3 | stores a double into local variable 3 | |
dsub | subtracts a double from another | |
dup | duplicates the value on top of the stack | |
dup_x1 | inserts a copy of the top value into the stack two values from the top | |
dup_x2 | inserts a copy of the top value into the stack two or three values from the top | |
dup2 | ||
dup2_x1 | ||
dup2_x2 | ||
f2d | converts a float to a double | |
f2i | converts a float to an int | |
f2l | converts a float to a long | |
fadd | adds two floats | |
faload | loads a float from an array | |
fastore | stores a float in an array | |
fcmpg | compares two floats | |
fcmpl | compares two floats | |
fconst_0 | pushes 0.0f on the stack | |
fconst_1 | pushes 1.0f on the stack | |
fconst_2 | pushes 2.0f on the stack | |
fdiv | divides two floats | |
fload | loads a float from a local value | |
fload_0 | loads a float from local variable 0 | |
fload_1 | loads a float from local variable 1 | |
fload_2 | loads a float from local variable 2 | |
fload_3 | loads a float from local variable 3 | |
fmul | multiplies two floats | |
fneg | negates a float | |
frem | gets the remainder from a division between two floats | |
freturn | returns a float | |
fstore | stores a float into a local variable | |
fstore_0 | stores a float into local variable 0 | |
fstore_1 | stores a float into local variable 1 | |
fstore_2 | stores a float into local variable 2 | |
fstore_3 | stores a float into local variable 3 | |
fsub | subtracts two floats | |
getfield | gets a field of an object | |
getstatic | gets a static field of a class | |
goto | goes to another instruction | |
goto_w | goes to another instruction | |
i2b | converts an int into a byte | |
i2c | converts an int into a character | |
i2d | converts an int into a double | |
i2f | converts an int into a float | |
i2l | converts an int into a long | |
i2s | converts an int into a short | |
iadd | adds two ints together | |
iaload | loads an int from an array | |
iand | performs a logical and on two integers | |
iastore | stores an int into an array | |
iconst_m1 | loads the int value -1 onto the stack | |
iconst_0 | loads the int value 0 onto the stack | |
iconst_1 | loads the int value 1 onto the stack | |
iconst_2 | loads the int value 2 onto the stack | |
iconst_3 | loads the int value 3 onto the stack | |
iconst_4 | loads the int value 4 onto the stack | |
iconst_5 | loads the int value 5 onto the stack | |
idiv | divides two integers | |
if_acmpeq | branch if reference comparision succeeds | |
if_acmpne | branch if int comparison succeeds | |
if_icmpeq | branch if int is value of comparator | |
if_icmpne | branch if int is not value of comparator | |
if_icmplt | branch if int is less than value of comparator | |
if_icmpge | branch if int is greater than or equal to value of comparator | |
if_icmpgt | branch if int is greater than value of comparator | |
if_icmple | branch if int is less than or equal to value of comparator | |
ifeq | branch if int is 0 | |
ifne | branch if int is not 0 | |
iflt | branch if int is less than 0 | |
ifge | branch if int is greater than or equal to 0 | |
ifgt | branch if int is greater than 0 | |
ifle | branch if int is less than or equal 0 | |
ifnonnull | branch if reference is not null 0 | |
ifnull | branch if reference is null 0 | |
iinc | increment local variable by constant | |
iload | loads an int from a variable | |
iload_0 | loads an int from variable 0 | |
iload_1 | loads an int from variable 1 | |
iload_2 | loads an int from variable 2 | |
iload_3 | loads an int from variable 3 | |
imul | multiply two integers | |
ineg | negate int | |
instanceof | determines if an object is of a given type | |
invokeinterface | invokes an interface | |
invokespecial | invoke instance method | |
invokestatic | invoke a static method | |
invokevirtual | invoke virtual method | |
ior | logical int or | |
irem | logical int remainder | |
ireturn | returns an integer from a method | |
ishl | int shift left | |
ishr | int shift right | |
istore | store int into variable | |
istore_0 | store int into variable 0 | |
istore_1 | store int into variable 1 | |
istore_2 | store int into variable 2 | |
istore_3 | store int into variable 3 | |
isub | int subtract | |
iushr | int shift right | |
ixor | int xor | |
jsr | ||
jsr_w | ||
l2d | ||
l2f | ||
l2i | ||
ladd | ||
laload | ||
land | ||
lastore | ||
lcmp | ||
lconst_0 | ||
lconst_1 | ||
ldc | ||
ldc_w | ||
ldc2_w | ||
ldiv | ||
lload | ||
lload_0 | ||
lload_1 | ||
lload_2 | ||
lload_3 | ||
lmul | ||
lneg | ||
lookupswitch | ||
lor | ||
lrem | ||
lreturn | ||
lshl | ||
lshr | ||
lstore | ||
lstore_0 | ||
lstore_1 | ||
lstore_2 | ||
lstore_3 | ||
lsub | ||
lushr | ||
lxor | ||
monitorenter | ||
monitorexit | ||
multianewarray | ||
new | ||
newarray | ||
nop | ||
pop | ||
pop2 | ||
putfield | ||
putstatic | ||
ret | ||
return | ||
saload | ||
sastore | ||
sipush | ||
swap | ||
tableswitch | ||
wide |
This list is incomplete.
See also
- ARM9E, a CPU family with direct Java bytecode execution ability
- Common Intermediate Language (CIL), a similar bytecode specification that runs on the CLR of the .NET Framework.