Skip to content

Commit 53f72ed

Browse files
committedFeb 7, 2023
8286510: Tests under dynamicArchive/methodHandles should check for loading of lambda proxy classes
Reviewed-by: iklam
1 parent 74485a3 commit 53f72ed

7 files changed

+120
-29
lines changed
 

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/CDSMHTest_generate.sh

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,7 @@ do
3131
fname="$i$name_suffix"
3232
cat << EOF > $fname
3333
/*
34-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
34+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
3535
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3636
*
3737
* This code is free software; you can redistribute it and/or modify it
@@ -94,6 +94,9 @@ public class $i extends DynamicArchiveTestBase {
9494
private static final String ps = System.getProperty("path.separator");
9595
private static final String testPackageName = "test.java.lang.invoke";
9696
private static final String testClassName = "$i";
97+
private static final String loggingOpts = "-Xlog:cds,cds+dynamic=debug,class+load=trace";
98+
private static final String lambdaLoadedFromArchive =
99+
".class.load. test.java.lang.invoke.$i[$][$]Lambda[$].*/0x.*source:.*shared.*objects.*file.*(top)";
97100
98101
static void testImpl() throws Exception {
99102
String topArchiveName = getNewArchiveName();
@@ -104,10 +107,20 @@ public class $i extends DynamicArchiveTestBase {
104107
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
105108
106109
String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
110+
String jars = appJar + ps + junitJar;
111+
String className = testPackageName + "." + testClassName;
112+
113+
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
114+
.assertNormalExit(output -> {
115+
output.shouldContain("Written dynamic archive 0x");
116+
});
117+
118+
run(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
119+
.assertNormalExit(output -> {
120+
output.shouldMatch(lambdaLoadedFromArchive)
121+
.shouldHaveExitValue(0);
122+
});
107123
108-
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
109-
"-cp", appJar + ps + junitJar, verifyOpt,
110-
mainClass, testPackageName + "." + testClassName);
111124
}
112125
}
113126
EOF

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesAsCollectorTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,9 @@ public void test() throws Exception {
6262
private static final String ps = System.getProperty("path.separator");
6363
private static final String testPackageName = "test.java.lang.invoke";
6464
private static final String testClassName = "MethodHandlesAsCollectorTest";
65+
private static final String loggingOpts = "-Xlog:cds,cds+dynamic=debug,class+load=trace";
66+
private static final String lambdaLoadedFromArchive =
67+
".class.load. test.java.lang.invoke.MethodHandlesAsCollectorTest[$][$]Lambda[$].*/0x.*source:.*shared.*objects.*file.*(top)";
6568

6669
static void testImpl() throws Exception {
6770
String topArchiveName = getNewArchiveName();
@@ -72,9 +75,19 @@ static void testImpl() throws Exception {
7275
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
7376

7477
String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
78+
String jars = appJar + ps + junitJar;
79+
String className = testPackageName + "." + testClassName;
80+
81+
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
82+
.assertNormalExit(output -> {
83+
output.shouldContain("Written dynamic archive 0x");
84+
});
85+
86+
run(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
87+
.assertNormalExit(output -> {
88+
output.shouldMatch(lambdaLoadedFromArchive)
89+
.shouldHaveExitValue(0);
90+
});
7591

76-
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
77-
"-cp", appJar + ps + junitJar, verifyOpt,
78-
mainClass, testPackageName + "." + testClassName);
7992
}
8093
}

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesCastFailureTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,9 @@ public void test() throws Exception {
6262
private static final String ps = System.getProperty("path.separator");
6363
private static final String testPackageName = "test.java.lang.invoke";
6464
private static final String testClassName = "MethodHandlesCastFailureTest";
65+
private static final String loggingOpts = "-Xlog:cds,cds+dynamic=debug,class+load=trace";
66+
private static final String lambdaLoadedFromArchive =
67+
".class.load. test.java.lang.invoke.MethodHandlesCastFailureTest[$][$]Lambda[$].*/0x.*source:.*shared.*objects.*file.*(top)";
6568

6669
static void testImpl() throws Exception {
6770
String topArchiveName = getNewArchiveName();
@@ -72,9 +75,19 @@ static void testImpl() throws Exception {
7275
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
7376

7477
String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
78+
String jars = appJar + ps + junitJar;
79+
String className = testPackageName + "." + testClassName;
80+
81+
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
82+
.assertNormalExit(output -> {
83+
output.shouldContain("Written dynamic archive 0x");
84+
});
85+
86+
run(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
87+
.assertNormalExit(output -> {
88+
output.shouldMatch(lambdaLoadedFromArchive)
89+
.shouldHaveExitValue(0);
90+
});
7591

76-
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
77-
"-cp", appJar + ps + junitJar, verifyOpt,
78-
mainClass, testPackageName + "." + testClassName);
7992
}
8093
}

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesGeneralTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,9 @@ public void test() throws Exception {
6262
private static final String ps = System.getProperty("path.separator");
6363
private static final String testPackageName = "test.java.lang.invoke";
6464
private static final String testClassName = "MethodHandlesGeneralTest";
65+
private static final String loggingOpts = "-Xlog:cds,cds+dynamic=debug,class+load=trace";
66+
private static final String lambdaLoadedFromArchive =
67+
".class.load. test.java.lang.invoke.MethodHandlesGeneralTest[$][$]Lambda[$].*/0x.*source:.*shared.*objects.*file.*(top)";
6568

6669
static void testImpl() throws Exception {
6770
String topArchiveName = getNewArchiveName();
@@ -72,9 +75,19 @@ static void testImpl() throws Exception {
7275
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
7376

7477
String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
78+
String jars = appJar + ps + junitJar;
79+
String className = testPackageName + "." + testClassName;
80+
81+
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
82+
.assertNormalExit(output -> {
83+
output.shouldContain("Written dynamic archive 0x");
84+
});
85+
86+
run(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
87+
.assertNormalExit(output -> {
88+
output.shouldMatch(lambdaLoadedFromArchive)
89+
.shouldHaveExitValue(0);
90+
});
7591

76-
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
77-
"-cp", appJar + ps + junitJar, verifyOpt,
78-
mainClass, testPackageName + "." + testClassName);
7992
}
8093
}

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesInvokersTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,9 @@ public void test() throws Exception {
6262
private static final String ps = System.getProperty("path.separator");
6363
private static final String testPackageName = "test.java.lang.invoke";
6464
private static final String testClassName = "MethodHandlesInvokersTest";
65+
private static final String loggingOpts = "-Xlog:cds,cds+dynamic=debug,class+load=trace";
66+
private static final String lambdaLoadedFromArchive =
67+
".class.load. test.java.lang.invoke.MethodHandlesInvokersTest[$][$]Lambda[$].*/0x.*source:.*shared.*objects.*file.*(top)";
6568

6669
static void testImpl() throws Exception {
6770
String topArchiveName = getNewArchiveName();
@@ -72,9 +75,19 @@ static void testImpl() throws Exception {
7275
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
7376

7477
String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
78+
String jars = appJar + ps + junitJar;
79+
String className = testPackageName + "." + testClassName;
80+
81+
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
82+
.assertNormalExit(output -> {
83+
output.shouldContain("Written dynamic archive 0x");
84+
});
85+
86+
run(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
87+
.assertNormalExit(output -> {
88+
output.shouldMatch(lambdaLoadedFromArchive)
89+
.shouldHaveExitValue(0);
90+
});
7591

76-
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
77-
"-cp", appJar + ps + junitJar, verifyOpt,
78-
mainClass, testPackageName + "." + testClassName);
7992
}
8093
}

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesPermuteArgumentsTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,9 @@ public void test() throws Exception {
6262
private static final String ps = System.getProperty("path.separator");
6363
private static final String testPackageName = "test.java.lang.invoke";
6464
private static final String testClassName = "MethodHandlesPermuteArgumentsTest";
65+
private static final String loggingOpts = "-Xlog:cds,cds+dynamic=debug,class+load=trace";
66+
private static final String lambdaLoadedFromArchive =
67+
".class.load. test.java.lang.invoke.MethodHandlesPermuteArgumentsTest[$][$]Lambda[$].*/0x.*source:.*shared.*objects.*file.*(top)";
6568

6669
static void testImpl() throws Exception {
6770
String topArchiveName = getNewArchiveName();
@@ -72,9 +75,19 @@ static void testImpl() throws Exception {
7275
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
7376

7477
String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
78+
String jars = appJar + ps + junitJar;
79+
String className = testPackageName + "." + testClassName;
80+
81+
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
82+
.assertNormalExit(output -> {
83+
output.shouldContain("Written dynamic archive 0x");
84+
});
85+
86+
run(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
87+
.assertNormalExit(output -> {
88+
output.shouldMatch(lambdaLoadedFromArchive)
89+
.shouldHaveExitValue(0);
90+
});
7591

76-
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
77-
"-cp", appJar + ps + junitJar, verifyOpt,
78-
mainClass, testPackageName + "." + testClassName);
7992
}
8093
}

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesSpreadArgumentsTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,9 @@ public void test() throws Exception {
6262
private static final String ps = System.getProperty("path.separator");
6363
private static final String testPackageName = "test.java.lang.invoke";
6464
private static final String testClassName = "MethodHandlesSpreadArgumentsTest";
65+
private static final String loggingOpts = "-Xlog:cds,cds+dynamic=debug,class+load=trace";
66+
private static final String lambdaLoadedFromArchive =
67+
".class.load. test.java.lang.invoke.MethodHandlesSpreadArgumentsTest[$][$]Lambda[$].*/0x.*source:.*shared.*objects.*file.*(top)";
6568

6669
static void testImpl() throws Exception {
6770
String topArchiveName = getNewArchiveName();
@@ -72,9 +75,19 @@ static void testImpl() throws Exception {
7275
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
7376

7477
String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
78+
String jars = appJar + ps + junitJar;
79+
String className = testPackageName + "." + testClassName;
80+
81+
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
82+
.assertNormalExit(output -> {
83+
output.shouldContain("Written dynamic archive 0x");
84+
});
85+
86+
run(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
87+
.assertNormalExit(output -> {
88+
output.shouldMatch(lambdaLoadedFromArchive)
89+
.shouldHaveExitValue(0);
90+
});
7591

76-
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
77-
"-cp", appJar + ps + junitJar, verifyOpt,
78-
mainClass, testPackageName + "." + testClassName);
7992
}
8093
}

0 commit comments

Comments
 (0)
Please sign in to comment.