9
9
*/
10
10
package org .truffleruby .language .control ;
11
11
12
- import com .oracle .truffle .api .profiles .CountingConditionProfile ;
12
+ import com .oracle .truffle .api .dsl .Cached ;
13
+ import com .oracle .truffle .api .dsl .Specialization ;
14
+ import com .oracle .truffle .api .profiles .InlinedCountingConditionProfile ;
13
15
import org .truffleruby .RubyContext ;
14
16
import org .truffleruby .RubyLanguage ;
15
17
import org .truffleruby .core .cast .BooleanCastNode ;
25
27
* having been executed once (the lazy initialization) it will be compiled expecting it to be used again. We know that
26
28
* it's unlikely to be used again, so only compile it in when it's been used more than once, by using a
27
29
* {@link RunTwiceBranchProfile}. */
28
- public class OrLazyValueDefinedNode extends RubyContextSourceNode {
30
+ public abstract class OrLazyValueDefinedNode extends RubyContextSourceNode {
29
31
30
32
@ Child private RubyNode left ;
31
33
@ Child private RubyNode right ;
32
34
33
- @ Child private BooleanCastNode leftCast = BooleanCastNode .create ();
34
-
35
35
private final RunTwiceBranchProfile rightTwiceProfile = new RunTwiceBranchProfile ();
36
- private final CountingConditionProfile countingProfile = CountingConditionProfile .create ();
37
36
38
37
public OrLazyValueDefinedNode (RubyNode left , RubyNode right ) {
39
38
this .left = left ;
40
39
this .right = right ;
41
40
}
42
41
43
- @ Override
44
- public Object execute (VirtualFrame frame ) {
42
+ @ Specialization
43
+ protected Object doOrLazyValueDefined (VirtualFrame frame ,
44
+ @ Cached BooleanCastNode leftCast ,
45
+ @ Cached InlinedCountingConditionProfile countingProfile ) {
45
46
final Object leftValue = left .execute (frame );
46
47
47
- if (countingProfile .profile (leftCast .execute (leftValue ))) {
48
+ if (countingProfile .profile (this , leftCast .execute (leftValue ))) {
48
49
return leftValue ;
49
50
} else {
50
51
rightTwiceProfile .enter ();
@@ -59,7 +60,7 @@ public Object isDefined(VirtualFrame frame, RubyLanguage language, RubyContext c
59
60
60
61
@ Override
61
62
public RubyNode cloneUninitialized () {
62
- var copy = new OrLazyValueDefinedNode (
63
+ var copy = OrLazyValueDefinedNodeGen . create (
63
64
left .cloneUninitialized (),
64
65
right .cloneUninitialized ());
65
66
return copy .copyFlags (this );
0 commit comments