Java Doc for ArrayAccessor.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » misc » accessors » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.misc.accessors 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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  HashMapobjectLockMap
     Internal hash which keeps the record for all locked arrays.


Method Summary
public  ObjectcreateArray(Class type, int size)
     Allocates a primitive type array that will be locked.
public  LockedArraycreateLockedArrayLong(Class type, int size)
     Allocates and immediately locks a primitive type array for supposedly a long period of time.
public  LockedArraycreateLockedArrayShort(Class type, int size)
     Allocates and immediately locks a primitive type array for supposedly a short period of time.
final public  longgetArrayBaseOffset(Class arrayClass)
     Reports the offset of the first element in the storage allocation of a given array class.
final public  intgetArrayElementSize(Class arrayClass)
     Reports the element size for addressing elements in the storage allocation of a given array class.
final native public  bytegetElement(byte[] arr, int index)
     Reads a byte element at the given index without bounds check.
final native public  booleangetElement(boolean[] arr, int index)
     Reads a boolean element at the given index without bounds check.
final native public  chargetElement(char[] arr, int index)
     Reads a char element at the given index without bounds check.
final native public  shortgetElement(short[] arr, int index)
     Reads a short element at the given index without bounds check.
final native public  intgetElement(int[] arr, int index)
     Reads a int element at the given index without bounds check.
final native public  longgetElement(long[] arr, int index)
     Reads a long element at the given index without bounds check.
final native public  floatgetElement(float[] arr, int index)
     Reads a float element at the given index without bounds check.
final native public  doublegetElement(double[] arr, int index)
     Reads a double element at the given index without bounds check.
final native public  ObjectgetElement(Object[] arr, int index)
     Reads an Object element at the given index without bounds check.
static  ArrayAccessorgetInstance()
    
public  LockedArraylockArrayLong(Object array)
     Locks an existing array for supposedly a long period of time and returns its location in memory.
public  LockedArraylockArrayShort(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  voidreleaseArray(Object array, long addr, boolean longLock)
    
static  voidreleaseArrayNoCopy(Object array, long addr, boolean longLock)
    
final native public  voidsetElement(byte[] arr, int index, byte value)
     Writes a byte element at the given index without bounds check.
final native public  voidsetElement(boolean[] arr, int index, boolean value)
     Writes a boolean element at the given index without bounds check.
final native public  voidsetElement(char[] arr, int index, char value)
     Writes a char element at the given index without bounds check.
final native public  voidsetElement(short[] arr, int index, short value)
     Writes a short element at the given index without bounds check.
final native public  voidsetElement(int[] arr, int index, int value)
     Writes a int element at the given index without bounds check.
final native public  voidsetElement(long[] arr, int index, long value)
     Writes a long element at the given index without bounds check.
final native public  voidsetElement(float[] arr, int index, float value)
     Writes a float element at the given index without bounds check.
final native public  voidsetElement(double[] arr, int index, double value)
     Writes a double element at the given index without bounds check.
final native public  voidsetElement(Object[] arr, int index, Object value)
     Writes an Object element at the given index without bounds check.
native static  voidstaticUnlockArray(Object array, long addr)
    
native static  voidstaticUnlockArrayNoCopy(Object array, long addr)
    

Field Detail
objectLockMap
final static HashMap objectLockMap(Code)
Internal hash which keeps the record for all locked arrays.





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



getElement
final native public Object getElement(Object[] arr, int index)(Code)
Reads an Object element at the given index without bounds check.
See Also:   ArrayAccessor.setElement(Object[],int,Object)
Parameters:
  arr - array those element needs to be read
Parameters:
  index - element index Object value of the element



getInstance
static ArrayAccessor getInstance()(Code)



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




lockArrayShort
public LockedArray lockArrayShort(Object array)(Code)
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. This method returns an instance of LockedArray object which can be queried for the array memory location. Use the LockedArray.release method to unlock the array after use.

Default implementation of this method delegates to the GetPrimitiveArrayCritical JNI call.

Please note that synchronization and waiting (including native) must be avoided between ArrayAccessor.lockArrayShort(Object) and LockedArray.release calls. If the array needs to be locked for a long period of time, it is recommended to use the ArrayAccessor.lockArrayLong(Object) method.
See Also:   ArrayAccessor.lockArrayLong(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)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.