Skip to content

Commit

Permalink
8281855: Rename ResourceScope to MemorySession
Browse files Browse the repository at this point in the history
Reviewed-by: psandoz, jvernee
  • Loading branch information
mcimadamore committed Feb 21, 2022
1 parent 14b6c7b commit 9214de4
Show file tree
Hide file tree
Showing 135 changed files with 2,595 additions and 2,427 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/scopedMemoryAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ JVM_END
#define PKG_FOREIGN "Ljava/lang/foreign/"

#define MEMACCESS "ScopedMemoryAccess"
#define SCOPE PKG_FOREIGN "ResourceScope;"
#define SCOPE PKG_FOREIGN "MemorySession;"

#define CC (char*) /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.io.File;
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.NativeSymbol;
import java.lang.foreign.ResourceScope;
import java.lang.foreign.MemorySession;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
Expand All @@ -59,7 +59,7 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import jdk.internal.foreign.ResourceScopeImpl;
import jdk.internal.foreign.MemorySessionImpl;
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.BuiltinClassLoader;
import jdk.internal.loader.ClassLoaders;
Expand Down Expand Up @@ -2476,9 +2476,9 @@ public final Optional<NativeSymbol> findNative(String name) {
: Optional.of(NativeSymbol.ofAddress(name, addr, loaderScope));
}

// A resource scope which keeps this loader reachable. Useful when returning
// A memory session which keeps this loader reachable. Useful when returning
// native symbols associated with libraries loaded by this loader.
private final ResourceScope loaderScope = ResourceScopeImpl.heapScope(this);
private final MemorySession loaderScope = MemorySessionImpl.heapSession(this);

// -- Assertion management --

Expand Down
28 changes: 14 additions & 14 deletions src/java.base/share/classes/java/lang/foreign/CLinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
*
* <h2><a id = "upcall-stubs">Upcall stubs</a></h2>
*
* {@linkplain #upcallStub(MethodHandle, FunctionDescriptor, ResourceScope) Creating an upcall stub} requires a method
* {@linkplain #upcallStub(MethodHandle, FunctionDescriptor, MemorySession) Creating an upcall stub} requires a method
* handle and a function descriptor; in this case, the set of memory layouts in the function descriptor
* specify the signature of the function pointer associated with the upcall stub.
* <p>
Expand All @@ -103,7 +103,7 @@
* </ul>
* Upcall stubs are modelled by instances of type {@link NativeSymbol}; upcall stubs can be passed by reference to other
* downcall method handles (as {@link NativeSymbol} implements the {@link Addressable} interface) and,
* when no longer required, they can be {@link ResourceScope#close() released}, via their {@linkplain NativeSymbol#scope() scope}.
* when no longer required, they can be {@link MemorySession#close() released}, via their associated {@linkplain MemorySession session}.
*
* <h2>Symbol lookup</h2>
* Clients can {@linkplain #lookup(String) look up} symbols in the standard libraries associated with this linker.
Expand All @@ -119,11 +119,11 @@
* the linker runtime guarantees the following for any argument that is a memory resource {@code R} (of type {@link MemorySegment},
* {@link NativeSymbol} or {@link VaList}):
* <ul>
* <li>The resource scope of {@code R} is {@linkplain ResourceScope#isAlive() alive}. Otherwise, the invocation throws
* <li>The memory session of {@code R} is {@linkplain MemorySession#isAlive() alive}. Otherwise, the invocation throws
* {@link IllegalStateException};</li>
* <li>The invocation occurs in same thread as the one {@link ResourceScope#ownerThread() owning} the resource scope of {@code R},
* if said scope is confined. Otherwise, the invocation throws {@link IllegalStateException}; and</li>
* <li>The scope of {@code R} is {@linkplain ResourceScope#keepAlive(ResourceScope) kept alive} (and cannot be closed) during the invocation.
* <li>The invocation occurs in same thread as the one {@link MemorySession#ownerThread() owning} the memory session of {@code R},
* if said session is confined. Otherwise, the invocation throws {@link IllegalStateException}; and</li>
* <li>The memory session of {@code R} is {@linkplain MemorySession#whileAlive(Runnable) kept alive} (and cannot be closed) during the invocation.
*</ul>
* <p>
* When creating upcall stubs the linker runtime validates the type of the target method handle against the provided
Expand Down Expand Up @@ -216,11 +216,11 @@ default MethodHandle downcallHandle(NativeSymbol symbol, FunctionDescriptor func
MethodHandle downcallHandle(FunctionDescriptor function);

/**
* Allocates a native stub with given scope which can be passed to other foreign functions (as a function pointer);
* calling such a function pointer from native code will result in the execution of the provided method handle.
*
* Allocates a native stub which can be passed to other foreign functions (as a function pointer), with given
* memory session. Calling such a function pointer from native code will result in the execution of the provided
* method handle.
* <p>
* The returned function pointer is associated with the provided scope. When such scope is closed,
* The returned function pointer is associated with the provided memory session. When such session is closed,
* the corresponding native stub will be deallocated.
* <p>
* The target method handle should not throw any exceptions. If the target method handle does throw an exception,
Expand All @@ -231,15 +231,15 @@ default MethodHandle downcallHandle(NativeSymbol symbol, FunctionDescriptor func
*
* @param target the target method handle.
* @param function the function descriptor.
* @param scope the upcall stub scope.
* @param session the upcall stub memory session.
* @return the native stub symbol.
* @throws IllegalArgumentException if the provided descriptor contains either a sequence or a padding layout,
* or if it is determined that the target method handle can throw an exception, or if the target method handle
* has a type that does not match the upcall stub <a href="CLinker.html#upcall-stubs"><em>inferred type</em></a>.
* @throws IllegalStateException if {@code scope} has been already closed, or if access occurs from a thread other
* than the thread owning {@code scope}.
* @throws IllegalStateException if {@code session} is not {@linkplain MemorySession#isAlive() alive}, or if access occurs from
* a thread other than the thread {@linkplain MemorySession#ownerThread() owning} {@code session}.
*/
NativeSymbol upcallStub(MethodHandle target, FunctionDescriptor function, ResourceScope scope);
NativeSymbol upcallStub(MethodHandle target, FunctionDescriptor function, MemorySession session);

/**
* Obtains the downcall method handle {@linkplain MethodType type} associated with a given function descriptor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* <li>By calling {@link Addressable#address()} on an instance of type {@link Addressable} (e.g. a memory segment);</li>
* <li>By invoking a {@linkplain CLinker#downcallHandle(FunctionDescriptor) downcall method handle} which returns a pointer;</li>
* <li>By reading an address from memory, e.g. via {@link MemorySegment#get(ValueLayout.OfAddress, long)}.</li>
* <li>By the invocation of an {@linkplain CLinker#upcallStub(MethodHandle, FunctionDescriptor, ResourceScope) upcall stub} which accepts a pointer.
* <li>By the invocation of an {@linkplain CLinker#upcallStub(MethodHandle, FunctionDescriptor, MemorySession) upcall stub} which accepts a pointer.
* </ul>
* A memory address is backed by a raw machine pointer, expressed as a {@linkplain #toRawLongValue() long value}.
*
Expand Down
Loading

0 comments on commit 9214de4

Please sign in to comment.