Second JNI extension for flattened arrays

Frederic Parain frederic.parain at
Tue Dec 17 16:37:06 UTC 2019

Here’s a second JNI extension for flattened arrays.

The first extension (JDK-8234761) was designed to provide fast native access
to flattened arrays of pure primitives inline types.
This second extension has a different goal: it aims at providing easy access
to any kind of flattened array.

One pain point of flattened arrays is that even if a code needs a single
field from a flattened value stored in an array, it usually has to get
the whole element first, and then get the field from the element. With
flattened fields, this process can include several more steps to get the
flattened field before being able to get one field from this flattened field.

This proposal of a new JNI extension tries to avoid this burden by defining
the notion of sub-element and sub-element selector.

A sub-element represents either a whole element of a flattened array, or a
field stored in an element of a flattened array. A sub-element can be at
any level of nesting: if the array element includes flattened fields which
themselves include flattened field, any field of any of these flattened
fields is a sub-element. Any kind of field is a sub-element: primitive
fields, reference fields, or flattened fields.

The new JNI APIs provide a way to create sub-element selectors, Java objects
designating a particular sub-element of a flattened array. They also provide
methods to directly read or write sub-elements without having to go through
all steps of nesting.


Comments are welcome.

Thank you,


More information about the valhalla-dev mailing list