Skip to content

Commit

Permalink
8275868: ciReplay: Inlining fails with "unloaded signature classes" d…
Browse files Browse the repository at this point in the history
…ue to wrong protection domains

Reviewed-by: kvn, dlong, thartmann
  • Loading branch information
chhagedorn committed Nov 1, 2021
1 parent 158831e commit 5bb1992
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/hotspot/share/ci/ciEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,9 @@ void ciEnv::dump_replay_data_helper(outputStream* out) {

GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata();
out->print_cr("# %d ciObject found", objects->length());
// The very first entry is the InstanceKlass of the root method of the current compilation in order to get the right
// protection domain to load subsequent classes during replay compilation.
out->print_cr("instanceKlass %s", CURRENT_ENV->replay_name(task()->method()->method_holder()));
for (int i = 0; i < objects->length(); i++) {
objects->at(i)->dump_replay_data(out);
}
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/ci/ciReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,12 @@ class CompileReplay : public StackObj {
void process_instanceKlass(TRAPS) {
// just load the referenced class
Klass* k = parse_klass(CHECK);
if (_protection_domain() == NULL) {
// The first entry is the holder class of the method for which a replay compilation is requested.
// Use the same protection domain to load all subsequent classes in order to resolve all classes
// in signatures of inlinees. This ensures that inlining can be done as stated in the replay file.
_protection_domain = Handle(_thread, k->protection_domain());
}
if (k == NULL) {
return;
}
Expand Down
17 changes: 13 additions & 4 deletions test/hotspot/jtreg/compiler/ciReplay/CiReplayBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public abstract class CiReplayBase {
REPLAY_FILE_OPTION};
private static final String[] REPLAY_OPTIONS = new String[]{DISABLE_COREDUMP_ON_CRASH,
"-XX:+IgnoreUnrecognizedVMOptions", "-XX:TypeProfileLevel=222",
"-XX:+ReplayCompiles", REPLAY_FILE_OPTION};
"-XX:+ReplayCompiles"};
protected final Optional<Boolean> runServer;
private static int dummy;

Expand Down Expand Up @@ -152,14 +152,18 @@ private static void removeFromCurrentDirectoryStartingWith(String prefix) {
.forEach(File::delete);
}

public static void cleanup() {
public void cleanup() {
removeFromCurrentDirectoryStartingWith("core");
removeFromCurrentDirectoryStartingWith("replay");
removeFromCurrentDirectoryStartingWith(HS_ERR_NAME);
remove(TEST_CORE_FILE_NAME);
remove(REPLAY_FILE_NAME);
}

public String getReplayFileName() {
return REPLAY_FILE_NAME;
}

public boolean generateReplay(boolean needCoreDump, String... vmopts) {
OutputAnalyzer crashOut;
String crashOutputString;
Expand All @@ -170,13 +174,13 @@ public boolean generateReplay(boolean needCoreDump, String... vmopts) {
options.add(needCoreDump ? ENABLE_COREDUMP_ON_CRASH : DISABLE_COREDUMP_ON_CRASH);
if (needCoreDump) {
// CiReplayBase$TestMain needs to be quoted because of shell eval
options.add("-XX:CompileOnly='" + getTestClass() + "::test'");
options.add("-XX:CompileOnly='" + getTestClass() + "::" + getTestMethod() + "'");
options.add("'" + getTestClass() + "'");
crashOut = ProcessTools.executeProcess(
CoreUtils.addCoreUlimitCommand(
ProcessTools.createTestJvm(options.toArray(new String[0]))));
} else {
options.add("-XX:CompileOnly=" + getTestClass() + "::test");
options.add("-XX:CompileOnly=" + getTestClass() + "::" + getTestMethod());
options.add(getTestClass());
crashOut = ProcessTools.executeProcess(ProcessTools.createTestJvm(options));
}
Expand Down Expand Up @@ -204,6 +208,10 @@ public String getTestClass() {
return TestMain.class.getName();
}

public String getTestMethod() {
return "test";
}

public void commonTests() {
positiveTest();
if (Platform.isTieredSupported()) {
Expand All @@ -215,6 +223,7 @@ public int startTest(String... additionalVmOpts) {
try {
List<String> allAdditionalOpts = new ArrayList<>();
allAdditionalOpts.addAll(Arrays.asList(REPLAY_OPTIONS));
allAdditionalOpts.add("-XX:ReplayDataFile=" + getReplayFileName());
allAdditionalOpts.addAll(Arrays.asList(additionalVmOpts));
OutputAnalyzer oa = ProcessTools.executeProcess(getTestJvmCommandlineWithPrefix(
RUN_SHELL_ZERO_LIMIT, allAdditionalOpts.toArray(new String[0])));
Expand Down
112 changes: 112 additions & 0 deletions test/hotspot/jtreg/compiler/ciReplay/DumpReplayBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2021, 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.
*/

package compiler.ciReplay;

import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public abstract class DumpReplayBase extends CiReplayBase {

private static final String DUMP_REPLAY_PATTERN = "replay_pid";
private List<File> replayFiles;
private String replayFileName;

@Override
public void runTest(boolean needCoreDump, String... args) {
throw new RuntimeException("use runTests(String...)");
}

public void runTest(String... args) {
if (generateReplay(args)) {
testAction();
cleanup();
} else {
throw new Error("Host is not configured to generate cores");
}
}

@Override
public void cleanup() {
replayFiles.forEach(f -> remove(f.getName()));
}

@Override
public String getReplayFileName() {
Asserts.assertEQ(replayFiles.size(), 1, "Test should only dump 1 replay file when trying to replay compile");
return replayFileName;
}

public boolean generateReplay(String... vmopts) {
OutputAnalyzer oa;
try {
List<String> options = new ArrayList<>(Arrays.asList(vmopts));
options.add("-XX:CompileCommand=option," + getTestClass() + "::" + getTestMethod() + ",bool,DumpReplay,true");
options.add("-XX:+IgnoreUnrecognizedVMOptions");
options.add("-XX:TypeProfileLevel=222");
options.add("-XX:CompileCommand=compileonly," + getTestClass() + "::" + getTestMethod());
options.add("-Xbatch");
options.add(getTestClass());
oa = ProcessTools.executeProcess(ProcessTools.createTestJvm(options));
Asserts.assertEquals(oa.getExitValue(), 0, "Crash JVM exits gracefully");
replayFiles = Files.list(Paths.get("."))
.map(Path::toFile)
.filter(f -> f.getName().startsWith(DUMP_REPLAY_PATTERN)).collect(Collectors.toList());
Asserts.assertFalse(replayFiles.isEmpty(), "Did not find a replay file starting with " + DUMP_REPLAY_PATTERN);
replayFileName = replayFiles.get(0).getName();
} catch (Throwable t) {
throw new Error("Can't create replay: " + t, t);
}
return true;
}

public int getCompileIdFromFile(String replayFileName) {
Pattern p = Pattern.compile("replay_pid.*_compid([0-9]+)\\.log");
Matcher matcher = p.matcher(replayFileName);
if (matcher.find()) {
try {
return Integer.parseInt(matcher.group(1));
} catch (NumberFormatException e) {
throw new RuntimeException("Could not parse compile id from filename \"" + replayFileName + "\"");
}
} else {
throw new RuntimeException("Could not find compile id in filename \"" + replayFileName + "\"");
}
}

public List<File> getReplayFiles() {
return replayFiles;
}
}
Loading

1 comment on commit 5bb1992

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.