Skip to content

Commit 26da569

Browse files
committed
Updates to make AllocationHelperNode#trace use compilation constant language
1 parent a569bc7 commit 26da569

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+424
-255
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.math.BigInteger;
1313
import java.util.concurrent.locks.ReentrantLock;
1414

15+
import com.oracle.truffle.api.dsl.CachedLanguage;
1516
import com.oracle.truffle.api.object.DynamicObjectLibrary;
1617
import org.jcodings.Encoding;
1718
import org.jcodings.IntHolder;
@@ -1029,14 +1030,15 @@ public abstract static class StringToPointerNode extends CoreMethodArrayArgument
10291030
@Specialization
10301031
protected RubyPointer toNative(RubyString string,
10311032
@Cached StringToNativeNode stringToNativeNode,
1032-
@Cached AllocateHelperNode allocateNode) {
1033+
@Cached AllocateHelperNode allocateNode,
1034+
@CachedLanguage RubyLanguage language) {
10331035
final NativeRope nativeRope = stringToNativeNode.executeToNative(string);
10341036

10351037
final RubyPointer instance = new RubyPointer(
10361038
coreLibrary().truffleFFIPointerClass,
10371039
RubyLanguage.truffleFFIPointerShape,
10381040
nativeRope.getNativePointer());
1039-
allocateNode.trace(instance, this);
1041+
allocateNode.trace(instance, this, language);
10401042
return instance;
10411043
}
10421044

@@ -1246,7 +1248,8 @@ public abstract static class RbTrMbcCaseFoldNode extends CoreMethodArrayArgument
12461248
protected Object rbTrEncMbcCaseFold(RubyEncoding enc, int flags, RubyString string, Object write_p, Object p,
12471249
@CachedLibrary("write_p") InteropLibrary receivers,
12481250
@Cached AllocateHelperNode allocateNode,
1249-
@Cached TranslateInteropExceptionNode translateInteropExceptionNode) {
1251+
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
1252+
@CachedLanguage RubyLanguage language) {
12501253
final byte[] bytes = string.rope.getBytes();
12511254
final byte[] to = new byte[bytes.length];
12521255
final IntHolder intHolder = new IntHolder();
@@ -1259,6 +1262,7 @@ protected Object rbTrEncMbcCaseFold(RubyEncoding enc, int flags, RubyString stri
12591262
System.arraycopy(to, 0, result, 0, resultLength);
12601263
}
12611264
return StringOperations.createString(
1265+
language,
12621266
getContext(),
12631267
allocateNode,
12641268
this,
@@ -1276,7 +1280,8 @@ public abstract static class RbTrMbcPutNode extends CoreMethodArrayArgumentsNode
12761280

12771281
@Specialization
12781282
protected Object rbTrEncMbcPut(RubyEncoding enc, int code,
1279-
@Cached AllocateHelperNode allocateNode) {
1283+
@Cached AllocateHelperNode allocateNode,
1284+
@CachedLanguage RubyLanguage language) {
12801285
final Encoding encoding = enc.encoding;
12811286
final byte buf[] = new byte[org.jcodings.Config.ENC_CODE_TO_MBC_MAXLEN];
12821287
final int resultLength = encoding.codeToMbc(code, buf, 0);
@@ -1285,6 +1290,7 @@ protected Object rbTrEncMbcPut(RubyEncoding enc, int code,
12851290
System.arraycopy(buf, 0, result, 0, resultLength);
12861291
}
12871292
return StringOperations.createString(
1293+
language,
12881294
getContext(),
12891295
allocateNode,
12901296
this,

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.io.PrintStream;
4141
import java.util.Map.Entry;
4242

43+
import com.oracle.truffle.api.dsl.CachedLanguage;
4344
import org.jcodings.specific.ASCIIEncoding;
4445
import org.jcodings.specific.UTF8Encoding;
4546
import org.truffleruby.RubyContext;
@@ -165,7 +166,8 @@ public static abstract class VMMethodLookupNode extends PrimitiveArrayArgumentsN
165166
@Specialization
166167
protected Object vmMethodLookup(VirtualFrame frame, Object receiver, Object name,
167168
@Cached NameToJavaStringNode nameToJavaStringNode,
168-
@Cached LookupMethodOnSelfNode lookupMethodNode) {
169+
@Cached LookupMethodOnSelfNode lookupMethodNode,
170+
@CachedLanguage RubyLanguage language) {
169171
// TODO BJF Sep 14, 2016 Handle private
170172
final String normalizedName = nameToJavaStringNode.execute(name);
171173
InternalMethod method = lookupMethodNode.lookupIgnoringVisibility(frame, receiver, normalizedName);
@@ -177,7 +179,7 @@ protected Object vmMethodLookup(VirtualFrame frame, Object receiver, Object name
177179
RubyLanguage.methodShape,
178180
receiver,
179181
method);
180-
allocateNode.trace(instance, this);
182+
allocateNode.trace(instance, this, language);
181183
return instance;
182184
}
183185

src/main/java/org/truffleruby/core/array/ArrayDupNode.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,21 @@ public abstract class ArrayDupNode extends RubyContextNode {
4141
protected RubyArray dupProfiledSize(RubyArray from,
4242
@CachedLibrary("from.store") ArrayStoreLibrary fromStores,
4343
@CachedLibrary(limit = "1") ArrayStoreLibrary toStores,
44-
@Cached("from.size") int cachedSize) {
45-
return copyArraySmall(fromStores, toStores, from, cachedSize);
44+
@Cached("from.size") int cachedSize,
45+
@CachedLanguage RubyLanguage language) {
46+
return copyArraySmall(language, fromStores, toStores, from, cachedSize);
4647
}
4748

4849
@ExplodeLoop
49-
private RubyArray copyArraySmall(ArrayStoreLibrary fromStores, ArrayStoreLibrary toStores, RubyArray from,
50+
private RubyArray copyArraySmall(RubyLanguage language, ArrayStoreLibrary fromStores, ArrayStoreLibrary toStores,
51+
RubyArray from,
5052
int cachedSize) {
5153
final Object original = from.store;
5254
final Object copy = fromStores.allocator(original).allocate(cachedSize);
5355
for (int i = 0; i < cachedSize; i++) {
5456
toStores.write(copy, i, fromStores.read(original, i));
5557
}
56-
return allocateArray(coreLibrary().arrayClass, RubyLanguage.arrayShape, copy, cachedSize);
58+
return allocateArray(language, coreLibrary().arrayClass, RubyLanguage.arrayShape, copy, cachedSize);
5759
}
5860

5961
@Specialization(replaces = "dupProfiledSize")
@@ -62,16 +64,17 @@ protected RubyArray dup(RubyArray from,
6264
@CachedLanguage RubyLanguage language) {
6365
final int size = from.size;
6466
final Object copy = cowNode.execute(from, 0, from.size);
65-
return allocateArray(coreLibrary().arrayClass, RubyLanguage.arrayShape, copy, size);
67+
return allocateArray(language, coreLibrary().arrayClass, RubyLanguage.arrayShape, copy, size);
6668
}
6769

68-
private RubyArray allocateArray(RubyClass rubyClass, Shape arrayShape, Object store, int size) {
70+
private RubyArray allocateArray(RubyLanguage language, RubyClass rubyClass, Shape arrayShape, Object store,
71+
int size) {
6972
if (helperNode == null) {
7073
CompilerDirectives.transferToInterpreterAndInvalidate();
7174
helperNode = insert(AllocateHelperNode.create());
7275
}
7376
RubyArray array = new RubyArray(rubyClass, arrayShape, store, size);
74-
helperNode.trace(array, this);
77+
helperNode.trace(array, this, language);
7578
return array;
7679
}
7780

src/main/java/org/truffleruby/core/array/ArrayIndexNodes.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
package org.truffleruby.core.array;
1111

12+
import com.oracle.truffle.api.dsl.CachedLanguage;
13+
import org.truffleruby.RubyLanguage;
1214
import org.truffleruby.builtins.CoreModule;
1315
import org.truffleruby.builtins.Primitive;
1416
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
@@ -116,27 +118,28 @@ protected Object readNegativeLength(RubyArray array, int index, int length) {
116118
@Specialization(guards = { "indexInBounds(array, index)", "length >= 0" })
117119
protected RubyArray readInBounds(RubyArray array, int index, int length,
118120
@Cached ArrayCopyOnWriteNode cowNode,
119-
@Cached ConditionProfile endsInBoundsProfile) {
121+
@Cached ConditionProfile endsInBoundsProfile,
122+
@CachedLanguage RubyLanguage language) {
120123
final int size = array.size;
121124
final int end = endsInBoundsProfile.profile(index + length <= size)
122125
? length
123126
: size - index;
124127
final Object slice = cowNode.execute(array, index, end);
125-
return createArrayOfSameClass(array, slice, end);
128+
return createArrayOfSameClass(language, array, slice, end);
126129
}
127130

128131
protected static boolean indexInBounds(RubyArray array, int index) {
129132
return index >= 0 && index <= array.size;
130133
}
131134

132-
protected RubyArray createArrayOfSameClass(RubyArray array, Object store, int size) {
135+
protected RubyArray createArrayOfSameClass(RubyLanguage language, RubyArray array, Object store, int size) {
133136
final RubyClass logicalClass = array.getLogicalClass();
134137
RubyArray newArray = new RubyArray(
135138
logicalClass,
136139
helperNode.getCachedShape(logicalClass),
137140
store,
138141
size);
139-
helperNode.trace(newArray, this);
142+
helperNode.trace(newArray, this, language);
140143
return newArray;
141144
}
142145
}

src/main/java/org/truffleruby/core/array/ArrayLiteralNode.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@
2323

2424
public abstract class ArrayLiteralNode extends RubyContextSourceNode {
2525

26-
public static ArrayLiteralNode create(RubyNode[] values) {
27-
return new UninitialisedArrayLiteralNode(values);
26+
public static ArrayLiteralNode create(RubyLanguage language, RubyNode[] values) {
27+
return new UninitialisedArrayLiteralNode(language, values);
2828
}
2929

3030
@Children protected final RubyNode[] values;
3131
@Child private AllocateHelperNode allocateHelperNode;
32+
protected final RubyLanguage language;
3233

33-
public ArrayLiteralNode(RubyNode[] values) {
34+
public ArrayLiteralNode(RubyLanguage language, RubyNode[] values) {
35+
this.language = language;
3436
this.values = values;
3537
}
3638

3739
protected RubyArray makeGeneric(VirtualFrame frame, Object[] alreadyExecuted) {
38-
final ArrayLiteralNode newNode = new ObjectArrayLiteralNode(values);
40+
final ArrayLiteralNode newNode = new ObjectArrayLiteralNode(language, values);
3941
newNode.unsafeSetSourceSection(getSourceIndexLength());
4042
replace(newNode);
4143

@@ -58,7 +60,7 @@ protected RubyArray cachedCreateArray(Object store, int size) {
5860
allocateHelperNode = insert(AllocateHelperNode.create());
5961
}
6062
final RubyArray array = new RubyArray(coreLibrary().arrayClass, RubyLanguage.arrayShape, store, size);
61-
allocateHelperNode.trace(array, this);
63+
allocateHelperNode.trace(array, this, language);
6264
return array;
6365
}
6466

@@ -98,8 +100,8 @@ public RubyNode stealNode(int index) {
98100

99101
private static class EmptyArrayLiteralNode extends ArrayLiteralNode {
100102

101-
public EmptyArrayLiteralNode(RubyNode[] values) {
102-
super(values);
103+
public EmptyArrayLiteralNode(RubyLanguage language, RubyNode[] values) {
104+
super(language, values);
103105
}
104106

105107
@Override
@@ -111,8 +113,8 @@ public Object execute(VirtualFrame frame) {
111113

112114
private static class FloatArrayLiteralNode extends ArrayLiteralNode {
113115

114-
public FloatArrayLiteralNode(RubyNode[] values) {
115-
super(values);
116+
public FloatArrayLiteralNode(RubyLanguage language, RubyNode[] values) {
117+
super(language, values);
116118
}
117119

118120
@ExplodeLoop
@@ -148,8 +150,8 @@ private RubyArray makeGeneric(VirtualFrame frame, final double[] executedValues,
148150

149151
private static class IntegerArrayLiteralNode extends ArrayLiteralNode {
150152

151-
public IntegerArrayLiteralNode(RubyNode[] values) {
152-
super(values);
153+
public IntegerArrayLiteralNode(RubyLanguage language, RubyNode[] values) {
154+
super(language, values);
153155
}
154156

155157
@ExplodeLoop
@@ -185,8 +187,8 @@ private RubyArray makeGeneric(VirtualFrame frame, final int[] executedValues, in
185187

186188
private static class LongArrayLiteralNode extends ArrayLiteralNode {
187189

188-
public LongArrayLiteralNode(RubyNode[] values) {
189-
super(values);
190+
public LongArrayLiteralNode(RubyLanguage language, RubyNode[] values) {
191+
super(language, values);
190192
}
191193

192194
@ExplodeLoop
@@ -222,8 +224,8 @@ private RubyArray makeGeneric(VirtualFrame frame, final long[] executedValues, i
222224

223225
private static class ObjectArrayLiteralNode extends ArrayLiteralNode {
224226

225-
public ObjectArrayLiteralNode(RubyNode[] values) {
226-
super(values);
227+
public ObjectArrayLiteralNode(RubyLanguage language, RubyNode[] values) {
228+
super(language, values);
227229
}
228230

229231
@ExplodeLoop
@@ -242,8 +244,8 @@ public Object execute(VirtualFrame frame) {
242244

243245
private static class UninitialisedArrayLiteralNode extends ArrayLiteralNode {
244246

245-
public UninitialisedArrayLiteralNode(RubyNode[] values) {
246-
super(values);
247+
public UninitialisedArrayLiteralNode(RubyLanguage language, RubyNode[] values) {
248+
super(language, values);
247249
}
248250

249251
@Override
@@ -264,15 +266,15 @@ public Object execute(VirtualFrame frame) {
264266
final RubyNode newNode;
265267

266268
if (store == ArrayStoreLibrary.INITIAL_STORE) {
267-
newNode = new EmptyArrayLiteralNode(values);
269+
newNode = new EmptyArrayLiteralNode(language, values);
268270
} else if (store instanceof int[]) {
269-
newNode = new IntegerArrayLiteralNode(values);
271+
newNode = new IntegerArrayLiteralNode(language, values);
270272
} else if (store instanceof long[]) {
271-
newNode = new LongArrayLiteralNode(values);
273+
newNode = new LongArrayLiteralNode(language, values);
272274
} else if (store instanceof double[]) {
273-
newNode = new FloatArrayLiteralNode(values);
275+
newNode = new FloatArrayLiteralNode(language, values);
274276
} else {
275-
newNode = new ObjectArrayLiteralNode(values);
277+
newNode = new ObjectArrayLiteralNode(language, values);
276278
}
277279

278280
newNode.unsafeSetSourceSection(getSourceIndexLength());

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
import java.util.Arrays;
1717

18+
import com.oracle.truffle.api.dsl.CachedLanguage;
1819
import com.oracle.truffle.api.profiles.LoopConditionProfile;
1920
import org.truffleruby.Layouts;
21+
import org.truffleruby.RubyLanguage;
2022
import org.truffleruby.builtins.CoreMethod;
2123
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
2224
import org.truffleruby.builtins.CoreMethodNode;
@@ -108,13 +110,14 @@ public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
108110
@Child private AllocateHelperNode helperNode = AllocateHelperNode.create();
109111

110112
@Specialization
111-
protected RubyArray allocate(RubyClass rubyClass) {
113+
protected RubyArray allocate(RubyClass rubyClass,
114+
@CachedLanguage RubyLanguage language) {
112115
RubyArray array = new RubyArray(
113116
rubyClass,
114117
helperNode.getCachedShape(rubyClass),
115118
ArrayStoreLibrary.INITIAL_STORE,
116119
0);
117-
helperNode.trace(array, this);
120+
helperNode.trace(array, this, language);
118121
return array;
119122
}
120123

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,11 @@ public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
612612

613613
@Specialization
614614
protected RubyBasicObject allocate(RubyClass rubyClass,
615-
@Cached AllocateHelperNode allocateHelperNode) {
615+
@Cached AllocateHelperNode allocateHelperNode,
616+
@CachedLanguage RubyLanguage language) {
616617
final Shape shape = allocateHelperNode.getCachedShape(rubyClass);
617618
final RubyBasicObject instance = new RubyBasicObject(rubyClass, shape);
618-
allocateHelperNode.trace(instance, this);
619+
allocateHelperNode.trace(instance, this, language);
619620
return instance;
620621
}
621622

src/main/java/org/truffleruby/core/encoding/EncodingConverterNodes.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.nio.charset.StandardCharsets;
1717
import java.util.Set;
1818

19+
import com.oracle.truffle.api.dsl.CachedLanguage;
1920
import org.jcodings.Encoding;
2021
import org.jcodings.Ptr;
2122
import org.jcodings.specific.ASCIIEncoding;
@@ -24,6 +25,7 @@
2425
import org.jcodings.transcode.EConvResult;
2526
import org.jcodings.transcode.Transcoder;
2627
import org.jcodings.transcode.TranscoderDB;
28+
import org.truffleruby.RubyLanguage;
2729
import org.truffleruby.builtins.CoreMethod;
2830
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
2931
import org.truffleruby.builtins.CoreMethodNode;
@@ -155,10 +157,11 @@ public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
155157
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
156158

157159
@Specialization
158-
protected RubyEncodingConverter allocate(RubyClass rubyClass) {
160+
protected RubyEncodingConverter allocate(RubyClass rubyClass,
161+
@CachedLanguage RubyLanguage language) {
159162
final Shape shape = allocateNode.getCachedShape(rubyClass);
160163
final RubyEncodingConverter instance = new RubyEncodingConverter(rubyClass, shape, null);
161-
allocateNode.trace(instance, this);
164+
allocateNode.trace(instance, this, language);
162165
return instance;
163166
}
164167

src/main/java/org/truffleruby/core/exception/ExceptionNodes.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
package org.truffleruby.core.exception;
1111

12+
import com.oracle.truffle.api.dsl.CachedLanguage;
13+
import org.truffleruby.RubyLanguage;
1214
import org.truffleruby.SuppressFBWarnings;
1315
import org.truffleruby.builtins.CoreMethod;
1416
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -43,10 +45,11 @@ public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
4345
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
4446

4547
@Specialization
46-
protected RubyException allocateException(RubyClass rubyClass) {
48+
protected RubyException allocateException(RubyClass rubyClass,
49+
@CachedLanguage RubyLanguage language) {
4750
final Shape shape = allocateNode.getCachedShape(rubyClass);
4851
final RubyException instance = new RubyException(rubyClass, shape, nil, null, nil);
49-
allocateNode.trace(instance, this);
52+
allocateNode.trace(instance, this, language);
5053
return instance;
5154
}
5255

0 commit comments

Comments
 (0)