< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/VirtualArrayNode.java

Print this page




 120                 baseOffset = Unsafe.ARRAY_LONG_BASE_OFFSET;
 121                 indexScale = Unsafe.ARRAY_LONG_INDEX_SCALE;
 122                 break;
 123             case Float:
 124                 baseOffset = Unsafe.ARRAY_FLOAT_BASE_OFFSET;
 125                 indexScale = Unsafe.ARRAY_FLOAT_INDEX_SCALE;
 126                 break;
 127             case Double:
 128                 baseOffset = Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
 129                 indexScale = Unsafe.ARRAY_DOUBLE_INDEX_SCALE;
 130                 break;
 131             case Object:
 132                 baseOffset = Unsafe.ARRAY_OBJECT_BASE_OFFSET;
 133                 indexScale = Unsafe.ARRAY_OBJECT_INDEX_SCALE;
 134                 break;
 135             default:
 136                 return -1;
 137         }
 138         long offset;
 139         if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN && componentType.isPrimitive()) {
 140             // On big endian, we do just get expect the type be right aligned in this memory slot
 141             offset = constantOffset - (componentType.getJavaKind().getByteCount() - Math.min(componentType.getJavaKind().getByteCount(), 4 + expectedEntryKind.getByteCount()));

 142         } else {
 143             offset = constantOffset;
 144         }
 145         long index = offset - baseOffset;
 146         if (index % indexScale != 0) {
 147             return -1;
 148         }
 149         long elementIndex = index / indexScale;
 150         if (elementIndex < 0 || elementIndex >= length) {
 151             return -1;
 152         }
 153         return (int) elementIndex;
 154     }
 155 
 156     @Override
 157     public JavaKind entryKind(int index) {
 158         assert index >= 0 && index < length;
 159         return componentType.getJavaKind();
 160     }
 161 


 120                 baseOffset = Unsafe.ARRAY_LONG_BASE_OFFSET;
 121                 indexScale = Unsafe.ARRAY_LONG_INDEX_SCALE;
 122                 break;
 123             case Float:
 124                 baseOffset = Unsafe.ARRAY_FLOAT_BASE_OFFSET;
 125                 indexScale = Unsafe.ARRAY_FLOAT_INDEX_SCALE;
 126                 break;
 127             case Double:
 128                 baseOffset = Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
 129                 indexScale = Unsafe.ARRAY_DOUBLE_INDEX_SCALE;
 130                 break;
 131             case Object:
 132                 baseOffset = Unsafe.ARRAY_OBJECT_BASE_OFFSET;
 133                 indexScale = Unsafe.ARRAY_OBJECT_INDEX_SCALE;
 134                 break;
 135             default:
 136                 return -1;
 137         }
 138         long offset;
 139         if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN && componentType.isPrimitive()) {
 140             // On big endian, we expect the value to be correctly aligned in memory
 141             int componentByteCount = componentType.getJavaKind().getByteCount();
 142             offset = constantOffset - (componentByteCount - Math.min(componentByteCount, 4 + expectedEntryKind.getByteCount()));
 143         } else {
 144             offset = constantOffset;
 145         }
 146         long index = offset - baseOffset;
 147         if (index % indexScale != 0) {
 148             return -1;
 149         }
 150         long elementIndex = index / indexScale;
 151         if (elementIndex < 0 || elementIndex >= length) {
 152             return -1;
 153         }
 154         return (int) elementIndex;
 155     }
 156 
 157     @Override
 158     public JavaKind entryKind(int index) {
 159         assert index >= 0 && index < length;
 160         return componentType.getJavaKind();
 161     }
 162 
< prev index next >