Class SimpleHeapManager
- java.lang.Object
-
- com.tonic.analysis.execution.heap.SimpleHeapManager
-
- All Implemented Interfaces:
HeapManager
public class SimpleHeapManager extends Object implements HeapManager
In-memory heap manager backed by concurrent maps, with a string pool and flat static-field storage.
-
-
Constructor Summary
Constructors Constructor Description SimpleHeapManager()Creates an empty heap with object ids starting at 1.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearStaticFields()Discards every stored static field value.StringextractString(ObjectInstance instance)Reads a guest string's character data back into a host string.ObjectgetStaticField(String owner, String name, String descriptor)booleanhasStaticField(String owner, String name, String descriptor)intidentityHashCode(ObjectInstance instance)ObjectInstanceinternString(String value)Returns the pooled guest string for a host string, allocating it on first request.booleanisNull(ObjectInstance instance)booleanisUsingCompactStrings()ArrayInstancenewArray(String componentType, int length)Allocates a one-dimensional array with default-initialized elements.ArrayInstancenewMultiArray(String componentType, int[] dimensions)Allocates a nested array, filling every dimension but the innermost with sub-arrays.ObjectInstancenewObject(String className)Allocates an instance of a class, with every field unset.longobjectCount()voidputStaticField(String owner, String name, String descriptor, Object value)Stores a static field value, replacing any previous one.voidsetClassResolver(Object classResolver)Sets the resolver attached to every subsequently allocated object.voidsetUseCompactStrings(boolean compact)Selects the string layout used when interning.
-
-
-
Method Detail
-
setClassResolver
public void setClassResolver(Object classResolver)
Sets the resolver attached to every subsequently allocated object.- Parameters:
classResolver- the resolver to attach
-
setUseCompactStrings
public void setUseCompactStrings(boolean compact)
Selects the string layout used when interning.- Specified by:
setUseCompactStringsin interfaceHeapManager- Parameters:
compact- true for the Java 9+ byte-array layout, false for char-array
-
isUsingCompactStrings
public boolean isUsingCompactStrings()
- Specified by:
isUsingCompactStringsin interfaceHeapManager- Returns:
- whether interned strings use the compact byte-array layout
-
newObject
public ObjectInstance newObject(String className)
Description copied from interface:HeapManagerAllocates an instance of a class, with every field unset.- Specified by:
newObjectin interfaceHeapManager- Parameters:
className- the internal name of the class to instantiate- Returns:
- the new instance
-
newArray
public ArrayInstance newArray(String componentType, int length)
Description copied from interface:HeapManagerAllocates a one-dimensional array with default-initialized elements.- Specified by:
newArrayin interfaceHeapManager- Parameters:
componentType- the internal name or descriptor of the element typelength- the element count- Returns:
- the new array
-
newMultiArray
public ArrayInstance newMultiArray(String componentType, int[] dimensions)
Description copied from interface:HeapManagerAllocates a nested array, filling every dimension but the innermost with sub-arrays.- Specified by:
newMultiArrayin interfaceHeapManager- Parameters:
componentType- the internal name or descriptor of the innermost element typedimensions- the length of each dimension, outermost first- Returns:
- the outermost array
-
internString
public ObjectInstance internString(String value)
Description copied from interface:HeapManagerReturns the pooled guest string for a host string, allocating it on first request.- Specified by:
internStringin interfaceHeapManager- Parameters:
value- the host string to intern- Returns:
- the guest
java/lang/Stringinstance
-
extractString
public String extractString(ObjectInstance instance)
Description copied from interface:HeapManagerReads a guest string's character data back into a host string.- Specified by:
extractStringin interfaceHeapManager- Parameters:
instance- the guest string, may be null- Returns:
- the host string, or null if the instance is null or is not a string
-
isNull
public boolean isNull(ObjectInstance instance)
- Specified by:
isNullin interfaceHeapManager- Parameters:
instance- the reference to test, may be null- Returns:
- true if the reference is null
-
identityHashCode
public int identityHashCode(ObjectInstance instance)
- Specified by:
identityHashCodein interfaceHeapManager- Parameters:
instance- the instance to identify, may be null- Returns:
- the instance's identity hash, or 0 for null
-
objectCount
public long objectCount()
- Specified by:
objectCountin interfaceHeapManager- Returns:
- how many objects are currently allocated
-
putStaticField
public void putStaticField(String owner, String name, String descriptor, Object value)
Description copied from interface:HeapManagerStores a static field value, replacing any previous one.- Specified by:
putStaticFieldin interfaceHeapManager- Parameters:
owner- the internal name of the declaring classname- the field namedescriptor- the field descriptorvalue- the value to store
-
getStaticField
public Object getStaticField(String owner, String name, String descriptor)
- Specified by:
getStaticFieldin interfaceHeapManager- Parameters:
owner- the internal name of the declaring classname- the field namedescriptor- the field descriptor- Returns:
- the stored value, or null if the field was never written
-
hasStaticField
public boolean hasStaticField(String owner, String name, String descriptor)
- Specified by:
hasStaticFieldin interfaceHeapManager- Parameters:
owner- the internal name of the declaring classname- the field namedescriptor- the field descriptor- Returns:
- true if the field has been written
-
clearStaticFields
public void clearStaticFields()
Description copied from interface:HeapManagerDiscards every stored static field value.- Specified by:
clearStaticFieldsin interfaceHeapManager
-
-