OSGeo / PROJ-JNI

Java Native Interface for PROJ
https://osgeo.github.io/PROJ-JNI/
MIT License
23 stars 15 forks source link

Verify pertinence of using GetPrimitiveArrayCritical #19

Closed desruisseaux closed 4 years ago

desruisseaux commented 5 years ago

The Java_org_kortforsyningen_proj_Transform_transform method gets an access to the Java double[] array by a call to the JNI function GetPrimitiveArrayCritical. Compared to the more usual GetDoubleArrayElements function, the "critical" version increases the chances to avoid an array copy, but at the cost of some restrictions. We should verify if it really avoids a copy. If not, GetDoubleArrayRegion would be a better alternative.

desruisseaux commented 4 years ago

Tests suggest that GetPrimitiveArrayCritical(…) has the desired behaviour (to not copy data) at least on my Linux machine. Consequently we do not implement the alternative approach based on GetDoubleArrayRegion(…) for now, but we log a warning if a copy has been done so we know that a particular platform may have a performance issue. The logging message is:

Java Native Interface (JNI) had to copy coordinate array on this platform. This constraint may reduce performance.

The logging level is DEBUG (map to FINE in java.util.logging).

Note: reading the documentation of IBM virtual machine and Android suggests that the use of GetPrimitiveArrayCritical instead of GetDoubleArrayElements really increase the chances of getting a direct access to the Java array elements.