Class ArrayInstance


  • public class ArrayInstance
    extends ObjectInstance
    A heap-allocated array with typed primitive or reference backing storage.
    • Constructor Detail

      • ArrayInstance

        public ArrayInstance​(int id,
                             String componentType,
                             int length)
        Allocates an array with zeroed storage matching the component type.
        Parameters:
        id - the heap object id
        componentType - descriptor of the element type
        length - the number of elements
        Throws:
        HeapException - if the length is negative
    • Method Detail

      • getLength

        public int getLength()
        Returns:
        the length
      • getComponentType

        public String getComponentType()
        Returns:
        the component type
      • isPrimitiveArray

        public boolean isPrimitiveArray()
        Returns:
        whether primitive array
      • get

        public Object get​(int index)
        Reads an element as a boxed value or reference.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if the index is out of bounds
      • set

        public void set​(int index,
                        Object value)
        Writes an element, unboxing to the storage type as needed.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if the index is out of bounds
      • getInt

        public int getInt​(int index)
        Reads an int element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not int[]
      • setInt

        public void setInt​(int index,
                           int value)
        Writes an int element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not int[]
      • getLong

        public long getLong​(int index)
        Reads a long element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not long[]
      • setLong

        public void setLong​(int index,
                            long value)
        Writes a long element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not long[]
      • getBoolean

        public boolean getBoolean​(int index)
        Reads a boolean element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not boolean[]
      • setBoolean

        public void setBoolean​(int index,
                               boolean value)
        Writes a boolean element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not boolean[]
      • getByte

        public byte getByte​(int index)
        Reads a byte element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not byte[]
      • setByte

        public void setByte​(int index,
                            byte value)
        Writes a byte element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not byte[]
      • getChar

        public char getChar​(int index)
        Reads a char element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not char[]
      • setChar

        public void setChar​(int index,
                            char value)
        Writes a char element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not char[]
      • getShort

        public short getShort​(int index)
        Reads a short element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not short[]
      • setShort

        public void setShort​(int index,
                             short value)
        Writes a short element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not short[]
      • getFloat

        public float getFloat​(int index)
        Reads a float element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not float[]
      • setFloat

        public void setFloat​(int index,
                             float value)
        Writes a float element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not float[]
      • getDouble

        public double getDouble​(int index)
        Reads a double element.
        Parameters:
        index - the element index
        Returns:
        the element value
        Throws:
        HeapException - if out of bounds or the storage is not double[]
      • setDouble

        public void setDouble​(int index,
                              double value)
        Writes a double element.
        Parameters:
        index - the element index
        value - the value to store
        Throws:
        HeapException - if out of bounds or the storage is not double[]