Skip to content

Commit 5bb1992

Browse files
committed
8275868: ciReplay: Inlining fails with "unloaded signature classes" due to wrong protection domains
Reviewed-by: kvn, dlong, thartmann
1 parent 158831e commit 5bb1992

File tree

5 files changed

+438
-4
lines changed

5 files changed

+438
-4
lines changed

src/hotspot/share/ci/ciEnv.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,9 @@ void ciEnv::dump_replay_data_helper(outputStream* out) {
16461646

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

src/hotspot/share/ci/ciReplay.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,12 @@ class CompileReplay : public StackObj {
874874
void process_instanceKlass(TRAPS) {
875875
// just load the referenced class
876876
Klass* k = parse_klass(CHECK);
877+
if (_protection_domain() == NULL) {
878+
// The first entry is the holder class of the method for which a replay compilation is requested.
879+
// Use the same protection domain to load all subsequent classes in order to resolve all classes
880+
// in signatures of inlinees. This ensures that inlining can be done as stated in the replay file.
881+
_protection_domain = Handle(_thread, k->protection_domain());
882+
}
877883
if (k == NULL) {
878884
return;
879885
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public abstract class CiReplayBase {
7272
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

@@ -152,14 +152,18 @@ private static void removeFromCurrentDirectoryStartingWith(String prefix) {
152152
.forEach(File::delete);
153153
}
154154

155-
public static void cleanup() {
155+
public void cleanup() {
156156
removeFromCurrentDirectoryStartingWith("core");
157157
removeFromCurrentDirectoryStartingWith("replay");
158158
removeFromCurrentDirectoryStartingWith(HS_ERR_NAME);
159159
remove(TEST_CORE_FILE_NAME);
160160
remove(REPLAY_FILE_NAME);
161161
}
162162

163+
public String getReplayFileName() {
164+
return REPLAY_FILE_NAME;
165+
}
166+
163167
public boolean generateReplay(boolean needCoreDump, String... vmopts) {
164168
OutputAnalyzer crashOut;
165169
String crashOutputString;
@@ -170,13 +174,13 @@ public boolean generateReplay(boolean needCoreDump, String... vmopts) {
170174
options.add(needCoreDump ? ENABLE_COREDUMP_ON_CRASH : DISABLE_COREDUMP_ON_CRASH);
171175
if (needCoreDump) {
172176
// CiReplayBase$TestMain needs to be quoted because of shell eval
173-
options.add("-XX:CompileOnly='" + getTestClass() + "::test'");
177+
options.add("-XX:CompileOnly='" + getTestClass() + "::" + getTestMethod() + "'");
174178
options.add("'" + getTestClass() + "'");
175179
crashOut = ProcessTools.executeProcess(
176180
CoreUtils.addCoreUlimitCommand(
177181
ProcessTools.createTestJvm(options.toArray(new String[0]))));
178182
} else {
179-
options.add("-XX:CompileOnly=" + getTestClass() + "::test");
183+
options.add("-XX:CompileOnly=" + getTestClass() + "::" + getTestMethod());
180184
options.add(getTestClass());
181185
crashOut = ProcessTools.executeProcess(ProcessTools.createTestJvm(options));
182186
}
@@ -204,6 +208,10 @@ public String getTestClass() {
204208
return TestMain.class.getName();
205209
}
206210

211+
public String getTestMethod() {
212+
return "test";
213+
}
214+
207215
public void commonTests() {
208216
positiveTest();
209217
if (Platform.isTieredSupported()) {
@@ -215,6 +223,7 @@ public int startTest(String... additionalVmOpts) {
215223
try {
216224
List<String> allAdditionalOpts = new ArrayList<>();
217225
allAdditionalOpts.addAll(Arrays.asList(REPLAY_OPTIONS));
226+
allAdditionalOpts.add("-XX:ReplayDataFile=" + getReplayFileName());
218227
allAdditionalOpts.addAll(Arrays.asList(additionalVmOpts));
219228
OutputAnalyzer oa = ProcessTools.executeProcess(getTestJvmCommandlineWithPrefix(
220229
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)