|
51 | 51 | import java.util.function.Supplier;
|
52 | 52 |
|
53 | 53 | import com.oracle.graal.python.PythonLanguage;
|
| 54 | +import com.oracle.graal.python.builtins.objects.frame.PFrame; |
| 55 | +import com.oracle.graal.python.builtins.objects.frame.PFrame.Reference; |
54 | 56 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
| 57 | +import com.oracle.graal.python.builtins.objects.function.Signature; |
| 58 | +import com.oracle.graal.python.nodes.PRootNode; |
55 | 59 | import com.oracle.graal.python.nodes.call.CallNode;
|
56 | 60 | import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
|
57 | 61 | import com.oracle.graal.python.nodes.frame.MaterializeFrameNodeGen;
|
| 62 | +import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode; |
| 63 | +import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext; |
58 | 64 | import com.oracle.truffle.api.CompilerDirectives;
|
59 | 65 | import com.oracle.truffle.api.RootCallTarget;
|
60 | 66 | import com.oracle.truffle.api.Truffle;
|
|
63 | 69 | import com.oracle.truffle.api.nodes.Node;
|
64 | 70 | import com.oracle.truffle.api.nodes.Node.Child;
|
65 | 71 | import com.oracle.truffle.api.nodes.RootNode;
|
| 72 | +import com.oracle.truffle.api.profiles.BranchProfile; |
66 | 73 |
|
67 | 74 | /**
|
68 | 75 | * A handler for asynchronous actions events that need to be handled on a main thread of execution,
|
@@ -129,28 +136,59 @@ public void run() {
|
129 | 136 | }
|
130 | 137 | }
|
131 | 138 |
|
132 |
| - private static class CallRootNode extends RootNode { |
| 139 | + private static class CallRootNode extends PRootNode { |
133 | 140 | static final int ASYNC_ARGS = 4;
|
134 | 141 |
|
135 | 142 | @Child private CallNode callNode = CallNode.create();
|
136 | 143 | @Child private MaterializeFrameNode materializeNode = MaterializeFrameNodeGen.create();
|
| 144 | + @Child private ReadCallerFrameNode readCallerFrameNode = ReadCallerFrameNode.create(); |
| 145 | + @Child private CalleeContext calleeContext = CalleeContext.create(); |
| 146 | + |
| 147 | + private final BranchProfile profile = BranchProfile.create(); |
137 | 148 |
|
138 | 149 | protected CallRootNode(TruffleLanguage<?> language) {
|
139 | 150 | super(language);
|
140 | 151 | }
|
141 | 152 |
|
142 | 153 | @Override
|
143 | 154 | public Object execute(VirtualFrame frame) {
|
| 155 | + CalleeContext.enter(frame, profile); |
144 | 156 | Object[] frameArguments = frame.getArguments();
|
145 | 157 | Object callable = PArguments.getArgument(frameArguments, 0);
|
146 | 158 | int frameIndex = (int) PArguments.getArgument(frameArguments, 1);
|
147 |
| - VirtualFrame callerFrame = (VirtualFrame) PArguments.getArgument(frameArguments, 3); |
148 | 159 | Object[] arguments = Arrays.copyOfRange(frameArguments, PArguments.USER_ARGUMENTS_OFFSET + ASYNC_ARGS, frameArguments.length);
|
| 160 | + |
| 161 | + // TODO: frames: This should eventually go away as soon as this root node is properly |
| 162 | + // called using an invoke node. |
| 163 | + PFrame.Reference callerInfo = PArguments.getCallerFrameInfo(frame); |
| 164 | + if (callerInfo != null) { |
| 165 | + VirtualFrame callerFrame = (VirtualFrame) PArguments.getArgument(frameArguments, 3); |
| 166 | + // the caller can't do, so it must be done here |
| 167 | + materializeNode.execute(frame, true, true, callerFrame); |
| 168 | + } |
149 | 169 | if (frameIndex >= 0) {
|
150 |
| - Node location = (Node) PArguments.getArgument(frameArguments, 2); |
151 |
| - arguments[frameIndex] = materializeNode.execute(frame, location, true, false, callerFrame); |
| 170 | + arguments[frameIndex] = readCallerFrameNode.executeWith(frame, 0); |
152 | 171 | }
|
153 |
| - return callNode.execute(callerFrame, callable, arguments); |
| 172 | + try { |
| 173 | + return callNode.execute(frame, callable, arguments); |
| 174 | + } finally { |
| 175 | + calleeContext.exit(frame, this); |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public Signature getSignature() { |
| 181 | + return Signature.EMPTY; |
| 182 | + } |
| 183 | + |
| 184 | + @Override |
| 185 | + public boolean isPythonInternal() { |
| 186 | + return true; |
| 187 | + } |
| 188 | + |
| 189 | + @Override |
| 190 | + public boolean isInternal() { |
| 191 | + return true; |
154 | 192 | }
|
155 | 193 | }
|
156 | 194 |
|
@@ -222,6 +260,15 @@ private void processAsyncActions(VirtualFrame frame, Node location) {
|
222 | 260 | PArguments.setArgument(args, 1, action.frameIndex());
|
223 | 261 | PArguments.setArgument(args, 2, location);
|
224 | 262 | PArguments.setArgument(args, 3, frame);
|
| 263 | + |
| 264 | + // TODO: frames: workaround because we can't use an invoke node here; this |
| 265 | + // should eventually be done properly |
| 266 | + RootNode rootNode = callTarget.getRootNode(); |
| 267 | + if (rootNode instanceof PRootNode && ((PRootNode) rootNode).needsCallerFrame()) { |
| 268 | + Reference currentFrameInfo = PArguments.getCurrentFrameInfo(frame); |
| 269 | + currentFrameInfo.setCallNode(location); |
| 270 | + PArguments.setCallerFrameInfo(args, currentFrameInfo); |
| 271 | + } |
225 | 272 | try {
|
226 | 273 | callTarget.call(args);
|
227 | 274 | } catch (RuntimeException e) {
|
|
0 commit comments