On Tue, 21 Jun 2022 16:10:24 GMT, Alan Bateman <[email protected]> wrote:
>> This is a dependent PR containing a cleanup of the so called *heap
>> sessions*. Heap sessions are used in two cases:
>>
>> * when a buffer segment is created, to keep the original buffer instance
>> reachable
>> * when a loader symbol lookup is created, to keep the classloader instance
>> reachable
>>
>> Spinning new sessions in these cases seems unnecessary, and inconsistent
>> with what we do for segments backed by on-heap arrays, whose session is set
>> to the global session. In that case, it's up to the segment to keep the
>> underlying array reachable. I think that's a better model.
>>
>> This patch adds the ability to attach Object references to native and mapped
>> memory segments, so that we can attach loader/byte buffer instances to these
>> segments, keeping them alive. This means that, in these cases we can go back
>> to just use the global memory session, like we do for array segments.
>>
>> This simplifies the implementation, makes the documentation more consistent,
>> and also simplifies the user model, as it removes a concept (of heap
>> session) that is not really documented anywhere. In fact, the javadoc for
>> MemorySegment::ofBuffer claims, (wrongly!) that the session of the resulting
>> segment is the global session - but that's not the case.
>
> src/java.base/share/classes/java/lang/foreign/SymbolLookup.java line 148:
>
>> 146: * <p>
>> 147: * The symbols obtained from the returned loader lookup are backed
>> by the {@linkplain MemorySession#global() global session}.
>> 148: * <p>
>
> Does the spec update mean this should have a CSR?
Yep - note that PR is in draft mode as we need to think through what changes we
actually want to pursue.
-------------
PR: https://git.openjdk.org/jdk19/pull/39