Java bytecode

This is an old revision of this page, as edited by 130.88.193.161 (talk) at 15:27, 23 May 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 byte code 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.

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    
  Opcode (in hex)   
Description

aaload
32
loads onto the stack a reference to an array
aastore
53
stores into a reference to an array
aconst_null
01
pushes a null reference onto the stack
aload
19
loads a reference onto the stack from a local variable
aload_0
2a
loads a reference from local variable 0
aload_1
2b
loads a reference from local variable 1
aload_2
2c
loads a reference from local variable 2
aload_3
2d
loads a reference from local variable 3
anewarray
bd
creates a new array of references
areturn
b0
returns a reference from a method
arraylength
be
gets the length of an array
astore
3a
stores a reference into a local variable
astore_0
4b
stores a reference into local variable 0
astore_1
4c
stores a reference into local variable 1
astore_2
4d
stores a reference into local variable 2
astore_3
4e
stores a reference into local variable 3
athrow
bf
throws an error or exception

baload
33
loads a byte or boolean value from an array
bastore
54
stores a byte or boolean value into an array
bipush
10
pushes a byte onto the stack

caload
34
loads a char from an array
castore
55
stores a char into an array
checkcast
c0
checks whether an object is of a certain type

d2f
90
converts a double to a float
d2i
8e
converts a double to an int
d2l
8f
converts a double to a long
dadd
63
adds two doubles
daload
31
loads a double from an array
dastore
52
stores a double into an array
dcmpg
98
compares two doubles
dcmpl
97
compares two doubles
dconst_0
0e
pushes the constant 0.0 onto the stack
dconst_1
0f
pushes the constant 1.0 onto the stack
ddiv
6f
divides two doubles
dload
18
loads a double from a local variable
dload_0
26
loads a double from local variable 0
dload_1
27
loads a double from local variable 1
dload_2
28
loads a double from local variable 2
dload_3
29
loads a double from local variable 3
dmul
6b
multiplies two doubles
dneg
77
negates a double
drem
73
gets the remainder from a division between two doubles
dreturn
af
returns a double from a method
dstore
39
stores a double into a local variable
dstore_0
47
stores a double into local variable 0
dstore_1
48
stores a double into local variable 1
dstore_2
49
stores a double into local variable 2
dstore_3
4a
stores a double into local variable 3
dsub
67
subtracts a double from another
dup
59
duplicates the value on top of the stack
dup_x1
5a
inserts a copy of the top value into the stack two values from the top
dup_x2
5b
inserts a copy of the top value into the stack two or three values from the top
dup2
5c
dup2_x1
5d
dup2_x2
5e

f2d
8d
converts a float to a double
f2i
8b
converts a float to an int
f2l
8c
converts a float to a long
fadd
62
adds two floats
faload
30
loads a float from an array
fastore
51
stores a float in an array
fcmpg
96
compares two floats
fcmpl
95
compares two floats
fconst_0
0b
pushes 0.0f on the stack
fconst_1
0c
pushes 1.0f on the stack
fconst_2
0d
pushes 2.0f on the stack
fdiv
6e
divides two floats
fload
17
loads a float from a local value
fload_0
22
loads a float from local variable 0
fload_1
23
loads a float from local variable 1
fload_2
24
loads a float from local variable 2
fload_3
25
loads a float from local variable 3
fmul
6a
multiplies two floats
fneg
76
negates a float
frem
72
gets the remainder from a division between two floats
freturn
ae
returns a float
fstore
38
stores a float into a local variable
fstore_0
43
stores a float into local variable 0
fstore_1
44
stores a float into local variable 1
fstore_2
45
stores a float into local variable 2
fstore_3
46
stores a float into local variable 3
fsub
66
subtracts two floats

getfield
b4
gets a field of an object
getstatic
b2
gets a static field of a class
goto
a7
goes to another instruction
goto_w
c8
goes to another instruction

i2b
91
i2c
92
i2d
87
i2f
86
i2l
85
i2s
93
iadd
60
iaload
2e
iand
7e
iastore
4f
iconst_m1
02
iconst_0
03
iconst_1
04
iconst_2
05
iconst_3
06
iconst_4
07
iconst_5
08
idiv
6c
if_acmpeq
a5
if_acmpne
a6
if_icmpeq
9f
if_icmpne
a0
if_icmplt
a1
if_icmpge
a2
if_icmpgt
a3
if_icmple
a4
ifeq
99
ifne
9a
iflt
9b
ifge
9c
ifgt
9d
ifle
9e
ifnonnull
c7
ifnull
c6
iinc
84
iload
15
iload_0
1a
iload_1
1b
iload_2
1c
iload_3
1d
imul
68
ineg
74
instanceof
c1
invokeinterface
b9
invokespecial
b7
invokestatic
b8
invokevirtual
b6
ior
80
irem
70
ireturn
ac
returns an integer from a method
ishl
78
ishr
7a
istore
36
istore_0
3b
istore_1
3c
istore_2
3d
istore_3
3e
isub
64
iushr
7c
ixor
82

jsr
a8
jsr_w
c9

This list is incomplete.

See also