com.claritysys.jvm.builder
Class ByteArray

java.lang.Object
  extended by com.claritysys.jvm.builder.ByteArray
All Implemented Interfaces:
JVM

public final class ByteArray
extends java.lang.Object
implements JVM

ByteArray is like java.util.ArrayList, except that its contents are primitive bytes. Direct access this the byte[] is provided, as well as maintenance of the "program counter".


Field Summary
static boolean[] UNREACHABLES
          Opcodes that cause forced change of flow control, such as ATHROW.
 
Fields inherited from interface com.claritysys.jvm.classfile.JVM
AALOAD, AASTORE, ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, ACCESS_NAMES, ACONST_NULL, ALOAD, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ANEWARRAY, ANEWARRAY_QUICK, ARETURN, ARRAYLENGTH, ASTORE, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, ATTR_CODE, ATTR_CONSTANT_VALUE, ATTR_DEPRECATED, ATTR_EXCEPTIONS, ATTR_LINE_NUMBER_TABLE, ATTR_LOCAL_VARIABLE_TABLE, ATTR_SOURCE_FILE, ATTR_SYNTHETIC, BALOAD, BASTORE, BIPUSH, BREAKPOINT, CALOAD, CASTORE, CHECKCAST, CHECKCAST_QUICK, CONSTANT_Class, CONSTANT_Double, CONSTANT_Fieldref, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodref, CONSTANT_Long, CONSTANT_Methodref, CONSTANT_NameAndType, CONSTANT_NAMES, CONSTANT_String, CONSTANT_Utf8, CONSTRUCTOR_NAME, CONSUME_STACK, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSTORE, 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, FCONST_2, FDIV, FLOAD, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSTORE, FSTORE_0, FSTORE_1, FSTORE_2, FSTORE_3, FSUB, GETFIELD, GETFIELD_QUICK, GETFIELD_QUICK_W, GETFIELD2_QUICK, GETSTATIC, GETSTATIC_QUICK, GETSTATIC2_QUICK, GOTO, GOTO_W, 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, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILLEGAL_OPCODE, ILLEGAL_TYPE, ILOAD, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMPDEP1, IMPDEP2, IMUL, INEG, INSTANCEOF, INSTANCEOF_QUICK, INT2BYTE, INT2CHAR, INT2SHORT, INTERFACES_IMPLEMENTED_BY_ARRAYS, INVOKEINTERFACE, INVOKEINTERFACE_QUICK, INVOKENONVIRTUAL, INVOKENONVIRTUAL_QUICK, INVOKESPECIAL, INVOKESTATIC, INVOKESTATIC_QUICK, INVOKESUPER_QUICK, INVOKEVIRTUAL, INVOKEVIRTUAL_QUICK, INVOKEVIRTUAL_QUICK_W, INVOKEVIRTUALOBJECT_QUICK, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, IUSHR, IXOR, JSR, JSR_W, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDC_QUICK, LDC_W, LDC_W_QUICK, LDC2_W, LDC2_W_QUICK, 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, MAJOR, MAJOR_1_1, MAJOR_1_2, MAJOR_1_3, MAX_ACC_FLAG, MAX_BYTE, MAX_CODE_SIZE, MAX_CP_ENTRIES, MAX_SHORT, MINOR, MINOR_1_1, MINOR_1_2, MINOR_1_3, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, MULTIANEWARRAY_QUICK, NEW, NEW_QUICK, NEWARRAY, NO_OF_OPERANDS, NOP, OPCODE_NAMES, POP, POP2, PRODUCE_STACK, PUSH, PUTFIELD, PUTFIELD_QUICK, PUTFIELD_QUICK_W, PUTFIELD2_QUICK, PUTSTATIC, PUTSTATIC_QUICK, PUTSTATIC2_QUICK, RESERVED, RET, RETURN, SALOAD, SASTORE, SHORT_TYPE_NAMES, SIPUSH, STATIC_INITIALIZER_NAME, SWAP, SWITCH, T_ADDRESS, T_ARRAY, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_OBJECT, T_REFERENCE, T_SHORT, T_UNKNOWN, T_VOID, TABLESWITCH, TYPE_NAMES, TYPE_OF_OPERANDS, UNDEFINED, UNPREDICTABLE, WIDE
 
Constructor Summary
ByteArray()
          Create a new byte array with the default capacity of 256.
ByteArray(int capacity)
          Create a new byte array with the given initialize capacity.
 
Method Summary
 void adjustStack(int delta)
          Adjust the stack pointer, updating maxStack if appropriate.
 byte[] getBytes()
          Get the underlying byte[] -- this does not create a new byte[], it returns the actual byte[] being used.
 byte[] getCode()
          Get the resulting byte[] -- this creates a NEW byte[] with only the contents!
 int getI2(int pc)
          Get a 16-bit short from the given offset.
 int getMaxStack()
          Return max stack size -- note that ByteArray cannot entirely compute this on its own using the opcode tables, for fields and methods the CodeBuilder must manually adjust the stack.
 int getPC()
          Allow us to think of the size as the Program Counter.
 int getSize()
          Return the current size.
 boolean isUnreachable()
          Test whether the current PC is unreachable.
 void put1(int i)
          Write an 8-bit byte to the current bytes-stream.
 void put2(int i)
          Write a 16-bit short to the current bytes-stream
 void put2(int pc, int i)
          Write a 16-bit short to the given pc location.
 void put4(int i)
          Write a 32-bit int to the current bytes-stream
 void putOpcode(int opcode)
          Write the given opcode to the byte stream.
 void reserve(int increment)
          EnsureCapacity, but with a smaller name :)
 void reset()
          Reset the byte array, in preparation to re-use it.
 void setUnreachable(boolean isUnreachable)
          Set whether the current statement is unreachable or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNREACHABLES

public static final boolean[] UNREACHABLES
Opcodes that cause forced change of flow control, such as ATHROW.

Constructor Detail

ByteArray

public ByteArray()
Create a new byte array with the default capacity of 256.


ByteArray

public ByteArray(int capacity)
Create a new byte array with the given initialize capacity.

Method Detail

reset

public void reset()
Reset the byte array, in preparation to re-use it.


reserve

public void reserve(int increment)
EnsureCapacity, but with a smaller name :)

Parameters:
increment - ensure there is room to add at least the given number of bytes.

putOpcode

public void putOpcode(int opcode)
Write the given opcode to the byte stream.

This automatically updates isUnreachable, depending on the opcode.

It also automatically adjusts maxStack for opcodes for which such is predictable (everything besides fields, methods, and multianewarray).


put1

public void put1(int i)
Write an 8-bit byte to the current bytes-stream.

Parameters:
i - the byte to write

put2

public void put2(int i)
Write a 16-bit short to the current bytes-stream

Parameters:
i - the value to write

put2

public void put2(int pc,
                 int i)
Write a 16-bit short to the given pc location.

Parameters:
pc - the offset to write at
i - the value to write

put4

public void put4(int i)
Write a 32-bit int to the current bytes-stream

Parameters:
i - the value to write

getI2

public int getI2(int pc)
Get a 16-bit short from the given offset.


getCode

public byte[] getCode()
Get the resulting byte[] -- this creates a NEW byte[] with only the contents!


getBytes

public byte[] getBytes()
Get the underlying byte[] -- this does not create a new byte[], it returns the actual byte[] being used.


getSize

public int getSize()
Return the current size.


getPC

public int getPC()
Allow us to think of the size as the Program Counter.


adjustStack

public void adjustStack(int delta)
Adjust the stack pointer, updating maxStack if appropriate.


getMaxStack

public int getMaxStack()
Return max stack size -- note that ByteArray cannot entirely compute this on its own using the opcode tables, for fields and methods the CodeBuilder must manually adjust the stack.


setUnreachable

public void setUnreachable(boolean isUnreachable)
Set whether the current statement is unreachable or not.


isUnreachable

public boolean isUnreachable()
Test whether the current PC is unreachable.



Copyright ? 2000-2003 Clarity Systems Group, LLC. All Rights Reserved.