Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@
package jdk.graal.compiler.hotspot.test;

import java.io.IOException;
import java.nio.file.AccessDeniedException;

import org.junit.Assert;
import org.junit.Test;

import jdk.graal.compiler.api.directives.GraalDirectives;
import jdk.graal.compiler.core.test.GraalCompilerTest;
import jdk.graal.compiler.debug.DebugCloseable;
import jdk.graal.compiler.debug.DebugContext;
import jdk.graal.compiler.debug.DebugOptions;
import jdk.graal.compiler.hotspot.CompilationTask;
import jdk.graal.compiler.hotspot.HotSpotGraalCompiler;
import jdk.graal.compiler.hotspot.ProfileReplaySupport;
import jdk.graal.compiler.nodes.spi.StableProfileProvider;
import jdk.graal.compiler.options.OptionValues;
import org.junit.Assert;
import org.junit.Test;

import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
Expand Down Expand Up @@ -116,6 +120,29 @@ public void testProfileReplay() throws IOException {
}
}

@Test
@SuppressWarnings("try")
public void testFailingProfileReplay() throws IOException {
final ResolvedJavaMethod method = getResolvedJavaMethod("foo");
try (TemporaryDirectory temp = new TemporaryDirectory("ProfileReplayTest")) {
OptionValues overrides = new OptionValues(getInitialOptions(), DebugOptions.DumpPath, temp.toString(), ProfileReplaySupport.Options.SaveProfiles, true);
try (DebugContext debug = getDebugContext(overrides)) {

// make sure the ProfileReplay fails when trying to save the profiles
temp.path.toFile().setWritable(false);
ProfileReplaySupport profileReplay = ProfileReplaySupport.profileReplayPrologue(debug, 0, method, new StableProfileProvider(), null);

try (DebugContext.Scope scope = debug.scope("TestScope"); DebugCloseable closable = debug.disableIntercept()) {
/*
* we haven't compiled anything, we just want ProfileReplay to save the profiles
* (and fail)
*/
Assert.assertThrows(AccessDeniedException.class, () -> profileReplay.profileReplayEpilogue(debug, null, null, new StableProfileProvider(), getCompilationId(method), 0, method));
}
}
}
}

private static void runInitialCompilation(ResolvedJavaMethod m, OptionValues rootOptions, HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalCompiler compiler) {
HotSpotCompilationRequest request = new HotSpotCompilationRequest((HotSpotResolvedJavaMethod) m, -1, 0L);
OptionValues opt = new OptionValues(rootOptions, ProfileReplaySupport.Options.StrictProfiles, true, ProfileReplaySupport.Options.SaveProfiles, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,14 @@ public String formatLamdaName(ResolvedJavaMethod m) {
* {@link Options#WarnAboutGraphSignatureMismatch}). If {@link Options#SaveProfiles} is set, the
* method additionally saves the previously collected profiles to the given profile path.
*/
@SuppressWarnings("try")
public void profileReplayEpilogue(DebugContext debug, CompilationResult result, StructuredGraph graph, StableProfileProvider profileProvider, CompilationIdentifier compilationId,
int entryBCI, ResolvedJavaMethod method) {
if ((SaveProfiles.getValue(debug.getOptions()) || LoadProfiles.getValue(debug.getOptions()) != null) && profileFilter.matches(method)) {
String codeSignature = null;
String graphSignature = null;
if (result != null) {
try {
try (DebugContext.Scope scope = debug.scope("ProfileReplay")) {
codeSignature = result.getCodeSignature();
assert graph != null;
String s = getCanonicalGraphString(graph);
Expand All @@ -252,7 +253,7 @@ public void profileReplayEpilogue(DebugContext debug, CompilationResult result,
}
}
if (SaveProfiles.getValue(debug.getOptions())) {
try {
try (DebugContext.Scope scope = debug.scope("ProfileReplay")) {
EconomicMap<String, Object> map = EconomicMap.create();
map.put("identifier", compilationId.toString());
map.put("method", method.format("%H.%n(%P)%R"));
Expand Down