Class ObjectBuffer


  • final class ObjectBuffer
    extends java.lang.Object
    Holds objects the native code must handle - such as primitive arrays
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int ARRAY  
      (package private) static int BOOLEAN  
      (package private) static int BUFFER  
      (package private) static int BYTE  
      (package private) static int CHAR  
      static int CLEAR
      For OUT arrays, clear the temporary native memory area
      (package private) static int DOUBLE  
      (package private) static int FLAGS_MASK  
      (package private) static int FLAGS_SHIFT  
      (package private) static int FLOAT  
      static int IN
      Copy the array contents to native memory before calling the function
      (package private) static int INDEX_MASK  
      (package private) static int INDEX_SHIFT  
      private int[] info
      The flags/offset/length descriptor array.
      private int infoIndex
      The index of the next descriptor storage slot
      (package private) static int INT  
      (package private) static int JNI  
      static int JNIENV
      The JNIEnv address
      static int JNIOBJECT
      The jobject handle
      (package private) static int LONG  
      private int objectIndex
      The index of the next object storage slot
      private java.lang.Object[] objects
      The objects stored in this buffer
      static int OUT
      After calling the function, reload the array contents from native memory
      static int PINNED
      Pin the array memory and pass the JVM memory pointer directly to the function
      (package private) static int PRIM_MASK  
      (package private) static int SHORT  
      (package private) static int TYPE_MASK  
      (package private) static int TYPE_SHIFT  
      static int ZERO_TERMINATE
      Append a NUL byte to the array contents after copying to native memory
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void ensureSpace()
      Ensures that sufficient space is available to insert at least one more object
      (package private) int[] info()
      Gets the object descriptor array.
      (package private) static int makeBufferFlags​(int index)
      Encodes the native object flags for an NIO Buffer.
      private static int makeJNIFlags​(int index, int type)  
      (package private) static int makeObjectFlags​(int ioflags, int type, int index)
      Encodes the native object flags for an array.
      (package private) int objectCount()
      Gets the number of objects stored in this ObjectBuffer.
      (package private) java.lang.Object[] objects()
      Gets the array of stored objects.
      void putArray​(int index, boolean[] array, int offset, int length, int flags)
      Adds a java boolean array as a pointer parameter.
      void putArray​(int index, byte[] array, int offset, int length, int flags)
      Adds a java byte array as a pointer parameter.
      void putArray​(int index, char[] array, int offset, int length, int flags)
      Adds a java char array as a pointer parameter.
      void putArray​(int index, double[] array, int offset, int length, int flags)
      Adds a java double array as a pointer parameter.
      void putArray​(int index, float[] array, int offset, int length, int flags)
      Adds a java float array as a pointer parameter.
      void putArray​(int index, int[] array, int offset, int length, int flags)
      Adds a java int array as a pointer parameter.
      void putArray​(int index, long[] array, int offset, int length, int flags)
      Adds a java long array as a pointer parameter.
      void putArray​(int index, short[] array, int offset, int length, int flags)
      Adds a java short array as a pointer parameter.
      void putDirectBuffer​(int index, java.nio.Buffer obj, int offset, int length)
      Adds a java direct buffer as a pointer parameter.
      void putJNI​(int index, java.lang.Object obj, int type)
      Put the address of the current JNIEnv into this parameter position
      (package private) void putObject​(java.lang.Object array, int offset, int length, int flags)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • IN

        @Native
        public static final int IN
        Copy the array contents to native memory before calling the function
        See Also:
        Constant Field Values
      • OUT

        @Native
        public static final int OUT
        After calling the function, reload the array contents from native memory
        See Also:
        Constant Field Values
      • ZERO_TERMINATE

        @Native
        public static final int ZERO_TERMINATE
        Append a NUL byte to the array contents after copying to native memory
        See Also:
        Constant Field Values
      • PINNED

        @Native
        public static final int PINNED
        Pin the array memory and pass the JVM memory pointer directly to the function
        See Also:
        Constant Field Values
      • CLEAR

        @Native
        public static final int CLEAR
        For OUT arrays, clear the temporary native memory area
        See Also:
        Constant Field Values
      • JNIOBJECT

        @Native
        public static final int JNIOBJECT
        The jobject handle
        See Also:
        Constant Field Values
      • objects

        private java.lang.Object[] objects
        The objects stored in this buffer
      • info

        private int[] info
        The flags/offset/length descriptor array. Along with each object, a 3-tuple is stored in the descriptor array. The first element of the tuple stores a mask of the type, parameter index and array flags The second element stores the offset within the array the data starts. The third element stores the length of data.
      • infoIndex

        private int infoIndex
        The index of the next descriptor storage slot
      • objectIndex

        private int objectIndex
        The index of the next object storage slot
    • Constructor Detail

      • ObjectBuffer

        ObjectBuffer()
      • ObjectBuffer

        ObjectBuffer​(int objectCount)
    • Method Detail

      • objectCount

        final int objectCount()
        Gets the number of objects stored in this ObjectBuffer.
        Returns:
        the number of objects already stored.
      • info

        final int[] info()
        Gets the object descriptor array.
        Returns:
        An array of integers describing the objects stored.
      • objects

        final java.lang.Object[] objects()
        Gets the array of stored objects.
        Returns:
        An array of objects stored in this buffer.
      • ensureSpace

        private final void ensureSpace()
        Ensures that sufficient space is available to insert at least one more object
      • makeObjectFlags

        static final int makeObjectFlags​(int ioflags,
                                         int type,
                                         int index)
        Encodes the native object flags for an array.
        Parameters:
        ioflags - The array flags (IN, OUT) for the object.
        type - The type of the object.
        index - The parameter index the object should be passed as.
        Returns:
        A bitmask of flags.
      • makeBufferFlags

        static final int makeBufferFlags​(int index)
        Encodes the native object flags for an NIO Buffer.
        Parameters:
        index - The parameter index of the buffer.
        Returns:
        A bitmask of flags.
      • makeJNIFlags

        private static final int makeJNIFlags​(int index,
                                              int type)
      • putArray

        public void putArray​(int index,
                             byte[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java byte array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT, NULTERMINATE)
      • putArray

        public void putArray​(int index,
                             short[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java short array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT)
      • putArray

        public void putArray​(int index,
                             int[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java int array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT)
      • putArray

        public void putArray​(int index,
                             long[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java long array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT)
      • putArray

        public void putArray​(int index,
                             float[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java float array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT)
      • putArray

        public void putArray​(int index,
                             double[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java double array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT)
      • putArray

        public void putArray​(int index,
                             boolean[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java boolean array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT)
      • putArray

        public void putArray​(int index,
                             char[] array,
                             int offset,
                             int length,
                             int flags)
        Adds a java char array as a pointer parameter.
        Parameters:
        array - The java array to use as the pointer parameter.
        offset - The offset from the start of the array.
        length - The length of the array to use.
        flags - The flags to use (IN, OUT)
      • putDirectBuffer

        public void putDirectBuffer​(int index,
                                    java.nio.Buffer obj,
                                    int offset,
                                    int length)
        Adds a java direct buffer as a pointer parameter.
        Parameters:
        buffer - The buffer to use as a pointer argument.
        offset - An offset to add to the buffer native address.
        length - The length of the buffer to use.
      • putJNI

        public void putJNI​(int index,
                           java.lang.Object obj,
                           int type)
        Put the address of the current JNIEnv into this parameter position
        Parameters:
        index - The index of the parameter.
      • putObject

        void putObject​(java.lang.Object array,
                       int offset,
                       int length,
                       int flags)