< prev index next > test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java
Print this page
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+ // -- This file was mechanically generated: Do not edit! -- //
+
/*
* @test
* @run testng/othervm -Diters=10 -Xint VarHandleTestAccessByte
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessByte
* @run testng/othervm -Diters=20000 VarHandleTestAccessByte
import java.util.List;
import static org.testng.Assert.*;
public class VarHandleTestAccessByte extends VarHandleBaseTest {
+ static final Class<?> type = byte.class;
+
static final byte static_final_v = (byte)0x01;
static byte static_v;
final byte final_v = (byte)0x01;
VarHandle vhStaticFinalField;
VarHandle vhArray;
+ VarHandle vhValueTypeField;
VarHandle[] allocate(boolean same) {
List<VarHandle> vhs = new ArrayList<>();
String postfix = same ? "" : "2";
VarHandle vh;
try {
vh = MethodHandles.lookup().findVarHandle(
- VarHandleTestAccessByte.class, "final_v" + postfix, byte.class);
+ VarHandleTestAccessByte.class, "final_v" + postfix, type);
vhs.add(vh);
vh = MethodHandles.lookup().findVarHandle(
- VarHandleTestAccessByte.class, "v" + postfix, byte.class);
+ VarHandleTestAccessByte.class, "v" + postfix, type);
vhs.add(vh);
vh = MethodHandles.lookup().findStaticVarHandle(
- VarHandleTestAccessByte.class, "static_final_v" + postfix, byte.class);
+ VarHandleTestAccessByte.class, "static_final_v" + postfix, type);
vhs.add(vh);
vh = MethodHandles.lookup().findStaticVarHandle(
- VarHandleTestAccessByte.class, "static_v" + postfix, byte.class);
+ VarHandleTestAccessByte.class, "static_v" + postfix, type);
vhs.add(vh);
if (same) {
vh = MethodHandles.arrayElementVarHandle(byte[].class);
}
}
@BeforeClass
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
- VarHandleTestAccessByte.class, "final_v", byte.class);
+ VarHandleTestAccessByte.class, "final_v", type);
vhField = MethodHandles.lookup().findVarHandle(
- VarHandleTestAccessByte.class, "v", byte.class);
+ VarHandleTestAccessByte.class, "v", type);
vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
- VarHandleTestAccessByte.class, "static_final_v", byte.class);
+ VarHandleTestAccessByte.class, "static_final_v", type);
vhStaticField = MethodHandles.lookup().findStaticVarHandle(
- VarHandleTestAccessByte.class, "static_v", byte.class);
+ VarHandleTestAccessByte.class, "static_v", type);
vhArray = MethodHandles.arrayElementVarHandle(byte[].class);
+
+ vhValueTypeField = MethodHandles.lookup().findVarHandle(
+ Value.class, "byte_v", type);
}
@DataProvider
public Object[][] varHandlesProvider() throws Exception {
return types.stream().toArray(Object[][]::new);
}
@Test(dataProvider = "typesProvider")
public void testTypes(VarHandle vh, List<Class<?>> pts) {
- assertEquals(vh.varType(), byte.class);
+ assertEquals(vh.varType(), type);
assertEquals(vh.coordinateTypes(), pts);
testTypes(vh);
}
@Test
public void testLookupInstanceToStatic() {
checkIAE("Lookup of static final field to instance final field", () -> {
MethodHandles.lookup().findStaticVarHandle(
- VarHandleTestAccessByte.class, "final_v", byte.class);
+ VarHandleTestAccessByte.class, "final_v", type);
});
checkIAE("Lookup of static field to instance field", () -> {
MethodHandles.lookup().findStaticVarHandle(
- VarHandleTestAccessByte.class, "v", byte.class);
+ VarHandleTestAccessByte.class, "v", type);
});
}
@Test
public void testLookupStaticToInstance() {
checkIAE("Lookup of instance final field to static final field", () -> {
MethodHandles.lookup().findVarHandle(
- VarHandleTestAccessByte.class, "static_final_v", byte.class);
+ VarHandleTestAccessByte.class, "static_final_v", type);
});
checkIAE("Lookup of instance field to static field", () -> {
vhStaticField = MethodHandles.lookup().findVarHandle(
- VarHandleTestAccessByte.class, "static_v", byte.class);
+ VarHandleTestAccessByte.class, "static_v", type);
});
}
@DataProvider
vhArray, VarHandleTestAccessByte::testArrayUnsupported,
false));
cases.add(new VarHandleAccessTestCase("Array index out of bounds",
vhArray, VarHandleTestAccessByte::testArrayIndexOutOfBounds,
false));
+ cases.add(new VarHandleAccessTestCase("Value type field",
+ vhValueTypeField, vh -> testValueTypeField(Value.getInstance(), vh)));
+ cases.add(new VarHandleAccessTestCase("Value type field unsupported",
+ vhValueTypeField, vh -> testValueTypeFieldUnsupported(Value.getInstance(), vh),
+ false));
// Work around issue with jtreg summary reporting which truncates
// the String result of Object.toString to 30 characters, hence
// the first dummy argument
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
}
+ static void testValueTypeField(Value recv, VarHandle vh) {
+ // Plain
+ {
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "get byte value");
+ }
+ }
+
+ static void testValueTypeFieldUnsupported(Value recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, (byte)0x23);
+ });
+ }
static void testStaticFinalField(VarHandle vh) {
// Plain
{
byte x = (byte) vh.get();
< prev index next >