8317819: Scope should reflect lifetime of underying resource (mainline)

Reviewed-by: jvernee
This commit is contained in:
Maurizio Cimadamore 2023-10-20 10:23:45 +00:00
parent 6f1d8962df
commit b07da3ae15
12 changed files with 254 additions and 64 deletions

View file

@ -165,7 +165,7 @@ public interface SymbolLookup {
* <p>
* Libraries associated with a class loader are unloaded when the class loader becomes
* <a href="../../../java/lang/ref/package.html#reachability">unreachable</a>. The symbol lookup
* returned by this method is associated with a fresh {@linkplain MemorySegment.Scope scope} which keeps the caller's
* returned by this method is associated with an automatic {@linkplain MemorySegment.Scope scope} which keeps the caller's
* class loader reachable. Therefore, libraries associated with the caller's class loader are kept loaded
* (and their symbols available) as long as a loader lookup for that class loader, or any of the segments
* obtained by it, is reachable.
@ -189,7 +189,7 @@ public interface SymbolLookup {
if ((loader == null || loader instanceof BuiltinClassLoader)) {
loaderArena = Arena.global();
} else {
MemorySessionImpl session = MemorySessionImpl.heapSession(loader);
MemorySessionImpl session = MemorySessionImpl.createHeap(loader);
loaderArena = session.asArena();
}
return name -> {