-
Notifications
You must be signed in to change notification settings - Fork 914
/
UninitializedYieldDispatchNode.java
84 lines (67 loc) · 3.58 KB
/
UninitializedYieldDispatchNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.yield;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.nodes.NodeUtil;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.util.cli.Options;
@NodeInfo(cost = NodeCost.UNINITIALIZED)
public class UninitializedYieldDispatchNode extends YieldDispatchNode {
private int depth = 0;
public UninitializedYieldDispatchNode(RubyContext context) {
super(context);
}
@Override
public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObjects) {
CompilerDirectives.transferToInterpreterAndInvalidate();
depth++;
if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
return newGeneralYield.dispatch(frame, block, argumentsObjects);
}
final CachedYieldDispatchNode dispatch = new CachedYieldDispatchNode(getContext(), block, this);
replace(dispatch);
return dispatch.dispatch(frame, block, argumentsObjects);
}
@Override
public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, RubyProc modifiedBlock, Object[] argumentsObjects) {
CompilerDirectives.transferToInterpreterAndInvalidate();
depth++;
if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
return newGeneralYield.dispatch(frame, block, argumentsObjects);
}
final CachedYieldDispatchNode dispatch = new CachedYieldDispatchNode(getContext(), block, this);
replace(dispatch);
return dispatch.dispatchWithModifiedBlock(frame, block, modifiedBlock, argumentsObjects);
}
@Override
public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Object self, Object... argumentsObjects) {
CompilerDirectives.transferToInterpreterAndInvalidate();
depth++;
if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
return newGeneralYield.dispatchWithModifiedSelf(frame, block, self, argumentsObjects);
}
final CachedYieldDispatchNode dispatch = new CachedYieldDispatchNode(getContext(), block, this);
replace(dispatch);
return dispatch.dispatchWithModifiedSelf(frame, block, self, argumentsObjects);
}
}