Skip to content

Commit

Permalink
Use a flag for compiler initialization as initialization might fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
chumer committed Oct 28, 2019
1 parent 68402a7 commit 3e12ef5
Showing 1 changed file with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ static class Lazy extends BackgroundCompileQueue {

private Boolean traceTransferToInterpreter;

public AbstractHotSpotTruffleRuntime() {
super(Arrays.asList(HotSpotOptimizedCallTarget.class));
setDontInlineCallBoundaryMethod();
}

private volatile Lazy lazy;
private volatile String lazyConfigurationName;

Expand All @@ -139,6 +134,12 @@ private Lazy lazy() {

private List<ResolvedJavaMethod> truffleCallBoundaryMethods;
private volatile CancellableCompileTask initializationTask;
private volatile boolean truffleCompilerInitialized;

public AbstractHotSpotTruffleRuntime() {
super(Arrays.asList(HotSpotOptimizedCallTarget.class));
setDontInlineCallBoundaryMethod();
}

@Override
public synchronized Iterable<ResolvedJavaMethod> getTruffleCallBoundaryMethods() {
Expand Down Expand Up @@ -184,20 +185,21 @@ public HotSpotTruffleCompiler getTruffleCompiler() {
* that case and we would use the HotSpot interpreter indefinitely.
*/
private void ensureInitialized(OptimizedCallTarget firstCallTarget) {
if (truffleCompiler != null) {
if (truffleCompilerInitialized) {
return;
}
CancellableCompileTask localTask = initializationTask;
if (localTask == null) {
final Object lock = this;
synchronized (lock) {
localTask = initializationTask;
if (localTask == null && truffleCompiler == null) {
if (localTask == null && !truffleCompilerInitialized) {
initializationTask = localTask = getCompileQueue().submitTask(Priority.INITIALIZATION, firstCallTarget, new BackgroundCompileQueue.Request() {
@Override
protected void execute(TruffleCompilationTask task, WeakReference<OptimizedCallTarget> targetRef) {
synchronized (lock) {
initializeTruffleCompiler();
assert truffleCompilerInitialized;
assert initializationTask != null;
initializationTask = null;
}
Expand All @@ -209,23 +211,20 @@ protected void execute(TruffleCompilationTask task, WeakReference<OptimizedCallT
if (localTask != null) {
firstCallTarget.maybeWaitForTask(localTask);
} else {
assert truffleCompiler != null;
assert truffleCompilerInitialized;
}
}

protected boolean reportedTruffleCompilerInitializationFailure;

private synchronized void initializeTruffleCompiler() {
// might occur for multiple compiler threads at the same time.
if (truffleCompiler == null) {
if (!truffleCompilerInitialized) {
try {
truffleCompiler = newTruffleCompiler();
} catch (Throwable e) {
if (!reportedTruffleCompilerInitializationFailure) {
// This should never happen so report it (once)
reportedTruffleCompilerInitializationFailure = true;
log(printStackTraceToString(e));
}
// This should never happen so report it (once)
log(printStackTraceToString(e));
} finally {
truffleCompilerInitialized = true;
}
}
}
Expand Down Expand Up @@ -265,11 +264,11 @@ public SpeculationLog createSpeculationLog() {

/**
* Prevents C1 or C2 from inlining a call to and compiling a method annotated by
* {@link TruffleCallBoundary} (i.e., {@link OptimizedCallTarget#callBoundary(Object[])}) so
* that we never miss the chance to jump from the Truffle interpreter to compiled code.
* {@link TruffleCallBoundary} (i.e., <code>OptimizedCallTarget.callBoundary(Object[])</code>)
* so that we never miss the chance to jump from the Truffle interpreter to compiled code.
*
* This is quite slow as it forces every call to
* {@link OptimizedCallTarget#callBoundary(Object[])} to run in the HotSpot interpreter, so
* <code>OptimizedCallTarget.callBoundary(Object[])</code> to run in the HotSpot interpreter, so
* later on we manually compile {@code callBoundary()} with Graal. This then lets a
* C1/C2-compiled caller jump to Graal-compiled {@code callBoundary()}, instead of having to go
* back to the HotSpot interpreter for every execution of {@code callBoundary()}.
Expand Down

0 comments on commit 3e12ef5

Please sign in to comment.