RFR: JNI support for flattened arrays

Frederic Parain frederic.parain at oracle.com
Fri Nov 22 21:08:08 UTC 2019

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

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).


Thank you,


More information about the valhalla-dev mailing list