On Wed, 14 Oct 2026 11:52:44 GMT, Liam Miller-Cushon <[email protected]> wrote:

>> src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java line 497:
>> 
>>> 495:      * {@return a {@linkplain MemorySegment#isReadOnly() read-only} 
>>> {@link MemorySegment} of the given {@link String}}
>>> 496:      */
>>> 497:     MemorySegment asReadOnlyMemorySegment(String str);
>> 
>> I remember that, back when we started adding fast paths to bypass copying 
>> string contents into a temp byte array, we deliberately wanted not to expose 
>> the string contents directly as a memory segment, as we were afraid that 
>> this thing would get used in 100 other places in the JDK, and we'd lose a 
>> bit of control. I'm not sure how to square this circle in this new case -- 
>> because what you want is to create a vector given a segment/byte array, and 
>> vector is incubating, so references to vector API types from String are not 
>> really possible...
>
>> and vector is incubating, so references to vector API types from String are 
>> not really possible
> 
> Yes, I think that's the crux of it. I wondered if once Vector is 
> non-incubating perhaps the Vector-returning methods could be directly in JLA, 
> but I haven't tried that.
> 
> I switched to a read-only view based on Alan's comment about using the 
> mutable `byte[]`.
> 
> One short-term alternative might be to keep this out of JLA and create a 
> separate accessor that's only visible to `jdk.incubator.vector` instead of to 
> everything that can use JLA.

The latest version of this uses `VectorSupport` (see `StringVectorSupport`) to 
keep the values array encapsulated, the new `JavaLangAccess` API does a vector 
load instead of allowing access to the value array (or a `MemorySegment` view 
of it)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32373#discussion_r4652454499

Reply via email to