8214086: [TESTBUG] Fix subgraph test cases in ReplaceCriticalClasses.java

Add subgraph test cases in ReplaceCriticalClassesForSubgraphs.java.

Reviewed-by: iklam
This commit is contained in:
Jiangli Zhou 2018-11-26 14:13:22 -05:00
parent ae4f1b1941
commit e0d9ae7699
3 changed files with 98 additions and 17 deletions

View file

@ -441,11 +441,6 @@ void HeapShared::initialize_from_archived_subgraph(Klass* k) {
// during VM initialization time. No lock is needed. // during VM initialization time. No lock is needed.
if (record != NULL) { if (record != NULL) {
Thread* THREAD = Thread::current(); Thread* THREAD = Thread::current();
if (log_is_enabled(Info, cds, heap)) {
ResourceMark rm;
log_info(cds, heap)("initialize_from_archived_subgraph " PTR_FORMAT " %s", p2i(k),
k->external_name());
}
int i; int i;
// Load/link/initialize the klasses of the objects in the subgraph. // Load/link/initialize the klasses of the objects in the subgraph.
@ -511,8 +506,13 @@ void HeapShared::initialize_from_archived_subgraph(Klass* k) {
log_debug(cds, heap)(" " PTR_FORMAT " init field @ %2d = " PTR_FORMAT, p2i(k), field_offset, p2i(v)); log_debug(cds, heap)(" " PTR_FORMAT " init field @ %2d = " PTR_FORMAT, p2i(k), field_offset, p2i(v));
} }
// Done. Java code can see the archived sub-graphs referenced from k's // Done. Java code can see the archived sub-graphs referenced from k's
// mirror after this point. // mirror after this point.
if (log_is_enabled(Info, cds, heap)) {
ResourceMark rm;
log_info(cds, heap)("initialize_from_archived_subgraph %s " PTR_FORMAT,
k->external_name(), p2i(k));
}
} }
} }
} }

View file

@ -41,8 +41,13 @@ import sun.hotspot.WhiteBox;
public class ReplaceCriticalClasses { public class ReplaceCriticalClasses {
public static void main(String args[]) throws Throwable { public static void main(String args[]) throws Throwable {
ReplaceCriticalClasses rcc = new ReplaceCriticalClasses();
rcc.process(args);
}
public void process(String args[]) throws Throwable {
if (args.length == 0) { if (args.length == 0) {
launchChildProcesses(); launchChildProcesses(getTests());
} else if (args.length == 3 && args[0].equals("child")) { } else if (args.length == 3 && args[0].equals("child")) {
Class klass = Class.forName(args[2].replace("/", ".")); Class klass = Class.forName(args[2].replace("/", "."));
if (args[1].equals("-shared")) { if (args[1].equals("-shared")) {
@ -58,7 +63,7 @@ public class ReplaceCriticalClasses {
} }
} }
static void launchChildProcesses() throws Throwable { public String[] getTests() {
String tests[] = { String tests[] = {
// CDS should be disabled -- these critical classes will be replaced // CDS should be disabled -- these critical classes will be replaced
// because JvmtiExport::early_class_hook_env() is true. // because JvmtiExport::early_class_hook_env() is true.
@ -74,18 +79,25 @@ public class ReplaceCriticalClasses {
"java/lang/Cloneable", "java/lang/Cloneable",
"java/io/Serializable", "java/io/Serializable",
// Try to replace classes that are used by the archived subgraph graphs. /* Try to replace classes that are used by the archived subgraph graphs.
"-subgraph java/util/ArrayList", The following test cases are in ReplaceCriticalClassesForSubgraphs.java.
"-subgraph java/lang/module/ResolvedModule", "-early -notshared -subgraph java/lang/module/ResolvedModule jdk.internal.module.ArchivedModuleGraph",
"-early -notshared -subgraph java/lang/Long java.lang.Long$LongCache",
"-subgraph java/lang/Long java.lang.Long$LongCache",
*/
// Replace classes that are loaded after JVMTI_PHASE_PRIMORDIAL. It's OK to replace such // Replace classes that are loaded after JVMTI_PHASE_PRIMORDIAL. It's OK to replace
// such
// classes even when CDS is enabled. Nothing bad should happen. // classes even when CDS is enabled. Nothing bad should happen.
"-notshared jdk/internal/vm/PostVMInitHook", "-notshared jdk/internal/vm/PostVMInitHook",
"-notshared java/util/Locale", "-notshared java/util/Locale",
"-notshared sun/util/locale/BaseLocale", "-notshared sun/util/locale/BaseLocale",
"-notshared java/lang/Readable", "-notshared java/lang/Readable",
}; };
return tests;
}
static void launchChildProcesses(String tests[]) throws Throwable {
int n = 0; int n = 0;
for (String s : tests) { for (String s : tests) {
System.out.println("Test case[" + (n++) + "] = \"" + s + "\""); System.out.println("Test case[" + (n++) + "] = \"" + s + "\"");
@ -96,9 +108,10 @@ public class ReplaceCriticalClasses {
static void launchChild(String args[]) throws Throwable { static void launchChild(String args[]) throws Throwable {
if (args.length < 1) { if (args.length < 1) {
throw new RuntimeException("Invalid test case. Should be <-early> <-subgraph> <-notshared> klassName"); throw new RuntimeException("Invalid test case. Should be <-early> <-subgraph> <-notshared> klassName subgraphKlass");
} }
String klassName = null; String klassName = null;
String subgraphKlass = null;
String early = ""; String early = "";
boolean subgraph = false; boolean subgraph = false;
String shared = "-shared"; String shared = "-shared";
@ -112,11 +125,19 @@ public class ReplaceCriticalClasses {
} else if (opt.equals("-notshared")) { } else if (opt.equals("-notshared")) {
shared = opt; shared = opt;
} else { } else {
if (!subgraph) {
throw new RuntimeException("Unknown option: " + opt); throw new RuntimeException("Unknown option: " + opt);
}
} }
} }
klassName = args[args.length-1]; if (subgraph) {
klassName = args[args.length-2];
subgraphKlass = args[args.length-1];
} else {
klassName = args[args.length-1];
}
Class.forName(klassName.replace("/", ".")); // make sure it's a valid class Class.forName(klassName.replace("/", ".")); // make sure it's a valid class
final String subgraphInit = "initialize_from_archived_subgraph " + subgraphKlass;
// We will pass an option like "-agentlib:SimpleClassFileLoadHook=java/util/Locale,XXX,XXX". // We will pass an option like "-agentlib:SimpleClassFileLoadHook=java/util/Locale,XXX,XXX".
// The SimpleClassFileLoadHook agent would attempt to hook the java/util/Locale class // The SimpleClassFileLoadHook agent would attempt to hook the java/util/Locale class
@ -142,8 +163,7 @@ public class ReplaceCriticalClasses {
"-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar")); "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"));
if (subgraph) { if (subgraph) {
opts.addSuffix("-Xlog:cds+heap", opts.addSuffix("-Xlog:cds,cds+heap");
"-Xlog:class+load");
} }
opts.addSuffix("ReplaceCriticalClasses", opts.addSuffix("ReplaceCriticalClasses",
@ -152,11 +172,22 @@ public class ReplaceCriticalClasses {
klassName); klassName);
final boolean expectDisable = !early.equals(""); final boolean expectDisable = !early.equals("");
final boolean checkSubgraph = subgraph;
final boolean expectShared = shared.equals("-shared");
CDSTestUtils.run(opts).assertNormalExit(out -> { CDSTestUtils.run(opts).assertNormalExit(out -> {
if (expectDisable) { if (expectDisable) {
out.shouldContain("UseSharedSpaces: CDS is disabled because early JVMTI ClassFileLoadHook is in use."); out.shouldContain("UseSharedSpaces: CDS is disabled because early JVMTI ClassFileLoadHook is in use.");
System.out.println("CDS disabled as expected"); System.out.println("CDS disabled as expected");
} }
if (checkSubgraph) {
if (expectShared) {
if (!out.getOutput().contains("UseSharedSpaces: Unable to map at required address in java heap")) {
out.shouldContain(subgraphInit);
}
} else {
out.shouldNotContain(subgraphInit);
}
}
}); });
} }

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2018, Oracle and/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.
*
*/
/*
* @test
* @summary Tests how CDS works when critical library classes are replaced with JVMTI ClassFileLoadHook
* @library /test/lib
* @requires vm.cds.archived.java.heap
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox
* @run main/othervm/native ReplaceCriticalClassesForSubgraphs
*/
public class ReplaceCriticalClassesForSubgraphs extends ReplaceCriticalClasses {
public static void main(String args[]) throws Throwable {
ReplaceCriticalClassesForSubgraphs rcc = new ReplaceCriticalClassesForSubgraphs();
rcc.process(args);
}
public String[] getTests() {
String tests[] = {
// Try to replace classes that are used by the archived subgraph graphs.
"-early -notshared -subgraph java/lang/module/ResolvedModule jdk.internal.module.ArchivedModuleGraph",
"-early -notshared -subgraph java/lang/Long java.lang.Long$LongCache",
"-subgraph java/lang/Long java.lang.Long$LongCache",
};
return tests;
}
}