-
Enhancement
-
Resolution: Unresolved
-
P3
-
None
-
22, 23, 24
-
None
The FFM API does not allow creating a memory segment view of a boolean array -- that is, MemorySegment::ofArray(boolean[]) does not exist. This means that bulk copy from a segment to a Java array is not supported -- this restriction is reflected in the lack of a SegmentAllocator::allocateFrom overload that works with a boolean[].
This asymmetry is not accidental: while boolean values in Java are stored as bytes, their values is always normalized to 0 (false) and 1 (true). This introduce a problem: if we allow copying data in bulk from a memory segment into a boolean[] there is a risk that non-normalized data might show up in the array. Which means we have a choice: either we support a slow bulk copy operation where values are normalized before being stored in a boolean[], or we do not support it at all. The FFM API opted for the latter option: all bulk operations are guaranteed to be fast (they just work on bytes) -- if additional normalization is required, clients can do so using a regular loop.
Unfortunately, this prevents future mapping of memory segments to composite data holders. Hence, it is proposed to strive for greater uniformity by allowing memory segment views of boolean[] -- and being extra careful in preserving important JVM invariants.
This asymmetry is not accidental: while boolean values in Java are stored as bytes, their values is always normalized to 0 (false) and 1 (true). This introduce a problem: if we allow copying data in bulk from a memory segment into a boolean[] there is a risk that non-normalized data might show up in the array. Which means we have a choice: either we support a slow bulk copy operation where values are normalized before being stored in a boolean[], or we do not support it at all. The FFM API opted for the latter option: all bulk operations are guaranteed to be fast (they just work on bytes) -- if additional normalization is required, clients can do so using a regular loop.
Unfortunately, this prevents future mapping of memory segments to composite data holders. Hence, it is proposed to strive for greater uniformity by allowing memory segment views of boolean[] -- and being extra careful in preserving important JVM invariants.