< prev index next >

test/hotspot/jtreg/runtime/cds/serviceability/ReplaceCriticalClasses.java

Print this page

 81             // because JvmtiExport::early_class_hook_env() is true.
 82             "-early -notshared java/lang/Object",
 83             "-early -notshared java/lang/String",
 84             "-early -notshared java/lang/Cloneable",
 85             "-early -notshared java/io/Serializable",
 86             "-early -notshared java/lang/Module",
 87             "-early -notshared java/lang/ModuleLayer",
 88 
 89             // CDS should not be disabled -- these critical classes cannot be replaced because
 90             // JvmtiExport::early_class_hook_env() is false.
 91             "java/lang/Object",
 92             "java/lang/String",
 93             "java/lang/Cloneable",
 94             "java/io/Serializable",
 95             "java/lang/Module",
 96             "java/lang/ModuleLayer",
 97 
 98             // Replace classes that are loaded after JVMTI_PHASE_PRIMORDIAL. It's OK to replace
 99             // such
100             // classes even when CDS is enabled. Nothing bad should happen.
101             "-notshared java/util/Locale",
102             "-notshared sun/util/locale/BaseLocale",
103         };
104         return tests;
105     }
106 
107     static void launchChildProcesses(String tests[]) throws Throwable {
108         int n = 0;
109         for (String s : tests) {
110             System.out.println("Test case[" + (n++) + "] = \"" + s + "\"");
111             String args[] = s.split("\\s+"); // split by space character
112             launchChild(args);
113         }
114     }
115 
116     static void launchChild(String args[]) throws Throwable {
117         if (args.length < 1) {
118             throw new RuntimeException("Invalid test case. Should be <-early> <-subgraph> <-notshared> <-nowhitebox> klassName subgraphKlass");
119         }
120         String klassName = null;
121         String subgraphKlass = null;
122         String early = "";

132                 subgraph = true;
133             } else if (opt.equals("-nowhitebox")) {
134                 whitebox = false;
135             } else if (opt.equals("-notshared")) {
136                 shared = opt;
137             } else {
138               if (!subgraph) {
139                 throw new RuntimeException("Unknown option: " + opt);
140               }
141             }
142         }
143         if (subgraph) {
144           klassName = args[args.length-2];
145           subgraphKlass = args[args.length-1];
146         } else {
147           klassName = args[args.length-1];
148         }
149         Class.forName(klassName.replace("/", ".")); // make sure it's a valid class
150         final String subgraphInit = "initialize_from_archived_subgraph " + subgraphKlass;
151 
152         // We will pass an option like "-agentlib:SimpleClassFileLoadHook=java/util/Locale,XXX,XXX".
153         // The SimpleClassFileLoadHook agent would attempt to hook the java/util/Locale class
154         // but leave the class file bytes unchanged (it replaces all bytes "XXX" with "XXX", i.e.,
155         // a no-op). JVMTI doesn't check the class file bytes returned by the agent, so as long
156         // as the agent returns a buffer, it will not load the class from CDS, and will instead
157         // load the class by parsing the buffer.
158         //
159         // Note that for safety we don't change the contents of the class file bytes. If in the
160         // future JVMTI starts checking the contents of the class file bytes, this test would need
161         // to be updated. (You'd see the test case with java/util/Locale staring to fail).
162         String agent = "-agentlib:SimpleClassFileLoadHook=" + early + klassName + ",XXX,XXX";
163 
164         CDSOptions opts = (new CDSOptions())
165             .setXShareMode("auto")
166             .setArchiveName(ReplaceCriticalClasses.class.getName() + ".jsa")
167             .setUseVersion(false)
168             .addSuffix("-showversion",
169                        "-Xlog:aot",
170                        "-Xlog:cds",
171                        "-XX:+UnlockDiagnosticVMOptions",
172                        agent);
173         if (whitebox) {
174             opts.addSuffix("-XX:+WhiteBoxAPI",
175                            "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"));
176         }
177         opts.addSuffix("-Xlog:aot,aot+heap,cds");
178         opts.addSuffix("ReplaceCriticalClasses",
179                        "child",
180                        shared,
181                        klassName);

 81             // because JvmtiExport::early_class_hook_env() is true.
 82             "-early -notshared java/lang/Object",
 83             "-early -notshared java/lang/String",
 84             "-early -notshared java/lang/Cloneable",
 85             "-early -notshared java/io/Serializable",
 86             "-early -notshared java/lang/Module",
 87             "-early -notshared java/lang/ModuleLayer",
 88 
 89             // CDS should not be disabled -- these critical classes cannot be replaced because
 90             // JvmtiExport::early_class_hook_env() is false.
 91             "java/lang/Object",
 92             "java/lang/String",
 93             "java/lang/Cloneable",
 94             "java/io/Serializable",
 95             "java/lang/Module",
 96             "java/lang/ModuleLayer",
 97 
 98             // Replace classes that are loaded after JVMTI_PHASE_PRIMORDIAL. It's OK to replace
 99             // such
100             // classes even when CDS is enabled. Nothing bad should happen.
101             "-notshared java/util/Calendar",

102         };
103         return tests;
104     }
105 
106     static void launchChildProcesses(String tests[]) throws Throwable {
107         int n = 0;
108         for (String s : tests) {
109             System.out.println("Test case[" + (n++) + "] = \"" + s + "\"");
110             String args[] = s.split("\\s+"); // split by space character
111             launchChild(args);
112         }
113     }
114 
115     static void launchChild(String args[]) throws Throwable {
116         if (args.length < 1) {
117             throw new RuntimeException("Invalid test case. Should be <-early> <-subgraph> <-notshared> <-nowhitebox> klassName subgraphKlass");
118         }
119         String klassName = null;
120         String subgraphKlass = null;
121         String early = "";

131                 subgraph = true;
132             } else if (opt.equals("-nowhitebox")) {
133                 whitebox = false;
134             } else if (opt.equals("-notshared")) {
135                 shared = opt;
136             } else {
137               if (!subgraph) {
138                 throw new RuntimeException("Unknown option: " + opt);
139               }
140             }
141         }
142         if (subgraph) {
143           klassName = args[args.length-2];
144           subgraphKlass = args[args.length-1];
145         } else {
146           klassName = args[args.length-1];
147         }
148         Class.forName(klassName.replace("/", ".")); // make sure it's a valid class
149         final String subgraphInit = "initialize_from_archived_subgraph " + subgraphKlass;
150 
151         // We will pass an option like "-agentlib:SimpleClassFileLoadHook=java/util/Calendar,XXX,XXX".
152         // The SimpleClassFileLoadHook agent would attempt to hook the java/util/Calendar class
153         // but leave the class file bytes unchanged (it replaces all bytes "XXX" with "XXX", i.e.,
154         // a no-op). JVMTI doesn't check the class file bytes returned by the agent, so as long
155         // as the agent returns a buffer, it will not load the class from CDS, and will instead
156         // load the class by parsing the buffer.
157         //
158         // Note that for safety we don't change the contents of the class file bytes. If in the
159         // future JVMTI starts checking the contents of the class file bytes, this test would need
160         // to be updated. (You'd see the test case with java/util/Calendar staring to fail).
161         String agent = "-agentlib:SimpleClassFileLoadHook=" + early + klassName + ",XXX,XXX";
162 
163         CDSOptions opts = (new CDSOptions())
164             .setXShareMode("auto")
165             .setArchiveName(ReplaceCriticalClasses.class.getName() + ".jsa")
166             .setUseVersion(false)
167             .addSuffix("-showversion",
168                        "-Xlog:aot",
169                        "-Xlog:cds",
170                        "-XX:+UnlockDiagnosticVMOptions",
171                        agent);
172         if (whitebox) {
173             opts.addSuffix("-XX:+WhiteBoxAPI",
174                            "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"));
175         }
176         opts.addSuffix("-Xlog:aot,aot+heap,cds");
177         opts.addSuffix("ReplaceCriticalClasses",
178                        "child",
179                        shared,
180                        klassName);
< prev index next >