Skip to content

Commit b36acc3

Browse files
committed
[GR-26288] Store the metaClass directly in RubyDynamicObject
1 parent 058635d commit b36acc3

File tree

103 files changed

+640
-230
lines changed

Some content is hidden

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

103 files changed

+640
-230
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ protected RubyPointer toNative(RubyString string,
10331033
final NativeRope nativeRope = stringToNativeNode.executeToNative(string);
10341034

10351035
final RubyPointer instance = new RubyPointer(
1036+
coreLibrary().truffleFFIPointerClass,
10361037
coreLibrary().truffleFFIPointerShape,
10371038
nativeRope.getNativePointer());
10381039
allocateNode.trace(instance, this);

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public class CoreLibrary {
159159
public final RubyClass arrayClass;
160160
public final Shape arrayShape;
161161
public final RubyClass basicObjectClass;
162+
public final RubyClass bindingClass;
162163
public final Shape bindingShape;
163164
public final RubyClass classClass;
164165
public final Shape classShape;
@@ -170,6 +171,7 @@ public class CoreLibrary {
170171
public final RubyClass encodingErrorClass;
171172
public final RubyClass exceptionClass;
172173
public final RubyClass falseClass;
174+
public final RubyClass fiberClass;
173175
public final Shape fiberShape;
174176
public final RubyClass floatClass;
175177
public final RubyClass floatDomainErrorClass;
@@ -182,6 +184,7 @@ public class CoreLibrary {
182184
public final RubyClass ioErrorClass;
183185
public final RubyClass loadErrorClass;
184186
public final RubyClass localJumpErrorClass;
187+
public final RubyClass matchDataClass;
185188
public final Shape matchDataShape;
186189
public final RubyClass moduleClass;
187190
public final RubyClass nameErrorClass;
@@ -203,6 +206,7 @@ public class CoreLibrary {
203206
public final Shape objectRangeShape;
204207
public final RubyClass rangeErrorClass;
205208
public final RubyClass rationalClass;
209+
public final RubyClass regexpClass;
206210
public final Shape regexpShape;
207211
public final RubyClass regexpErrorClass;
208212
public final RubyClass graalErrorClass;
@@ -221,6 +225,7 @@ public class CoreLibrary {
221225
public final RubyClass systemExitClass;
222226
public final RubyClass threadClass;
223227
public final Shape threadShape;
228+
public final RubyClass threadBacktraceLocationClass;
224229
public final Shape threadBacktraceLocationShape;
225230
public final RubyClass trueClass;
226231
public final RubyClass typeErrorClass;
@@ -254,17 +259,23 @@ public class CoreLibrary {
254259
public final Shape bigDecimalShape;
255260
public final RubyClass encodingCompatibilityErrorClass;
256261
public final RubyClass encodingUndefinedConversionErrorClass;
262+
public final RubyClass methodClass;
257263
public final Shape methodShape;
264+
public final RubyClass unboundMethodClass;
258265
public final Shape unboundMethodShape;
266+
public final RubyClass byteArrayClass;
259267
public final Shape byteArrayShape;
260268
public final RubyClass fiberErrorClass;
261269
public final RubyClass threadErrorClass;
262270
public final RubyModule objectSpaceModule;
271+
public final RubyClass randomizerClass;
263272
public final Shape randomizerShape;
273+
public final RubyClass handleClass;
264274
public final Shape handleShape;
265275
public final RubyClass ioClass;
266276
public final RubyClass closedQueueErrorClass;
267277
public final RubyModule warningModule;
278+
public final RubyClass digestClass;
268279
public final Shape digestShape;
269280
public final RubyClass structClass;
270281
public final RubyClass weakMapClass;
@@ -381,15 +392,15 @@ public CoreLibrary(RubyContext context) {
381392
classShape = classClass.getShape();
382393
classClass.instanceShape = classShape;
383394

384-
basicObjectClass = ClassNodes.createBootClass(context, null, classShape, Nil.INSTANCE, "BasicObject");
395+
basicObjectClass = ClassNodes.createBootClass(context, null, classClass, Nil.INSTANCE, "BasicObject");
385396
Shape basicObjectShape = createShape(RubyBasicObject.class, basicObjectClass);
386397
basicObjectClass.instanceShape = basicObjectShape;
387398

388-
objectClass = ClassNodes.createBootClass(context, null, classShape, basicObjectClass, "Object");
399+
objectClass = ClassNodes.createBootClass(context, null, classClass, basicObjectClass, "Object");
389400
objectShape = createShape(RubyBasicObject.class, objectClass);
390401
objectClass.instanceShape = objectShape;
391402

392-
moduleClass = ClassNodes.createBootClass(context, null, classShape, objectClass, "Module");
403+
moduleClass = ClassNodes.createBootClass(context, null, classClass, objectClass, "Module");
393404
Shape moduleShape = createShape(RubyModule.class, moduleClass);
394405
moduleClass.instanceShape = moduleShape;
395406

@@ -494,7 +505,7 @@ public CoreLibrary(RubyContext context) {
494505
arrayClass = defineClass("Array");
495506
arrayShape = createShape(RubyArray.class, arrayClass);
496507
arrayClass.instanceShape = arrayShape;
497-
RubyClass bindingClass = defineClass("Binding");
508+
bindingClass = defineClass("Binding");
498509
bindingShape = createShape(RubyBinding.class, bindingClass);
499510
bindingClass.instanceShape = bindingShape;
500511
RubyClass conditionVariableClass = defineClass("ConditionVariable");
@@ -506,17 +517,17 @@ public CoreLibrary(RubyContext context) {
506517
encodingShape = createShape(RubyEncoding.class, encodingClass);
507518
encodingClass.instanceShape = encodingShape;
508519
falseClass = defineClass("FalseClass");
509-
RubyClass fiberClass = defineClass("Fiber");
520+
fiberClass = defineClass("Fiber");
510521
fiberShape = createShape(RubyFiber.class, fiberClass);
511522
fiberClass.instanceShape = fiberShape;
512523
defineModule("FileTest");
513524
hashClass = defineClass("Hash");
514525
hashShape = createShape(RubyHash.class, hashClass);
515526
hashClass.instanceShape = hashShape;
516-
RubyClass matchDataClass = defineClass("MatchData");
527+
matchDataClass = defineClass("MatchData");
517528
matchDataShape = createShape(RubyMatchData.class, matchDataClass);
518529
matchDataClass.instanceShape = matchDataShape;
519-
RubyClass methodClass = defineClass("Method");
530+
methodClass = defineClass("Method");
520531
methodShape = createShape(RubyMethod.class, methodClass);
521532
methodClass.instanceShape = methodShape;
522533
RubyClass mutexClass = defineClass("Mutex");
@@ -540,7 +551,7 @@ public CoreLibrary(RubyContext context) {
540551
objectRangeShape = createShape(RubyObjectRange.class, rangeClass);
541552
rangeClass.instanceShape = objectRangeShape;
542553

543-
RubyClass regexpClass = defineClass("Regexp");
554+
regexpClass = defineClass("Regexp");
544555
regexpShape = createShape(RubyRegexp.class, regexpClass);
545556
regexpClass.instanceShape = regexpShape;
546557
stringClass = defineClass("String");
@@ -555,14 +566,14 @@ public CoreLibrary(RubyContext context) {
555566
threadClass.instanceShape = threadShape;
556567

557568
RubyClass threadBacktraceClass = defineClass(threadClass, objectClass, "Backtrace");
558-
RubyClass threadBacktraceLocationClass = defineClass(threadBacktraceClass, objectClass, "Location");
569+
threadBacktraceLocationClass = defineClass(threadBacktraceClass, objectClass, "Location");
559570
threadBacktraceLocationShape = createShape(RubyBacktraceLocation.class, threadBacktraceLocationClass);
560571
threadBacktraceLocationClass.instanceShape = threadBacktraceLocationShape;
561572
RubyClass timeClass = defineClass("Time");
562573
Shape timeShape = createShape(RubyTime.class, timeClass);
563574
timeClass.instanceShape = timeShape;
564575
trueClass = defineClass("TrueClass");
565-
RubyClass unboundMethodClass = defineClass("UnboundMethod");
576+
unboundMethodClass = defineClass("UnboundMethod");
566577
unboundMethodShape = createShape(RubyUnboundMethod.class, unboundMethodClass);
567578
unboundMethodClass.instanceShape = unboundMethodShape;
568579
ioClass = defineClass("IO");
@@ -652,7 +663,7 @@ public CoreLibrary(RubyContext context) {
652663
defineModule(truffleModule, "ReadlineHistory");
653664
truffleThreadOperationsModule = defineModule(truffleModule, "ThreadOperations");
654665
defineModule(truffleModule, "WeakRefOperations");
655-
RubyClass handleClass = defineClass(truffleModule, objectClass, "Handle");
666+
handleClass = defineClass(truffleModule, objectClass, "Handle");
656667
handleShape = createShape(RubyHandle.class, handleClass);
657668
handleClass.instanceShape = handleShape;
658669
warningModule = defineModule("Warning");
@@ -671,18 +682,18 @@ public CoreLibrary(RubyContext context) {
671682

672683
truffleTypeModule = defineModule(truffleModule, "Type");
673684

674-
RubyClass byteArrayClass = defineClass(truffleModule, objectClass, "ByteArray");
685+
byteArrayClass = defineClass(truffleModule, objectClass, "ByteArray");
675686
byteArrayShape = createShape(RubyByteArray.class, byteArrayClass);
676687
byteArrayClass.instanceShape = byteArrayShape;
677688
defineClass(truffleModule, objectClass, "StringData");
678689
defineClass(encodingClass, objectClass, "Transcoding");
679-
RubyClass randomizerClass = defineClass(truffleModule, objectClass, "Randomizer");
690+
randomizerClass = defineClass(truffleModule, objectClass, "Randomizer");
680691
randomizerShape = createShape(RubyRandomizer.class, randomizerClass);
681692
randomizerClass.instanceShape = randomizerShape;
682693

683694
// Standard library
684695

685-
RubyClass digestClass = defineClass(truffleModule, basicObjectClass, "Digest");
696+
digestClass = defineClass(truffleModule, basicObjectClass, "Digest");
686697
digestShape = createShape(RubyDigest.class, digestClass);
687698
digestClass.instanceShape = digestShape;
688699

@@ -692,9 +703,9 @@ public CoreLibrary(RubyContext context) {
692703

693704
// Create some key objects
694705

695-
mainObject = new RubyBasicObject(objectShape);
706+
mainObject = new RubyBasicObject(objectClass, objectShape);
696707
emptyDescriptor = new FrameDescriptor(Nil.INSTANCE);
697-
argv = new RubyArray(arrayShape, ArrayStoreLibrary.INITIAL_STORE, 0);
708+
argv = new RubyArray(arrayClass, arrayShape, ArrayStoreLibrary.INITIAL_STORE, 0);
698709

699710
globalVariables = new GlobalVariables();
700711

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
package org.truffleruby.core;
1111

1212
import com.oracle.truffle.api.object.Shape;
13+
import org.truffleruby.core.klass.RubyClass;
1314
import org.truffleruby.language.RubyDynamicObject;
1415

1516
public class RubyHandle extends RubyDynamicObject {
1617

1718
public final Object object;
1819

19-
public RubyHandle(Shape shape, Object object) {
20-
super(shape);
20+
public RubyHandle(RubyClass rubyClass, Shape shape, Object object) {
21+
super(rubyClass, shape);
2122
this.object = object;
2223
}
2324

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ protected Object vmMethodLookup(VirtualFrame frame, Object receiver, Object name
174174
if (method == null) {
175175
return nil;
176176
}
177-
final RubyMethod instance = new RubyMethod(coreLibrary().methodShape, receiver, method);
177+
final RubyMethod instance = new RubyMethod(
178+
coreLibrary().methodClass,
179+
coreLibrary().methodShape,
180+
receiver,
181+
method);
178182
allocateNode.trace(instance, this);
179183
return instance;
180184
}

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

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

1212
import org.truffleruby.core.array.library.ArrayStoreLibrary;
13+
import org.truffleruby.core.klass.RubyClass;
1314
import org.truffleruby.language.RubyContextNode;
1415
import org.truffleruby.language.objects.AllocateHelperNode;
1516

@@ -50,23 +51,23 @@ private RubyArray copyArraySmall(ArrayStoreLibrary fromStores, ArrayStoreLibrary
5051
for (int i = 0; i < cachedSize; i++) {
5152
toStores.write(copy, i, fromStores.read(original, i));
5253
}
53-
return allocateArray(coreLibrary().arrayShape, copy, cachedSize);
54+
return allocateArray(coreLibrary().arrayClass, coreLibrary().arrayShape, copy, cachedSize);
5455
}
5556

5657
@Specialization(replaces = "dupProfiledSize")
5758
protected RubyArray dup(RubyArray from,
5859
@Cached ArrayCopyOnWriteNode cowNode) {
5960
final int size = from.size;
6061
final Object copy = cowNode.execute(from, 0, from.size);
61-
return allocateArray(coreLibrary().arrayShape, copy, size);
62+
return allocateArray(coreLibrary().arrayClass, coreLibrary().arrayShape, copy, size);
6263
}
6364

64-
private RubyArray allocateArray(Shape arrayShape, Object store, int size) {
65+
private RubyArray allocateArray(RubyClass rubyClass, Shape arrayShape, Object store, int size) {
6566
if (helperNode == null) {
6667
CompilerDirectives.transferToInterpreterAndInvalidate();
6768
helperNode = insert(AllocateHelperNode.create());
6869
}
69-
RubyArray array = new RubyArray(arrayShape, store, size);
70+
RubyArray array = new RubyArray(rubyClass, arrayShape, store, size);
7071
helperNode.trace(array, this);
7172
return array;
7273
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void setSize(RubyArray array, int size) {
3030

3131
public static RubyArray createArray(RubyContext context, Object store, int size) {
3232
assert !(store instanceof Object[]) || store.getClass() == Object[].class;
33-
return new RubyArray(context.getCoreLibrary().arrayShape, store, size);
33+
return new RubyArray(context.getCoreLibrary().arrayClass, context.getCoreLibrary().arrayShape, store, size);
3434
}
3535

3636
public static RubyArray createArray(RubyContext context, int[] store) {
@@ -47,7 +47,11 @@ public static RubyArray createArray(RubyContext context, Object[] store) {
4747
}
4848

4949
public static RubyArray createEmptyArray(RubyContext context) {
50-
return new RubyArray(context.getCoreLibrary().arrayShape, ArrayStoreLibrary.INITIAL_STORE, 0);
50+
return new RubyArray(
51+
context.getCoreLibrary().arrayClass,
52+
context.getCoreLibrary().arrayShape,
53+
ArrayStoreLibrary.INITIAL_STORE,
54+
0);
5155
}
5256

5357
/** Returns a Java array of the narrowest possible type holding {@code object}. */

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.truffleruby.builtins.Primitive;
1414
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
1515
import org.truffleruby.core.array.library.ArrayStoreLibrary;
16+
import org.truffleruby.core.klass.RubyClass;
1617
import org.truffleruby.language.RubyContextSourceNode;
1718
import org.truffleruby.language.RubyNode;
1819
import org.truffleruby.language.objects.AllocateHelperNode;
@@ -129,8 +130,10 @@ protected static boolean indexInBounds(RubyArray array, int index) {
129130
}
130131

131132
protected RubyArray createArrayOfSameClass(RubyArray array, Object store, int size) {
133+
final RubyClass logicalClass = array.getLogicalClass();
132134
RubyArray newArray = new RubyArray(
133-
helperNode.getCachedShape(array.getLogicalClass()),
135+
logicalClass,
136+
helperNode.getCachedShape(logicalClass),
134137
store,
135138
size);
136139
helperNode.trace(newArray, this);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected RubyArray cachedCreateArray(Object store, int size) {
5656
CompilerDirectives.transferToInterpreterAndInvalidate();
5757
allocateHelperNode = insert(AllocateHelperNode.create());
5858
}
59-
final RubyArray array = new RubyArray(coreLibrary().arrayShape, store, size);
59+
final RubyArray array = new RubyArray(coreLibrary().arrayClass, coreLibrary().arrayShape, store, size);
6060
allocateHelperNode.trace(array, this);
6161
return array;
6262
}

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
109109

110110
@Specialization
111111
protected RubyArray allocate(RubyClass rubyClass) {
112-
RubyArray array = new RubyArray(helperNode.getCachedShape(rubyClass), ArrayStoreLibrary.INITIAL_STORE, 0);
112+
RubyArray array = new RubyArray(
113+
rubyClass,
114+
helperNode.getCachedShape(rubyClass),
115+
ArrayStoreLibrary.INITIAL_STORE,
116+
0);
113117
helperNode.trace(array, this);
114118
return array;
115119
}
@@ -154,8 +158,10 @@ public abstract static class MulNode extends PrimitiveArrayArgumentsNode {
154158

155159
@Specialization(guards = "count == 0")
156160
protected RubyArray mulZero(RubyArray array, int count) {
161+
final RubyClass logicalClass = array.getLogicalClass();
157162
final RubyArray result = new RubyArray(
158-
helperNode.getCachedShape(array.getLogicalClass()),
163+
logicalClass,
164+
helperNode.getCachedShape(logicalClass),
159165
ArrayStoreLibrary.INITIAL_STORE,
160166
0);
161167
propagateTaintNode.executePropagate(array, result);
@@ -183,8 +189,12 @@ protected RubyArray mulOther(RubyArray array, int count,
183189
arrays.copyContents(store, 0, newStore, n * size, size);
184190
}
185191

186-
final RubyArray result = new RubyArray(helperNode
187-
.getCachedShape(array.getLogicalClass()), newStore, newSize);
192+
final RubyClass logicalClass = array.getLogicalClass();
193+
final RubyArray result = new RubyArray(
194+
logicalClass,
195+
helperNode.getCachedShape(logicalClass),
196+
newStore,
197+
newSize);
188198
propagateTaintNode.executePropagate(array, result);
189199
return result;
190200
}
@@ -201,8 +211,12 @@ protected RubyArray mulLong(RubyArray array, long count) {
201211

202212
@Specialization(guards = { "isEmptyArray(array)" })
203213
protected RubyArray mulEmpty(RubyArray array, long count) {
204-
final RubyArray result = new RubyArray(helperNode
205-
.getCachedShape(array.getLogicalClass()), ArrayStoreLibrary.INITIAL_STORE, 0);
214+
final RubyClass logicalClass = array.getLogicalClass();
215+
final RubyArray result = new RubyArray(
216+
logicalClass,
217+
helperNode.getCachedShape(logicalClass),
218+
ArrayStoreLibrary.INITIAL_STORE,
219+
0);
206220
propagateTaintNode.executePropagate(array, result);
207221
return result;
208222
}

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

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

1212
import java.util.Set;
1313

14+
import org.truffleruby.core.klass.RubyClass;
1415
import org.truffleruby.language.RubyDynamicObject;
1516
import org.truffleruby.language.RubyGuards;
1617
import org.truffleruby.language.dispatch.DispatchNode;
@@ -36,8 +37,8 @@ public final class RubyArray extends RubyDynamicObject implements ObjectGraphNod
3637
public Object store;
3738
public int size;
3839

39-
public RubyArray(Shape shape, Object store, int size) {
40-
super(shape);
40+
public RubyArray(RubyClass rubyClass, Shape shape, Object store, int size) {
41+
super(rubyClass, shape);
4142
this.store = store;
4243
this.size = size;
4344
}

0 commit comments

Comments
 (0)