< prev index next >

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

Print this page

336             }
337             SharedSecrets.getJavaNioAccess().force(fd, address, isSync, index, length);
338         } finally {
339             Reference.reachabilityFence(scope);
340         }
341     }
342 
343     // ByteBuffer vector access ops
344 
345     // Buffer access constants, to be initalized when required.
346     // Avoids a null value for NIO_ACCESS, due to class initalization dependencies
347     static final class BufferAccess {
348         // Buffer.address
349         static final long BUFFER_ADDRESS
350                 = UNSAFE.objectFieldOffset(Buffer.class, "address");
351 
352         // ByteBuffer.hb
353         static final long BYTE_BUFFER_HB
354                 = UNSAFE.objectFieldOffset(ByteBuffer.class, "hb");
355 



356         @ForceInline
357         static Object bufferBase(ByteBuffer bb) {
358             return UNSAFE.getReference(bb, BYTE_BUFFER_HB);
359         }
360 
361         @ForceInline
362         static long bufferAddress(ByteBuffer bb, long offset) {
363             return UNSAFE.getLong(bb, BUFFER_ADDRESS) + offset;
364         }
365 
366         static final JavaNioAccess NIO_ACCESS = SharedSecrets.getJavaNioAccess();
367 
368         @ForceInline
369         static ScopedMemoryAccess.Scope scope(ByteBuffer bb) {
370             MemorySegmentProxy segmentProxy = NIO_ACCESS.bufferSegment(bb);
371             return segmentProxy != null ?
372                     segmentProxy.scope() : null;
373         }
374     }
375 





376     @ForceInline
377     public static
378     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
379     V loadFromByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
380                           ByteBuffer bb, int offset,
381                           S s,
382                           VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
383         try {
384             return loadFromByteBufferScoped(
385                     BufferAccess.scope(bb),
386                     vmClass, e, length,
387                     bb, offset,
388                     s,
389                     defaultImpl);
390         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
391             throw new IllegalStateException("This segment is already closed");
392         }
393     }
394 
395     @Scoped
396     @ForceInline
397     private static
398     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
399     V loadFromByteBufferScoped(ScopedMemoryAccess.Scope scope,
400                           Class<? extends V> vmClass, Class<E> e, int length,
401                           ByteBuffer bb, int offset,
402                           S s,
403                           VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
404         try {
405             if (scope != null) {
406                 scope.checkValidState();
407             }
408 


409             return VectorSupport.load(vmClass, e, length,
410                     BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),











































411                     bb, offset, s,
412                     defaultImpl);
413         } finally {
414             Reference.reachabilityFence(scope);
415         }
416     }
417 
418     @ForceInline
419     public static
420     <V extends VectorSupport.Vector<E>, E>
421     void storeIntoByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
422                              V v,
423                              ByteBuffer bb, int offset,
424                              VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
425         try {
426             storeIntoByteBufferScoped(
427                     BufferAccess.scope(bb),
428                     vmClass, e, length,
429                     v,
430                     bb, offset,
431                     defaultImpl);
432         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
433             throw new IllegalStateException("This segment is already closed");
434         }
435     }
436 
437     @Scoped
438     @ForceInline
439     private static
440     <V extends VectorSupport.Vector<E>, E>
441     void storeIntoByteBufferScoped(ScopedMemoryAccess.Scope scope,
442                                    Class<? extends V> vmClass, Class<E> e, int length,
443                                    V v,
444                                    ByteBuffer bb, int offset,
445                                    VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
446         try {
447             if (scope != null) {
448                 scope.checkValidState();
449             }
450 


451             VectorSupport.store(vmClass, e, length,











































452                     BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
453                     v,
454                     bb, offset,
455                     defaultImpl);
456         } finally {
457             Reference.reachabilityFence(scope);
458         }
459     }
460 
461 
462     // typed-ops here
463 
464     // Note: all the accessor methods defined below take advantage of argument type profiling
465     // (see src/hotspot/share/oops/methodData.cpp) which greatly enhances performance when the same accessor
466     // method is used repeatedly with different 'base' objects.

336             }
337             SharedSecrets.getJavaNioAccess().force(fd, address, isSync, index, length);
338         } finally {
339             Reference.reachabilityFence(scope);
340         }
341     }
342 
343     // ByteBuffer vector access ops
344 
345     // Buffer access constants, to be initalized when required.
346     // Avoids a null value for NIO_ACCESS, due to class initalization dependencies
347     static final class BufferAccess {
348         // Buffer.address
349         static final long BUFFER_ADDRESS
350                 = UNSAFE.objectFieldOffset(Buffer.class, "address");
351 
352         // ByteBuffer.hb
353         static final long BYTE_BUFFER_HB
354                 = UNSAFE.objectFieldOffset(ByteBuffer.class, "hb");
355 
356         static final long BYTE_BUFFER_IS_READ_ONLY
357                 = UNSAFE.objectFieldOffset(ByteBuffer.class, "isReadOnly");
358 
359         @ForceInline
360         static Object bufferBase(ByteBuffer bb) {
361             return UNSAFE.getReference(bb, BYTE_BUFFER_HB);
362         }
363 
364         @ForceInline
365         static long bufferAddress(ByteBuffer bb, long offset) {
366             return UNSAFE.getLong(bb, BUFFER_ADDRESS) + offset;
367         }
368 
369         static final JavaNioAccess NIO_ACCESS = SharedSecrets.getJavaNioAccess();
370 
371         @ForceInline
372         static ScopedMemoryAccess.Scope scope(ByteBuffer bb) {
373             MemorySegmentProxy segmentProxy = NIO_ACCESS.bufferSegment(bb);
374             return segmentProxy != null ?
375                     segmentProxy.scope() : null;
376         }
377     }
378 
379     @ForceInline
380     public static boolean isReadOnly(ByteBuffer bb) {
381         return UNSAFE.getBoolean(bb, BufferAccess.BYTE_BUFFER_IS_READ_ONLY);
382     }
383 
384     @ForceInline
385     public static
386     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
387     V loadFromByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
388                           ByteBuffer bb, int offset,
389                           S s,
390                           VectorSupport.LoadOperation<ByteBuffer, V, S> defaultImpl) {
391         try {
392             return loadFromByteBufferScoped(
393                     BufferAccess.scope(bb),
394                     vmClass, e, length,
395                     bb, offset,
396                     s,
397                     defaultImpl);
398         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
399             throw new IllegalStateException("This segment is already closed");
400         }
401     }
402 
403     @Scoped
404     @ForceInline
405     private static
406     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
407     V loadFromByteBufferScoped(ScopedMemoryAccess.Scope scope,
408                           Class<? extends V> vmClass, Class<E> e, int length,
409                           ByteBuffer bb, int offset,
410                           S s,
411                           VectorSupport.LoadOperation<ByteBuffer, V, S> defaultImpl) {
412         try {
413             if (scope != null) {
414                 scope.checkValidState();
415             }
416 
417             final byte[] base = (byte[]) BufferAccess.bufferBase(bb);
418 
419             return VectorSupport.load(vmClass, e, length,
420                       base, BufferAccess.bufferAddress(bb, offset),
421                       bb, offset, s,
422                       defaultImpl);
423         } finally {
424             Reference.reachabilityFence(scope);
425         }
426     }
427 
428     @ForceInline
429     public static
430     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>,
431      M extends VectorSupport.VectorMask<E>>
432     V loadFromByteBufferMasked(Class<? extends V> vmClass, Class<M> maskClass, Class<E> e,
433                                int length, ByteBuffer bb, int offset, M m, S s,
434                                VectorSupport.LoadVectorMaskedOperation<ByteBuffer, V, S, M> defaultImpl) {
435         try {
436             return loadFromByteBufferMaskedScoped(
437                     BufferAccess.scope(bb),
438                     vmClass, maskClass, e, length,
439                     bb, offset, m,
440                     s,
441                     defaultImpl);
442         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
443             throw new IllegalStateException("This segment is already closed");
444         }
445     }
446 
447     @Scoped
448     @ForceInline
449     private static
450     <V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>,
451      M extends VectorSupport.VectorMask<E>>
452     V loadFromByteBufferMaskedScoped(ScopedMemoryAccess.Scope scope, Class<? extends V> vmClass,
453                                      Class<M> maskClass, Class<E> e, int length,
454                                      ByteBuffer bb, int offset, M m,
455                                      S s,
456                                      VectorSupport.LoadVectorMaskedOperation<ByteBuffer, V, S, M> defaultImpl) {
457         try {
458             if (scope != null) {
459                 scope.checkValidState();
460             }
461 
462             return VectorSupport.loadMasked(vmClass, maskClass, e, length,
463                     BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset), m,
464                     bb, offset, s,
465                     defaultImpl);
466         } finally {
467             Reference.reachabilityFence(scope);
468         }
469     }
470 
471     @ForceInline
472     public static
473     <V extends VectorSupport.Vector<E>, E>
474     void storeIntoByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
475                              V v,
476                              ByteBuffer bb, int offset,
477                              VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
478         try {
479             storeIntoByteBufferScoped(
480                     BufferAccess.scope(bb),
481                     vmClass, e, length,
482                     v,
483                     bb, offset,
484                     defaultImpl);
485         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
486             throw new IllegalStateException("This segment is already closed");
487         }
488     }
489 
490     @Scoped
491     @ForceInline
492     private static
493     <V extends VectorSupport.Vector<E>, E>
494     void storeIntoByteBufferScoped(ScopedMemoryAccess.Scope scope,
495                                    Class<? extends V> vmClass, Class<E> e, int length,
496                                    V v,
497                                    ByteBuffer bb, int offset,
498                                    VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
499         try {
500             if (scope != null) {
501                 scope.checkValidState();
502             }
503 
504             final byte[] base = (byte[]) BufferAccess.bufferBase(bb);
505 
506             VectorSupport.store(vmClass, e, length,
507                                 base, BufferAccess.bufferAddress(bb, offset),
508                                 v,
509                                 bb, offset,
510                                 defaultImpl);
511         } finally {
512             Reference.reachabilityFence(scope);
513         }
514     }
515 
516     @ForceInline
517     public static
518     <V extends VectorSupport.Vector<E>, E, M extends VectorSupport.VectorMask<E>>
519     void storeIntoByteBufferMasked(Class<? extends V> vmClass, Class<M> maskClass, Class<E> e,
520                                    int length, V v, M m,
521                                    ByteBuffer bb, int offset,
522                                    VectorSupport.StoreVectorMaskedOperation<ByteBuffer, V, M> defaultImpl) {
523         try {
524             storeIntoByteBufferMaskedScoped(
525                     BufferAccess.scope(bb),
526                     vmClass, maskClass, e, length,
527                     v, m,
528                     bb, offset,
529                     defaultImpl);
530         } catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
531             throw new IllegalStateException("This segment is already closed");
532         }
533     }
534 
535     @Scoped
536     @ForceInline
537     private static
538     <V extends VectorSupport.Vector<E>, E, M extends VectorSupport.VectorMask<E>>
539     void storeIntoByteBufferMaskedScoped(ScopedMemoryAccess.Scope scope,
540                                          Class<? extends V> vmClass, Class<M> maskClass,
541                                          Class<E> e, int length, V v, M m,
542                                          ByteBuffer bb, int offset,
543                                          VectorSupport.StoreVectorMaskedOperation<ByteBuffer, V, M> defaultImpl) {
544         try {
545             if (scope != null) {
546                 scope.checkValidState();
547             }
548 
549             VectorSupport.storeMasked(vmClass, maskClass, e, length,
550                     BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
551                     v, m,
552                     bb, offset,
553                     defaultImpl);
554         } finally {
555             Reference.reachabilityFence(scope);
556         }
557     }
558 

559     // typed-ops here
560 
561     // Note: all the accessor methods defined below take advantage of argument type profiling
562     // (see src/hotspot/share/oops/methodData.cpp) which greatly enhances performance when the same accessor
563     // method is used repeatedly with different 'base' objects.
< prev index next >