Skip to content
Snippets Groups Projects
Commit 43aa1442 authored by Mick Jordan's avatar Mick Jordan
Browse files

Merge

parents 6dfb4b7a 6fec0848
Branches
No related tags found
No related merge requests found
......@@ -141,6 +141,9 @@ public class PromiseHelperNode extends Node {
* @return The value the given Promise evaluates to
*/
private Object doEvaluate(VirtualFrame frame, RPromise promise, SourceSection callSrc) {
if (isEvaluated(promise)) {
return promise.getValue();
}
RPromise current = promise;
if (current.getOptType() == OptType.VARARG) {
varArgProfile.enter();
......@@ -149,9 +152,9 @@ public class PromiseHelperNode extends Node {
multiVarArgProfile.enter();
current = ((VarargPromise) current).getVararg();
}
}
if (isEvaluated(current)) {
return current.getValue();
if (isEvaluated(current)) {
return current.getValue();
}
}
// Check for dependency cycle
......
......@@ -30,6 +30,7 @@ import com.oracle.truffle.api.*;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.instrument.*;
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.r.runtime.conn.*;
import com.oracle.truffle.r.runtime.data.*;
......@@ -444,6 +445,9 @@ public final class RContext extends ExecutionContext {
threadLocalContext.set(this);
}
private static final Assumption singleContextAssumption = Truffle.getRuntime().createAssumption("single RContext");
@CompilationFinal private static RContext singleContext;
private RContext(Kind kind, RContext parent, String[] commandArgs, ConsoleHandler consoleHandler) {
this.kind = kind;
this.parent = parent;
......@@ -454,6 +458,15 @@ public final class RContext extends ExecutionContext {
}
this.consoleHandler = consoleHandler;
this.interactive = consoleHandler.isInteractive();
if (singleContextAssumption.isValid()) {
if (singleContext == null) {
singleContext = this;
} else {
singleContext = null;
singleContextAssumption.invalidate();
}
}
}
public void installCustomClassState(ClassStateKind classStateKind, ContextState state) {
......@@ -564,13 +577,26 @@ public final class RContext extends ExecutionContext {
}
@TruffleBoundary
public static RContext getInstance() {
private static RContext getInstanceInternal() {
RContext result = threadLocalContext.get();
assert result != null;
assert result.active;
return result;
}
public static RContext getInstance() {
RContext context = singleContext;
if (context != null) {
try {
singleContextAssumption.check();
return context;
} catch (InvalidAssumptionException e) {
// fallback to slow case
}
}
return getInstanceInternal();
}
/**
* Access to the engine, when an {@link RContext} object is available, and/or when {@code this}
* context is not active.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment