Skip to content

Commit

Permalink
ValueTypeTests for migrated value classes
Browse files Browse the repository at this point in the history
Signed-off-by: Theresa Mammarella <[email protected]>
  • Loading branch information
theresa-m committed Nov 20, 2024
1 parent 291f1d4 commit 5285e46
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,14 @@ public static Class<?> generateVerifiableValueClass(String name, String[] fields
return generator.defineClass(name, bytes, 0, bytes.length);
}

public static Class<?> generateRefClass(String name) throws Throwable {
ClassConfiguration classConfig = new ClassConfiguration(name, new String[0]);
classConfig.setIsReference(true);

byte[] bytes = generateClass(classConfig);
return generator.defineClass(name, bytes, 0, bytes.length);
}

public static Class<?> generateRefClass(String name, String[] fields) throws Throwable {
ClassConfiguration classConfig = new ClassConfiguration(name, fields);
classConfig.setIsReference(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,33 @@ static public void testMonitorEnterAndExitWithRefType() throws Throwable {
}
}

@Test(priority=1)
static public void testMigratedValueClasses() {
Integer a = new Integer(1);
Integer b = new Integer(1);

Assert.assertTrue(a.getClass().isValue(),
"java/lang/Integer should be migrated to a value class.");
Assert.assertTrue(a.hashCode() == b.hashCode(),
"Two objects of value type classes with the same values should have the same hash code.");
Assert.assertTrue(a == b,
"Two objects of value type classes with the same values should be equal.");
}

@Test(priority=1)
static public void testMigratedValueClassesMonitorEnterAndExit() throws Throwable {
Integer i = new Integer(1);
Object refType = (Object)i;

Class<?> testMigratedValueClassesMonitorEnterAndExit = ValueTypeGenerator.generateRefClass("TestMigratedValueClassesMonitorEnterAndExit");
MethodHandle monitorEnterAndExitWithRefType = lookup.findStatic(testMigratedValueClassesMonitorEnterAndExit, "testMonitorEnterAndExitWithRefType", MethodType.methodType(void.class, Object.class));
try {
monitorEnterAndExitWithRefType.invoke(refType);
fail("Synchronization attempts on migrated value classes should fail.");
} catch (IdentityException e) {
}
}

/*
* Create a valueType with three valueType members
*
Expand Down

0 comments on commit 5285e46

Please sign in to comment.