< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java

Print this page
rev 52865 : [mq]: 8210031

*** 48,57 **** --- 48,65 ---- final long final_v = 0x0123456789ABCDEFL; long v; + static final long static_final_v2 = 0x0123456789ABCDEFL; + + static long static_v2; + + final long final_v2 = 0x0123456789ABCDEFL; + + long v2; + VarHandle vhFinalField; VarHandle vhField; VarHandle vhStaticField;
*** 59,68 **** --- 67,111 ---- VarHandle vhStaticFinalField; VarHandle vhArray; + VarHandle[] allocate(boolean same) { + List<VarHandle> vhs = new ArrayList<>(); + + String postfix = same ? "" : "2"; + VarHandle vh; + try { + vh = MethodHandles.lookup().findVarHandle( + VarHandleTestAccessLong.class, "final_v" + postfix, long.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findVarHandle( + VarHandleTestAccessLong.class, "v" + postfix, long.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findStaticVarHandle( + VarHandleTestAccessLong.class, "static_final_v" + postfix, long.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findStaticVarHandle( + VarHandleTestAccessLong.class, "static_v" + postfix, long.class); + vhs.add(vh); + + if (same) { + vh = MethodHandles.arrayElementVarHandle(long[].class); + } + else { + vh = MethodHandles.arrayElementVarHandle(String[].class); + } + vhs.add(vh); + } catch (Exception e) { + throw new InternalError(e); + } + return vhs.toArray(new VarHandle[0]); + } + @BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessLong.class, "final_v", long.class);
*** 87,96 **** --- 130,164 ---- vhs.add(vhArray); return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new); } + @Test + public void testEqualsAndHashCode() { + VarHandle[] vhs1 = allocate(true); + VarHandle[] vhs2 = allocate(true); + + for (int i = 0; i < vhs1.length; i++) { + for (int j = 0; j < vhs1.length; j++) { + if (i == j) { + assertEquals(vhs1[i], vhs1[i]); + assertEquals(vhs1[i], vhs2[i]); + assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode()); + } + else { + assertNotEquals(vhs1[i], vhs1[j]); + assertNotEquals(vhs1[i], vhs2[j]); + } + } + } + + VarHandle[] vhs3 = allocate(false); + for (int i = 0; i < vhs1.length; i++) { + assertNotEquals(vhs1[i], vhs3[i]); + } + } + @Test(dataProvider = "varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
< prev index next >