Class 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 Detail

      • SimpleHeapManager

        public SimpleHeapManager()
        Creates an empty heap with object ids starting at 1.
    • 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:
        setUseCompactStrings in interface HeapManager
        Parameters:
        compact - true for the Java 9+ byte-array layout, false for char-array
      • isUsingCompactStrings

        public boolean isUsingCompactStrings()
        Specified by:
        isUsingCompactStrings in interface HeapManager
        Returns:
        whether interned strings use the compact byte-array layout
      • newObject

        public ObjectInstance newObject​(String className)
        Description copied from interface: HeapManager
        Allocates an instance of a class, with every field unset.
        Specified by:
        newObject in interface HeapManager
        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: HeapManager
        Allocates a one-dimensional array with default-initialized elements.
        Specified by:
        newArray in interface HeapManager
        Parameters:
        componentType - the internal name or descriptor of the element type
        length - the element count
        Returns:
        the new array
      • newMultiArray

        public ArrayInstance newMultiArray​(String componentType,
                                           int[] dimensions)
        Description copied from interface: HeapManager
        Allocates a nested array, filling every dimension but the innermost with sub-arrays.
        Specified by:
        newMultiArray in interface HeapManager
        Parameters:
        componentType - the internal name or descriptor of the innermost element type
        dimensions - the length of each dimension, outermost first
        Returns:
        the outermost array
      • internString

        public ObjectInstance internString​(String value)
        Description copied from interface: HeapManager
        Returns the pooled guest string for a host string, allocating it on first request.
        Specified by:
        internString in interface HeapManager
        Parameters:
        value - the host string to intern
        Returns:
        the guest java/lang/String instance
      • extractString

        public String extractString​(ObjectInstance instance)
        Description copied from interface: HeapManager
        Reads a guest string's character data back into a host string.
        Specified by:
        extractString in interface HeapManager
        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:
        isNull in interface HeapManager
        Parameters:
        instance - the reference to test, may be null
        Returns:
        true if the reference is null
      • identityHashCode

        public int identityHashCode​(ObjectInstance instance)
        Specified by:
        identityHashCode in interface HeapManager
        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:
        objectCount in interface HeapManager
        Returns:
        how many objects are currently allocated
      • putStaticField

        public void putStaticField​(String owner,
                                   String name,
                                   String descriptor,
                                   Object value)
        Description copied from interface: HeapManager
        Stores a static field value, replacing any previous one.
        Specified by:
        putStaticField in interface HeapManager
        Parameters:
        owner - the internal name of the declaring class
        name - the field name
        descriptor - the field descriptor
        value - the value to store
      • getStaticField

        public Object getStaticField​(String owner,
                                     String name,
                                     String descriptor)
        Specified by:
        getStaticField in interface HeapManager
        Parameters:
        owner - the internal name of the declaring class
        name - the field name
        descriptor - 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:
        hasStaticField in interface HeapManager
        Parameters:
        owner - the internal name of the declaring class
        name - the field name
        descriptor - the field descriptor
        Returns:
        true if the field has been written
      • clearStaticFields

        public void clearStaticFields()
        Description copied from interface: HeapManager
        Discards every stored static field value.
        Specified by:
        clearStaticFields in interface HeapManager