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: mdoerr
Backport-of: 5bb1992b8408a0d196b1afa308bc00d007458dbd
  • Loading branch information
GoeLin committed Mar 29, 2024
1 parent a6180f7 commit ba77d0b
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/hotspot/share/ci/ciEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,27 @@ ciInstance* ciEnv::unloaded_ciinstance() {
// Don't change thread state and acquire any locks.
// Safe to call from VM error reporter.


// Look up the location descriptor for the given class and return it as a string.
// Returns the class name as a fallback if no location is found.
const char *ciEnv::replay_name(ciKlass* k) const {
if (k->is_instance_klass()) {
return replay_name(k->as_instance_klass()->get_instanceKlass());
}
return k->name()->as_quoted_ascii();
}

// Look up the location descriptor for the given class and return it as a string.
// Returns the class name as a fallback if no location is found.
const char *ciEnv::replay_name(const InstanceKlass* ik) const {
// JDK-8271911 is not in JDK 17, so we fall back to using the class name below.
const char* name = nullptr; // dyno_name(ik);
if (name != nullptr) {
return name;
}
return ik->name()->as_quoted_ascii();
}

void ciEnv::dump_compile_data(outputStream* out) {
CompileTask* task = this->task();
if (task) {
Expand Down Expand Up @@ -1223,6 +1244,9 @@ void ciEnv::dump_replay_data_unsafe(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
3 changes: 3 additions & 0 deletions src/hotspot/share/ci/ciEnv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ class ciEnv : StackObj {
void dump_replay_data(outputStream* out);
void dump_replay_data_unsafe(outputStream* out);
void dump_compile_data(outputStream* out);

const char *replay_name(const InstanceKlass* ik) const;
const char *replay_name(ciKlass* i) const;
};

#endif // SHARE_CI_CIENV_HPP
6 changes: 6 additions & 0 deletions src/hotspot/share/ci/ciReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,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());
}
}

// ciInstanceKlass <name> <is_linked> <is_initialized> <length> tag*
Expand Down
23 changes: 18 additions & 5 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 {
"-XX:+PreferInterpreterNativeStubs", 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 @@ -124,7 +124,7 @@ public void runTest(boolean needCoreDump, String... args) {

public abstract void testAction();

private static void remove(String item) {
public static void remove(String item) {
File toDelete = new File(item);
toDelete.delete();
if (Platform.isWindows()) {
Expand All @@ -138,14 +138,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 @@ -156,13 +160,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='" + TestMain.class.getName() + "::test'");
options.add("-XX:CompileOnly='" + TestMain.class.getName() + "::" + getTestMethod() + "'");
options.add("'" + TestMain.class.getName() + "'");
crashOut = ProcessTools.executeProcess(
CoreUtils.addCoreUlimitCommand(
ProcessTools.createTestJvm(options.toArray(new String[0]))));
} else {
options.add("-XX:CompileOnly=" + TestMain.class.getName() + "::test");
options.add("-XX:CompileOnly=" + TestMain.class.getName() + "::" + getTestMethod());
options.add(TestMain.class.getName());
crashOut = ProcessTools.executeProcess(ProcessTools.createTestJvm(options));
}
Expand All @@ -186,6 +190,14 @@ public boolean generateReplay(boolean needCoreDump, String... vmopts) {
return true;
}

public String getTestClass() {
return TestMain.class.getName();
}

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

public void commonTests() {
positiveTest();
if (Platform.isTieredSupported()) {
Expand All @@ -197,6 +209,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 ba77d0b

@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.