< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/UpcallStubs.java

Print this page
*** 23,22 ***
   * questions.
   */
  package jdk.internal.foreign.abi;
  
  import jdk.incubator.foreign.MemoryAddress;
! import jdk.incubator.foreign.MemorySegment;
  import jdk.internal.foreign.ResourceScopeImpl;
- import jdk.internal.foreign.NativeMemorySegmentImpl;
  
  public class UpcallStubs {
  
-     public static MemoryAddress upcallAddress(UpcallHandler handler, ResourceScopeImpl scope) {
-         long stubAddress = handler.entryPoint();
-         return NativeMemorySegmentImpl.makeNativeSegmentUnchecked(MemoryAddress.ofLong(stubAddress), 0,
-                 () -> freeUpcallStub(stubAddress), scope).address();
-     }
- 
      private static void freeUpcallStub(long stubAddress) {
          if (!freeUpcallStub0(stubAddress)) {
              throw new IllegalStateException("Not a stub address: " + stubAddress);
          }
      }
--- 23,17 ---
   * questions.
   */
  package jdk.internal.foreign.abi;
  
  import jdk.incubator.foreign.MemoryAddress;
! import jdk.incubator.foreign.NativeSymbol;
+ import jdk.incubator.foreign.ResourceScope;
+ import jdk.internal.foreign.NativeSymbolImpl;
  import jdk.internal.foreign.ResourceScopeImpl;
  
  public class UpcallStubs {
  
      private static void freeUpcallStub(long stubAddress) {
          if (!freeUpcallStub0(stubAddress)) {
              throw new IllegalStateException("Not a stub address: " + stubAddress);
          }
      }

*** 50,6 ***
--- 45,16 ---
  
      private static native void registerNatives();
      static {
          registerNatives();
      }
+ 
+     static NativeSymbol makeUpcall(long entry, ResourceScope scope) {
+         ((ResourceScopeImpl)scope).addOrCleanupIfFail(new ResourceScopeImpl.ResourceList.ResourceCleanup() {
+             @Override
+             public void cleanup() {
+                 freeUpcallStub(entry);
+             }
+         });
+         return new NativeSymbolImpl("upcall:" + Long.toHexString(entry), MemoryAddress.ofLong(entry), scope);
+     }
  }
< prev index next >