Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350374

The FFM API should provide reading Strings safely from native calls

XMLWordPrintable

      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.

            pminborg Per-Ake Minborg
            pminborg Per-Ake Minborg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: