-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8342283: CDS cannot handle a large number of classes #24877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
test/hotspot/jtreg/runtime/cds/appcds/LotsOfSyntheticClasses.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * 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. | ||
| * | ||
| */ | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.nio.file.Files; | ||
|
|
||
| import jdk.test.lib.cds.CDSJarUtils; | ||
| import jdk.test.lib.cds.CDSTestUtils; | ||
| import jdk.test.lib.process.OutputAnalyzer; | ||
|
|
||
| /* | ||
| * @test | ||
| * @summary Try to archive lots and lots of classes. | ||
| * @requires vm.cds | ||
| * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds | ||
| * @run driver/timeout=500 LotsOfSyntheticClasses | ||
| */ | ||
|
|
||
| public class LotsOfSyntheticClasses { | ||
|
|
||
| // Generate 100 top-level classes, each containing 1000 nested classes. | ||
| // 100K total classes are more than enough to push the CDS limits. | ||
| private static final int NUM_CLASSES = 100; | ||
| private static final int NUM_NESTED_CLASSES = 1000; | ||
|
|
||
| private static final Path USER_DIR = Paths.get(CDSTestUtils.getOutputDir()); | ||
| private static final Path APP_JAR = USER_DIR.resolve("test.jar"); | ||
| private static final Path SRC_DIR = USER_DIR.resolve("src"); | ||
|
|
||
| private static final String TOP_CLASS_NAME = "Class"; | ||
| private static final String NESTED_CLASS_NAME = "Nested"; | ||
| private static final String MAIN_CLASS_NAME = "Main"; | ||
|
|
||
| public static List<String> generateClass(int idx) { | ||
| List<String> out = new ArrayList<>(); | ||
| out.add("public class " + TOP_CLASS_NAME + idx + " {"); | ||
| out.add("public " + TOP_CLASS_NAME + idx + "() {"); | ||
| for (int c = 0; c < NUM_NESTED_CLASSES; c++) { | ||
| out.add("new " + NESTED_CLASS_NAME + c + "();"); | ||
| } | ||
| out.add("}"); | ||
| for (int c = 0; c < NUM_NESTED_CLASSES; c++) { | ||
| out.add("public static class " + NESTED_CLASS_NAME + c + " {}"); | ||
| } | ||
| out.add("}"); | ||
| return out; | ||
| } | ||
|
|
||
| public static List<String> generateMainClass() { | ||
| List<String> out = new ArrayList<>(); | ||
| out.add("public class " + MAIN_CLASS_NAME + " {"); | ||
| out.add("public static void main(String... args) {"); | ||
| for (int c = 0; c < NUM_CLASSES; c++) { | ||
| out.add("new " + TOP_CLASS_NAME + c + "();"); | ||
| } | ||
| out.add("System.out.println(\"Success\");"); | ||
| out.add("}"); | ||
| out.add("}"); | ||
| return out; | ||
| } | ||
|
|
||
| public static String[] listAppClasses() { | ||
| String[] res = new String[NUM_CLASSES * NUM_NESTED_CLASSES]; | ||
| for (int c = 0; c < NUM_CLASSES; c++) { | ||
| for (int sc = 0; sc < NUM_NESTED_CLASSES; sc++) { | ||
| res[c * NUM_NESTED_CLASSES + sc] = TOP_CLASS_NAME + c + "$" + NESTED_CLASS_NAME + sc; | ||
| } | ||
| } | ||
| return res; | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| // Step 1. Generate classes and build the JAR with them. | ||
| { | ||
| SRC_DIR.toFile().mkdirs(); | ||
|
|
||
| for (int i = 0; i < NUM_CLASSES; i++) { | ||
| Path file = SRC_DIR.resolve(TOP_CLASS_NAME + i + ".java"); | ||
| Files.write(file, generateClass(i)); | ||
| } | ||
|
|
||
| Path mainFile = SRC_DIR.resolve(MAIN_CLASS_NAME + ".java"); | ||
| Files.write(mainFile, generateMainClass()); | ||
|
|
||
| CDSJarUtils.buildFromSourceDirectory( | ||
| APP_JAR.toString(), | ||
| SRC_DIR.toString() | ||
| ); | ||
| } | ||
|
|
||
| // Step 2. Try to dump the archive. | ||
| { | ||
| OutputAnalyzer output = TestCommon.createArchive( | ||
| APP_JAR.toString(), | ||
| listAppClasses(), | ||
| MAIN_CLASS_NAME | ||
| ); | ||
| TestCommon.checkDump(output); | ||
| } | ||
|
|
||
| // Step 3. Try to run, touching every class. | ||
| { | ||
| TestCommon.run( | ||
| // Verifying dependencies for lots of classes slows down the test. | ||
| "-XX:+IgnoreUnrecognizedVMOptions", "-XX:-VerifyDependencies", | ||
| "-Xlog:cds", | ||
| "-cp", APP_JAR.toString(), | ||
| MAIN_CLASS_NAME). | ||
| assertNormalExit("Success"); | ||
| } | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a tiny technical debt here. If future AOT code generation uses a future aggressive constant folding of object fields (cf.
TrustFinalNonStaticFields) and a constant CL reference ends up in optimized code and there is a constant-folded reference (and.. and…) it is remotely possible that the old value of the field will get wrongly embedded in AOT code.If we arrange AOT code generation to occur after all of these fixups (in Java code) are done, then the problem will not occur. It's a delicate set of invariants. Your expanded comment is a good start at calling them out, but this is a long string we are pulling on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I borrowed this comment from the initial @iklam's PR, so I need to credit him as contributor.)
Yes, CDS does awkward state manipulations at dump time. Resetting the states of final/
@Stableobjects can run into issues that you described. I think this is one of the reasons why Leyden generates AOT code with-XX:-FoldStableValues:https://github.com/openjdk/leyden/blob/885096a8b3194371cde6b96ce5554d89f99618d7/src/hotspot/share/code/aotCodeCache.cpp#L162
I would guess we need to do the same with
TrustFinalNonStaticFields. The awkward part of currenttrust_final_non_static_fields()code is that it implicitly trusts things injava/lang, even with-TrustFinalNonStaticFields. That sounds like something we need to rectify for Leyden AOT code.