Interface HeapManager

  • All Known Implementing Classes:
    SimpleHeapManager

    public interface HeapManager
    Allocation, string interning, and static-field services for the simulated heap.
    • Method Detail

      • newObject

        ObjectInstance newObject​(String className)
        Allocates an instance of a class, with every field unset.
        Parameters:
        className - the internal name of the class to instantiate
        Returns:
        the new instance
      • newArray

        ArrayInstance newArray​(String componentType,
                               int length)
        Allocates a one-dimensional array with default-initialized elements.
        Parameters:
        componentType - the internal name or descriptor of the element type
        length - the element count
        Returns:
        the new array
        Throws:
        HeapException - if length is negative
      • newMultiArray

        ArrayInstance newMultiArray​(String componentType,
                                    int[] dimensions)
        Allocates a nested array, filling every dimension but the innermost with sub-arrays.
        Parameters:
        componentType - the internal name or descriptor of the innermost element type
        dimensions - the length of each dimension, outermost first
        Returns:
        the outermost array
        Throws:
        HeapException - if dimensions is null, empty, or holds a negative length
      • internString

        ObjectInstance internString​(String value)
        Returns the pooled guest string for a host string, allocating it on first request.
        Parameters:
        value - the host string to intern
        Returns:
        the guest java/lang/String instance
      • extractString

        String extractString​(ObjectInstance instance)
        Reads a guest string's character data back into a host string.
        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

        boolean isNull​(ObjectInstance instance)
        Parameters:
        instance - the reference to test, may be null
        Returns:
        true if the reference is null
      • identityHashCode

        int identityHashCode​(ObjectInstance instance)
        Parameters:
        instance - the instance to identify, may be null
        Returns:
        the instance's identity hash, or 0 for null
      • objectCount

        long objectCount()
        Returns:
        how many objects are currently allocated
      • putStaticField

        void putStaticField​(String owner,
                            String name,
                            String descriptor,
                            Object value)
        Stores a static field value, replacing any previous one.
        Parameters:
        owner - the internal name of the declaring class
        name - the field name
        descriptor - the field descriptor
        value - the value to store
      • getStaticField

        Object getStaticField​(String owner,
                              String name,
                              String descriptor)
        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

        boolean hasStaticField​(String owner,
                               String name,
                               String descriptor)
        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

        void clearStaticFields()
        Discards every stored static field value.
      • setUseCompactStrings

        default void setUseCompactStrings​(boolean compact)
        Selects the string layout used by internString(java.lang.String); ignored unless overridden.
        Parameters:
        compact - true for the Java 9+ byte-array layout, false for the char-array layout
      • isUsingCompactStrings

        default boolean isUsingCompactStrings()
        Returns:
        true if interned strings use the compact byte-array layout, false unless overridden