Skip to content

Commit 0dbe4c5

Browse files
committed
8278131: runtime/cds/appcds/dynamicArchive/* tests failing in loom repo
Reviewed-by: iklam, dholmes, minqi
1 parent e6b28e0 commit 0dbe4c5

File tree

9 files changed

+66
-14
lines changed

9 files changed

+66
-14
lines changed

test/hotspot/jtreg/runtime/HiddenClasses/InstantiateHiddenClass.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.lang.invoke.MethodType;
3333
import java.lang.invoke.MethodHandles;
3434
import java.lang.invoke.MethodHandles.Lookup;
35+
import java.lang.invoke.MethodHandles.Lookup.ClassOption;
3536
import static java.lang.invoke.MethodHandles.Lookup.ClassOption.*;
3637
import jdk.test.lib.compiler.InMemoryJavaCompiler;
3738

@@ -44,12 +45,19 @@ public class InstantiateHiddenClass {
4445
" } } ");
4546

4647
public static void main(String[] args) throws Throwable {
48+
// This class is also used by the appcds/dynamicArchive/RegularHiddenClass.java
49+
// test which will pass the "keep-alive" argument during dynamic CDS dump
50+
// for preventing from being GC'ed prior to the dumping operation.
51+
boolean keepAlive = false;
52+
if (args.length == 1 && args[0].equals("keep-alive")) {
53+
keepAlive = true;
54+
}
4755

4856
// Test that a hidden class cannot be found through its name.
4957
try {
5058
Lookup lookup = MethodHandles.lookup();
51-
Class<?> cl = lookup.defineHiddenClass(klassbuf, false, NESTMATE).lookupClass();
52-
Class.forName(cl.getName()).newInstance();
59+
Class<?> c0 = lookup.defineHiddenClass(klassbuf, false, NESTMATE).lookupClass();
60+
Class.forName(c0.getName()).newInstance();
5361
throw new RuntimeException("Expected ClassNotFoundException not thrown");
5462
} catch (ClassNotFoundException e ) {
5563
// Test passed
@@ -60,8 +68,9 @@ public static void main(String[] args) throws Throwable {
6068
// Verify that the references to these objects are different and references
6169
// to their classes are not equal either.
6270
Lookup lookup = MethodHandles.lookup();
63-
Class<?> c1 = lookup.defineHiddenClass(klassbuf, false, NESTMATE).lookupClass();
64-
Class<?> c2 = lookup.defineHiddenClass(klassbuf, false, NESTMATE).lookupClass();
71+
ClassOption classOption = keepAlive ? STRONG : NESTMATE;
72+
Class<?> c1 = lookup.defineHiddenClass(klassbuf, false, classOption).lookupClass();
73+
Class<?> c2 = lookup.defineHiddenClass(klassbuf, false, classOption).lookupClass();
6574
Object o1 = c1.newInstance();
6675
Object o2 = c2.newInstance();
6776
if (o1 == o2) {

test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030

3131
public class HelloUnload {
3232
private static String className = "CustomLoadee";
33+
// Prevent the following class from being GC'ed too soon.
34+
private static Class keptC = null;
3335

3436
public static void main(String args[]) throws Exception {
35-
if (args.length != 3) {
36-
throw new RuntimeException("Unexpected number of arguments: expected 3, actual " + args.length);
37+
if (args.length < 3) {
38+
throw new RuntimeException("Unexpected number of arguments: expected at least 3, actual " + args.length);
3739
}
3840

3941
String path = args[0];
@@ -62,9 +64,20 @@ public static void main(String args[]) throws Exception {
6264
throw new RuntimeException("args[2] can only be either \"true\" or \"false\", actual " + args[1]);
6365
}
6466

67+
// The HelloDynamicCustom.java and PrintSharedArchiveAndExit.java tests
68+
// under appcds/dynamicArchive pass the keep-alive argument for preventing
69+
// the class from being GC'ed prior to dumping of the dynamic CDS archive.
70+
boolean keepAlive = false;
71+
if (args[args.length - 1].equals("keep-alive")) {
72+
keepAlive = true;
73+
}
74+
6575
URLClassLoader urlClassLoader =
6676
new URLClassLoader("HelloClassLoader", urls, null);
6777
Class c = Class.forName(className, true, urlClassLoader);
78+
if (keepAlive) {
79+
keptC = c;
80+
}
6881
System.out.println(c);
6982
System.out.println(c.getClassLoader());
7083
Object o = c.newInstance();

test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/OldClassApp.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import java.io.File;
2626
import java.net.URL;
2727
import java.net.URLClassLoader;
28+
import java.util.HashMap;
2829
import sun.hotspot.WhiteBox;
2930

3031
public class OldClassApp {
32+
// Prevent the classes from being GC'ed too soon.
33+
static HashMap<String, Class> clsMap = new HashMap<>();
3134
public static void main(String args[]) throws Exception {
3235
String path = args[0];
3336
URL url = new File(path).toURI().toURL();
@@ -44,13 +47,26 @@ public static void main(String args[]) throws Exception {
4447
throw new RuntimeException("args[1] can only be either \"true\" or \"false\", actual " + args[1]);
4548
}
4649

50+
// The OldClassAndInf.java test under appcds/dynamicArchive passes the keep-alive
51+
// argument for preventing the classes from being GC'ed prior to dumping of
52+
// the dynamic CDS archive.
53+
int startIdx = 2;
54+
boolean keepAlive = false;
55+
if (args[2].equals("keep-alive")) {
56+
keepAlive = true;
57+
startIdx = 3;
58+
}
59+
4760
URLClassLoader urlClassLoader =
4861
new URLClassLoader("OldClassAppClassLoader", urls, null);
4962

50-
for (int i = 2; i < args.length; i++) {
63+
for (int i = startIdx; i < args.length; i++) {
5164
Class c = urlClassLoader.loadClass(args[i]);
5265
System.out.println(c);
5366
System.out.println(c.getClassLoader());
67+
if (keepAlive) {
68+
clsMap.put(args[i], c);
69+
}
5470

5571
// [1] Check that class is defined by the correct loader
5672
if (c.getClassLoader() != urlClassLoader) {

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/HelloDynamicCustom.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static void testDefaultBase() throws Exception {
6464
"-Xlog:cds",
6565
"-Xlog:cds+dynamic=debug",
6666
"-cp", appJar,
67-
mainAppClass, customJarPath, "false", "false")
67+
mainAppClass, customJarPath, "false", "false", "keep-alive")
6868
.assertNormalExit(output -> {
6969
output.shouldContain("Written dynamic archive 0x")
7070
.shouldNotContain("klasses.*=.*CustomLoadee")

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/LambdaCustomLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void test() throws Exception {
4949
// 1. Host class loaded by a custom loader is initialized during dump time.
5050
dump(topArchiveName,
5151
"-Xlog:class+load,cds=debug,cds+dynamic",
52-
"-cp", appJar, mainClass, appJar, "init")
52+
"-cp", appJar, mainClass, appJar, "init", "keep-alive")
5353
.assertNormalExit(output -> {
5454
output.shouldMatch("Skipping.LambHello[$][$]Lambda[$].*0x.*:.Hidden.class")
5555
.shouldHaveExitValue(0);
@@ -67,7 +67,7 @@ static void test() throws Exception {
6767
// 2. Host class loaded by a custom loader is NOT initialized during dump time.
6868
dump(topArchiveName,
6969
"-Xlog:class+load,cds=debug,cds+dynamic",
70-
"-cp", appJar, mainClass, appJar)
70+
"-cp", appJar, mainClass, appJar, "keep-alive")
7171
.assertNormalExit(output -> {
7272
output.shouldHaveExitValue(0);
7373
});

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/OldClassAndInf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static void doTest(String loadeesJar, String inArchive, String ...loadee
8080
"-Xlog:cds",
8181
"-Xlog:cds+dynamic=debug",
8282
"-cp", appJar,
83-
mainAppClass, loadeesJar, inArchive),
83+
mainAppClass, loadeesJar, inArchive, "keep-alive"),
8484
loadees))
8585
.assertNormalExit(output -> {
8686
output.shouldContain("Written dynamic archive 0x")

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/PrintSharedArchiveAndExit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static void testPrtNExit() throws Exception {
6464
"-Xlog:cds",
6565
"-Xlog:cds+dynamic=debug",
6666
"-cp", appJar,
67-
mainAppClass, customJarPath, "false", "false")
67+
mainAppClass, customJarPath, "false", "false", "keep-alive")
6868
.assertNormalExit(output -> {
6969
output.shouldContain("Written dynamic archive 0x")
7070
.shouldNotContain("klasses.*=.*CustomLoadee")

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/RegularHiddenClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void test() throws Exception {
5454

5555
dump(topArchiveName,
5656
"-Xlog:class+load=debug,cds+dynamic,cds=debug",
57-
"-cp", appJar, mainClass)
57+
"-cp", appJar, mainClass, "keep-alive")
5858
.assertNormalExit(output -> {
5959
output.shouldMatch("cds.*Skipping.TestClass.0x.*Hidden.class")
6060
.shouldNotMatch("cds.dynamic.*Archiving.hidden.TestClass.*")

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes/CustomLoaderApp.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
public class CustomLoaderApp {
3030
private static String className = "LambHello";
31+
// Prevent the class from being GC'ed too soon.
32+
private static Class keptC = null;
3133

3234
public static void main(String args[]) throws Exception {
3335
String path = args[0];
@@ -37,13 +39,25 @@ public static void main(String args[]) throws Exception {
3739
System.out.println(url);
3840

3941
boolean init = false;
40-
if (args.length ==2 && args[1].equals("init")) {
42+
if (args.length >= 2 && args[1].equals("init")) {
4143
init = true;
4244
}
4345

46+
// The dynamicArchive/LambdaCustomLoader.java test passes the keep-alive
47+
// argument for preventing the class from being GC'ed prior to dumping of
48+
// the dynamic CDS archive.
49+
boolean keepAlive = false;
50+
if (args[args.length - 1].equals("keep-alive")) {
51+
keepAlive = true;
52+
}
53+
4454
URLClassLoader urlClassLoader =
4555
new URLClassLoader("HelloClassLoader", urls, null);
4656
Class c = Class.forName(className, init, urlClassLoader);
57+
if (keepAlive) {
58+
keptC = c;
59+
}
60+
4761
System.out.println(c);
4862
System.out.println(c.getClassLoader());
4963
if (c.getClassLoader() != urlClassLoader) {

0 commit comments

Comments
 (0)