< prev index next >

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

Print this page
rev 52865 : [mq]: 8210031

*** 48,57 **** --- 48,65 ---- final float final_v = 1.0f; float v; + static final float static_final_v2 = 1.0f; + + static float static_v2; + + final float final_v2 = 1.0f; + + float 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( + VarHandleTestAccessFloat.class, "final_v" + postfix, float.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findVarHandle( + VarHandleTestAccessFloat.class, "v" + postfix, float.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findStaticVarHandle( + VarHandleTestAccessFloat.class, "static_final_v" + postfix, float.class); + vhs.add(vh); + + vh = MethodHandles.lookup().findStaticVarHandle( + VarHandleTestAccessFloat.class, "static_v" + postfix, float.class); + vhs.add(vh); + + if (same) { + vh = MethodHandles.arrayElementVarHandle(float[].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( VarHandleTestAccessFloat.class, "final_v", float.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 >