RFR: 8287788: Implement a better allocator for downcalls [v8]
Matthias Ernst
duke at openjdk.org
Thu Jan 23 13:09:51 UTC 2025
On Thu, 23 Jan 2025 12:59:53 GMT, Matthias Ernst <duke at openjdk.org> wrote:
>>> the shared memory segment is confined on the carrier thread
>>
>> But is it? When the CarrierThreadLocal is initialized, we may be executing in a VT and Arena.ofConfined will confine to it. We'd need something like an Arena.ofCarrierConfined() to make that work.
>
> I mean, it is totally possible:
>
> public PerThread(long size) {
> this.arena = MemorySessionImpl.createConfined(JLA.currentCarrierThread()).asArena();
> this.stack = new SlicingAllocator(arena.allocate(size));
> }
>
> public void close() {
> arena.close();
> }
Ah no, the allocate fails of course:
java.lang.WrongThreadException: Attempted access outside owning thread
at java.base/jdk.internal.foreign.MemorySessionImpl.wrongThread(MemorySessionImpl.java:322)
at java.base/jdk.internal.misc.ScopedMemoryAccess$ScopedAccessError.newRuntimeException(ScopedMemoryAccess.java:114)
at java.base/jdk.internal.foreign.MemorySessionImpl.checkValidState(MemorySessionImpl.java:217)
at java.base/jdk.internal.foreign.SegmentFactories.allocateSegment(SegmentFactories.java:181)
at java.base/jdk.internal.foreign.ArenaImpl.allocateNoInit(ArenaImpl.java:52)
at java.base/jdk.internal.foreign.ArenaImpl.allocate(ArenaImpl.java:57)
at java.base/jdk.internal.foreign.ArenaImpl.allocate(ArenaImpl.java:31)
at java.base/java.lang.foreign.SegmentAllocator.allocate(SegmentAllocator.java:644)
at java.base/jdk.internal.foreign.abi.BufferStack$PerThread.<init>(BufferStack.java:73)
at java.base/jdk.internal.foreign.abi.BufferStack$1.initialValue(BufferStack.java:50)
at java.base/jdk.internal.foreign.abi.BufferStack$1.initialValue(BufferStack.java:47)
at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:224)
at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:193)
at java.base/java.lang.ThreadLocal.getCarrierThreadLocal(ThreadLocal.java:180)
at java.base/java.lang.System$1.getCarrierThreadLocal(System.java:2237)
at java.base/jdk.internal.misc.CarrierThreadLocal.get(CarrierThreadLocal.java:39)
at java.base/jdk.internal.foreign.abi.BufferStack.pushFrame(BufferStack.java:61)
at TestBufferStack.lambda$stress$1(TestBufferStack.java:113)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23142#discussion_r1926950494
More information about the core-libs-dev
mailing list