| java.lang.Object org.apache.harmony.misc.accessors.ArrayAccessor
ArrayAccessor | public class ArrayAccessor (Code) | | This class is a performance optimization aid which provides the low-level
access to arrays. It contains the following groups of methods:
- lockArray/lockArrayLong methods - used to lock the memory
location for the primitive type arrays for either short or long amounts of
time such that their contents can be directly accessed in the memory.
Typically, this is used to pass java arrays as arguments to native functions.
One array can not be locked for the short and long period of time
simultaneously.
- set/getElement methods - used to read and write individual array
elements bypassing the bounds checks.
- getArrayBaseOffset/ElementSize methods - used to obtain
information about arrays layout in the memory.
The typical implementations of the
ArrayAccessor.lockArrayShort(Object) and
ArrayAccessor.lockArrayLong(Object) methods would instruct a virtual machine that
the given array should stay unmovable for a certain period of time (i.e.
until it is released by
LockedArray.release call). On virtual
machines which do not support the unmovable arrays for some reason,
functionality of the lockArray/release pair still can be
emulated by copying the array content into the native heap and back. However,
whatever implementation exists, the
LockedArray.getAddress method
must return the memory location which is applicable for direct memory access
operations, such as the ones provided by
MemoryAccessor class.
A typical usage example for the locked arrays would look like that:
ArrayAccessor aa = AccessorFactory.getArrayAccessor();
byte[] bytearr = (byte[])aa.createArray(Byte.TYPE, 1024);
...fill the bytearr ...
LockedArray la = aa.lockArrayShort(bytearr);
int pixmap = x11.XCreateBitmapFromData(display, wnd, la.getAddress(), width,
height);
la.release();
|
Field Summary | |
final static HashMap | objectLockMap Internal hash which keeps the record for all locked arrays. |
Method Summary | |
public Object | createArray(Class type, int size) Allocates a primitive type array that will be locked. | public LockedArray | createLockedArrayLong(Class type, int size) Allocates and immediately locks a primitive type array for supposedly a
long period of time. | public LockedArray | createLockedArrayShort(Class type, int size) Allocates and immediately locks a primitive type array for supposedly a
short period of time. | final public long | getArrayBaseOffset(Class arrayClass) Reports the offset of the first element in the storage allocation of a
given array class. | final public int | getArrayElementSize(Class arrayClass) Reports the element size for addressing elements in the storage
allocation of a given array class. | final native public byte | getElement(byte[] arr, int index) Reads a byte element at the given index without bounds check. | final native public boolean | getElement(boolean[] arr, int index) Reads a boolean element at the given index without bounds check. | final native public char | getElement(char[] arr, int index) Reads a char element at the given index without bounds check. | final native public short | getElement(short[] arr, int index) Reads a short element at the given index without bounds check. | final native public int | getElement(int[] arr, int index) Reads a int element at the given index without bounds check. | final native public long | getElement(long[] arr, int index) Reads a long element at the given index without bounds check. | final native public float | getElement(float[] arr, int index) Reads a float element at the given index without bounds check. | final native public double | getElement(double[] arr, int index) Reads a double element at the given index without bounds check. | final native public Object | getElement(Object[] arr, int index) Reads an Object element at the given index without bounds check. | static ArrayAccessor | getInstance() | public LockedArray | lockArrayLong(Object array) Locks an existing array for supposedly a long period of time and returns
its location in memory. | public LockedArray | lockArrayShort(Object array) Locks an existing array for supposedly a short period of time.
Typically, this method would instruct a virtual machine that the given
array should stay unmovable for a short period of time, such as one
native library call. | static void | releaseArray(Object array, long addr, boolean longLock) | static void | releaseArrayNoCopy(Object array, long addr, boolean longLock) | final native public void | setElement(byte[] arr, int index, byte value) Writes a byte element at the given index without bounds check. | final native public void | setElement(boolean[] arr, int index, boolean value) Writes a boolean element at the given index without bounds check. | final native public void | setElement(char[] arr, int index, char value) Writes a char element at the given index without bounds check. | final native public void | setElement(short[] arr, int index, short value) Writes a short element at the given index without bounds check. | final native public void | setElement(int[] arr, int index, int value) Writes a int element at the given index without bounds check. | final native public void | setElement(long[] arr, int index, long value) Writes a long element at the given index without bounds check. | final native public void | setElement(float[] arr, int index, float value) Writes a float element at the given index without bounds check. | final native public void | setElement(double[] arr, int index, double value) Writes a double element at the given index without bounds check. | final native public void | setElement(Object[] arr, int index, Object value) Writes an Object element at the given index without bounds check. | native static void | staticUnlockArray(Object array, long addr) | native static void | staticUnlockArrayNoCopy(Object array, long addr) |
objectLockMap | final static HashMap objectLockMap(Code) | | Internal hash which keeps the record for all locked arrays.
|
createArray | public Object createArray(Class type, int size)(Code) | | Allocates a primitive type array that will be locked. The purpose of this
method is to give a hint to object allocator that an array will be locked.
This may help to increase the performance on certain virtual machine
implementations.
Parameters: type - the primitive type class. For example, use theInteger.TYPEto specify the array of integers. Parameters: size - number of elements in the array allocated array |
createLockedArrayLong | public LockedArray createLockedArrayLong(Class type, int size)(Code) | | Allocates and immediately locks a primitive type array for supposedly a
long period of time. The purpose of this method is to give a hint to
object allocator that an array needs to be locked initially. This may
help to increase the performance on certain virtual machine
implementations.
Parameters: type - the primitive type class. For example, use theInteger.TYPEto specify the array of integers. Parameters: size - number of elements in the array allocated array See Also: ArrayAccessor.lockArrayLong(Object) See Also: LockedArray.getAddress |
createLockedArrayShort | public LockedArray createLockedArrayShort(Class type, int size)(Code) | | Allocates and immediately locks a primitive type array for supposedly a
short period of time. The purpose of this method is to give a hint to
object allocator that an array needs to be locked initially. This may
help to increase the performance on certain virtual machine
implementations. Use the
LockedArray.release method to unlock
the array after use.
Parameters: type - the primitive type class. For example, use theInteger.TYPEto specify the array of integers. Parameters: size - number of elements in the array allocated array See Also: ArrayAccessor.lockArrayShort(Object) See Also: LockedArray.getAddress |
getArrayBaseOffset | final public long getArrayBaseOffset(Class arrayClass)(Code) | | Reports the offset of the first element in the storage allocation of a
given array class.
Parameters: arrayClass - class of array (ex.: byte[].class) the first element location See Also: ArrayAccessor.getArrayElementSize(Class) |
getArrayElementSize | final public int getArrayElementSize(Class arrayClass)(Code) | | Reports the element size for addressing elements in the storage
allocation of a given array class.
Parameters: arrayClass - class of array (ex.: byte[].class) element size |
getElement | final native public byte getElement(byte[] arr, int index)(Code) | | Reads a byte element at the given index without bounds check.
See Also: ArrayAccessor.setElement(byte[],int,byte) Parameters: arr - array those element needs to be read Parameters: index - element index byte value of the element |
getElement | final native public boolean getElement(boolean[] arr, int index)(Code) | | Reads a boolean element at the given index without bounds check.
See Also: ArrayAccessor.setElement(boolean[],int,boolean) Parameters: arr - array those element needs to be read Parameters: index - element index boolean value of the element |
getElement | final native public char getElement(char[] arr, int index)(Code) | | Reads a char element at the given index without bounds check.
See Also: ArrayAccessor.setElement(char[],int,char) Parameters: arr - array those element needs to be read Parameters: index - element index char value of the element |
getElement | final native public short getElement(short[] arr, int index)(Code) | | Reads a short element at the given index without bounds check.
See Also: ArrayAccessor.setElement(short[],int,short) Parameters: arr - array those element needs to be read Parameters: index - element index short value of the element |
getElement | final native public int getElement(int[] arr, int index)(Code) | | Reads a int element at the given index without bounds check.
See Also: ArrayAccessor.setElement(int[],int,int) Parameters: arr - array those element needs to be read Parameters: index - element index int value of the element |
getElement | final native public long getElement(long[] arr, int index)(Code) | | Reads a long element at the given index without bounds check.
See Also: ArrayAccessor.setElement(long[],int,long) Parameters: arr - array those element needs to be read Parameters: index - element index long value of the element |
getElement | final native public float getElement(float[] arr, int index)(Code) | | Reads a float element at the given index without bounds check.
See Also: ArrayAccessor.setElement(float[],int,float) Parameters: arr - array those element needs to be read Parameters: index - element index float value of the element |
getElement | final native public double getElement(double[] arr, int index)(Code) | | Reads a double element at the given index without bounds check.
See Also: ArrayAccessor.setElement(double[],int,double) Parameters: arr - array those element needs to be read Parameters: index - element index double value of the element |
lockArrayLong | public LockedArray lockArrayLong(Object array)(Code) | | Locks an existing array for supposedly a long period of time and returns
its location in memory. Typically, this method would instruct a virtual
machine that the given array should stay unmovable for a long period of
time. As a consequence, this method call may be expensive potentially may
reduce GC efficiency. Use the
ArrayAccessor.lockArrayShort(Object) method in
case the array needs to be locked only for a short period of time. This
method returns an instance of
LockedArray object which can then
be queried for the array memory location. To unlock the array, use the
LockedArray.release method.
Default implementation of this method delegates to the
GetXXXArrayElements JNI call.
See Also: ArrayAccessor.lockArrayShort(Object) See Also: LockedArray.release See Also: LockedArray.getAddress throws: RuntimeException - if array is already locked. throws: NullPointerException - if array is null . Parameters: array - an array of primitive type to lock locked array object |
releaseArray | static void releaseArray(Object array, long addr, boolean longLock)(Code) | | |
releaseArrayNoCopy | static void releaseArrayNoCopy(Object array, long addr, boolean longLock)(Code) | | |
setElement | final native public void setElement(byte[] arr, int index, byte value)(Code) | | Writes a byte element at the given index without bounds check.
See Also: ArrayAccessor.getElement(byte[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a byte value to be set |
setElement | final native public void setElement(boolean[] arr, int index, boolean value)(Code) | | Writes a boolean element at the given index without bounds check.
See Also: ArrayAccessor.getElement(boolean[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a boolean value to be set |
setElement | final native public void setElement(char[] arr, int index, char value)(Code) | | Writes a char element at the given index without bounds check.
See Also: ArrayAccessor.getElement(char[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a char value to be set |
setElement | final native public void setElement(short[] arr, int index, short value)(Code) | | Writes a short element at the given index without bounds check.
See Also: ArrayAccessor.getElement(short[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a short value to be set |
setElement | final native public void setElement(int[] arr, int index, int value)(Code) | | Writes a int element at the given index without bounds check.
See Also: ArrayAccessor.getElement(int[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a int value to be set |
setElement | final native public void setElement(long[] arr, int index, long value)(Code) | | Writes a long element at the given index without bounds check.
See Also: ArrayAccessor.getElement(long[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a long value to be set |
setElement | final native public void setElement(float[] arr, int index, float value)(Code) | | Writes a float element at the given index without bounds check.
See Also: ArrayAccessor.getElement(float[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a float value to be set |
setElement | final native public void setElement(double[] arr, int index, double value)(Code) | | Writes a double element at the given index without bounds check.
See Also: ArrayAccessor.getElement(double[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a double value to be set |
setElement | final native public void setElement(Object[] arr, int index, Object value)(Code) | | Writes an Object element at the given index without bounds check.
See Also: ArrayAccessor.getElement(Object[],int) Parameters: arr - array those element needs to be set Parameters: index - element index Parameters: value - a Object value to be set |
staticUnlockArray | native static void staticUnlockArray(Object array, long addr)(Code) | | |
staticUnlockArrayNoCopy | native static void staticUnlockArrayNoCopy(Object array, long addr)(Code) | | |
|
|