9
9
*/
10
10
package org .truffleruby .language .arguments ;
11
11
12
+ import com .oracle .truffle .api .CompilerDirectives ;
12
13
import com .oracle .truffle .api .frame .FrameInstance ;
13
14
import org .truffleruby .language .RubyBaseNode ;
14
15
import org .truffleruby .language .dispatch .CachedDispatchNode ;
15
16
17
+ import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
16
18
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
17
19
import com .oracle .truffle .api .frame .MaterializedFrame ;
18
20
import com .oracle .truffle .api .frame .VirtualFrame ;
23
25
public class ReadCallerFrameNode extends RubyBaseNode {
24
26
25
27
private final ConditionProfile callerFrameProfile = ConditionProfile .createBinaryProfile ();
28
+ @ CompilationFinal private volatile boolean firstCall = true ;
26
29
27
30
public static ReadCallerFrameNode create () {
28
31
return new ReadCallerFrameNode ();
29
32
}
30
33
31
34
public MaterializedFrame execute (VirtualFrame frame ) {
35
+ // Avoid polluting the profile for the first call which has to use getCallerFrame()
36
+ if (firstCall ) {
37
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
38
+ firstCall = false ;
39
+ notifyCallerToSendFrame ();
40
+ return getCallerFrame ();
41
+ }
42
+
32
43
final MaterializedFrame callerFrame = RubyArguments .getCallerFrame (frame );
33
44
34
45
if (callerFrameProfile .profile (callerFrame != null )) {
@@ -38,7 +49,7 @@ public MaterializedFrame execute(VirtualFrame frame) {
38
49
}
39
50
}
40
51
41
- private void replaceDispatchNode () {
52
+ private void notifyCallerToSendFrame () {
42
53
final Node callerNode = getContext ().getCallStack ().getCallerNode (0 , false );
43
54
if (callerNode instanceof DirectCallNode ) {
44
55
final Node parent = callerNode .getParent ();
@@ -50,7 +61,6 @@ private void replaceDispatchNode() {
50
61
51
62
@ TruffleBoundary
52
63
private MaterializedFrame getCallerFrame () {
53
- replaceDispatchNode ();
54
64
return getContext ().getCallStack ().getCallerFrameIgnoringSend ().getFrame (FrameInstance .FrameAccess .MATERIALIZE ).materialize ();
55
65
}
56
66
0 commit comments