-
Enhancement
-
Resolution: Unresolved
-
P3
-
22, 23, 24
Today, it is possible to read a Java `String` from a `MemorySegment` that is returned from native calls (e.g. `char*`). The client has to reinterpret such a `MemorySegment` (as it initially has a size of zero) and then call other methods to convert the content of the segment to a Java `String`.
This is inconvenient and also exposes non-obvious problems where the C2 complier might think that the segment is much larger than the portion up until the first null terminator. In such cases, auto-vectorization and unrolling might create code that addresses out-of-valid memory.
One of many solutions to this would be to add a restricted method that safely can convert a zero-sized `MemorySegment` to a Java `String`, for example by respecting block/cache-line sizes.
This is inconvenient and also exposes non-obvious problems where the C2 complier might think that the segment is much larger than the portion up until the first null terminator. In such cases, auto-vectorization and unrolling might create code that addresses out-of-valid memory.
One of many solutions to this would be to add a restricted method that safely can convert a zero-sized `MemorySegment` to a Java `String`, for example by respecting block/cache-line sizes.