Skip to content

Commit

Permalink
Throw in case of errors at end of compilation in LibGraalCompilationD…
Browse files Browse the repository at this point in the history
…river
  • Loading branch information
c-refice committed Mar 4, 2024
1 parent 2a40e67 commit 5d31d56
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public CompileTheWorld(HotSpotJVMCIRuntime jvmciRuntime,
super(jvmciRuntime, compiler,
Options.InvalidateInstalledCode.getValue(harnessOptions),
false,
Options.IgnoreCompilationFailures.getValue(harnessOptions),
Options.MultiThreaded.getValue(harnessOptions),
Options.Threads.getValue(harnessOptions),
Options.StatsInterval.getValue(harnessOptions));
Expand Down Expand Up @@ -1031,6 +1032,7 @@ static class Options {
public static final OptionKey<Boolean> Help = new OptionKey<>(false);
public static final OptionKey<String> Classpath = new OptionKey<>(CompileTheWorld.SUN_BOOT_CLASS_PATH);
public static final OptionKey<Boolean> Verbose = new OptionKey<>(true);
public static final OptionKey<Boolean> IgnoreCompilationFailures = new OptionKey<>(false);
/**
* Ignore Graal classes by default to avoid problems associated with compiling snippets and
* method substitutions.
Expand Down Expand Up @@ -1061,6 +1063,7 @@ static class Options {
static final ReflectionOptionDescriptors DESCRIPTORS = new ReflectionOptionDescriptors(Options.class,
"Help", "List options and their help messages and then exit.",
"Classpath", "Class path denoting methods to compile. Default is to compile boot classes.",
"IgnoreCompilationFailures", "Do not exit with an error if any errors in compilation are detected. Defaults to false.",
"Verbose", "Verbose operation. Default is !MultiThreaded.",
"LimitModules", "Comma separated list of module names to which compilation should be limited. " +
"Module names can be prefixed with \"~\" to exclude the named module.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.graalvm.collections.UnmodifiableMapCursor;
Expand All @@ -48,6 +49,7 @@
import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalScope;

import jdk.graal.compiler.api.test.ModuleSupport;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.debug.TTY;
import jdk.graal.compiler.hotspot.CompilationTask;
import jdk.graal.compiler.hotspot.HotSpotGraalCompiler;
Expand All @@ -60,6 +62,7 @@
import jdk.graal.compiler.serviceprovider.GraalUnsafeAccess;
import jdk.graal.compiler.util.OptionsEncoder;
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
import jdk.vm.ci.hotspot.HotSpotInstalledCode;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
Expand Down Expand Up @@ -103,6 +106,11 @@ public class LibGraalCompilationDriver {
*/
private final boolean eagerResolving;

/**
* If true, will not exit with an error in case of errors during compilation.
*/
private final boolean ignoreFailures;

/**
* Whether to use multiple threads for compilation.
*/
Expand All @@ -129,12 +137,13 @@ public class LibGraalCompilationDriver {
* @param statsInterval Interval between compilation progress reports, in seconds.
*/
public LibGraalCompilationDriver(HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalCompiler compiler,
boolean invalidateInstalledCode, boolean eagerResolving,
boolean invalidateInstalledCode, boolean eagerResolving, boolean ignoreFailures,
boolean multiThreaded, int threadCount, int statsInterval) {
this.jvmciRuntime = jvmciRuntime;
this.compiler = compiler;
this.invalidateInstalledCode = invalidateInstalledCode;
this.eagerResolving = eagerResolving;
this.ignoreFailures = ignoreFailures;
this.multiThreaded = multiThreaded;
this.numThreads = threadCount;
this.statsInterval = statsInterval;
Expand Down Expand Up @@ -591,16 +600,19 @@ protected CompilationResult compileWithJarGraal(Compilation compilation, OptionV
long allocatedAtStart = getCurrentThreadAllocatedBytes();

CompilationTask task = createCompilationTask(method, useProfilingInfo, installAsDefault);
task.runCompilation(compileOptions);
HotSpotInstalledCode installedCode = task.getInstalledCode();
if (installedCode == null) {
return null;
HotSpotCompilationRequestResult result = task.runCompilation(compileOptions);
if (result.getFailure() != null) {
throw new GraalError("Compilation request failed: %s", result.getFailureMessage());
}
HotSpotInstalledCode installedCode = task.getInstalledCode();
assert installedCode != null : "installed code is null yet no failure detected";
long duration = System.nanoTime() - start;
long memoryUsed = getCurrentThreadAllocatedBytes() - allocatedAtStart;
return new CompilationResult(installedCode, duration, memoryUsed);
}

private final AtomicInteger failedCompilations = new AtomicInteger(0);

/**
* Compiles all the given methods, using libgraal if available.
*/
Expand All @@ -612,6 +624,7 @@ public void compileAll(List<? extends Compilation> compilations, OptionValues op
}

private void compileAll(LibGraalParams libgraal, List<? extends Compilation> compilations, OptionValues options) {
failedCompilations.set(0);
int threadCount = getThreadCount();

AtomicLong compileTime = new AtomicLong();
Expand All @@ -630,6 +643,9 @@ private void compileAll(LibGraalParams libgraal, List<? extends Compilation> com
} else {
results = compileAllMultiThreaded(libgraal, compilations, options, threadCount, compileTime, memoryUsed, codeSize);
}
if (!ignoreFailures && failedCompilations.get() > 0) {
throw new GraalError("%d failures occurred during compilation", failedCompilations.get());
}

long elapsedTime = System.nanoTime() - start;

Expand Down Expand Up @@ -664,7 +680,7 @@ private void compileAndRecord(Compilation task, LibGraalParams libgraal, OptionV
Map<ResolvedJavaMethod, CompilationResult> results) {
CompilationResult result = compile(task, libgraal, options);
if (result == null) {
TTY.println("Compilation failed: %s", task);
failedCompilations.getAndAdd(1);
return;
}
compileTime.getAndAdd(result.compileTime());
Expand Down Expand Up @@ -748,7 +764,7 @@ private Map<ResolvedJavaMethod, CompilationResult> compileAllMultiThreaded(
TTY.println("%s : Using %d threads", testName(), threadCount);

Map<ResolvedJavaMethod, CompilationResult> results = new ConcurrentHashMap<>();
try (ThreadPoolExecutor threadPool = new ThreadPoolExecutor(numThreads, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),
try (ThreadPoolExecutor threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),
new GraalCompileThreadFactory(libgraal))) {
for (Compilation task : compilations) {
threadPool.submit(() -> compileAndRecord(task, libgraal, options, compileTime, memoryUsed, codeSize, results));
Expand Down
1 change: 1 addition & 0 deletions vm/mx.vm/mx_vm_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def _test_libgraal_ctw(extra_vm_arguments):
'-Djdk.graal.InlineDuringParsing=false',
'-Djdk.graal.TrackNodeSourcePosition=true',
'-Djdk.graal.LogFile=' + compiler_log_file,
'-DCompileTheWorld.IgnoreCompilationFailures=true',
'-DCompileTheWorld.Verbose=true',
'-DCompileTheWorld.MethodFilter=StackOverflowError.*,String.*',
'-Djvmci.ForceTranslateFailure=nmethod/StackOverflowError:hotspot,method/String.hashCode:native,valueOf',
Expand Down

0 comments on commit 5d31d56

Please sign in to comment.