58 |
58 |
59 VarHandle vhStaticFinalField; |
59 VarHandle vhStaticFinalField; |
60 |
60 |
61 VarHandle vhArray; |
61 VarHandle vhArray; |
62 |
62 |
|
63 VarHandle vhArrayObject; |
|
64 |
63 @BeforeClass |
65 @BeforeClass |
64 public void setup() throws Exception { |
66 public void setup() throws Exception { |
65 vhFinalField = MethodHandles.lookup().findVarHandle( |
67 vhFinalField = MethodHandles.lookup().findVarHandle( |
66 VarHandleTestAccessString.class, "final_v", String.class); |
68 VarHandleTestAccessString.class, "final_v", String.class); |
67 |
69 |
73 |
75 |
74 vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
76 vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
75 VarHandleTestAccessString.class, "static_v", String.class); |
77 VarHandleTestAccessString.class, "static_v", String.class); |
76 |
78 |
77 vhArray = MethodHandles.arrayElementVarHandle(String[].class); |
79 vhArray = MethodHandles.arrayElementVarHandle(String[].class); |
|
80 vhArrayObject = MethodHandles.arrayElementVarHandle(Object[].class); |
78 } |
81 } |
79 |
82 |
80 |
83 |
81 @DataProvider |
84 @DataProvider |
82 public Object[][] varHandlesProvider() throws Exception { |
85 public Object[][] varHandlesProvider() throws Exception { |
202 vhStaticField, VarHandleTestAccessString::testStaticFieldUnsupported, |
205 vhStaticField, VarHandleTestAccessString::testStaticFieldUnsupported, |
203 false)); |
206 false)); |
204 |
207 |
205 cases.add(new VarHandleAccessTestCase("Array", |
208 cases.add(new VarHandleAccessTestCase("Array", |
206 vhArray, VarHandleTestAccessString::testArray)); |
209 vhArray, VarHandleTestAccessString::testArray)); |
|
210 cases.add(new VarHandleAccessTestCase("Array Object[]", |
|
211 vhArrayObject, VarHandleTestAccessString::testArray)); |
207 cases.add(new VarHandleAccessTestCase("Array unsupported", |
212 cases.add(new VarHandleAccessTestCase("Array unsupported", |
208 vhArray, VarHandleTestAccessString::testArrayUnsupported, |
213 vhArray, VarHandleTestAccessString::testArrayUnsupported, |
209 false)); |
214 false)); |
210 cases.add(new VarHandleAccessTestCase("Array index out of bounds", |
215 cases.add(new VarHandleAccessTestCase("Array index out of bounds", |
211 vhArray, VarHandleTestAccessString::testArrayIndexOutOfBounds, |
216 vhArray, VarHandleTestAccessString::testArrayIndexOutOfBounds, |
212 false)); |
217 false)); |
213 |
218 cases.add(new VarHandleAccessTestCase("Array store exception", |
|
219 vhArrayObject, VarHandleTestAccessString::testArrayStoreException, |
|
220 false)); |
214 // Work around issue with jtreg summary reporting which truncates |
221 // Work around issue with jtreg summary reporting which truncates |
215 // the String result of Object.toString to 30 characters, hence |
222 // the String result of Object.toString to 30 characters, hence |
216 // the first dummy argument |
223 // the first dummy argument |
217 return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); |
224 return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); |
218 } |
225 } |
1144 }); |
1151 }); |
1145 |
1152 |
1146 |
1153 |
1147 } |
1154 } |
1148 } |
1155 } |
|
1156 |
|
1157 static void testArrayStoreException(VarHandle vh) throws Throwable { |
|
1158 Object[] array = new String[10]; |
|
1159 Arrays.fill(array, "foo"); |
|
1160 Object value = new Object(); |
|
1161 |
|
1162 // Set |
|
1163 checkASE(() -> { |
|
1164 vh.set(array, 0, value); |
|
1165 }); |
|
1166 |
|
1167 // SetVolatile |
|
1168 checkASE(() -> { |
|
1169 vh.setVolatile(array, 0, value); |
|
1170 }); |
|
1171 |
|
1172 // SetOpaque |
|
1173 checkASE(() -> { |
|
1174 vh.setOpaque(array, 0, value); |
|
1175 }); |
|
1176 |
|
1177 // SetRelease |
|
1178 checkASE(() -> { |
|
1179 vh.setRelease(array, 0, value); |
|
1180 }); |
|
1181 |
|
1182 // CompareAndSet |
|
1183 checkASE(() -> { // receiver reference class |
|
1184 boolean r = vh.compareAndSet(array, 0, "foo", value); |
|
1185 }); |
|
1186 |
|
1187 // WeakCompareAndSet |
|
1188 checkASE(() -> { // receiver reference class |
|
1189 boolean r = vh.weakCompareAndSetPlain(array, 0, "foo", value); |
|
1190 }); |
|
1191 |
|
1192 // WeakCompareAndSetVolatile |
|
1193 checkASE(() -> { // receiver reference class |
|
1194 boolean r = vh.weakCompareAndSet(array, 0, "foo", value); |
|
1195 }); |
|
1196 |
|
1197 // WeakCompareAndSetAcquire |
|
1198 checkASE(() -> { // receiver reference class |
|
1199 boolean r = vh.weakCompareAndSetAcquire(array, 0, "foo", value); |
|
1200 }); |
|
1201 |
|
1202 // WeakCompareAndSetRelease |
|
1203 checkASE(() -> { // receiver reference class |
|
1204 boolean r = vh.weakCompareAndSetRelease(array, 0, "foo", value); |
|
1205 }); |
|
1206 |
|
1207 // CompareAndExchange |
|
1208 checkASE(() -> { // receiver reference class |
|
1209 String x = (String) vh.compareAndExchange(array, 0, "foo", value); |
|
1210 }); |
|
1211 |
|
1212 // CompareAndExchangeAcquire |
|
1213 checkASE(() -> { // receiver reference class |
|
1214 String x = (String) vh.compareAndExchangeAcquire(array, 0, "foo", value); |
|
1215 }); |
|
1216 |
|
1217 // CompareAndExchangeRelease |
|
1218 checkASE(() -> { // receiver reference class |
|
1219 String x = (String) vh.compareAndExchangeRelease(array, 0, "foo", value); |
|
1220 }); |
|
1221 |
|
1222 // GetAndSet |
|
1223 checkASE(() -> { // receiver reference class |
|
1224 String x = (String) vh.getAndSet(array, 0, value); |
|
1225 }); |
|
1226 |
|
1227 // GetAndSetAcquire |
|
1228 checkASE(() -> { // receiver reference class |
|
1229 String x = (String) vh.getAndSetAcquire(array, 0, value); |
|
1230 }); |
|
1231 |
|
1232 // GetAndSetRelease |
|
1233 checkASE(() -> { // receiver reference class |
|
1234 String x = (String) vh.getAndSetRelease(array, 0, value); |
|
1235 }); |
|
1236 } |
1149 } |
1237 } |
1150 |
1238 |