< prev index next >

src/java.base/share/classes/java/lang/invoke/VarHandles.java

Print this page




 145                        ? new VarHandleDoubles.FieldStaticReadOnly(base, foffset)
 146                        : new VarHandleDoubles.FieldStaticReadWrite(base, foffset);
 147             }
 148             else {
 149                 throw new UnsupportedOperationException();
 150             }
 151         }
 152     }
 153 
 154     static VarHandle makeArrayElementHandle(Class<?> arrayClass) {
 155         if (!arrayClass.isArray())
 156             throw new IllegalArgumentException("not an array: " + arrayClass);
 157 
 158         Class<?> componentType = arrayClass.getComponentType();
 159 
 160         int aoffset = UNSAFE.arrayBaseOffset(arrayClass);
 161         int ascale = UNSAFE.arrayIndexScale(arrayClass);
 162         int ashift = 31 - Integer.numberOfLeadingZeros(ascale);
 163 
 164         if (!componentType.isPrimitive()) {
 165             return new VarHandleObjects.Array(aoffset, ashift, arrayClass);





 166         }
 167         else if (componentType == boolean.class) {
 168             return new VarHandleBooleans.Array(aoffset, ashift);
 169         }
 170         else if (componentType == byte.class) {
 171             return new VarHandleBytes.Array(aoffset, ashift);
 172         }
 173         else if (componentType == short.class) {
 174             return new VarHandleShorts.Array(aoffset, ashift);
 175         }
 176         else if (componentType == char.class) {
 177             return new VarHandleChars.Array(aoffset, ashift);
 178         }
 179         else if (componentType == int.class) {
 180             return new VarHandleInts.Array(aoffset, ashift);
 181         }
 182         else if (componentType == long.class) {
 183             return new VarHandleLongs.Array(aoffset, ashift);
 184         }
 185         else if (componentType == float.class) {




 145                        ? new VarHandleDoubles.FieldStaticReadOnly(base, foffset)
 146                        : new VarHandleDoubles.FieldStaticReadWrite(base, foffset);
 147             }
 148             else {
 149                 throw new UnsupportedOperationException();
 150             }
 151         }
 152     }
 153 
 154     static VarHandle makeArrayElementHandle(Class<?> arrayClass) {
 155         if (!arrayClass.isArray())
 156             throw new IllegalArgumentException("not an array: " + arrayClass);
 157 
 158         Class<?> componentType = arrayClass.getComponentType();
 159 
 160         int aoffset = UNSAFE.arrayBaseOffset(arrayClass);
 161         int ascale = UNSAFE.arrayIndexScale(arrayClass);
 162         int ashift = 31 - Integer.numberOfLeadingZeros(ascale);
 163 
 164         if (!componentType.isPrimitive()) {
 165             // the redundant componentType.isValue() check is there to
 166             // minimize the performance impact to non-value array.
 167             // It should be removed when Unsafe::isFlattenedArray is intrinsified.
 168             return componentType.isValue() && UNSAFE.isFlattenedArray(arrayClass)
 169                 ? new VarHandleObjects.ValueArray(aoffset, ashift, arrayClass)
 170                 : new VarHandleObjects.Array(aoffset, ashift, arrayClass);
 171         }
 172         else if (componentType == boolean.class) {
 173             return new VarHandleBooleans.Array(aoffset, ashift);
 174         }
 175         else if (componentType == byte.class) {
 176             return new VarHandleBytes.Array(aoffset, ashift);
 177         }
 178         else if (componentType == short.class) {
 179             return new VarHandleShorts.Array(aoffset, ashift);
 180         }
 181         else if (componentType == char.class) {
 182             return new VarHandleChars.Array(aoffset, ashift);
 183         }
 184         else if (componentType == int.class) {
 185             return new VarHandleInts.Array(aoffset, ashift);
 186         }
 187         else if (componentType == long.class) {
 188             return new VarHandleLongs.Array(aoffset, ashift);
 189         }
 190         else if (componentType == float.class) {


< prev index next >