Skip to content

Commit 2cfd347

Browse files
committed
[GR-27506] Replace CoreLibrary.{getMetaClass,getLogicalClass} with uncached nodes
PullRequest: truffleruby/2171
2 parents 8e52290 + 35abf7a commit 2cfd347

19 files changed

+70
-101
lines changed

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.truffleruby.language.loader.CodeLoader;
7171
import org.truffleruby.language.loader.FeatureLoader;
7272
import org.truffleruby.language.methods.InternalMethod;
73+
import org.truffleruby.language.objects.MetaClassNode;
7374
import org.truffleruby.language.objects.shared.SharedObjects;
7475
import org.truffleruby.options.LanguageOptions;
7576
import org.truffleruby.options.Options;
@@ -424,7 +425,7 @@ private TruffleNFIPlatform createNativePlatform() {
424425
@TruffleBoundary
425426
public Object send(Object object, String methodName, Object... arguments) {
426427
final InternalMethod method = ModuleOperations
427-
.lookupMethodUncached(coreLibrary.getMetaClass(object), methodName, null);
428+
.lookupMethodUncached(MetaClassNode.getUncached().execute(object), methodName, null);
428429
if (method == null || method.isUndefined()) {
429430
return null;
430431
}

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

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.concurrent.ConcurrentHashMap;
2424
import java.util.concurrent.ConcurrentMap;
2525

26-
import com.oracle.truffle.api.CompilerAsserts;
2726
import com.oracle.truffle.api.object.Shape;
2827
import org.jcodings.specific.USASCIIEncoding;
2928
import org.jcodings.transcode.EConvFlags;
@@ -48,15 +47,12 @@
4847
import org.truffleruby.core.rope.LeafRope;
4948
import org.truffleruby.core.string.RubyString;
5049
import org.truffleruby.core.string.StringOperations;
51-
import org.truffleruby.core.symbol.RubySymbol;
5250
import org.truffleruby.debug.GlobalVariablesObject;
5351
import org.truffleruby.debug.TopScopeObject;
5452
import org.truffleruby.extra.ffi.Pointer;
5553
import org.truffleruby.language.ImmutableRubyString;
5654
import org.truffleruby.language.Nil;
5755
import org.truffleruby.language.NotProvided;
58-
import org.truffleruby.language.RubyDynamicObject;
59-
import org.truffleruby.language.RubyGuards;
6056
import org.truffleruby.language.RubyRootNode;
6157
import org.truffleruby.language.control.RaiseException;
6258
import org.truffleruby.language.globals.GlobalVariableReader;
@@ -867,47 +863,6 @@ private void afterLoadCoreLibrary() {
867863
.getValue();
868864
}
869865

870-
public RubyClass getMetaClass(Object object) {
871-
CompilerAsserts.neverPartOfCompilation("MetaClassNode should be used instead");
872-
if (object instanceof RubyDynamicObject) {
873-
return ((RubyDynamicObject) object).getMetaClass();
874-
} else {
875-
return getLogicalClass(object);
876-
}
877-
}
878-
879-
public RubyClass getLogicalClass(Object object) {
880-
CompilerAsserts.neverPartOfCompilation("LogicalClassNode should be used instead");
881-
if (object instanceof RubyDynamicObject) {
882-
return ((RubyDynamicObject) object).getLogicalClass();
883-
} else if (object instanceof Nil) {
884-
return nilClass;
885-
} else if (object instanceof RubyBignum) {
886-
return integerClass;
887-
} else if (object instanceof RubySymbol) {
888-
return symbolClass;
889-
} else if (object instanceof ImmutableRubyString) {
890-
return stringClass;
891-
} else if (object instanceof Boolean) {
892-
return (boolean) object ? trueClass : falseClass;
893-
} else if (object instanceof Byte) {
894-
return integerClass;
895-
} else if (object instanceof Short) {
896-
return integerClass;
897-
} else if (object instanceof Integer) {
898-
return integerClass;
899-
} else if (object instanceof Long) {
900-
return integerClass;
901-
} else if (object instanceof Float) {
902-
return floatClass;
903-
} else if (object instanceof Double) {
904-
return floatClass;
905-
} else {
906-
assert RubyGuards.isForeignObject(object);
907-
return truffleInteropForeignClass;
908-
}
909-
}
910-
911866
/** Convert a value to a {@code Float}, without doing any lookup. */
912867
public static double toDouble(Object value, Object nil) {
913868
assert value != null;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.truffleruby.language.methods.UnsupportedOperationBehavior;
5656
import org.truffleruby.language.objects.AllocateHelperNode;
5757
import org.truffleruby.language.objects.AllocationTracing;
58+
import org.truffleruby.language.objects.MetaClassNode;
5859
import org.truffleruby.language.objects.ObjectIDOperations;
5960
import org.truffleruby.language.supercall.SuperCallNode;
6061
import org.truffleruby.language.yield.CallBlockNode;
@@ -586,7 +587,7 @@ private Visibility lastCallWasCallingPrivateOrProtectedMethod(Object self, Strin
586587
FrameAndCallNode callerFrame) {
587588
final DeclarationContext declarationContext = RubyArguments.tryGetDeclarationContext(callerFrame.frame);
588589
final InternalMethod method = ModuleOperations
589-
.lookupMethodUncached(coreLibrary().getMetaClass(self), name, declarationContext);
590+
.lookupMethodUncached(MetaClassNode.getUncached().execute(self), name, declarationContext);
590591
if (method != null && !method.isUndefined()) {
591592
assert method.getVisibility() == Visibility.PRIVATE || method.getVisibility() == Visibility.PROTECTED;
592593
return method.getVisibility();

src/main/java/org/truffleruby/core/cast/CmpIntNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3232
import com.oracle.truffle.api.dsl.Cached;
3333
import com.oracle.truffle.api.dsl.Specialization;
34+
import org.truffleruby.language.objects.LogicalClassNode;
3435

3536
/** This is a port of MRI's rb_cmpint, as taken from RubyComparable and broken out into specialized nodes. */
3637
public abstract class CmpIntNode extends RubyContextNode {
@@ -73,8 +74,8 @@ protected int cmpNil(Nil nil, Object receiver, Object other) {
7374
private String formatMessage(Object receiver, Object other) {
7475
return StringUtils.format(
7576
"comparison of %s with %s failed",
76-
coreLibrary().getLogicalClass(receiver).fields.getName(),
77-
coreLibrary().getLogicalClass(other).fields.getName());
77+
LogicalClassNode.getUncached().execute(receiver).fields.getName(),
78+
LogicalClassNode.getUncached().execute(other).fields.getName());
7879
}
7980

8081
@Specialization(guards = { "!isRubyInteger(value)", "!isNil(value)" })

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.truffle.api.nodes.Node;
4848
import com.oracle.truffle.api.object.DynamicObjectLibrary;
4949
import com.oracle.truffle.api.source.SourceSection;
50+
import org.truffleruby.language.objects.LogicalClassNode;
5051

5152
public class CoreExceptions {
5253

@@ -203,7 +204,7 @@ public RubyException argumentErrorEmptyVarargs(Node currentNode) {
203204

204205
@TruffleBoundary
205206
public RubyException argumentErrorWrongArgumentType(Object object, String expectedType, Node currentNode) {
206-
String badClassName = context.getCoreLibrary().getLogicalClass(object).fields.getName();
207+
String badClassName = LogicalClassNode.getUncached().execute(object).fields.getName();
207208
return argumentError(
208209
StringUtils.format("wrong argument type %s (expected %s)", badClassName, expectedType),
209210
currentNode);
@@ -248,15 +249,15 @@ public RubyException argumentErrorInvalidBigDecimal(String string, Node currentN
248249

249250
@TruffleBoundary
250251
public RubyException argumentErrorCantUnfreeze(Object self, Node currentNode) {
251-
String className = context.getCoreLibrary().getLogicalClass(self).fields.getName();
252+
String className = LogicalClassNode.getUncached().execute(self).fields.getName();
252253
return argumentError(StringUtils.format("can't unfreeze %s", className), currentNode);
253254
}
254255

255256
// FrozenError
256257

257258
@TruffleBoundary
258259
public RubyException frozenError(Object object, Node currentNode) {
259-
String className = context.getCoreLibrary().getLogicalClass(object).fields.getName();
260+
String className = LogicalClassNode.getUncached().execute(object).fields.getName();
260261
return frozenError(StringUtils.format("can't modify frozen %s", className), currentNode);
261262
}
262263

@@ -485,21 +486,21 @@ public RubyException typeErrorCantBeCastedToBigDecimal(Node currentNode) {
485486
@TruffleBoundary
486487
public RubyException typeErrorCantConvertTo(Object from, String toClass, String methodUsed, Object result,
487488
Node currentNode) {
488-
String fromClass = context.getCoreLibrary().getLogicalClass(from).fields.getName();
489+
String fromClass = LogicalClassNode.getUncached().execute(from).fields.getName();
489490
return typeError(StringUtils.format(
490491
"can't convert %s to %s (%s#%s gives %s)",
491492
fromClass,
492493
toClass,
493494
fromClass,
494495
methodUsed,
495-
context.getCoreLibrary().getLogicalClass(result).toString()), currentNode);
496+
LogicalClassNode.getUncached().execute(result).toString()), currentNode);
496497
}
497498

498499
@TruffleBoundary
499500
public RubyException typeErrorCantConvertInto(Object from, String toClass, Node currentNode) {
500501
return typeError(StringUtils.format(
501502
"can't convert %s into %s",
502-
context.getCoreLibrary().getLogicalClass(from).fields.getName(),
503+
LogicalClassNode.getUncached().execute(from).fields.getName(),
503504
toClass), currentNode);
504505
}
505506

@@ -530,32 +531,34 @@ public RubyException typeErrorIsNotAClassModule(Object value, Node currentNode)
530531
public RubyException typeErrorNoImplicitConversion(Object from, String to, Node currentNode) {
531532
return typeError(StringUtils.format(
532533
"no implicit conversion of %s into %s",
533-
context.getCoreLibrary().getLogicalClass(from).fields.getName(),
534+
LogicalClassNode.getUncached().execute(from).fields.getName(),
534535
to), currentNode);
535536
}
536537

537538
@TruffleBoundary
538539
public RubyException typeErrorBadCoercion(Object from, String to, String coercionMethod, Object coercedTo,
539540
Node currentNode) {
540-
String badClassName = context.getCoreLibrary().getLogicalClass(from).fields.getName();
541-
return typeError(StringUtils.format(
542-
"can't convert %s to %s (%s#%s gives %s)",
543-
badClassName,
544-
to,
545-
badClassName,
546-
coercionMethod,
547-
context.getCoreLibrary().getLogicalClass(coercedTo).fields.getName()), currentNode);
541+
String badClassName = LogicalClassNode.getUncached().execute(from).fields.getName();
542+
return typeError(
543+
StringUtils.format(
544+
"can't convert %s to %s (%s#%s gives %s)",
545+
badClassName,
546+
to,
547+
badClassName,
548+
coercionMethod,
549+
LogicalClassNode.getUncached().execute(coercedTo).fields.getName()),
550+
currentNode);
548551
}
549552

550553
@TruffleBoundary
551554
public RubyException typeErrorCantDump(Object object, Node currentNode) {
552-
String logicalClass = context.getCoreLibrary().getLogicalClass(object).fields.getName();
555+
String logicalClass = LogicalClassNode.getUncached().execute(object).fields.getName();
553556
return typeError(StringUtils.format("can't dump %s", logicalClass), currentNode);
554557
}
555558

556559
@TruffleBoundary
557560
public RubyException typeErrorWrongArgumentType(Object object, String expectedType, Node currentNode) {
558-
String badClassName = context.getCoreLibrary().getLogicalClass(object).fields.getName();
561+
String badClassName = LogicalClassNode.getUncached().execute(object).fields.getName();
559562
return typeError(
560563
StringUtils.format("wrong argument type %s (expected %s)", badClassName, expectedType),
561564
currentNode);
@@ -678,7 +681,7 @@ public RubyNameError nameErrorUndefinedMethod(String name, RubyModule module, No
678681

679682
@TruffleBoundary
680683
public RubyNameError nameErrorUndefinedSingletonMethod(String name, Object receiver, Node currentNode) {
681-
String className = context.getCoreLibrary().getLogicalClass(receiver).fields.getName();
684+
String className = LogicalClassNode.getUncached().execute(receiver).fields.getName();
682685
return nameError(
683686
StringUtils.format("undefined singleton method `%s' for %s", name, className),
684687
receiver,

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public abstract static class KernelClassNode extends CoreMethodArrayArgumentsNod
447447

448448
@Specialization
449449
protected RubyClass getClass(Object self) {
450-
return classNode.executeLogicalClass(self);
450+
return classNode.execute(self);
451451
}
452452

453453
}
@@ -1002,7 +1002,7 @@ protected Object initializeCopy(Object self, Object from,
10021002
@Cached LogicalClassNode rhsClassNode,
10031003
@Cached BranchProfile errorProfile) {
10041004
checkFrozenNode.execute(self);
1005-
if (lhsClassNode.executeLogicalClass(self) != rhsClassNode.executeLogicalClass(from)) {
1005+
if (lhsClassNode.execute(self) != rhsClassNode.execute(from)) {
10061006
errorProfile.enter();
10071007
throw new RaiseException(
10081008
getContext(),
@@ -1032,7 +1032,7 @@ public abstract static class InstanceOfNode extends CoreMethodArrayArgumentsNode
10321032

10331033
@Specialization
10341034
protected boolean instanceOf(Object self, RubyModule module) {
1035-
return classNode.executeLogicalClass(self) == module;
1035+
return classNode.execute(self) == module;
10361036
}
10371037

10381038
}
@@ -1329,7 +1329,7 @@ protected RubyMethod method(VirtualFrame frame, Object self, Object name,
13291329
getContext(),
13301330
coreExceptions().nameErrorUndefinedMethod(
13311331
normalizedName,
1332-
logicalClassNode.executeLogicalClass(self),
1332+
logicalClassNode.execute(self),
13331333
this));
13341334
}
13351335
}
@@ -1359,7 +1359,7 @@ private InternalMethod createMissingMethod(Object self, Object name, String norm
13591359
Split.HEURISTIC);
13601360
final RootCallTarget newCallTarget = Truffle.getRuntime().createCallTarget(newRootNode);
13611361

1362-
final RubyClass module = coreLibrary().getMetaClass(self);
1362+
final RubyClass module = MetaClassNode.getUncached().execute(self);
13631363
return new InternalMethod(
13641364
getContext(),
13651365
info,
@@ -2039,7 +2039,7 @@ protected RubyString toS(Object self,
20392039
@Cached ObjectIDNode objectIDNode,
20402040
@Cached ToHexStringNode toHexStringNode,
20412041
@Cached PropagateTaintNode propagateTaintNode) {
2042-
String className = classNode.executeLogicalClass(self).fields.getName();
2042+
String className = classNode.execute(self).fields.getName();
20432043
Object id = objectIDNode.execute(self);
20442044
String hexID = toHexStringNode.executeToHexString(id);
20452045

src/main/java/org/truffleruby/core/kernel/TraceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private RubyClass getLogicalClass(Object object) {
213213
logicalClassNode = insert(LogicalClassNode.create());
214214
}
215215

216-
return logicalClassNode.executeLogicalClass(object);
216+
return logicalClassNode.execute(object);
217217
}
218218

219219
}

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public abstract static class UnbindNode extends CoreMethodArrayArgumentsNode {
230230

231231
@Specialization
232232
protected RubyUnboundMethod unbind(RubyMethod method) {
233-
final RubyClass receiverClass = classNode.executeLogicalClass(method.receiver);
233+
final RubyClass receiverClass = classNode.execute(method.receiver);
234234
final RubyUnboundMethod instance = new RubyUnboundMethod(
235235
coreLibrary().unboundMethodClass,
236236
getLanguage().unboundMethodShape,

src/main/java/org/truffleruby/core/regexp/MatchDataNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ protected Object getIndex(RubyMatchData matchData, int index, NotProvided length
264264
final int end = region.end[index];
265265
if (hasValueProfile.profile(start > -1 && end > -1)) {
266266
Rope rope = substringNode.executeSubstring(sourceRope, start, end - start);
267-
final RubyClass logicalClass = logicalClassNode.executeLogicalClass(source);
267+
final RubyClass logicalClass = logicalClassNode.execute(source);
268268
final Shape shape = allocateHelperNode.getCachedShape(logicalClass);
269269
final RubyString string = new RubyString(logicalClass, shape, false, false, rope);
270270
AllocationTracing.trace(string, this);
@@ -479,7 +479,7 @@ protected Object[] getValuesSlow(RubyMatchData matchData,
479479

480480
if (start > -1 && end > -1) {
481481
Rope rope = substringNode.executeSubstring(sourceRope, start, end - start);
482-
final RubyClass logicalClass = logicalClassNode.executeLogicalClass(source);
482+
final RubyClass logicalClass = logicalClassNode.execute(source);
483483
final Shape shape = allocateHelperNode.getCachedShape(logicalClass);
484484
final RubyString string = new RubyString(logicalClass, shape, false, isTainted, rope);
485485
AllocationTracing.trace(string, this);
@@ -597,7 +597,7 @@ protected RubyString preMatch(RubyMatchData matchData,
597597
int start = 0;
598598
int length = region.beg[0];
599599
Rope rope = substringNode.executeSubstring(sourceRope, start, length);
600-
final RubyClass logicalClass = logicalClassNode.executeLogicalClass(source);
600+
final RubyClass logicalClass = logicalClassNode.execute(source);
601601
final Shape shape = allocateHelperNode.getCachedShape(logicalClass);
602602
final RubyString string = new RubyString(logicalClass, shape, false, false, rope);
603603
AllocationTracing.trace(string, this);
@@ -623,7 +623,7 @@ protected RubyString postMatch(RubyMatchData matchData,
623623
int start = region.end[0];
624624
int length = sourceRope.byteLength() - region.end[0];
625625
Rope rope = substringNode.executeSubstring(sourceRope, start, length);
626-
final RubyClass logicalClass = logicalClassNode.executeLogicalClass(source);
626+
final RubyClass logicalClass = logicalClassNode.execute(source);
627627
final Shape shape = allocateHelperNode.getCachedShape(logicalClass);
628628
final RubyString string = new RubyString(logicalClass, shape, false, false, rope);
629629
AllocationTracing.trace(string, this);

0 commit comments

Comments
 (0)