[foreign-memaccess+abi] RFR: 8317514: Ensure MemorySegment is initialized before touching NativeMemorySegmentImpl [v2]

Jorn Vernee jvernee at openjdk.org
Mon Oct 9 21:24:16 UTC 2023


On Mon, 9 Oct 2023 21:02:51 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Add test for FileChannel::map
>
> src/java.base/share/classes/jdk/internal/foreign/ArenaImpl.java line 40:
> 
>> 38:         // if multiple threads try to initialize NativeMemorySegmentImpl and MS through allocateNoInit
>> 39:         // and a method on MS at the same time
>> 40:         Unsafe.getUnsafe().ensureClassInitialized(MemorySegment.class);
> 
> If you want to avoid unsafe, another way is to use:
> https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#ensureInitialized(java.lang.Class)

Yeah. I figured using Unsafe is a little more lightweight, especially for FileChannel::map. Maybe it doesn't matter that much though.

Would you prefer using Methodhandles::ensureInitialized?

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

PR Review Comment: https://git.openjdk.org/panama-foreign/pull/902#discussion_r1350797048


More information about the panama-dev mailing list