src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template
changeset 49788 5375d426822a
parent 47216 71c04702a3d5
child 52914 4fa75d8ad418
equal deleted inserted replaced
49787:99b627637911 49788:5375d426822a
   590         @Override
   590         @Override
   591         final MethodType accessModeTypeUncached(AccessMode accessMode) {
   591         final MethodType accessModeTypeUncached(AccessMode accessMode) {
   592             return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
   592             return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
   593         }
   593         }
   594 
   594 
       
   595 #if[Object]
       
   596         @ForceInline
       
   597         static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
       
   598             if (handle.arrayType == oarray.getClass()) {
       
   599                 // Fast path: static array type same as argument array type
       
   600                 return handle.componentType.cast(value);
       
   601             } else {
       
   602                 // Slow path: check value against argument array component type
       
   603                 return reflectiveTypeCheck(oarray, value);
       
   604             }
       
   605         }
       
   606 
       
   607         @ForceInline
       
   608         static Object reflectiveTypeCheck(Object[] oarray, Object value) {
       
   609             try {
       
   610                 return oarray.getClass().getComponentType().cast(value);
       
   611             } catch (ClassCastException e) {
       
   612                 throw new ArrayStoreException();
       
   613             }
       
   614         }
       
   615 #end[Object]
       
   616 
   595         @ForceInline
   617         @ForceInline
   596         static $type$ get(Array handle, Object oarray, int index) {
   618         static $type$ get(Array handle, Object oarray, int index) {
   597 #if[Object]
   619 #if[Object]
   598             Object[] array = (Object[]) handle.arrayType.cast(oarray);
   620             Object[] array = (Object[]) handle.arrayType.cast(oarray);
   599 #else[Object]
   621 #else[Object]
   630 #else[Object]
   652 #else[Object]
   631             $type$[] array = ($type$[]) oarray;
   653             $type$[] array = ($type$[]) oarray;
   632 #end[Object]
   654 #end[Object]
   633             UNSAFE.put$Type$Volatile(array,
   655             UNSAFE.put$Type$Volatile(array,
   634                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   656                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   635                     {#if[Object]?handle.componentType.cast(value):value});
   657                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   636         }
   658         }
   637 
   659 
   638         @ForceInline
   660         @ForceInline
   639         static $type$ getOpaque(Array handle, Object oarray, int index) {
   661         static $type$ getOpaque(Array handle, Object oarray, int index) {
   640 #if[Object]
   662 #if[Object]
   653 #else[Object]
   675 #else[Object]
   654             $type$[] array = ($type$[]) oarray;
   676             $type$[] array = ($type$[]) oarray;
   655 #end[Object]
   677 #end[Object]
   656             UNSAFE.put$Type$Opaque(array,
   678             UNSAFE.put$Type$Opaque(array,
   657                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   679                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   658                     {#if[Object]?handle.componentType.cast(value):value});
   680                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   659         }
   681         }
   660 
   682 
   661         @ForceInline
   683         @ForceInline
   662         static $type$ getAcquire(Array handle, Object oarray, int index) {
   684         static $type$ getAcquire(Array handle, Object oarray, int index) {
   663 #if[Object]
   685 #if[Object]
   676 #else[Object]
   698 #else[Object]
   677             $type$[] array = ($type$[]) oarray;
   699             $type$[] array = ($type$[]) oarray;
   678 #end[Object]
   700 #end[Object]
   679             UNSAFE.put$Type$Release(array,
   701             UNSAFE.put$Type$Release(array,
   680                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   702                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   681                     {#if[Object]?handle.componentType.cast(value):value});
   703                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   682         }
   704         }
   683 #if[CAS]
   705 #if[CAS]
   684 
   706 
   685         @ForceInline
   707         @ForceInline
   686         static boolean compareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   708         static boolean compareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   690             $type$[] array = ($type$[]) oarray;
   712             $type$[] array = ($type$[]) oarray;
   691 #end[Object]
   713 #end[Object]
   692             return UNSAFE.compareAndSet$Type$(array,
   714             return UNSAFE.compareAndSet$Type$(array,
   693                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   715                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   694                     {#if[Object]?handle.componentType.cast(expected):expected},
   716                     {#if[Object]?handle.componentType.cast(expected):expected},
   695                     {#if[Object]?handle.componentType.cast(value):value});
   717                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   696         }
   718         }
   697 
   719 
   698         @ForceInline
   720         @ForceInline
   699         static $type$ compareAndExchange(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   721         static $type$ compareAndExchange(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   700 #if[Object]
   722 #if[Object]
   703             $type$[] array = ($type$[]) oarray;
   725             $type$[] array = ($type$[]) oarray;
   704 #end[Object]
   726 #end[Object]
   705             return UNSAFE.compareAndExchange$Type$(array,
   727             return UNSAFE.compareAndExchange$Type$(array,
   706                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   728                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   707                     {#if[Object]?handle.componentType.cast(expected):expected},
   729                     {#if[Object]?handle.componentType.cast(expected):expected},
   708                     {#if[Object]?handle.componentType.cast(value):value});
   730                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   709         }
   731         }
   710 
   732 
   711         @ForceInline
   733         @ForceInline
   712         static $type$ compareAndExchangeAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   734         static $type$ compareAndExchangeAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   713 #if[Object]
   735 #if[Object]
   716             $type$[] array = ($type$[]) oarray;
   738             $type$[] array = ($type$[]) oarray;
   717 #end[Object]
   739 #end[Object]
   718             return UNSAFE.compareAndExchange$Type$Acquire(array,
   740             return UNSAFE.compareAndExchange$Type$Acquire(array,
   719                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   741                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   720                     {#if[Object]?handle.componentType.cast(expected):expected},
   742                     {#if[Object]?handle.componentType.cast(expected):expected},
   721                     {#if[Object]?handle.componentType.cast(value):value});
   743                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   722         }
   744         }
   723 
   745 
   724         @ForceInline
   746         @ForceInline
   725         static $type$ compareAndExchangeRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   747         static $type$ compareAndExchangeRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   726 #if[Object]
   748 #if[Object]
   729             $type$[] array = ($type$[]) oarray;
   751             $type$[] array = ($type$[]) oarray;
   730 #end[Object]
   752 #end[Object]
   731             return UNSAFE.compareAndExchange$Type$Release(array,
   753             return UNSAFE.compareAndExchange$Type$Release(array,
   732                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   754                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   733                     {#if[Object]?handle.componentType.cast(expected):expected},
   755                     {#if[Object]?handle.componentType.cast(expected):expected},
   734                     {#if[Object]?handle.componentType.cast(value):value});
   756                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   735         }
   757         }
   736 
   758 
   737         @ForceInline
   759         @ForceInline
   738         static boolean weakCompareAndSetPlain(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   760         static boolean weakCompareAndSetPlain(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   739 #if[Object]
   761 #if[Object]
   742             $type$[] array = ($type$[]) oarray;
   764             $type$[] array = ($type$[]) oarray;
   743 #end[Object]
   765 #end[Object]
   744             return UNSAFE.weakCompareAndSet$Type$Plain(array,
   766             return UNSAFE.weakCompareAndSet$Type$Plain(array,
   745                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   767                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   746                     {#if[Object]?handle.componentType.cast(expected):expected},
   768                     {#if[Object]?handle.componentType.cast(expected):expected},
   747                     {#if[Object]?handle.componentType.cast(value):value});
   769                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   748         }
   770         }
   749 
   771 
   750         @ForceInline
   772         @ForceInline
   751         static boolean weakCompareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   773         static boolean weakCompareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   752 #if[Object]
   774 #if[Object]
   755             $type$[] array = ($type$[]) oarray;
   777             $type$[] array = ($type$[]) oarray;
   756 #end[Object]
   778 #end[Object]
   757             return UNSAFE.weakCompareAndSet$Type$(array,
   779             return UNSAFE.weakCompareAndSet$Type$(array,
   758                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   780                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   759                     {#if[Object]?handle.componentType.cast(expected):expected},
   781                     {#if[Object]?handle.componentType.cast(expected):expected},
   760                     {#if[Object]?handle.componentType.cast(value):value});
   782                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   761         }
   783         }
   762 
   784 
   763         @ForceInline
   785         @ForceInline
   764         static boolean weakCompareAndSetAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   786         static boolean weakCompareAndSetAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   765 #if[Object]
   787 #if[Object]
   768             $type$[] array = ($type$[]) oarray;
   790             $type$[] array = ($type$[]) oarray;
   769 #end[Object]
   791 #end[Object]
   770             return UNSAFE.weakCompareAndSet$Type$Acquire(array,
   792             return UNSAFE.weakCompareAndSet$Type$Acquire(array,
   771                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   793                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   772                     {#if[Object]?handle.componentType.cast(expected):expected},
   794                     {#if[Object]?handle.componentType.cast(expected):expected},
   773                     {#if[Object]?handle.componentType.cast(value):value});
   795                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   774         }
   796         }
   775 
   797 
   776         @ForceInline
   798         @ForceInline
   777         static boolean weakCompareAndSetRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   799         static boolean weakCompareAndSetRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
   778 #if[Object]
   800 #if[Object]
   781             $type$[] array = ($type$[]) oarray;
   803             $type$[] array = ($type$[]) oarray;
   782 #end[Object]
   804 #end[Object]
   783             return UNSAFE.weakCompareAndSet$Type$Release(array,
   805             return UNSAFE.weakCompareAndSet$Type$Release(array,
   784                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   806                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   785                     {#if[Object]?handle.componentType.cast(expected):expected},
   807                     {#if[Object]?handle.componentType.cast(expected):expected},
   786                     {#if[Object]?handle.componentType.cast(value):value});
   808                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   787         }
   809         }
   788 
   810 
   789         @ForceInline
   811         @ForceInline
   790         static $type$ getAndSet(Array handle, Object oarray, int index, $type$ value) {
   812         static $type$ getAndSet(Array handle, Object oarray, int index, $type$ value) {
   791 #if[Object]
   813 #if[Object]
   793 #else[Object]
   815 #else[Object]
   794             $type$[] array = ($type$[]) oarray;
   816             $type$[] array = ($type$[]) oarray;
   795 #end[Object]
   817 #end[Object]
   796             return UNSAFE.getAndSet$Type$(array,
   818             return UNSAFE.getAndSet$Type$(array,
   797                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   819                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   798                     {#if[Object]?handle.componentType.cast(value):value});
   820                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   799         }
   821         }
   800 
   822 
   801         @ForceInline
   823         @ForceInline
   802         static $type$ getAndSetAcquire(Array handle, Object oarray, int index, $type$ value) {
   824         static $type$ getAndSetAcquire(Array handle, Object oarray, int index, $type$ value) {
   803 #if[Object]
   825 #if[Object]
   805 #else[Object]
   827 #else[Object]
   806             $type$[] array = ($type$[]) oarray;
   828             $type$[] array = ($type$[]) oarray;
   807 #end[Object]
   829 #end[Object]
   808             return UNSAFE.getAndSet$Type$Acquire(array,
   830             return UNSAFE.getAndSet$Type$Acquire(array,
   809                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   831                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   810                     {#if[Object]?handle.componentType.cast(value):value});
   832                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   811         }
   833         }
   812 
   834 
   813         @ForceInline
   835         @ForceInline
   814         static $type$ getAndSetRelease(Array handle, Object oarray, int index, $type$ value) {
   836         static $type$ getAndSetRelease(Array handle, Object oarray, int index, $type$ value) {
   815 #if[Object]
   837 #if[Object]
   817 #else[Object]
   839 #else[Object]
   818             $type$[] array = ($type$[]) oarray;
   840             $type$[] array = ($type$[]) oarray;
   819 #end[Object]
   841 #end[Object]
   820             return UNSAFE.getAndSet$Type$Release(array,
   842             return UNSAFE.getAndSet$Type$Release(array,
   821                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   843                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
   822                     {#if[Object]?handle.componentType.cast(value):value});
   844                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
   823         }
   845         }
   824 #end[CAS]
   846 #end[CAS]
   825 #if[AtomicAdd]
   847 #if[AtomicAdd]
   826 
   848 
   827         @ForceInline
   849         @ForceInline