RFR: JNI support for flattened arrays

Frederic Parain frederic.parain at oracle.com
Mon Nov 25 20:09:04 UTC 2019


David,

Thank you for the review and for clarifying the motivation
of this work.
I’ve fixed the indentation in jni.h.

Fred


> On Nov 25, 2019, at 11:36, David Simms <david.simms at oracle.com> wrote:
> 
> 
> So there is an element of "you have got to know what you doing" with these APIs. But that is the nature of JNI itself.
> 
> So this does enable very specific use case where users wish to transfer the specific types of raw data, with no Java object references embedded, as that is not technically feasible just now (perhaps with some pinning). Get/SetObjectArrayElement provide a good general purpose solution for most...
> 
> ...however for raw performance, we need to open this possibility of using raw array data. Even for JDK internals, it would be nice to have in the repo. One might argue that Panama would be the way forward, but until it exists side by side we can't rely upon it's existence, or pretend to know each other's release schedules.
> 
> Code itself follows the rest, there is a small indent issue at jni.h:1905
> 
> ...otherwise, go and head and push.
> 
> /D
> 
> 
> On 2019-11-22 22: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