8214086: [TESTBUG] Fix subgraph test cases in ReplaceCriticalClasses.java
Add subgraph test cases in ReplaceCriticalClassesForSubgraphs.java. Reviewed-by: iklam
This commit is contained in:
parent
ae4f1b1941
commit
e0d9ae7699
src/hotspot/share/memory
test/hotspot/jtreg/runtime/SharedArchiveFile/serviceability
@ -441,11 +441,6 @@ void HeapShared::initialize_from_archived_subgraph(Klass* k) {
|
||||
// during VM initialization time. No lock is needed.
|
||||
if (record != NULL) {
|
||||
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;
|
||||
// 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));
|
||||
}
|
||||
|
||||
// Done. Java code can see the archived sub-graphs referenced from k's
|
||||
// mirror after this point.
|
||||
// Done. Java code can see the archived sub-graphs referenced from k's
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,13 @@ import sun.hotspot.WhiteBox;
|
||||
|
||||
public class ReplaceCriticalClasses {
|
||||
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) {
|
||||
launchChildProcesses();
|
||||
launchChildProcesses(getTests());
|
||||
} else if (args.length == 3 && args[0].equals("child")) {
|
||||
Class klass = Class.forName(args[2].replace("/", "."));
|
||||
if (args[1].equals("-shared")) {
|
||||
@ -58,7 +63,7 @@ public class ReplaceCriticalClasses {
|
||||
}
|
||||
}
|
||||
|
||||
static void launchChildProcesses() throws Throwable {
|
||||
public String[] getTests() {
|
||||
String tests[] = {
|
||||
// CDS should be disabled -- these critical classes will be replaced
|
||||
// because JvmtiExport::early_class_hook_env() is true.
|
||||
@ -74,18 +79,25 @@ public class ReplaceCriticalClasses {
|
||||
"java/lang/Cloneable",
|
||||
"java/io/Serializable",
|
||||
|
||||
// Try to replace classes that are used by the archived subgraph graphs.
|
||||
"-subgraph java/util/ArrayList",
|
||||
"-subgraph java/lang/module/ResolvedModule",
|
||||
/* Try to replace classes that are used by the archived subgraph graphs.
|
||||
The following test cases are in ReplaceCriticalClassesForSubgraphs.java.
|
||||
"-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.
|
||||
"-notshared jdk/internal/vm/PostVMInitHook",
|
||||
"-notshared java/util/Locale",
|
||||
"-notshared sun/util/locale/BaseLocale",
|
||||
"-notshared java/lang/Readable",
|
||||
};
|
||||
return tests;
|
||||
}
|
||||
|
||||
static void launchChildProcesses(String tests[]) throws Throwable {
|
||||
int n = 0;
|
||||
for (String s : tests) {
|
||||
System.out.println("Test case[" + (n++) + "] = \"" + s + "\"");
|
||||
@ -96,9 +108,10 @@ public class ReplaceCriticalClasses {
|
||||
|
||||
static void launchChild(String args[]) throws Throwable {
|
||||
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 subgraphKlass = null;
|
||||
String early = "";
|
||||
boolean subgraph = false;
|
||||
String shared = "-shared";
|
||||
@ -112,11 +125,19 @@ public class ReplaceCriticalClasses {
|
||||
} else if (opt.equals("-notshared")) {
|
||||
shared = opt;
|
||||
} else {
|
||||
if (!subgraph) {
|
||||
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
|
||||
final String subgraphInit = "initialize_from_archived_subgraph " + subgraphKlass;
|
||||
|
||||
// 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
|
||||
@ -142,8 +163,7 @@ public class ReplaceCriticalClasses {
|
||||
"-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"));
|
||||
|
||||
if (subgraph) {
|
||||
opts.addSuffix("-Xlog:cds+heap",
|
||||
"-Xlog:class+load");
|
||||
opts.addSuffix("-Xlog:cds,cds+heap");
|
||||
}
|
||||
|
||||
opts.addSuffix("ReplaceCriticalClasses",
|
||||
@ -152,11 +172,22 @@ public class ReplaceCriticalClasses {
|
||||
klassName);
|
||||
|
||||
final boolean expectDisable = !early.equals("");
|
||||
final boolean checkSubgraph = subgraph;
|
||||
final boolean expectShared = shared.equals("-shared");
|
||||
CDSTestUtils.run(opts).assertNormalExit(out -> {
|
||||
if (expectDisable) {
|
||||
out.shouldContain("UseSharedSpaces: CDS is disabled because early JVMTI ClassFileLoadHook is in use.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
50
test/hotspot/jtreg/runtime/SharedArchiveFile/serviceability/ReplaceCriticalClassesForSubgraphs.java
Normal file
50
test/hotspot/jtreg/runtime/SharedArchiveFile/serviceability/ReplaceCriticalClassesForSubgraphs.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user