Skip to content

Commit 95235a5

Browse files
committed
[GR-14420] Add boundary to avoid too deep PE inlining in CreateBigDecimalNode
PullRequest: truffleruby/694
2 parents 1de566b + b7befda commit 95235a5

10 files changed

+223
-330
lines changed

src/main/java/org/truffleruby/stdlib/bigdecimal/AbstractAddNode.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.truffleruby.stdlib.bigdecimal;
1111

1212
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
13-
import com.oracle.truffle.api.frame.VirtualFrame;
1413
import com.oracle.truffle.api.object.DynamicObject;
1514
import com.oracle.truffle.api.profiles.ConditionProfile;
1615
import org.truffleruby.Layouts;
@@ -25,28 +24,28 @@ public abstract class AbstractAddNode extends BigDecimalOpNode {
2524
private final ConditionProfile negInfinityProfile = ConditionProfile.createBinaryProfile();
2625
private final ConditionProfile aNormalProfile = ConditionProfile.createBinaryProfile();
2726

28-
protected Object add(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
29-
return createBigDecimal(frame, addBigDecimal(a, b, new MathContext(precision, getRoundMode(frame))));
27+
protected Object add(DynamicObject a, DynamicObject b, int precision) {
28+
return createBigDecimal(addBigDecimal(a, b, new MathContext(precision, getRoundMode())));
3029
}
3130

32-
protected Object addSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
31+
protected Object addSpecial(DynamicObject a, DynamicObject b, int precision) {
3332
final BigDecimalType aType = Layouts.BIG_DECIMAL.getType(a);
3433
final BigDecimalType bType = Layouts.BIG_DECIMAL.getType(b);
3534

3635
if (nanProfile.profile(aType == BigDecimalType.NAN || bType == BigDecimalType.NAN ||
3736
(aType == BigDecimalType.POSITIVE_INFINITY && bType == BigDecimalType.NEGATIVE_INFINITY) ||
3837
(aType == BigDecimalType.NEGATIVE_INFINITY && bType == BigDecimalType.POSITIVE_INFINITY))) {
39-
return createBigDecimal(frame, BigDecimalType.NAN);
38+
return createBigDecimal(BigDecimalType.NAN);
4039
}
4140

4241
if (posInfinityProfile.profile(aType == BigDecimalType.POSITIVE_INFINITY
4342
|| bType == BigDecimalType.POSITIVE_INFINITY)) {
44-
return createBigDecimal(frame, BigDecimalType.POSITIVE_INFINITY);
43+
return createBigDecimal(BigDecimalType.POSITIVE_INFINITY);
4544
}
4645

4746
if (negInfinityProfile.profile(aType == BigDecimalType.NEGATIVE_INFINITY
4847
|| bType == BigDecimalType.NEGATIVE_INFINITY)) {
49-
return createBigDecimal(frame, BigDecimalType.NEGATIVE_INFINITY);
48+
return createBigDecimal(BigDecimalType.NEGATIVE_INFINITY);
5049
}
5150

5251
// One is NEGATIVE_ZERO and second is NORMAL

src/main/java/org/truffleruby/stdlib/bigdecimal/AbstractDivNode.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import com.oracle.truffle.api.CompilerDirectives;
1313
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
14-
import com.oracle.truffle.api.frame.VirtualFrame;
1514
import com.oracle.truffle.api.object.DynamicObject;
1615
import com.oracle.truffle.api.profiles.ConditionProfile;
1716
import org.truffleruby.Layouts;
@@ -49,11 +48,11 @@ private BigDecimal divBigDecimal(BigDecimal a, BigDecimal b, MathContext mathCon
4948
return a.divide(b, mathContext);
5049
}
5150

52-
protected Object div(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
53-
return createBigDecimal(frame, divBigDecimalConsideringSignum(a, b, new MathContext(precision, getRoundMode(frame))));
51+
protected Object div(DynamicObject a, DynamicObject b, int precision) {
52+
return createBigDecimal(divBigDecimalConsideringSignum(a, b, new MathContext(precision, getRoundMode())));
5453
}
5554

56-
protected Object divNormalSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
55+
protected Object divNormalSpecial(DynamicObject a, DynamicObject b, int precision) {
5756
Object value = null;
5857

5958
switch (Layouts.BIG_DECIMAL.getType(b)) {
@@ -100,10 +99,10 @@ protected Object divNormalSpecial(VirtualFrame frame, DynamicObject a, DynamicOb
10099
throw new UnsupportedOperationException("unreachable code branch for value: " + Layouts.BIG_DECIMAL.getType(b));
101100
}
102101

103-
return createBigDecimal(frame, value);
102+
return createBigDecimal(value);
104103
}
105104

106-
protected Object divSpecialNormal(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
105+
protected Object divSpecialNormal(DynamicObject a, DynamicObject b, int precision) {
107106
Object value = null;
108107

109108
switch (Layouts.BIG_DECIMAL.getType(a)) {
@@ -150,35 +149,35 @@ protected Object divSpecialNormal(VirtualFrame frame, DynamicObject a, DynamicOb
150149
throw new UnsupportedOperationException("unreachable code branch for value: " + Layouts.BIG_DECIMAL.getType(a));
151150
}
152151

153-
return createBigDecimal(frame, value);
152+
return createBigDecimal(value);
154153
}
155154

156-
protected Object divSpecialSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
155+
protected Object divSpecialSpecial(DynamicObject a, DynamicObject b, int precision) {
157156
final BigDecimalType aType = Layouts.BIG_DECIMAL.getType(a);
158157
final BigDecimalType bType = Layouts.BIG_DECIMAL.getType(b);
159158

160159
if (aType == BigDecimalType.NAN || bType == BigDecimalType.NAN ||
161160
(aType == BigDecimalType.NEGATIVE_ZERO && bType == BigDecimalType.NEGATIVE_ZERO)) {
162-
return createBigDecimal(frame, BigDecimalType.NAN);
161+
return createBigDecimal(BigDecimalType.NAN);
163162
}
164163

165164
if (aType == BigDecimalType.NEGATIVE_ZERO) {
166165
if (bType == BigDecimalType.POSITIVE_INFINITY) {
167-
return createBigDecimal(frame, BigDecimalType.NEGATIVE_ZERO);
166+
return createBigDecimal(BigDecimalType.NEGATIVE_ZERO);
168167
} else {
169-
return createBigDecimal(frame, BigDecimalType.POSITIVE_INFINITY);
168+
return createBigDecimal(BigDecimalType.POSITIVE_INFINITY);
170169
}
171170
}
172171

173172
if (bType == BigDecimalType.NEGATIVE_ZERO) {
174173
if (aType == BigDecimalType.POSITIVE_INFINITY) {
175-
return createBigDecimal(frame, BigDecimalType.NEGATIVE_INFINITY);
174+
return createBigDecimal(BigDecimalType.NEGATIVE_INFINITY);
176175
} else {
177-
return createBigDecimal(frame, BigDecimalType.POSITIVE_INFINITY);
176+
return createBigDecimal(BigDecimalType.POSITIVE_INFINITY);
178177
}
179178
}
180179

181180
// a and b are only +-Infinity
182-
return createBigDecimal(frame, BigDecimalType.NAN);
181+
return createBigDecimal(BigDecimalType.NAN);
183182
}
184183
}

src/main/java/org/truffleruby/stdlib/bigdecimal/AbstractMultNode.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import com.oracle.truffle.api.CompilerDirectives;
1313
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
14-
import com.oracle.truffle.api.frame.VirtualFrame;
1514
import com.oracle.truffle.api.object.DynamicObject;
1615
import com.oracle.truffle.api.profiles.ConditionProfile;
1716
import org.truffleruby.Layouts;
@@ -38,15 +37,15 @@ private Object multBigDecimal(BigDecimal a, BigDecimal b, MathContext mathContex
3837
return a.multiply(b, mathContext);
3938
}
4039

41-
protected Object mult(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
42-
return createBigDecimal(frame, multBigDecimalConsideringSignum(a, b, new MathContext(precision, getRoundMode(frame))));
40+
protected Object mult(DynamicObject a, DynamicObject b, int precision) {
41+
return createBigDecimal(multBigDecimalConsideringSignum(a, b, new MathContext(precision, getRoundMode())));
4342
}
4443

45-
protected Object multNormalSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
46-
return multSpecialNormal(frame, b, a, precision);
44+
protected Object multNormalSpecial(DynamicObject a, DynamicObject b, int precision) {
45+
return multSpecialNormal(b, a, precision);
4746
}
4847

49-
protected Object multSpecialNormal(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
48+
protected Object multSpecialNormal(DynamicObject a, DynamicObject b, int precision) {
5049
Object value = null;
5150

5251
switch (Layouts.BIG_DECIMAL.getType(a)) {
@@ -95,19 +94,19 @@ protected Object multSpecialNormal(VirtualFrame frame, DynamicObject a, DynamicO
9594
throw new UnsupportedOperationException("unreachable code branch");
9695
}
9796

98-
return createBigDecimal(frame, value);
97+
return createBigDecimal(value);
9998
}
10099

101-
protected Object multSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
100+
protected Object multSpecial(DynamicObject a, DynamicObject b, int precision) {
102101
final BigDecimalType aType = Layouts.BIG_DECIMAL.getType(a);
103102
final BigDecimalType bType = Layouts.BIG_DECIMAL.getType(b);
104103

105104
if (aType == BigDecimalType.NAN || bType == BigDecimalType.NAN) {
106-
return createBigDecimal(frame, BigDecimalType.NAN);
105+
return createBigDecimal(BigDecimalType.NAN);
107106
} else if (aType == BigDecimalType.NEGATIVE_ZERO && bType == BigDecimalType.NEGATIVE_ZERO) {
108-
return createBigDecimal(frame, BigDecimal.ZERO);
107+
return createBigDecimal(BigDecimal.ZERO);
109108
} else if (aType == BigDecimalType.NEGATIVE_ZERO || bType == BigDecimalType.NEGATIVE_ZERO) {
110-
return createBigDecimal(frame, BigDecimalType.NAN);
109+
return createBigDecimal(BigDecimalType.NAN);
111110
}
112111

113112
// a and b are only +-Infinity
@@ -116,13 +115,13 @@ protected Object multSpecial(VirtualFrame frame, DynamicObject a, DynamicObject
116115
if (bType == BigDecimalType.POSITIVE_INFINITY) {
117116
return a;
118117
} else {
119-
return createBigDecimal(frame, BigDecimalType.NEGATIVE_INFINITY);
118+
return createBigDecimal(BigDecimalType.NEGATIVE_INFINITY);
120119
}
121120
} else if (aType == BigDecimalType.NEGATIVE_INFINITY) {
122121
if (bType == BigDecimalType.POSITIVE_INFINITY) {
123122
return a;
124123
} else {
125-
return createBigDecimal(frame, (BigDecimalType.POSITIVE_INFINITY));
124+
return createBigDecimal((BigDecimalType.POSITIVE_INFINITY));
126125
}
127126
}
128127

src/main/java/org/truffleruby/stdlib/bigdecimal/AbstractSubNode.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.truffleruby.stdlib.bigdecimal;
1111

1212
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
13-
import com.oracle.truffle.api.frame.VirtualFrame;
1413
import com.oracle.truffle.api.object.DynamicObject;
1514
import com.oracle.truffle.api.profiles.ConditionProfile;
1615
import org.truffleruby.Layouts;
@@ -30,36 +29,36 @@ private BigDecimal subBigDecimal(DynamicObject a, DynamicObject b, MathContext m
3029
return Layouts.BIG_DECIMAL.getValue(a).subtract(Layouts.BIG_DECIMAL.getValue(b), mathContext);
3130
}
3231

33-
protected Object subNormal(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
34-
return createBigDecimal(frame, subBigDecimal(a, b, new MathContext(precision, getRoundMode(frame))));
32+
protected Object subNormal(DynamicObject a, DynamicObject b, int precision) {
33+
return createBigDecimal(subBigDecimal(a, b, new MathContext(precision, getRoundMode())));
3534
}
3635

37-
protected Object subSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b, int precision) {
36+
protected Object subSpecial(DynamicObject a, DynamicObject b, int precision) {
3837
final BigDecimalType aType = Layouts.BIG_DECIMAL.getType(a);
3938
final BigDecimalType bType = Layouts.BIG_DECIMAL.getType(b);
4039

4140
if (nanProfile.profile(aType == BigDecimalType.NAN || bType == BigDecimalType.NAN ||
4241
(aType == BigDecimalType.POSITIVE_INFINITY && bType == BigDecimalType.POSITIVE_INFINITY) ||
4342
(aType == BigDecimalType.NEGATIVE_INFINITY && bType == BigDecimalType.NEGATIVE_INFINITY))) {
44-
return createBigDecimal(frame, BigDecimalType.NAN);
43+
return createBigDecimal(BigDecimalType.NAN);
4544
}
4645

4746
if (posInfinityProfile.profile(aType == BigDecimalType.POSITIVE_INFINITY
4847
|| bType == BigDecimalType.NEGATIVE_INFINITY)) {
49-
return createBigDecimal(frame, BigDecimalType.POSITIVE_INFINITY);
48+
return createBigDecimal(BigDecimalType.POSITIVE_INFINITY);
5049
}
5150

5251
if (negInfinityProfile.profile(aType == BigDecimalType.NEGATIVE_INFINITY
5352
|| bType == BigDecimalType.POSITIVE_INFINITY)) {
54-
return createBigDecimal(frame, BigDecimalType.NEGATIVE_INFINITY);
53+
return createBigDecimal(BigDecimalType.NEGATIVE_INFINITY);
5554
}
5655

5756
// One is NEGATIVE_ZERO and second is NORMAL
5857

5958
if (normalProfile.profile(isNormal(a))) {
6059
return a;
6160
} else {
62-
return createBigDecimal(frame, Layouts.BIG_DECIMAL.getValue(b).negate());
61+
return createBigDecimal(Layouts.BIG_DECIMAL.getValue(b).negate());
6362
}
6463
}
6564
}

src/main/java/org/truffleruby/stdlib/bigdecimal/BigDecimalCastNode.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import com.oracle.truffle.api.dsl.NodeChild;
4444
import com.oracle.truffle.api.dsl.NodeChildren;
4545
import com.oracle.truffle.api.dsl.Specialization;
46-
import com.oracle.truffle.api.frame.VirtualFrame;
4746
import com.oracle.truffle.api.object.DynamicObject;
4847
import org.truffleruby.Layouts;
4948
import org.truffleruby.language.RubyGuards;
@@ -62,9 +61,9 @@
6261
@ImportStatic(BigDecimalCoreMethodNode.class)
6362
public abstract class BigDecimalCastNode extends RubyNode {
6463

65-
public abstract BigDecimal executeBigDecimal(VirtualFrame frame, Object value, RoundingMode roundingMode);
64+
public abstract BigDecimal executeBigDecimal(Object value, RoundingMode roundingMode);
6665

67-
public abstract Object executeObject(VirtualFrame frame, Object value, RoundingMode roundingMode);
66+
public abstract Object executeObject(Object value, RoundingMode roundingMode);
6867

6968
@Specialization
7069
public BigDecimal doInt(long value, Object roundingMode) {
@@ -91,10 +90,7 @@ public BigDecimal doBigDecimal(DynamicObject value, Object roundingMode) {
9190
"!isRubyBignum(value)",
9291
"!isRubyBigDecimal(value)"
9392
})
94-
public Object doOther(
95-
VirtualFrame frame,
96-
DynamicObject value,
97-
Object roundingMode,
93+
public Object doOther(DynamicObject value, Object roundingMode,
9894
@Cached("create()") IsANode isRationalNode,
9995
@Cached("createPrivate()") CallDispatchHeadNode numeratorCallNode,
10096
@Cached("createPrivate()") CallDispatchHeadNode denominatorCallNode) {

src/main/java/org/truffleruby/stdlib/bigdecimal/BigDecimalCoerceNode.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.oracle.truffle.api.dsl.NodeChild;
1414
import com.oracle.truffle.api.dsl.NodeChildren;
1515
import com.oracle.truffle.api.dsl.Specialization;
16-
import com.oracle.truffle.api.frame.VirtualFrame;
1716
import com.oracle.truffle.api.object.DynamicObject;
1817
import org.truffleruby.language.RubyNode;
1918

@@ -36,33 +35,26 @@ public static BigDecimalCoerceNode create(RubyNode value) {
3635
BigDecimalCastNodeGen.create(null, null));
3736
}
3837

39-
protected DynamicObject createBigDecimal(VirtualFrame frame, Object value) {
38+
protected DynamicObject createBigDecimal(Object value) {
4039
if (createBigDecimal == null) {
4140
CompilerDirectives.transferToInterpreterAndInvalidate();
4241
createBigDecimal = insert(CreateBigDecimalNodeFactory.create(null, null, null));
4342
}
4443

45-
return createBigDecimal.executeCreate(frame, value);
44+
return createBigDecimal.executeCreate(value);
4645
}
4746

48-
public abstract DynamicObject executeBigDecimal(VirtualFrame frame, RoundingMode roundingMode, Object value);
49-
5047
@Specialization
51-
public DynamicObject doBigDecimal(VirtualFrame frame, Object value, RoundingMode roundingMode, BigDecimal cast) {
52-
return createBigDecimal(frame, cast);
48+
public DynamicObject doBigDecimal(Object value, RoundingMode roundingMode, BigDecimal cast) {
49+
return createBigDecimal(cast);
5350
}
5451

55-
@Specialization(guards = {
56-
"isRubyBigDecimal(value)",
57-
"isNil(cast)"
58-
})
52+
@Specialization(guards = { "isRubyBigDecimal(value)", "isNil(cast)" })
5953
public Object doBigDecimal(DynamicObject value, RoundingMode roundingMode, DynamicObject cast) {
6054
return value;
6155
}
6256

63-
@Specialization(guards = {
64-
"!isRubyBigDecimal(value)",
65-
})
57+
@Specialization(guards = "!isRubyBigDecimal(value)")
6658
public Object notBigDecimal(Object value, RoundingMode roundingMode, DynamicObject cast) {
6759
return value;
6860
}

src/main/java/org/truffleruby/stdlib/bigdecimal/BigDecimalCoreMethodNode.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import com.oracle.truffle.api.CompilerDirectives;
1313
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
14-
import com.oracle.truffle.api.frame.VirtualFrame;
1514
import com.oracle.truffle.api.object.DynamicObject;
1615
import org.truffleruby.Layouts;
1716
import org.truffleruby.builtins.CoreMethodNode;
@@ -50,15 +49,15 @@ public static boolean isNan(DynamicObject value) {
5049
return Layouts.BIG_DECIMAL.getType(value) == BigDecimalType.NAN;
5150
}
5251

53-
protected DynamicObject createBigDecimal(VirtualFrame frame, Object value) {
54-
return getCreateBigDecimal().executeCreate(frame, value);
52+
protected DynamicObject createBigDecimal(Object value) {
53+
return getCreateBigDecimal().executeCreate(value);
5554
}
5655

57-
protected DynamicObject initializeBigDecimal(VirtualFrame frame, Object value, DynamicObject self, Object digits) {
58-
return getCreateBigDecimal().executeInitialize(frame, value, self, digits);
56+
protected DynamicObject initializeBigDecimal(Object value, DynamicObject self, Object digits) {
57+
return getCreateBigDecimal().executeInitialize(value, self, digits);
5958
}
6059

61-
protected RoundingMode getRoundMode(VirtualFrame frame) {
60+
protected RoundingMode getRoundMode() {
6261
return toRoundingMode(getRoundModeIntegerCast().executeCastInt(
6362
// TODO (pitr 21-Jun-2015): read the actual constant
6463
getRoundModeCall().call(getBigDecimalClass(), "mode", 256)));

0 commit comments

Comments
 (0)