RFR: JNI support for flattened arrays

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Dec 2 15:54:02 UTC 2019


Looks nice - at some point I'd like to experiment with this on the 
Panama side to e.g. build a Layout object out of an inline class which 
does not (transitively) contain oops. Then we could easily create an 
heap-based inline array, then move it off-heap using an array segment 
with the required layout.

Maurizio

On 22/11/2019 21:08, Frederic Parain wrote:
> Please review these changes adding JNI support for flattened arrays.
>
> The model for accessing flattened arrays from native code is the same
> as for primitive arrays, with these two new methods:
>
> void* (JNICALL *GetFlattenedArrayElements)
>         (JNIEnv* env, jarray array , jboolean *isCopy);
> void (JNICALL *ReleaseFlattenedArrayElements)
>         (JNIEnv* env, jarray, void* elem, jint mode);
>
> Native access to inline types arrays is allowed only if the array is
> flattened and array elements do not contain oops.
>
> However, native code needs more information to deal with inline types
> arrays:
>
> In order to get the size of an element of the array:
>
> jsize (JNICALL *GetFlattenedArrayElementSize)
>         (JNIEnv* env, jarray array);
>
> In order to get the class of the array elements:
>
> jclass (JNICALL *GetFlattenedArrayElementClass)
>         (JNIEnv* env, jarray array);
>
>
> An in order to get the offset of a field inside an array element, or
> inside a flattened field:
>
> jsize (JNICALL *GetFieldOffsetInFlattenedLayout)
>         (JNIEnv* env, jclass clazz,  const char *name, const char *signature, jboolean* isFlattened);
>
> The webrev includes tests showing examples on how to interact with
> a flattened array from native code (initialization, update, sorting).
>
> Webrev:
> http://cr.openjdk.java.net/~fparain/jniflattenedarrays/webrev.00/index.html
>
> Thank you,
>
> Fred
>   
>


More information about the valhalla-dev mailing list