Skip to content

Commit ba77d0b

Browse files
committed
8275868: ciReplay: Inlining fails with "unloaded signature classes" due to wrong protection domains
Reviewed-by: mdoerr Backport-of: 5bb1992b8408a0d196b1afa308bc00d007458dbd
1 parent a6180f7 commit ba77d0b

File tree

6 files changed

+467
-5
lines changed

6 files changed

+467
-5
lines changed

src/hotspot/share/ci/ciEnv.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,27 @@ ciInstance* ciEnv::unloaded_ciinstance() {
11851185
// Don't change thread state and acquire any locks.
11861186
// Safe to call from VM error reporter.
11871187

1188+
1189+
// Look up the location descriptor for the given class and return it as a string.
1190+
// Returns the class name as a fallback if no location is found.
1191+
const char *ciEnv::replay_name(ciKlass* k) const {
1192+
if (k->is_instance_klass()) {
1193+
return replay_name(k->as_instance_klass()->get_instanceKlass());
1194+
}
1195+
return k->name()->as_quoted_ascii();
1196+
}
1197+
1198+
// Look up the location descriptor for the given class and return it as a string.
1199+
// Returns the class name as a fallback if no location is found.
1200+
const char *ciEnv::replay_name(const InstanceKlass* ik) const {
1201+
// JDK-8271911 is not in JDK 17, so we fall back to using the class name below.
1202+
const char* name = nullptr; // dyno_name(ik);
1203+
if (name != nullptr) {
1204+
return name;
1205+
}
1206+
return ik->name()->as_quoted_ascii();
1207+
}
1208+
11881209
void ciEnv::dump_compile_data(outputStream* out) {
11891210
CompileTask* task = this->task();
11901211
if (task) {
@@ -1223,6 +1244,9 @@ void ciEnv::dump_replay_data_unsafe(outputStream* out) {
12231244

12241245
GrowableArray<ciMetadata*>* objects = _factory->get_ci_metadata();
12251246
out->print_cr("# %d ciObject found", objects->length());
1247+
// The very first entry is the InstanceKlass of the root method of the current compilation in order to get the right
1248+
// protection domain to load subsequent classes during replay compilation.
1249+
out->print_cr("instanceKlass %s", CURRENT_ENV->replay_name(task()->method()->method_holder()));
12261250
for (int i = 0; i < objects->length(); i++) {
12271251
objects->at(i)->dump_replay_data(out);
12281252
}

src/hotspot/share/ci/ciEnv.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ class ciEnv : StackObj {
466466
void dump_replay_data(outputStream* out);
467467
void dump_replay_data_unsafe(outputStream* out);
468468
void dump_compile_data(outputStream* out);
469+
470+
const char *replay_name(const InstanceKlass* ik) const;
471+
const char *replay_name(ciKlass* i) const;
469472
};
470473

471474
#endif // SHARE_CI_CIENV_HPP

src/hotspot/share/ci/ciReplay.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,12 @@ class CompileReplay : public StackObj {
685685
void process_instanceKlass(TRAPS) {
686686
// just load the referenced class
687687
Klass* k = parse_klass(CHECK);
688+
if (_protection_domain() == NULL) {
689+
// The first entry is the holder class of the method for which a replay compilation is requested.
690+
// Use the same protection domain to load all subsequent classes in order to resolve all classes
691+
// in signatures of inlinees. This ensures that inlining can be done as stated in the replay file.
692+
_protection_domain = Handle(_thread, k->protection_domain());
693+
}
688694
}
689695

690696
// ciInstanceKlass <name> <is_linked> <is_initialized> <length> tag*

test/hotspot/jtreg/compiler/ciReplay/CiReplayBase.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public abstract class CiReplayBase {
7272
"-XX:+PreferInterpreterNativeStubs", REPLAY_FILE_OPTION};
7373
private static final String[] REPLAY_OPTIONS = new String[]{DISABLE_COREDUMP_ON_CRASH,
7474
"-XX:+IgnoreUnrecognizedVMOptions", "-XX:TypeProfileLevel=222",
75-
"-XX:+ReplayCompiles", REPLAY_FILE_OPTION};
75+
"-XX:+ReplayCompiles"};
7676
protected final Optional<Boolean> runServer;
7777
private static int dummy;
7878

@@ -124,7 +124,7 @@ public void runTest(boolean needCoreDump, String... args) {
124124

125125
public abstract void testAction();
126126

127-
private static void remove(String item) {
127+
public static void remove(String item) {
128128
File toDelete = new File(item);
129129
toDelete.delete();
130130
if (Platform.isWindows()) {
@@ -138,14 +138,18 @@ private static void removeFromCurrentDirectoryStartingWith(String prefix) {
138138
.forEach(File::delete);
139139
}
140140

141-
public static void cleanup() {
141+
public void cleanup() {
142142
removeFromCurrentDirectoryStartingWith("core");
143143
removeFromCurrentDirectoryStartingWith("replay");
144144
removeFromCurrentDirectoryStartingWith(HS_ERR_NAME);
145145
remove(TEST_CORE_FILE_NAME);
146146
remove(REPLAY_FILE_NAME);
147147
}
148148

149+
public String getReplayFileName() {
150+
return REPLAY_FILE_NAME;
151+
}
152+
149153
public boolean generateReplay(boolean needCoreDump, String... vmopts) {
150154
OutputAnalyzer crashOut;
151155
String crashOutputString;
@@ -156,13 +160,13 @@ public boolean generateReplay(boolean needCoreDump, String... vmopts) {
156160
options.add(needCoreDump ? ENABLE_COREDUMP_ON_CRASH : DISABLE_COREDUMP_ON_CRASH);
157161
if (needCoreDump) {
158162
// CiReplayBase$TestMain needs to be quoted because of shell eval
159-
options.add("-XX:CompileOnly='" + TestMain.class.getName() + "::test'");
163+
options.add("-XX:CompileOnly='" + TestMain.class.getName() + "::" + getTestMethod() + "'");
160164
options.add("'" + TestMain.class.getName() + "'");
161165
crashOut = ProcessTools.executeProcess(
162166
CoreUtils.addCoreUlimitCommand(
163167
ProcessTools.createTestJvm(options.toArray(new String[0]))));
164168
} else {
165-
options.add("-XX:CompileOnly=" + TestMain.class.getName() + "::test");
169+
options.add("-XX:CompileOnly=" + TestMain.class.getName() + "::" + getTestMethod());
166170
options.add(TestMain.class.getName());
167171
crashOut = ProcessTools.executeProcess(ProcessTools.createTestJvm(options));
168172
}
@@ -186,6 +190,14 @@ public boolean generateReplay(boolean needCoreDump, String... vmopts) {
186190
return true;
187191
}
188192

193+
public String getTestClass() {
194+
return TestMain.class.getName();
195+
}
196+
197+
public String getTestMethod() {
198+
return "test";
199+
}
200+
189201
public void commonTests() {
190202
positiveTest();
191203
if (Platform.isTieredSupported()) {
@@ -197,6 +209,7 @@ public int startTest(String... additionalVmOpts) {
197209
try {
198210
List<String> allAdditionalOpts = new ArrayList<>();
199211
allAdditionalOpts.addAll(Arrays.asList(REPLAY_OPTIONS));
212+
allAdditionalOpts.add("-XX:ReplayDataFile=" + getReplayFileName());
200213
allAdditionalOpts.addAll(Arrays.asList(additionalVmOpts));
201214
OutputAnalyzer oa = ProcessTools.executeProcess(getTestJvmCommandlineWithPrefix(
202215
RUN_SHELL_ZERO_LIMIT, allAdditionalOpts.toArray(new String[0])));
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package compiler.ciReplay;
25+
26+
import jdk.test.lib.Asserts;
27+
import jdk.test.lib.process.OutputAnalyzer;
28+
import jdk.test.lib.process.ProcessTools;
29+
30+
import java.io.File;
31+
import java.nio.file.Files;
32+
import java.nio.file.Path;
33+
import java.nio.file.Paths;
34+
import java.util.ArrayList;
35+
import java.util.Arrays;
36+
import java.util.List;
37+
import java.util.regex.Matcher;
38+
import java.util.regex.Pattern;
39+
import java.util.stream.Collectors;
40+
41+
public abstract class DumpReplayBase extends CiReplayBase {
42+
43+
private static final String DUMP_REPLAY_PATTERN = "replay_pid";
44+
private List<File> replayFiles;
45+
private String replayFileName;
46+
47+
@Override
48+
public void runTest(boolean needCoreDump, String... args) {
49+
throw new RuntimeException("use runTests(String...)");
50+
}
51+
52+
public void runTest(String... args) {
53+
if (generateReplay(args)) {
54+
testAction();
55+
cleanup();
56+
} else {
57+
throw new Error("Host is not configured to generate cores");
58+
}
59+
}
60+
61+
@Override
62+
public void cleanup() {
63+
replayFiles.forEach(f -> remove(f.getName()));
64+
}
65+
66+
@Override
67+
public String getReplayFileName() {
68+
Asserts.assertEQ(replayFiles.size(), 1, "Test should only dump 1 replay file when trying to replay compile");
69+
return replayFileName;
70+
}
71+
72+
public boolean generateReplay(String... vmopts) {
73+
OutputAnalyzer oa;
74+
try {
75+
List<String> options = new ArrayList<>(Arrays.asList(vmopts));
76+
options.add("-XX:CompileCommand=option," + getTestClass() + "::" + getTestMethod() + ",bool,DumpReplay,true");
77+
options.add("-XX:+IgnoreUnrecognizedVMOptions");
78+
options.add("-XX:TypeProfileLevel=222");
79+
options.add("-XX:CompileCommand=compileonly," + getTestClass() + "::" + getTestMethod());
80+
options.add("-Xbatch");
81+
options.add(getTestClass());
82+
oa = ProcessTools.executeProcess(ProcessTools.createTestJvm(options));
83+
Asserts.assertEquals(oa.getExitValue(), 0, "Crash JVM exits gracefully");
84+
replayFiles = Files.list(Paths.get("."))
85+
.map(Path::toFile)
86+
.filter(f -> f.getName().startsWith(DUMP_REPLAY_PATTERN)).collect(Collectors.toList());
87+
Asserts.assertFalse(replayFiles.isEmpty(), "Did not find a replay file starting with " + DUMP_REPLAY_PATTERN);
88+
replayFileName = replayFiles.get(0).getName();
89+
} catch (Throwable t) {
90+
throw new Error("Can't create replay: " + t, t);
91+
}
92+
return true;
93+
}
94+
95+
public int getCompileIdFromFile(String replayFileName) {
96+
Pattern p = Pattern.compile("replay_pid.*_compid([0-9]+)\\.log");
97+
Matcher matcher = p.matcher(replayFileName);
98+
if (matcher.find()) {
99+
try {
100+
return Integer.parseInt(matcher.group(1));
101+
} catch (NumberFormatException e) {
102+
throw new RuntimeException("Could not parse compile id from filename \"" + replayFileName + "\"");
103+
}
104+
} else {
105+
throw new RuntimeException("Could not find compile id in filename \"" + replayFileName + "\"");
106+
}
107+
}
108+
109+
public List<File> getReplayFiles() {
110+
return replayFiles;
111+
}
112+
}

0 commit comments

Comments
 (0)