< prev index next >

test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template

Print this page
rev 52865 : [mq]: 8210031

*** 48,57 **** --- 48,65 ---- final $type$ final_v = $value1$; $type$ v; + static final $type$ static_final_v2 = $value1$; + + static $type$ static_v2; + + final $type$ final_v2 = $value1$; + + $type$ v2; + VarHandle vhFinalField; VarHandle vhField; VarHandle vhStaticField;
*** 62,71 **** --- 70,118 ---- #if[String] VarHandle vhArrayObject; #end[String] + VarHandle[] allocate(boolean same) { + List<VarHandle> vhs = new ArrayList<>(); + + String postfix = same ? "" : "2"; + VarHandle vh; + try { + vh = MethodHandles.lookup().findVarHandle( + VarHandleTestAccess$Type$.class, "final_v" + postfix, $type$.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findVarHandle( + VarHandleTestAccess$Type$.class, "v" + postfix, $type$.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findStaticVarHandle( + VarHandleTestAccess$Type$.class, "static_final_v" + postfix, $type$.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findStaticVarHandle( + VarHandleTestAccess$Type$.class, "static_v" + postfix, $type$.class); + vhs.add(vh); + + if (same) { + vh = MethodHandles.arrayElementVarHandle($type$[].class); + } + else { + #if[String] + vh = MethodHandles.arrayElementVarHandle(int[].class); + #else[String] + vh = MethodHandles.arrayElementVarHandle(String[].class); + #end[String] + } + 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( VarHandleTestAccess$Type$.class, "final_v", $type$.class);
*** 93,102 **** --- 140,174 ---- 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 >