< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/NativeMemorySegmentImpl.java

Print this page
@@ -26,12 +26,10 @@
  
  package jdk.internal.foreign;
  
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemorySegment;
- import jdk.incubator.foreign.ResourceScope;
- import jdk.incubator.foreign.SegmentAllocator;
  import jdk.internal.misc.Unsafe;
  import jdk.internal.misc.VM;
  import jdk.internal.vm.annotation.ForceInline;
  import sun.security.action.GetBooleanAction;
  

@@ -41,16 +39,14 @@
   * Implementation for native memory segments. A native memory segment is essentially a wrapper around
   * a native long address.
   */
  public class NativeMemorySegmentImpl extends AbstractMemorySegmentImpl {
  
-     public static final MemorySegment EVERYTHING = makeNativeSegmentUnchecked(MemoryAddress.NULL, Long.MAX_VALUE, null, ResourceScopeImpl.GLOBAL);
+     public static final MemorySegment EVERYTHING = makeNativeSegmentUnchecked(MemoryAddress.NULL, Long.MAX_VALUE, ResourceScopeImpl.GLOBAL);
  
      private static final Unsafe unsafe = Unsafe.getUnsafe();
  
-     public static final SegmentAllocator IMPLICIT_ALLOCATOR = (size, align) -> MemorySegment.allocateNative(size, align, ResourceScope.newImplicitScope());
- 
      // The maximum alignment supported by malloc - typically 16 on
      // 64-bit platforms and 8 on 32-bit platforms.
      private static final long MAX_MALLOC_ALIGN = Unsafe.ADDRESS_SIZE == 4 ? 8 : 16;
  
      private static final boolean skipZeroMemory = GetBooleanAction.privilegedGetProperty("jdk.internal.foreign.skipZeroMemory");

@@ -61,10 +57,17 @@
      NativeMemorySegmentImpl(long min, long length, int mask, ResourceScopeImpl scope) {
          super(length, mask, scope);
          this.min = min;
      }
  
+     @ForceInline
+     @Override
+     public MemoryAddress address() {
+         checkValidState();
+         return MemoryAddress.ofLong(unsafeGetOffset());
+     }
+ 
      @Override
      NativeMemorySegmentImpl dup(long offset, long size, int mask, ResourceScopeImpl scope) {
          return new NativeMemorySegmentImpl(min + offset, size, mask, scope);
      }
  

@@ -121,14 +124,11 @@
              segment = segment.asSlice(delta, bytesSize);
          }
          return segment;
      }
  
-     public static MemorySegment makeNativeSegmentUnchecked(MemoryAddress min, long bytesSize, Runnable cleanupAction, ResourceScopeImpl scope) {
+     public static MemorySegment makeNativeSegmentUnchecked(MemoryAddress min, long bytesSize, ResourceScopeImpl scope) {
          scope.checkValidStateSlow();
          AbstractMemorySegmentImpl segment = new NativeMemorySegmentImpl(min.toRawLongValue(), bytesSize, defaultAccessModes(bytesSize), scope);
-         if (cleanupAction != null) {
-             scope.addCloseAction(cleanupAction);
-         }
          return segment;
      }
  }
< prev index next >