< prev index next >

src/java.base/share/classes/jdk/internal/misc/X-ScopedMemoryAccess.java.template

Print this page
*** 351,10 ***
--- 351,13 ---
  
          // ByteBuffer.hb
          static final long BYTE_BUFFER_HB
                  = UNSAFE.objectFieldOffset(ByteBuffer.class, "hb");
  
+         static final long BYTE_BUFFER_IS_READ_ONLY
+                 = UNSAFE.objectFieldOffset(ByteBuffer.class, "isReadOnly");
+ 
          @ForceInline
          static Object bufferBase(ByteBuffer bb) {
              return UNSAFE.getReference(bb, BYTE_BUFFER_HB);
          }
  

*** 371,17 ***
              return segmentProxy != null ?
                      segmentProxy.scope() : null;
          }
      }
  
      @ForceInline
      public static
      <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
      V loadFromByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
                            ByteBuffer bb, int offset,
                            S s,
!                           VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
          try {
              return loadFromByteBufferScoped(
                      BufferAccess.scope(bb),
                      vmClass, e, length,
                      bb, offset,
--- 374,22 ---
              return segmentProxy != null ?
                      segmentProxy.scope() : null;
          }
      }
  
+     @ForceInline
+     public static boolean isReadOnly(ByteBuffer bb) {
+         return UNSAFE.getBoolean(bb, BufferAccess.BYTE_BUFFER_IS_READ_ONLY);
+     }
+ 
      @ForceInline
      public static
      <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
      V loadFromByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
                            ByteBuffer bb, int offset,
                            S s,
!                           VectorSupport.LoadOperation<ByteBuffer, V, S> defaultImpl) {
          try {
              return loadFromByteBufferScoped(
                      BufferAccess.scope(bb),
                      vmClass, e, length,
                      bb, offset,

*** 398,18 ***
      <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
      V loadFromByteBufferScoped(ScopedMemoryAccess.Scope scope,
                            Class<? extends V> vmClass, Class<E> e, int length,
                            ByteBuffer bb, int offset,
                            S s,
!                           VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
          try {
              if (scope != null) {
                  scope.checkValidState();
              }
  
              return VectorSupport.load(vmClass, e, length,
!                     BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
                      bb, offset, s,
                      defaultImpl);
          } finally {
              Reference.reachabilityFence(scope);
          }
--- 406,63 ---
      <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
      V loadFromByteBufferScoped(ScopedMemoryAccess.Scope scope,
                            Class<? extends V> vmClass, Class<E> e, int length,
                            ByteBuffer bb, int offset,
                            S s,
!                           VectorSupport.LoadOperation<ByteBuffer, V, S> defaultImpl) {
          try {
              if (scope != null) {
                  scope.checkValidState();
              }
  
+             final byte[] base = (byte[]) BufferAccess.bufferBase(bb);
+ 
              return VectorSupport.load(vmClass, e, length,
!                       base, BufferAccess.bufferAddress(bb, offset),
+                       bb, offset, s,
+                       defaultImpl);
+         } finally {
+             Reference.reachabilityFence(scope);
+         }
+     }
+ 
+     @ForceInline
+     public static
+     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>,
+      M extends VectorSupport.VectorMask<E>>
+     V loadFromByteBufferMasked(Class<? extends V> vmClass, Class<M> maskClass, Class<E> e,
+                                int length, ByteBuffer bb, int offset, M m, S s,
+                                VectorSupport.LoadVectorMaskedOperation<ByteBuffer, V, S, M> defaultImpl) {
+         try {
+             return loadFromByteBufferMaskedScoped(
+                     BufferAccess.scope(bb),
+                     vmClass, maskClass, e, length,
+                     bb, offset, m,
+                     s,
+                     defaultImpl);
+         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
+             throw new IllegalStateException("This segment is already closed");
+         }
+     }
+ 
+     @Scoped
+     @ForceInline
+     private static
+     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>,
+      M extends VectorSupport.VectorMask<E>>
+     V loadFromByteBufferMaskedScoped(ScopedMemoryAccess.Scope scope, Class<? extends V> vmClass,
+                                      Class<M> maskClass, Class<E> e, int length,
+                                      ByteBuffer bb, int offset, M m,
+                                      S s,
+                                      VectorSupport.LoadVectorMaskedOperation<ByteBuffer, V, S, M> defaultImpl) {
+         try {
+             if (scope != null) {
+                 scope.checkValidState();
+             }
+ 
+             return VectorSupport.loadMasked(vmClass, maskClass, e, length,
+                     BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset), m,
                      bb, offset, s,
                      defaultImpl);
          } finally {
              Reference.reachabilityFence(scope);
          }

*** 446,21 ***
          try {
              if (scope != null) {
                  scope.checkValidState();
              }
  
              VectorSupport.store(vmClass, e, length,
                      BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
!                     v,
                      bb, offset,
                      defaultImpl);
          } finally {
              Reference.reachabilityFence(scope);
          }
      }
  
- 
      // typed-ops here
  
      // Note: all the accessor methods defined below take advantage of argument type profiling
      // (see src/hotspot/share/oops/methodData.cpp) which greatly enhances performance when the same accessor
      // method is used repeatedly with different 'base' objects.
--- 499,65 ---
          try {
              if (scope != null) {
                  scope.checkValidState();
              }
  
+             final byte[] base = (byte[]) BufferAccess.bufferBase(bb);
+ 
              VectorSupport.store(vmClass, e, length,
+                                 base, BufferAccess.bufferAddress(bb, offset),
+                                 v,
+                                 bb, offset,
+                                 defaultImpl);
+         } finally {
+             Reference.reachabilityFence(scope);
+         }
+     }
+ 
+     @ForceInline
+     public static
+     <V extends VectorSupport.Vector<E>, E, M extends VectorSupport.VectorMask<E>>
+     void storeIntoByteBufferMasked(Class<? extends V> vmClass, Class<M> maskClass, Class<E> e,
+                                    int length, V v, M m,
+                                    ByteBuffer bb, int offset,
+                                    VectorSupport.StoreVectorMaskedOperation<ByteBuffer, V, M> defaultImpl) {
+         try {
+             storeIntoByteBufferMaskedScoped(
+                     BufferAccess.scope(bb),
+                     vmClass, maskClass, e, length,
+                     v, m,
+                     bb, offset,
+                     defaultImpl);
+         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
+             throw new IllegalStateException("This segment is already closed");
+         }
+     }
+ 
+     @Scoped
+     @ForceInline
+     private static
+     <V extends VectorSupport.Vector<E>, E, M extends VectorSupport.VectorMask<E>>
+     void storeIntoByteBufferMaskedScoped(ScopedMemoryAccess.Scope scope,
+                                          Class<? extends V> vmClass, Class<M> maskClass,
+                                          Class<E> e, int length, V v, M m,
+                                          ByteBuffer bb, int offset,
+                                          VectorSupport.StoreVectorMaskedOperation<ByteBuffer, V, M> defaultImpl) {
+         try {
+             if (scope != null) {
+                 scope.checkValidState();
+             }
+ 
+             VectorSupport.storeMasked(vmClass, maskClass, e, length,
                      BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
!                     v, m,
                      bb, offset,
                      defaultImpl);
          } finally {
              Reference.reachabilityFence(scope);
          }
      }
  
      // typed-ops here
  
      // Note: all the accessor methods defined below take advantage of argument type profiling
      // (see src/hotspot/share/oops/methodData.cpp) which greatly enhances performance when the same accessor
      // method is used repeatedly with different 'base' objects.
< prev index next >