61 private static final Object[] ARRAY = new Object[10]; 62 63 private static final long F_OFFSET; 64 private static final long E_OFFSET; 65 66 static { 67 try { 68 Field field = OpaqueAccesses.class.getDeclaredField("f"); 69 F_OFFSET = UNSAFE.objectFieldOffset(field); 70 71 E_OFFSET = UNSAFE.arrayBaseOffset(ARRAY.getClass()); 72 } catch (NoSuchFieldException e) { 73 throw new Error(e); 74 } 75 } 76 77 private Object f = new Object(); 78 private long l1, l2; 79 80 static Object testFixedOffsetField(Object o) { 81 return UNSAFE.getObject(o, F_OFFSET); 82 } 83 84 static int testFixedOffsetHeader0(Object o) { 85 return UNSAFE.getInt(o, 0); 86 } 87 88 static int testFixedOffsetHeader4(Object o) { 89 return UNSAFE.getInt(o, 4); 90 } 91 92 static int testFixedOffsetHeader8(Object o) { 93 return UNSAFE.getInt(o, 8); 94 } 95 96 static int testFixedOffsetHeader12(Object o) { 97 return UNSAFE.getInt(o, 12); 98 } 99 100 static int testFixedOffsetHeader16(Object o) { 101 return UNSAFE.getInt(o, 16); 102 } 103 104 static int testFixedOffsetHeader17(Object o) { 105 return UNSAFE.getIntUnaligned(o, 17); 106 } 107 108 static Object testFixedBase(long off) { 109 return UNSAFE.getObject(INSTANCE, off); 110 } 111 112 static Object testOpaque(Object o, long off) { 113 return UNSAFE.getObject(o, off); 114 } 115 116 static int testFixedOffsetHeaderArray0(Object[] arr) { 117 return UNSAFE.getInt(arr, 0); 118 } 119 120 static int testFixedOffsetHeaderArray4(Object[] arr) { 121 return UNSAFE.getInt(arr, 4); 122 } 123 124 static int testFixedOffsetHeaderArray8(Object[] arr) { 125 return UNSAFE.getInt(arr, 8); 126 } 127 128 static int testFixedOffsetHeaderArray12(Object[] arr) { 129 return UNSAFE.getInt(arr, 12); 130 } 131 132 static int testFixedOffsetHeaderArray16(Object[] arr) { 133 return UNSAFE.getInt(arr, 16); 134 } 135 136 static int testFixedOffsetHeaderArray17(Object[] arr) { 137 return UNSAFE.getIntUnaligned(arr, 17); 138 } 139 140 static Object testFixedOffsetArray(Object[] arr) { 141 return UNSAFE.getObject(arr, E_OFFSET); 142 } 143 144 static Object testFixedBaseArray(long off) { 145 return UNSAFE.getObject(ARRAY, off); 146 } 147 148 static Object testOpaqueArray(Object[] o, long off) { 149 return UNSAFE.getObject(o, off); 150 } 151 152 static final long ADDR = UNSAFE.allocateMemory(10); 153 static boolean flag; 154 155 static int testMixedAccess() { 156 flag = !flag; 157 Object o = (flag ? INSTANCE : null); 158 long off = (flag ? F_OFFSET : ADDR); 159 return UNSAFE.getInt(o, off); 160 } 161 162 public static void main(String[] args) { 163 for (int i = 0; i < 20_000; i++) { 164 // Instance 165 testFixedOffsetField(INSTANCE); 166 testFixedOffsetHeader0(INSTANCE); 167 testFixedOffsetHeader4(INSTANCE); 168 testFixedOffsetHeader8(INSTANCE); 169 testFixedOffsetHeader12(INSTANCE); | 61 private static final Object[] ARRAY = new Object[10]; 62 63 private static final long F_OFFSET; 64 private static final long E_OFFSET; 65 66 static { 67 try { 68 Field field = OpaqueAccesses.class.getDeclaredField("f"); 69 F_OFFSET = UNSAFE.objectFieldOffset(field); 70 71 E_OFFSET = UNSAFE.arrayBaseOffset(ARRAY.getClass()); 72 } catch (NoSuchFieldException e) { 73 throw new Error(e); 74 } 75 } 76 77 private Object f = new Object(); 78 private long l1, l2; 79 80 static Object testFixedOffsetField(Object o) { 81 return UNSAFE.getReference(o, F_OFFSET); 82 } 83 84 static int testFixedOffsetHeader0(Object o) { 85 return UNSAFE.getInt(o, 0); 86 } 87 88 static int testFixedOffsetHeader4(Object o) { 89 return UNSAFE.getInt(o, 4); 90 } 91 92 static int testFixedOffsetHeader8(Object o) { 93 return UNSAFE.getInt(o, 8); 94 } 95 96 static int testFixedOffsetHeader12(Object o) { 97 return UNSAFE.getInt(o, 12); 98 } 99 100 static int testFixedOffsetHeader16(Object o) { 101 return UNSAFE.getInt(o, 16); 102 } 103 104 static int testFixedOffsetHeader17(Object o) { 105 return UNSAFE.getIntUnaligned(o, 17); 106 } 107 108 static Object testFixedBase(long off) { 109 return UNSAFE.getReference(INSTANCE, off); 110 } 111 112 static Object testOpaque(Object o, long off) { 113 return UNSAFE.getReference(o, off); 114 } 115 116 static int testFixedOffsetHeaderArray0(Object[] arr) { 117 return UNSAFE.getInt(arr, 0); 118 } 119 120 static int testFixedOffsetHeaderArray4(Object[] arr) { 121 return UNSAFE.getInt(arr, 4); 122 } 123 124 static int testFixedOffsetHeaderArray8(Object[] arr) { 125 return UNSAFE.getInt(arr, 8); 126 } 127 128 static int testFixedOffsetHeaderArray12(Object[] arr) { 129 return UNSAFE.getInt(arr, 12); 130 } 131 132 static int testFixedOffsetHeaderArray16(Object[] arr) { 133 return UNSAFE.getInt(arr, 16); 134 } 135 136 static int testFixedOffsetHeaderArray17(Object[] arr) { 137 return UNSAFE.getIntUnaligned(arr, 17); 138 } 139 140 static Object testFixedOffsetArray(Object[] arr) { 141 return UNSAFE.getReference(arr, E_OFFSET); 142 } 143 144 static Object testFixedBaseArray(long off) { 145 return UNSAFE.getReference(ARRAY, off); 146 } 147 148 static Object testOpaqueArray(Object[] o, long off) { 149 return UNSAFE.getReference(o, off); 150 } 151 152 static final long ADDR = UNSAFE.allocateMemory(10); 153 static boolean flag; 154 155 static int testMixedAccess() { 156 flag = !flag; 157 Object o = (flag ? INSTANCE : null); 158 long off = (flag ? F_OFFSET : ADDR); 159 return UNSAFE.getInt(o, off); 160 } 161 162 public static void main(String[] args) { 163 for (int i = 0; i < 20_000; i++) { 164 // Instance 165 testFixedOffsetField(INSTANCE); 166 testFixedOffsetHeader0(INSTANCE); 167 testFixedOffsetHeader4(INSTANCE); 168 testFixedOffsetHeader8(INSTANCE); 169 testFixedOffsetHeader12(INSTANCE); |