Skip to content
Snippets Groups Projects
Commit 1bbd8f19 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

check frame assumptions at RFunction creation time, and not at function execution time

parent 717e1ad6
No related branches found
No related tags found
No related merge requests found
......@@ -22,8 +22,8 @@
*/
package com.oracle.truffle.r.nodes;
import com.oracle.truffle.api.*;
import com.oracle.truffle.api.CompilerDirectives.*;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.source.*;
......@@ -39,9 +39,6 @@ import com.oracle.truffle.r.runtime.env.frame.*;
*/
public abstract class RRootNode extends RootNode implements HasSignature {
@CompilationFinal private StableValue<MaterializedFrame> enclosingFrameAssumption;
@CompilationFinal private StableValue<FrameDescriptor> enclosingFrameDescriptorAssumption;
private final ValueProfile enclosingFrameProfile = ValueProfile.createClassProfile();
@CompilationFinal protected boolean checkSingletonFrame = true;
private final ValueProfile functionProfile = ValueProfile.createIdentityProfile();
......@@ -53,8 +50,6 @@ public abstract class RRootNode extends RootNode implements HasSignature {
protected RRootNode(SourceSection src, FormalArguments formalArguments, FrameDescriptor frameDescriptor) {
super(src, frameDescriptor);
this.formalArguments = formalArguments;
this.enclosingFrameAssumption = FrameSlotChangeMonitor.getEnclosingFrameAssumption(frameDescriptor);
this.enclosingFrameDescriptorAssumption = FrameSlotChangeMonitor.getEnclosingFrameDescriptorAssumption(frameDescriptor);
}
protected void verifyEnclosingAssumptions(VirtualFrame vf) {
......@@ -63,38 +58,6 @@ public abstract class RRootNode extends RootNode implements HasSignature {
if (checkSingletonFrame) {
checkSingletonFrame = FrameSlotChangeMonitor.checkSingletonFrame(vf);
}
if (enclosingFrameAssumption != null) {
try {
enclosingFrameAssumption.getAssumption().check();
} catch (InvalidAssumptionException e) {
enclosingFrameAssumption = FrameSlotChangeMonitor.getEnclosingFrameAssumption(getFrameDescriptor());
}
if (enclosingFrameAssumption != null) {
MaterializedFrame enclosingFrame = RArguments.getEnclosingFrame(vf);
if (enclosingFrameAssumption != null) {
if (enclosingFrameAssumption.getValue() != enclosingFrame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
enclosingFrameAssumption = FrameSlotChangeMonitor.getOrInitializeEnclosingFrameAssumption(vf.materialize(), getFrameDescriptor(), enclosingFrameAssumption, enclosingFrame);
}
}
}
}
if (enclosingFrameDescriptorAssumption != null) {
try {
enclosingFrameDescriptorAssumption.getAssumption().check();
} catch (InvalidAssumptionException e) {
enclosingFrameDescriptorAssumption = FrameSlotChangeMonitor.getEnclosingFrameDescriptorAssumption(getFrameDescriptor());
}
if (enclosingFrameDescriptorAssumption != null) {
MaterializedFrame enclosingFrame = RArguments.getEnclosingFrame(vf);
FrameDescriptor enclosingFrameDescriptor = enclosingFrame == null ? null : enclosingFrameProfile.profile(enclosingFrame).getFrameDescriptor();
if (enclosingFrameDescriptorAssumption.getValue() != enclosingFrameDescriptor) {
CompilerDirectives.transferToInterpreterAndInvalidate();
enclosingFrameDescriptorAssumption = FrameSlotChangeMonitor.getOrInitializeEnclosingFrameDescriptorAssumption(vf, getFrameDescriptor(), enclosingFrameDescriptorAssumption,
enclosingFrameDescriptor);
}
}
}
}
/**
......
......@@ -23,6 +23,7 @@
package com.oracle.truffle.r.nodes.function;
import com.oracle.truffle.api.*;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.nodes.NodeUtil.NodeCountFilter;
......@@ -31,9 +32,11 @@ import com.oracle.truffle.r.nodes.access.variables.*;
import com.oracle.truffle.r.nodes.function.PromiseHelperNode.*;
import com.oracle.truffle.r.nodes.function.opt.*;
import com.oracle.truffle.r.nodes.instrument.*;
import com.oracle.truffle.r.runtime.*;
import com.oracle.truffle.r.runtime.RDeparse.State;
import com.oracle.truffle.r.runtime.data.*;
import com.oracle.truffle.r.runtime.env.*;
import com.oracle.truffle.r.runtime.env.frame.*;
public final class FunctionExpressionNode extends RNode {
......@@ -45,6 +48,9 @@ public final class FunctionExpressionNode extends RNode {
private final PromiseDeoptimizeFrameNode deoptFrameNode;
private final boolean containsDispatch;
@CompilationFinal private StableValue<MaterializedFrame> enclosingFrameAssumption;
@CompilationFinal private StableValue<FrameDescriptor> enclosingFrameDescriptorAssumption;
public FunctionExpressionNode(RootCallTarget callTarget) {
this.callTarget = callTarget;
this.deoptFrameNode = EagerEvalHelper.optExprs() || EagerEvalHelper.optVars() || EagerEvalHelper.optDefault() ? new PromiseDeoptimizeFrameNode() : null;
......@@ -57,6 +63,9 @@ public final class FunctionExpressionNode extends RNode {
return false;
};
this.containsDispatch = NodeUtil.countNodes(callTarget.getRootNode(), dispatchingMethodsFilter) > 0;
this.enclosingFrameAssumption = FrameSlotChangeMonitor.getEnclosingFrameAssumption(callTarget.getRootNode().getFrameDescriptor());
this.enclosingFrameDescriptorAssumption = FrameSlotChangeMonitor.getEnclosingFrameDescriptorAssumption(callTarget.getRootNode().getFrameDescriptor());
}
@Override
......@@ -64,6 +73,37 @@ public final class FunctionExpressionNode extends RNode {
return executeFunction(frame);
}
protected void verifyEnclosingAssumptions(VirtualFrame enclosingFrame, FrameDescriptor descriptor) {
if (enclosingFrameAssumption != null) {
try {
enclosingFrameAssumption.getAssumption().check();
} catch (InvalidAssumptionException e) {
enclosingFrameAssumption = FrameSlotChangeMonitor.getEnclosingFrameAssumption(descriptor);
}
if (enclosingFrameAssumption != null) {
if (enclosingFrameAssumption.getValue() != enclosingFrame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
enclosingFrameAssumption = FrameSlotChangeMonitor.getOrInitializeEnclosingFrameAssumption(null, descriptor, enclosingFrameAssumption, enclosingFrame.materialize());
}
}
}
if (enclosingFrameDescriptorAssumption != null) {
try {
enclosingFrameDescriptorAssumption.getAssumption().check();
} catch (InvalidAssumptionException e) {
enclosingFrameDescriptorAssumption = FrameSlotChangeMonitor.getEnclosingFrameDescriptorAssumption(descriptor);
}
if (enclosingFrameDescriptorAssumption != null) {
FrameDescriptor enclosingFrameDescriptor = enclosingFrame.getFrameDescriptor();
if (enclosingFrameDescriptorAssumption.getValue() != enclosingFrameDescriptor) {
CompilerDirectives.transferToInterpreterAndInvalidate();
enclosingFrameDescriptorAssumption = FrameSlotChangeMonitor.getOrInitializeEnclosingFrameDescriptorAssumption(null, descriptor, enclosingFrameDescriptorAssumption,
enclosingFrameDescriptor);
}
}
}
}
@Override
public RFunction executeFunction(VirtualFrame frame) {
MaterializedFrame matFrame = frame.materialize();
......@@ -71,6 +111,7 @@ public final class FunctionExpressionNode extends RNode {
// Deoptimize every promise which is now in this frame, as it might leave it's stack
deoptFrameNode.deoptimizeFrame(matFrame);
}
verifyEnclosingAssumptions(frame, callTarget.getRootNode().getFrameDescriptor());
RFunction func = RDataFactory.createFunction("", callTarget, matFrame, containsDispatch);
if (RInstrument.instrumentingEnabled()) {
RInstrument.checkDebugRequested(callTarget.toString(), func);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment