Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

ClassEncoder::ByteCode Class Reference

This class is used to handle and create java bytecode. More...

#include <bytecode.hpp>

Inheritance diagram for ClassEncoder::ByteCode:

Inheritance graph
[legend]
Collaboration diagram for ClassEncoder::ByteCode:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ByteCode (ConstantPool *pool)
 Constructor.

virtual ~ByteCode ()
 Destructor.

unsigned int maxStackSize () const
 Get the maximum stack size during execution.

unsigned int nextInstrAddr () const
 Get the address of the next instruction.

void write (std::ofstream &stream) const
 Write bytecode to stream.

pushtostack
Push constants onto the stack

unsigned int emit_iconst (int number)
 Push integer between 0 and 5 to the stack.

unsigned int emit_bipush (u1 num)
 Push an unsigned byte onto the stack.

unsigned int emit_sipush (u2 num)
 Push an unsigned two-byte value onto the stack.

unsigned int emit_ldc (u1 index)
 push single-word constant onto stack

unsigned int emit_ldc2 (u2 index)
 push single-word constant onto stack (wide index)

localtostack
Loading locals onto the stack

unsigned int emit_iload (u1 vindex)
 Load integer from local variable.

unsigned int emit_lload (u1 vindex)
 Load long integer from local variable.

unsigned int emit_fload (u1 vindex)
 Load single float from local variable.

unsigned int emit_dload (u1 vindex)
 Load double float from local variable.

unsigned int emit_aload (u1 vindex)
 Load object reference from local variable.

storetostack
Store stack values into locals.

unsigned int emit_istore (u1 vindex)
 Store integer into local variable.

unsigned int emit_lstore (u1 vindex)
 Store long integer into local variable.

unsigned int emit_fstore (u1 vindex)
 Store float into local variable.

unsigned int emit_dstore (u1 vindex)
 Store double float into local variable.

unsigned int emit_astore (u1 vindex)
 Store double float into local variable.

unsigned int emit_iinc (u1 vindex, u1 value)
 Increment local variable by constant.

arrayfunctions
Stack instructions

unsigned int emit_newarray (_basic_data_types type)
unsigned int emit_multianewarray (u2 index, u1 dimensions)
 Allocate new multi-dimensional array.

unsigned int emit_multianewarray (const std::string classType, u1 dimensions)
 Allocate new multi-dimensional array.

unsigned int emit_iastore ()
 Store into integer array.

unsigned int emit_lastore ()
 Store into long integer array.

unsigned int emit_fastore ()
 Store into single float array.

unsigned int emit_dastore ()
 Store into double float array.

unsigned int emit_aastore ()
 Store into object reference array.

unsigned int emit_bastore ()
 Store into signed byte array.

unsigned int emit_castore ()
 Store into character array.

unsigned int emit_sastore ()
 Store into short array.

unsigned int emit_iaload ()
 Load integer from array.

unsigned int emit_laload ()
 Load long integer from array.

unsigned int emit_faload ()
 Load single float from array.

unsigned int emit_daload ()
 Load double float from array.

unsigned int emit_aaload ()
 Load object reference from array.

unsigned int emit_baload ()
 Load signed byte from array.

unsigned int emit_caload ()
 Load character from array.

unsigned int emit_saload ()
 Load short from array.

stackinstructions
Stack instructions

unsigned int emit_pop ()
 Pop top stack word.

unsigned int emit_pop2 ()
 Pop top two stack word.

unsigned int emit_dup ()
 Duplicate top stack word.

unsigned int emit_dup2 ()
 Duplicate top two stack word.

unsigned int emit_dup_x1 ()
 Duplicate top stack word and put it two down.

unsigned int emit_dup_x2 ()
 Duplicate top stack word and put it three down.

unsigned int emit_swap ()
 Swap top two stack words.

arithmetic
Arithmetic instructions

unsigned int emit_iadd ()
 Integer add.

unsigned int emit_ladd ()
 Long integer add.

unsigned int emit_fadd ()
 Float add.

unsigned int emit_dadd ()
 Double float add.

unsigned int emit_isub ()
 Integer subtract.

unsigned int emit_lsub ()
 Long Integer subtract.

unsigned int emit_fsub ()
 Float subtract.

unsigned int emit_dsub ()
 Double Float subtract.

unsigned int emit_imul ()
 Integer multiplication.

unsigned int emit_lmul ()
 Long Integer multiplication.

unsigned int emit_fmul ()
 Float multiplication.

unsigned int emit_dmul ()
 Double Float multiplication.

unsigned int emit_idiv ()
 Integer division.

unsigned int emit_ldiv ()
 Long Integer division.

unsigned int emit_fdiv ()
 Float division.

unsigned int emit_ddiv ()
 Double Float division.

unsigned int emit_irem ()
 Integer remainder.

unsigned int emit_lrem ()
 Long Integer remainder.

unsigned int emit_frem ()
 Float remainder.

unsigned int emit_drem ()
 Double Float remainder.

unsigned int emit_ineg ()
 Integer negate.

unsigned int emit_lneg ()
 Long Integer negate.

unsigned int emit_fneg ()
 Float negate.

unsigned int emit_dneg ()
 Double Float negate.

logical
Transfer control in the program.

unsigned int emit_iand ()
 Integer logical and.

unsigned int emit_ior ()
 Integer logical or.

unsigned int emit_ixor ()
 Integer logical xor.

controltransfer
Transfer control in the program.

void patch (unsigned int instrAddr, u2 jump)
 Patch jump to jump to a new position.

unsigned int emit_ifeq (u2 jump)
 Branch if equal.

unsigned int emit_ifnull (u2 jump)
 Branch if null.

unsigned int emit_iflt (u2 jump)
 Branch if less than.

unsigned int emit_ifle (u2 jump)
 Branch if less or equal.

unsigned int emit_ifne (u2 jump)
 Branch if not equal.

unsigned int emit_ifnonnull (u2 jump)
 Branch if not null.

unsigned int emit_ifgt (u2 jump)
 Branch if greater than.

unsigned int emit_ifge (u2 jump)
 Branch if greater or equal.

unsigned int emit_if_icmpeq (u2 jump)
 Branch if integers equal.

unsigned int emit_if_icmpne (u2 jump)
 Branch if integers not equal.

unsigned int emit_if_icmplt (u2 jump)
 Branch if integer less than.

unsigned int emit_if_icmpgt (u2 jump)
 Branch if integer greater than.

unsigned int emit_if_icmple (u2 jump)
 Branch if integer less or equal.

unsigned int emit_if_icmpge (u2 jump)
 Branch if integer greater or equal.

unsigned int emit_goto (u2 jump)
 Branch.

unsigned int emit_jsr (u2 jump)
 Jump subroutine.

unsigned int emit_ret (u1 vindex)
 Return from subroutine.

manipulateobjectfields
Manipulate object fields

unsigned int emit_getstatic (u2 index)
 Get static field from class.

unsigned int emit_getstatic (const std::string &className, const std::string &fieldName, const std::string &fieldType)
 Get static field from class.

manipulateobjectfields
Manipulate object fields

unsigned int emit_invokevirtual (u2 index)
 Invoke instance method.

unsigned int emit_invokespecial (u2 index)
 Invoke instance method, dispatching based on compile-time type.

unsigned int emit_invokestatic (u2 index)
 Invoke a class (static) method.

unsigned int emit_invokeinterface (u2 index, u1 nargs)
 Invoke an interface method.

unsigned int emit_invokestatic (const std::string &classType, const std::string &function, const std::string &footprint)
 Invoke a class (static) method.

unsigned int emit_invokevirtual (const std::string &classType, const std::string &function, const std::string &footprint)
 Invoke instance method.

unsigned int emit_invokespecial (const std::string &object, const std::string &function, const std::string &footprint)
 Invoke instance method, dispatching based on compile-time type.

unsigned int emit_invokeinterface (const std::string &objectType, const std::string &function, const std::string &footprint, u1 nargs)
 Invoke interface method.

miscobjectfunc
Manipulate object fields

unsigned int emit_new (u2 index)
 Allocate an object on the heap.

unsigned int emit_new (const std::string &className)
 Allocate an object on the heap.

manipulateobjectfields
Manipulate object fields

unsigned int emit_ireturn ()
 Return integer from function.

unsigned int emit_lreturn ()
 Return long integer from function.

unsigned int emit_freturn ()
 Return float from function.

unsigned int emit_dreturn ()
 Return double float from function.

unsigned int emit_return ()
 Return from function.


Private Member Functions

unsigned int emit_arithmetic (_opcode code, unsigned int popVal=1)
 Internal arithmetic helper function.

unsigned int emit_transfer (_opcode code, u2 jump, unsigned int popVal=1)
 Internal control transfer helper function.

void push (int num=1)
 Internal push function to monitor run time stack size.

void pop (int num=1)
 Internal pop function to monitor run time stack size.


Private Attributes

unsigned int MaxStackSize
unsigned int StackSize
std::vector< u1 > Code
ConstantPoolConstantPoolEntries

Detailed Description

This class is used to handle and create java bytecode.

This is done through the emit_xxx... functions representing java assembly commands. The java assembly codes are not documented in detail, however detailed information about what they do can be found here: http://mrl.nyu.edu/~meyer/jvmref/ This class consists of quite a lot of duplicated or very similar code. This was a design decision to keep things simple. Smart and short functions would be error prone and hard to maintain.

Definition at line 30 of file bytecode.hpp.


Constructor & Destructor Documentation

ClassEncoder::ByteCode::ByteCode ConstantPool pool  ) 
 

Constructor.

Init of object.

Definition at line 34 of file bytecode.cpp.

ClassEncoder::ByteCode::~ByteCode  )  [virtual]
 

Destructor.

Emptry

Definition at line 45 of file bytecode.cpp.


Member Function Documentation

unsigned int ClassEncoder::ByteCode::emit_aload u1  vindex  ) 
 

Load object reference from local variable.

Parameters:
vindex The value of the local variable at vindex in the current Java frame is pushed onto the operand stack.
Returns:
The instruction position.

Definition at line 317 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_arithmetic _opcode  code,
unsigned int  popVal = 1
[private]
 

Internal arithmetic helper function.

Since all arithmetic instructions take no parameters this helper function avoids duplicating code.

Parameters:
code Opcode for the arithmetic function to perform.
popVal Number of items this function pops from the stack (in total)
Returns:
The instruction position.

Definition at line 793 of file bytecode.cpp.

References pop().

Referenced by emit_dadd(), emit_ddiv(), emit_dmul(), emit_dneg(), emit_drem(), emit_dsub(), emit_fadd(), emit_fdiv(), emit_fmul(), emit_fneg(), emit_frem(), emit_fsub(), emit_iadd(), emit_idiv(), emit_imul(), emit_ineg(), emit_irem(), emit_isub(), emit_ladd(), emit_ldiv(), emit_lmul(), emit_lneg(), emit_lrem(), and emit_lsub().

unsigned int ClassEncoder::ByteCode::emit_astore u1  vindex  ) 
 

Store double float into local variable.

Parameters:
vindex Top double float stack item is pushed to the double float variable at vindex.
Returns:
The instruction position.

Definition at line 476 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_bipush u1  num  ) 
 

Push an unsigned byte onto the stack.

Parameters:
num Number to push.
Returns:
The instruction position.

Definition at line 132 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_dadd  ) 
 

Double float add.

Returns:
The instruction position.

Definition at line 839 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_ddiv  ) 
 

Double Float division.

Returns:
The instruction position.

Definition at line 947 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_dload u1  vindex  ) 
 

Load double float from local variable.

Parameters:
vindex The value of the local variable at vindex in the current Java frame is pushed onto the operand stack.
Returns:
The instruction position.

Definition at line 287 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_dmul  ) 
 

Double Float multiplication.

Returns:
The instruction position.

Definition at line 911 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_dneg  ) 
 

Double Float negate.

Returns:
The instruction position.

Definition at line 1019 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_drem  ) 
 

Double Float remainder.

Returns:
The instruction position.

Definition at line 983 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_dreturn  ) 
 

Return double float from function.

Returns the top double float value on the stack.

Definition at line 1624 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_dstore u1  vindex  ) 
 

Store double float into local variable.

Parameters:
vindex Top double float stack item is pushed to the double float variable at vindex.
Returns:
The instruction position.

Definition at line 446 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_dsub  ) 
 

Double Float subtract.

Returns:
The instruction position.

Definition at line 875 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_dup  ) 
 

Duplicate top stack word.

Returns:
The instruction position.

Definition at line 727 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_dup2  ) 
 

Duplicate top two stack word.

Returns:
The instruction position.

Definition at line 739 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_dup_x1  ) 
 

Duplicate top stack word and put it two down.

Returns:
The instruction position.

Definition at line 751 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_dup_x2  ) 
 

Duplicate top stack word and put it three down.

Returns:
The instruction position.

Definition at line 763 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_fadd  ) 
 

Float add.

Returns:
The instruction position.

Definition at line 830 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_fdiv  ) 
 

Float division.

Returns:
The instruction position.

Definition at line 938 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_fload u1  vindex  ) 
 

Load single float from local variable.

Parameters:
vindex The value of the local variable at vindex in the current Java frame is pushed onto the operand stack.
Returns:
The instruction position.

Definition at line 257 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_fmul  ) 
 

Float multiplication.

Returns:
The instruction position.

Definition at line 902 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_fneg  ) 
 

Float negate.

Returns:
The instruction position.

Definition at line 1010 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_frem  ) 
 

Float remainder.

Returns:
The instruction position.

Definition at line 974 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_freturn  ) 
 

Return float from function.

Returns the top float value on the stack.

Definition at line 1613 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_fstore u1  vindex  ) 
 

Store float into local variable.

Parameters:
vindex Top float stack item is pushed to the float variable at vindex.
Returns:
The instruction position.

Definition at line 415 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_fsub  ) 
 

Float subtract.

Returns:
The instruction position.

Definition at line 866 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_getstatic const std::string &  className,
const std::string &  fieldName,
const std::string &  fieldType
 

Get static field from class.

Convenience function for getting static fields. This function creates the needed entries in the static pool for you.

Parameters:
className Name of class where the object can be found.
fieldName The name of the wanted field.
fieldType The type of the wanted object. Note that this must be a fully qualified java name.
Returns:
The instruction position.

Definition at line 1342 of file bytecode.cpp.

References ClassEncoder::ConstantPool::add(), and emit_getstatic().

unsigned int ClassEncoder::ByteCode::emit_getstatic u2  index  ) 
 

Get static field from class.

Parameters:
index Index to a valid entry in the constant pool. The constant pool item will be a field reference to a static field of a class.
Returns:
The instruction position.

Definition at line 1323 of file bytecode.cpp.

References push().

Referenced by emit_getstatic().

unsigned int ClassEncoder::ByteCode::emit_goto u2  jump  ) 
 

Branch.

Unconditional jump.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1274 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_iadd  ) 
 

Integer add.

Returns:
The instruction position.

Definition at line 812 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_iand  ) 
 

Integer logical and.

Performs logical and on the two top integer stack values. Result on stack top.

Returns:
The instruction position.

Definition at line 1037 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_iconst int  number  ) 
 

Push integer between 0 and 5 to the stack.

Parameters:
number Number to push.
Returns:
The instruction position.

Definition at line 95 of file bytecode.cpp.

References emit_sipush(), and push().

unsigned int ClassEncoder::ByteCode::emit_idiv  ) 
 

Integer division.

Returns:
The instruction position.

Definition at line 920 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_if_icmpeq u2  jump  ) 
 

Branch if integers equal.

Jumps if top two integers on stack are equal.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1208 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_if_icmpge u2  jump  ) 
 

Branch if integer greater or equal.

Jumps if first value on stack is greater than or equal to the top value.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1263 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_if_icmpgt u2  jump  ) 
 

Branch if integer greater than.

Jumps if first value on stack is greater than the top value.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1241 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_if_icmple u2  jump  ) 
 

Branch if integer less or equal.

Jumps if first value on stack is less than or equal to the top value.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1252 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_if_icmplt u2  jump  ) 
 

Branch if integer less than.

Jumps if first value on stack is less than the top value.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1230 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_if_icmpne u2  jump  ) 
 

Branch if integers not equal.

Jumps if top two integers on stack are not equal.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1219 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_ifeq u2  jump  ) 
 

Branch if equal.

Jumps if top integer on stack is zero.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1120 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_ifge u2  jump  ) 
 

Branch if greater or equal.

Jumps if top integer on stack is greater than or equal to zero.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1197 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_ifgt u2  jump  ) 
 

Branch if greater than.

Jumps if top integer on stack is greater than zero.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1186 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_ifle u2  jump  ) 
 

Branch if less or equal.

Jumps if top integer on stack is less or equal to zero.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1153 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_iflt u2  jump  ) 
 

Branch if less than.

Jumps if top integer on stack is less than zero.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1142 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_ifne u2  jump  ) 
 

Branch if not equal.

Jumps if top integer on stack is not equal to zero.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1164 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_ifnonnull u2  jump  ) 
 

Branch if not null.

Jumps if top reference on stack is not null.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1175 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_ifnull u2  jump  ) 
 

Branch if null.

Jumps if top reference on stack is null.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.

Definition at line 1131 of file bytecode.cpp.

References emit_transfer().

unsigned int ClassEncoder::ByteCode::emit_iinc u1  vindex,
u1  value
 

Increment local variable by constant.

Parameters:
vindex Index of local integer variable to increment.
value The local variable is incremented with this value.
Returns:
The instruction position.

Definition at line 507 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_iload u1  vindex  ) 
 

Load integer from local variable.

Parameters:
vindex The value of the local variable at vindex in the current Java frame is pushed onto the operand stack.
Returns:
The instruction position.

Definition at line 197 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_imul  ) 
 

Integer multiplication.

Returns:
The instruction position.

Definition at line 884 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_ineg  ) 
 

Integer negate.

Returns:
The instruction position.

Definition at line 992 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_invokeinterface const std::string &  objectType,
const std::string &  function,
const std::string &  footprint,
u1  nargs
 

Invoke interface method.

Convenience function for invoking interface methods This function creates the needed entries in the static pool for you.

Parameters:
objectType The class of the object to invoke the method on.
function The name of the function to invoke.
footprint The method signature of the class.
nargs The number of arguments you have pushed on the stack for this function counting the object reference as a parameter.
Returns:
The instruction position.

Definition at line 1529 of file bytecode.cpp.

References ClassEncoder::ConstantPool::add(), and emit_invokeinterface().

unsigned int ClassEncoder::ByteCode::emit_invokeinterface u2  index,
u1  nargs
 

Invoke an interface method.

The operand stack must contain the required number of arguments for the function.

Parameters:
index Index must point to valid entry in the constant pool.
nargs The number of arguments of the called function. The item at that index in the constant pool contains the complete method signature and class.

Definition at line 1422 of file bytecode.cpp.

Referenced by emit_invokeinterface().

unsigned int ClassEncoder::ByteCode::emit_invokespecial const std::string &  object,
const std::string &  function,
const std::string &  footprint
 

Invoke instance method, dispatching based on compile-time type.

Convenience function for invoking a special function. This function creates the needed entries in the static pool for you.

Parameters:
object The object type to invoke the function on.
function The name of the function to invoke.
footprint The method signature of the class.
Returns:
The instruction position.

Definition at line 1443 of file bytecode.cpp.

References ClassEncoder::ConstantPool::add(), and emit_invokespecial().

unsigned int ClassEncoder::ByteCode::emit_invokespecial u2  index  ) 
 

Invoke instance method, dispatching based on compile-time type.

The operand stack must contain a reference to an object and some number of arguments

Parameters:
index Index must point to a valid entry in the constant pool. The item at that index in the constant pool contains the complete method signature.
Returns:
The instruction position.

Definition at line 1389 of file bytecode.cpp.

Referenced by emit_invokespecial().

unsigned int ClassEncoder::ByteCode::emit_invokestatic const std::string &  classType,
const std::string &  function,
const std::string &  footprint
 

Invoke a class (static) method.

Convenience function for invoking a static function. This function creates the needed entries in the static pool for you.

Parameters:
classType The class of the static method.
function The name of the function to invoke.
footprint The method signature of the class.
Returns:
The instruction position.

Definition at line 1474 of file bytecode.cpp.

References ClassEncoder::ConstantPool::add(), and emit_invokestatic().

unsigned int ClassEncoder::ByteCode::emit_invokestatic u2  index  ) 
 

Invoke a class (static) method.

The operand stack must contain the required number of arguments for the function.

Parameters:
index Index must point to a valid entry in the constant pool. The item at that index in the constant pool contains the complete method signature and class.
Returns:
The instruction position.

Definition at line 1405 of file bytecode.cpp.

References push().

Referenced by emit_invokestatic().

unsigned int ClassEncoder::ByteCode::emit_invokevirtual const std::string &  classType,
const std::string &  function,
const std::string &  footprint
 

Invoke instance method.

Convenience function for invoking normal class function. This function creates the needed entries in the static pool for you.

Parameters:
classType The class of the object to invoke the method on.
function The name of the function to invoke.
footprint The method signature of the class.
Returns:
The instruction position.

Definition at line 1501 of file bytecode.cpp.

References ClassEncoder::ConstantPool::add(), and emit_invokevirtual().

unsigned int ClassEncoder::ByteCode::emit_invokevirtual u2  index  ) 
 

Invoke instance method.

This is the normal method dispatch in Java. The operand stack must contain a reference to an object and some number of arguments

Parameters:
index Index must point to a valid entry in the constant pool. The item at that index in the constant pool contains the complete method signature.
Returns:
The instruction position.

Definition at line 1373 of file bytecode.cpp.

Referenced by emit_invokevirtual().

unsigned int ClassEncoder::ByteCode::emit_ior  ) 
 

Integer logical or.

Performs logical or on the two top integer stack values. Result on stack top.

Returns:
The instruction position.

Definition at line 1050 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_irem  ) 
 

Integer remainder.

Returns:
The instruction position.

Definition at line 956 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_ireturn  ) 
 

Return integer from function.

Returns the top integer value on the stack.

Definition at line 1591 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_istore u1  vindex  ) 
 

Store integer into local variable.

Parameters:
vindex Top integer stack item is pushed to the integer variable at vindex.
Returns:
The instruction position.

Definition at line 355 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_isub  ) 
 

Integer subtract.

Returns:
The instruction position.

Definition at line 848 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_ixor  ) 
 

Integer logical xor.

Performs logical xor on the two top integer stack values. Result on stack top.

Returns:
The instruction position.

Definition at line 1063 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_jsr u2  jump  ) 
 

Jump subroutine.

Pushes ret value to stack and jumps.

Parameters:
jump Position to resume execution after jump.
Returns:
The instruction position.
See also:
emit_ret

Definition at line 1286 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_ladd  ) 
 

Long integer add.

Returns:
The instruction position.

Definition at line 821 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_ldc u1  index  ) 
 

push single-word constant onto stack

Parameters:
index One byte index in the constant pool of the entry to be pushed.
Returns:
The instruction position.

Definition at line 161 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_ldc2 u2  index  ) 
 

push single-word constant onto stack (wide index)

Parameters:
index Two byte index in the constant pool of the entry to be pushed.
Returns:
The instruction position.

Definition at line 174 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_ldiv  ) 
 

Long Integer division.

Returns:
The instruction position.

Definition at line 929 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_lload u1  vindex  ) 
 

Load long integer from local variable.

Parameters:
vindex The value of the local variable at vindex in the current Java frame is pushed onto the operand stack.
Returns:
The instruction position.

Definition at line 227 of file bytecode.cpp.

References push().

unsigned int ClassEncoder::ByteCode::emit_lmul  ) 
 

Long Integer multiplication.

Returns:
The instruction position.

Definition at line 893 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_lneg  ) 
 

Long Integer negate.

Returns:
The instruction position.

Definition at line 1001 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_lrem  ) 
 

Long Integer remainder.

Returns:
The instruction position.

Definition at line 965 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_lreturn  ) 
 

Return long integer from function.

Returns the top long integer value on the stack.

Definition at line 1602 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_lstore u1  vindex  ) 
 

Store long integer into local variable.

Parameters:
vindex Top long integer stack item is pushed to the long integer variable at vindex.
Returns:
The instruction position.

Definition at line 385 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_lsub  ) 
 

Long Integer subtract.

Returns:
The instruction position.

Definition at line 857 of file bytecode.cpp.

References emit_arithmetic().

unsigned int ClassEncoder::ByteCode::emit_multianewarray const std::string  classType,
u1  dimensions
 

Allocate new multi-dimensional array.

Convenience function for getting static fields. This function creates the needed entries in the static pool for you.

Parameters:
 

Definition at line 556 of file bytecode.cpp.

References ClassEncoder::ConstantPool::add(), and emit_multianewarray().

unsigned int ClassEncoder::ByteCode::emit_multianewarray u2  index,
u1  dimensions
 

Allocate new multi-dimensional array.

the index is used to construct an index into the constant pool of the current class. The item at that index is resolved. The resulting entry must be an array class of one or more dimensions.

Parameters:
index Two byte index in the constant pool of the entry to be pushed.
dimensions the number of dimensions to create.
Returns:
The instruction position.

Definition at line 541 of file bytecode.cpp.

Referenced by emit_multianewarray().

unsigned int ClassEncoder::ByteCode::emit_new const std::string &  classType  ) 
 

Allocate an object on the heap.

Parameters:
classType The type of the object want to create. An index in the constant pool will be created for you.

Definition at line 1572 of file bytecode.cpp.

References ClassEncoder::ConstantPool::add(), and emit_new().

unsigned int ClassEncoder::ByteCode::emit_new u2  index  ) 
 

Allocate an object on the heap.

Parameters:
index Index to a class item in the constant pool. This item must be a class name that can be resolved to a class pointer. A new instance of that class is created and a reference to it pushed on the stack.

Definition at line 1558 of file bytecode.cpp.

References push().

Referenced by emit_new().

unsigned int ClassEncoder::ByteCode::emit_pop  ) 
 

Pop top stack word.

Returns:
The instruction position.

Definition at line 702 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_pop2  ) 
 

Pop top two stack word.

Returns:
The instruction position.

Definition at line 714 of file bytecode.cpp.

References pop().

unsigned int ClassEncoder::ByteCode::emit_ret u1  vindex  ) 
 

Return from subroutine.

Parameters:
vindex Local variable vindex in the current Java frame must contain a return address.
Returns:
The instruction position.
See also:
emit_jsr

Definition at line 1302 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_sipush u2  num  ) 
 

Push an unsigned two-byte value onto the stack.

Parameters:
num Number to push.
Returns:
The instruction position.

Definition at line 146 of file bytecode.cpp.

References push().

Referenced by emit_iconst().

unsigned int ClassEncoder::ByteCode::emit_swap  ) 
 

Swap top two stack words.

Returns:
The instruction position.

Definition at line 775 of file bytecode.cpp.

unsigned int ClassEncoder::ByteCode::emit_transfer _opcode  code,
u2  jump,
unsigned int  popVal = 1
[private]
 

Internal control transfer helper function.

Since all control instructions take the same parameters this helper function avoids duplicating code.

Parameters:
code Opcode for the control transfer function to perform.
jump Position in the bytecode to resume execution after jump.
popVal Number of items this function pops from the stack (in total)
Returns:
The instruction position.

Definition at line 1084 of file bytecode.cpp.

References pop().

Referenced by emit_goto(), emit_if_icmpeq(), emit_if_icmpge(), emit_if_icmpgt(), emit_if_icmple(), emit_if_icmplt(), emit_if_icmpne(), emit_ifeq(), emit_ifge(), emit_ifgt(), emit_ifle(), emit_iflt(), emit_ifne(), emit_ifnonnull(), and emit_ifnull().

unsigned int ClassEncoder::ByteCode::maxStackSize  )  const [inline]
 

Get the maximum stack size during execution.

Returns:
Maximum stack size during execution. Note that this value may be wrong if jumps are used in the code.

Definition at line 40 of file bytecode.hpp.

Referenced by ClassEncoder::code_attribute::write().

unsigned int ClassEncoder::ByteCode::nextInstrAddr  )  const [inline]
 

Get the address of the next instruction.

Returns:
Next instruction address.

Definition at line 45 of file bytecode.hpp.

Referenced by ClassEncoder::code_attribute::size(), and ClassEncoder::code_attribute::write().

void ClassEncoder::ByteCode::patch unsigned int  instrAddr,
u2  jump
 

Patch jump to jump to a new position.

Patches the given jump to jump to the new position given. This can be useful when the position to jump to is not known at the time the jump is created.

Parameters:
instrAddr The position of the jump instruction to patch.
jump The new position this jump should jump to.
Returns:
The instruction position.

Definition at line 1108 of file bytecode.cpp.

void ClassEncoder::ByteCode::pop int  num = 1  )  [private]
 

Internal pop function to monitor run time stack size.

This function must be called each time an emit function is called that pops something to the stack.

Parameters:
num The number of elements to pop (not bytes)

Definition at line 78 of file bytecode.cpp.

Referenced by emit_arithmetic(), emit_astore(), emit_dstore(), emit_fstore(), emit_iand(), emit_ior(), emit_istore(), emit_ixor(), emit_lstore(), emit_pop(), emit_pop2(), and emit_transfer().

void ClassEncoder::ByteCode::push int  num = 1  )  [private]
 

Internal push function to monitor run time stack size.

This function must be called each time an emit function is called that pushes something to the stack.

Parameters:
num The number of elements to push (not bytes)

Definition at line 66 of file bytecode.cpp.

Referenced by emit_aload(), emit_bipush(), emit_dload(), emit_dup(), emit_dup2(), emit_dup_x1(), emit_dup_x2(), emit_fload(), emit_getstatic(), emit_iconst(), emit_iload(), emit_invokestatic(), emit_jsr(), emit_lload(), emit_new(), and emit_sipush().

void ClassEncoder::ByteCode::write std::ofstream &  stream  )  const
 

Write bytecode to stream.

Parameters:
stream The class stream to write to.

Definition at line 53 of file bytecode.cpp.

References ClassEncoder::ClassWriterBase::writeu1().

Referenced by ClassEncoder::code_attribute::write().


The documentation for this class was generated from the following files:
Generated on Mon Dec 1 14:26:29 2003 for Ck by doxygen 1.3.3