BytecodePages
ByteCode is the instruction set for a VirtualMachine.
When a JavaSource file is compiled, the corresponding
MachineLanguage instructions necessary to carry out
the implementation of the class is created and
packed into a ClassFile along with other information,
such as constants, field/method meta data, etc.
When this class is distributed, the target computer
uses the ByteCode to understand how to animate the
objects of the class appropriately. There are many
ways to do this, including interpreting, just in-time
compiling, compiling, and many other variants.
In effect, Byte Code becomes a common way for a class
to describe the behavior of its implementation so
that it may be animated on a wide variety of computers
and platforms.
To do this, Byte Code needs to provide all of the
fundamental building blocks that describe behavior
of an object. The internal representation of classes within a particular implementation of a VirtualMachine may or may not be ByteCode. A VirtualMachine may for example choose to interpret directly the ByteCode. Alternatively it might convert the ByteCode into native machine instructions (e.g. by using JustInTime compilation techniques)
To better understand what these building blocks, here is a summary.
Java Byte Code Summary:
- Primative Stack Operations
- Pushing Constants Onto Stack
bipush, sipush, ldc, ldcw, ldc2w, aconstnull, iconstm1, iconst, lconst, fconst, dconst
- Minipulation
nop, pop, pop2, dup, dup2, dupx1, dup2x1, dupx2, dup2x2, swap
- Local Variables
- Pushing Local Variables Onto The Stack
iload, iload, lload, lload, fload, fload, dload, dload, aload, aload_
- Poping Stack Into Local Variables
istore, istore, lstore, lstore, fstore, fstore, dstore, dstore, astore, astore_
- Miscellaneous
iinc (increment local variable directly)
wide (next instruction used 16 bit index instead of 8 bits)
- Arrays
- Creating
newarray, anewarray, multianewarray
- Pusing Array Onto The Stack
iaload, laload, faload, daload, aaload, baload, caload, saload
- Poping Stack Into Array
iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore
- Miscellaneous
arrraylength (pust array length on stack)
- Objects
- Creating
new,invokespecial (for calling constructor)
- Field Instructions
putfield (pop stack into object field)
getfield (push object field onto stack)
putstatic (pop stack into class static field)
getstatic (push class static field onto stack)
- Miscellaneous
checkcast (raises exception is cast invalid)
instanceof (pushes true or false on stack)
- Arithmetic Stack Operations
All of these operations just do stuff to current stack like an HP calculator.
- Flow Control: Branches and Subroutines
These operations (jmp, goto, etc.) control flow within a method. There can be labled subrountines inside a method. These are used to simulate if/then, for/next, while, case/else structual programming constructs.
- Object Methods
- Invocation
invokevirtual ( call instance method )
invokespecial ( initilizer, private methods, superclasses, etc.)
invokestatic ( call class method )
invokeinterface ( invoke methods in an interface)
- Return
ireturn, lreturn, freturn, dreturn, areturn, return
- Exceptions
- Threads
- Monitors
monitorenter, monitorexit
See Also: JavaVirtualMachineSpecification; The Java Soft VM Specification
Content of these pages are owned and copyrighted by the poster.
|
Hosted by:
|
|