joeq.Allocator
Class HeapAllocator

java.lang.Object
  extended by joeq.Allocator.HeapAllocator
All Implemented Interfaces:
jq_ClassFileConstants
Direct Known Subclasses:
SimpleAllocator

public abstract class HeapAllocator
extends Object
implements jq_ClassFileConstants

HeapAllocator

Version:
$Id: HeapAllocator.java,v 1.28 2005/01/21 07:13:15 joewhaley Exp $
Author:
John Whaley

Nested Class Summary
static class HeapAllocator.HeapPointer
          An object of this class represents a pointer to a heap address.
 
Field Summary
static jq_Class _class
           
static jq_StaticMethod _clsinitAndAllocateObject
           
static jq_StaticField _data_segment_end
           
static jq_StaticField _data_segment_start
           
static HeapAddress data_segment_end
           
static HeapAddress data_segment_start
           
static boolean TRACE
           
 
Fields inherited from interface joeq.Class.jq_ClassFileConstants
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, CONSTANT_Class, CONSTANT_Double, CONSTANT_FieldRef, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodRef, CONSTANT_Long, CONSTANT_MethodRef, CONSTANT_NameAndType, CONSTANT_ResolvedClass, CONSTANT_ResolvedIFieldRef, CONSTANT_ResolvedIMethodRef, CONSTANT_ResolvedSFieldRef, CONSTANT_ResolvedSMethodRef, CONSTANT_String, CONSTANT_Utf8, CONSUME_STACK, ILLEGAL_OPCODE, ILLEGAL_TYPE, jbc_AALOAD, jbc_AASTORE, jbc_ACONST_NULL, jbc_ALOAD, jbc_ALOAD_0, jbc_ALOAD_1, jbc_ALOAD_2, jbc_ALOAD_3, jbc_ANEWARRAY, jbc_ARETURN, jbc_ARRAYLENGTH, jbc_ASTORE, jbc_ASTORE_0, jbc_ASTORE_1, jbc_ASTORE_2, jbc_ASTORE_3, jbc_ATHROW, jbc_BALOAD, jbc_BASTORE, jbc_BIPUSH, jbc_BREAKPOINT, jbc_CALOAD, jbc_CASTORE, jbc_CHECKCAST, jbc_D2F, jbc_D2I, jbc_D2L, jbc_DADD, jbc_DALOAD, jbc_DASTORE, jbc_DCMPG, jbc_DCMPL, jbc_DCONST_0, jbc_DCONST_1, jbc_DDIV, jbc_DLOAD, jbc_DLOAD_0, jbc_DLOAD_1, jbc_DLOAD_2, jbc_DLOAD_3, jbc_DMUL, jbc_DNEG, jbc_DREM, jbc_DRETURN, jbc_DSTORE, jbc_DSTORE_0, jbc_DSTORE_1, jbc_DSTORE_2, jbc_DSTORE_3, jbc_DSUB, jbc_DUP, jbc_DUP_X1, jbc_DUP_X2, jbc_DUP2, jbc_DUP2_X1, jbc_DUP2_X2, jbc_F2D, jbc_F2I, jbc_F2L, jbc_FADD, jbc_FALOAD, jbc_FASTORE, jbc_FCMPG, jbc_FCMPL, jbc_FCONST_0, jbc_FCONST_1, jbc_FCONST_2, jbc_FDIV, jbc_FLOAD, jbc_FLOAD_0, jbc_FLOAD_1, jbc_FLOAD_2, jbc_FLOAD_3, jbc_FMUL, jbc_FNEG, jbc_FREM, jbc_FRETURN, jbc_FSTORE, jbc_FSTORE_0, jbc_FSTORE_1, jbc_FSTORE_2, jbc_FSTORE_3, jbc_FSUB, jbc_GETFIELD, jbc_GETSTATIC, jbc_GOTO, jbc_GOTO_W, jbc_I2B, jbc_I2C, jbc_I2D, jbc_I2F, jbc_I2L, jbc_I2S, jbc_IADD, jbc_IALOAD, jbc_IAND, jbc_IASTORE, jbc_ICONST_0, jbc_ICONST_1, jbc_ICONST_2, jbc_ICONST_3, jbc_ICONST_4, jbc_ICONST_5, jbc_ICONST_M1, jbc_IDIV, jbc_IF_ACMPEQ, jbc_IF_ACMPNE, jbc_IF_ICMPEQ, jbc_IF_ICMPGE, jbc_IF_ICMPGT, jbc_IF_ICMPLE, jbc_IF_ICMPLT, jbc_IF_ICMPNE, jbc_IFEQ, jbc_IFGE, jbc_IFGT, jbc_IFLE, jbc_IFLT, jbc_IFNE, jbc_IFNONNULL, jbc_IFNULL, jbc_IINC, jbc_ILOAD, jbc_ILOAD_0, jbc_ILOAD_1, jbc_ILOAD_2, jbc_ILOAD_3, jbc_IMUL, jbc_INEG, jbc_INSTANCEOF, jbc_INT2BYTE, jbc_INT2CHAR, jbc_INT2SHORT, jbc_INVOKEINTERFACE, jbc_INVOKENONVIRTUAL, jbc_INVOKESPECIAL, jbc_INVOKESTATIC, jbc_INVOKEVIRTUAL, jbc_IOR, jbc_IREM, jbc_IRETURN, jbc_ISHL, jbc_ISHR, jbc_ISTORE, jbc_ISTORE_0, jbc_ISTORE_1, jbc_ISTORE_2, jbc_ISTORE_3, jbc_ISUB, jbc_IUSHR, jbc_IXOR, jbc_JSR, jbc_JSR_W, jbc_L2D, jbc_L2F, jbc_L2I, jbc_LADD, jbc_LALOAD, jbc_LAND, jbc_LASTORE, jbc_LCMP, jbc_LCONST_0, jbc_LCONST_1, jbc_LDC, jbc_LDC_W, jbc_LDC2_W, jbc_LDIV, jbc_LLOAD, jbc_LLOAD_0, jbc_LLOAD_1, jbc_LLOAD_2, jbc_LLOAD_3, jbc_LMUL, jbc_LNEG, jbc_LOOKUPSWITCH, jbc_LOR, jbc_LREM, jbc_LRETURN, jbc_LSHL, jbc_LSHR, jbc_LSTORE, jbc_LSTORE_0, jbc_LSTORE_1, jbc_LSTORE_2, jbc_LSTORE_3, jbc_LSUB, jbc_LUSHR, jbc_LXOR, jbc_MONITORENTER, jbc_MONITOREXIT, jbc_MULTIANEWARRAY, jbc_NEW, jbc_NEWARRAY, jbc_NOP, jbc_POP, jbc_POP2, jbc_PUTFIELD, jbc_PUTSTATIC, jbc_RET, jbc_RETURN, jbc_SALOAD, jbc_SASTORE, jbc_SIPUSH, jbc_SWAP, jbc_TABLESWITCH, jbc_WIDE, NO_OF_OPERANDS, OPCODE_NAMES, PRODUCE_STACK, RESERVED, STATE_CLSINITERROR, STATE_CLSINITIALIZED, STATE_CLSINITIALIZING, STATE_CLSINITRUNNING, STATE_COMPILED, STATE_COMPILING, STATE_LOADED, STATE_LOADERROR, STATE_LOADING1, STATE_LOADING2, STATE_LOADING3, STATE_PREPARED, STATE_PREPARING, STATE_SFINITIALIZED, STATE_SFINITIALIZING, STATE_UNLOADED, STATE_VERIFIED, STATE_VERIFYING, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TC_ARRAY, TC_BOOLEAN, TC_BYTE, TC_CHAR, TC_CLASS, TC_CLASSEND, TC_DOUBLE, TC_FLOAT, TC_INT, TC_LONG, TC_PARAM, TC_PARAMEND, TC_SHORT, TC_VOID, TYPE_OF_OPERANDS, UNDEFINED, UNPREDICTABLE
 
Constructor Summary
HeapAllocator()
           
 
Method Summary
abstract  Object allocateArray(int length, int size, Object vtable)
          Allocate an array with the default alignment.
abstract  Object allocateArrayAlign8(int length, int size, Object vtable)
          Allocate an array such that the elements are 8-byte aligned.
abstract  Object allocateObject(int size, Object vtable)
          Allocate an object with the default alignment.
abstract  Object allocateObjectAlign8(int size, Object vtable)
          Allocate an object such that the first field is 8-byte aligned.
static boolean checkObjectReferences(Object o, int depth)
          Check if the object references are legal up to a given depth.
static Object clone(Object o)
          Clone the given object.
static Object clsinitAndAllocateObject(jq_Type t)
          Initialize class t and return a new uninitialized object of that type.
abstract  void collect()
          Initiate a garbage collection.
abstract  int freeMemory()
          Returns an estimate of the amount of free memory available.
static boolean getGCBit(Object o)
           
static int[] getScalarObjectReferenceOffsets(Object o)
           
abstract  void init()
          Perform initialization for this allocator.
static void initializeDataSegment()
           
static boolean isInDataSegment(Address a)
           
abstract  boolean isInHeap(Address a)
          Returns whether the given address falls within the boundaries of this heap.
static boolean isObjectAssignableType(Address a, jq_Reference t)
          Return true if the given address is null or looks like it points to an object whose type is assignable to the given reference type.
static boolean isObjectExactType(Address a, jq_Reference t)
          Return true if the given address looks like it points to an object whose type is exactly the given reference type.
static boolean isValidArray(Address a)
          Returns true if the given address looks like it points to an array.
static boolean isValidArray(Address a, int depth)
          Returns true if the given address looks like it points to an array.
static boolean isValidArrayType(Address typeAddress)
          Given an address, return true if it looks like it points to a jq_Array object.
static boolean isValidArrayVTable(Address a)
          Return true if the given address looks like it points to a vtable for an array object.
static boolean isValidHeapAddress(Address a)
           
static boolean isValidObject(Address a)
          Returns true if the given address looks like it points to an object.
static boolean isValidObject(Address a, int depth)
          Returns true if the given address looks like it points to an object.
static boolean isValidReferenceType(Address typeAddress)
          Given an address, return true if it looks like it points to a jq_Class or jq_Array object.
static boolean isValidVTable(Address a)
          Return true if the given address looks like it points to a vtable.
static void outOfMemory()
          Called in an out of memory situation.
abstract  void processObjectReference(Address a)
          Process a reference to a heap object during garbage collection.
abstract  void processPossibleObjectReference(Address a)
          Process a possible reference to a heap object during garbage collection.
static void setGCBit(Object o, boolean b)
           
abstract  int totalMemory()
          Returns an estimate of the total memory allocated (both used and unused).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACE

public static final boolean TRACE
See Also:
Constant Field Values

data_segment_start

public static HeapAddress data_segment_start

data_segment_end

public static HeapAddress data_segment_end

_class

public static final jq_Class _class

_clsinitAndAllocateObject

public static final jq_StaticMethod _clsinitAndAllocateObject

_data_segment_start

public static final jq_StaticField _data_segment_start

_data_segment_end

public static final jq_StaticField _data_segment_end
Constructor Detail

HeapAllocator

public HeapAllocator()
Method Detail

init

public abstract void init()
                   throws OutOfMemoryError
Perform initialization for this allocator. This will be called before any other methods.

Throws:
OutOfMemoryError - if there is not enough memory for initialization

allocateObject

public abstract Object allocateObject(int size,
                                      Object vtable)
                               throws OutOfMemoryError
Allocate an object with the default alignment. If the object cannot be allocated due to lack of memory, throws OutOfMemoryError.

Parameters:
size - size of object to allocate (including object header), in bytes
vtable - vtable pointer for new object
Returns:
new uninitialized object
Throws:
OutOfMemoryError - if there is insufficient memory to perform the operation

allocateObjectAlign8

public abstract Object allocateObjectAlign8(int size,
                                            Object vtable)
                                     throws OutOfMemoryError
Allocate an object such that the first field is 8-byte aligned. If the object cannot be allocated due to lack of memory, throws OutOfMemoryError.

Parameters:
size - size of object to allocate (including object header), in bytes
vtable - vtable pointer for new object
Returns:
new uninitialized object
Throws:
OutOfMemoryError - if there is insufficient memory to perform the operation

allocateArray

public abstract Object allocateArray(int length,
                                     int size,
                                     Object vtable)
                              throws OutOfMemoryError,
                                     NegativeArraySizeException
Allocate an array with the default alignment. If length is negative, throws NegativeArraySizeException. If the array cannot be allocated due to lack of memory, throws OutOfMemoryError.

Parameters:
length - length of new array
size - size of array to allocate (including array header), in bytes
vtable - vtable pointer for new array
Returns:
new array
Throws:
NegativeArraySizeException - if length is negative
OutOfMemoryError - if there is insufficient memory to perform the operation

allocateArrayAlign8

public abstract Object allocateArrayAlign8(int length,
                                           int size,
                                           Object vtable)
                                    throws OutOfMemoryError,
                                           NegativeArraySizeException
Allocate an array such that the elements are 8-byte aligned. If length is negative, throws NegativeArraySizeException. If the array cannot be allocated due to lack of memory, throws OutOfMemoryError.

Parameters:
length - length of new array
size - size of array to allocate (including array header), in bytes
vtable - vtable pointer for new array
Returns:
new array
Throws:
NegativeArraySizeException - if length is negative
OutOfMemoryError - if there is insufficient memory to perform the operation

freeMemory

public abstract int freeMemory()
Returns an estimate of the amount of free memory available.

Returns:
bytes of free memory

totalMemory

public abstract int totalMemory()
Returns an estimate of the total memory allocated (both used and unused).

Returns:
bytes of memory allocated

isInHeap

public abstract boolean isInHeap(Address a)
Returns whether the given address falls within the boundaries of this heap.


collect

public abstract void collect()
Initiate a garbage collection.


processObjectReference

public abstract void processObjectReference(Address a)
Process a reference to a heap object during garbage collection.


processPossibleObjectReference

public abstract void processPossibleObjectReference(Address a)
Process a possible reference to a heap object during garbage collection.


clsinitAndAllocateObject

public static Object clsinitAndAllocateObject(jq_Type t)
                                       throws VerifyError
Initialize class t and return a new uninitialized object of that type. If t is not a class type, throw a VerifyError.

Parameters:
t - type to initialize and create object of
Returns:
new uninitialized object of type t
Throws:
VerifyError - if t is not a class type

clone

public static Object clone(Object o)
                    throws OutOfMemoryError
Clone the given object. NOTE: Does not check if the object implements Cloneable.

Parameters:
o - object to clone
Returns:
new clone
Throws:
OutOfMemoryError - if there is not enough memory to perform operation

outOfMemory

public static void outOfMemory()
                        throws OutOfMemoryError
Called in an out of memory situation.

Throws:
OutOfMemoryError - always thrown

initializeDataSegment

public static void initializeDataSegment()

isInDataSegment

public static final boolean isInDataSegment(Address a)

isValidHeapAddress

public static boolean isValidHeapAddress(Address a)

getGCBit

public static boolean getGCBit(Object o)

setGCBit

public static void setGCBit(Object o,
                            boolean b)

getScalarObjectReferenceOffsets

public static int[] getScalarObjectReferenceOffsets(Object o)

checkObjectReferences

public static boolean checkObjectReferences(Object o,
                                            int depth)
Check if the object references are legal up to a given depth.

Parameters:
o -
depth -
Returns:
true if object refs are legal

isValidObject

public static boolean isValidObject(Address a)
Returns true if the given address looks like it points to an object.

Parameters:
a -
Returns:
true if it looks like a valid object

isValidObject

public static boolean isValidObject(Address a,
                                    int depth)
Returns true if the given address looks like it points to an object. Checks up to the given depth of object nesting.

Parameters:
a -
depth -
Returns:
true if it looks like a valid object

isValidArray

public static boolean isValidArray(Address a)
Returns true if the given address looks like it points to an array.

Parameters:
a -
Returns:
true if it looks like a valid array

isValidArray

public static boolean isValidArray(Address a,
                                   int depth)
Returns true if the given address looks like it points to an array. Checks up to the given depth of object nesting.

Parameters:
a -
depth -
Returns:
true if it looks like a valid array

isValidVTable

public static boolean isValidVTable(Address a)
Return true if the given address looks like it points to a vtable.

Parameters:
a -
Returns:
true if it looks like a vtable

isValidArrayVTable

public static boolean isValidArrayVTable(Address a)
Return true if the given address looks like it points to a vtable for an array object.

Parameters:
a -
Returns:
true if it looks like a valid array vtable

isObjectExactType

public static boolean isObjectExactType(Address a,
                                        jq_Reference t)
Return true if the given address looks like it points to an object whose type is exactly the given reference type.

Parameters:
a -
t -
Returns:
true if it looks like an object of the correct type

isObjectAssignableType

public static boolean isObjectAssignableType(Address a,
                                             jq_Reference t)
Return true if the given address is null or looks like it points to an object whose type is assignable to the given reference type.

Parameters:
a -
t -
Returns:
true if it is null or looks like an object of assignable type

isValidReferenceType

public static boolean isValidReferenceType(Address typeAddress)
Given an address, return true if it looks like it points to a jq_Class or jq_Array object.

Parameters:
typeAddress -
Returns:
true if it looks like a jq_Class or jq_Array object

isValidArrayType

public static boolean isValidArrayType(Address typeAddress)
Given an address, return true if it looks like it points to a jq_Array object.

Parameters:
typeAddress -
Returns:
true if it looks like a jq_Array object


Copyright © 2001-2005 John Whaley. All Rights Reserved.