Skip to content

Commit c402896

Browse files
author
Nicolas Laurent
committed
[GR-25977] Make LookupMethodNode return null for foreign objects, to speed up inlined node performance.
PullRequest: truffleruby/1974
2 parents f736b21 + 21efc63 commit c402896

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

src/main/java/org/truffleruby/core/inlined/InlinedIsANode.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ public InlinedIsANode(RubyContext context, RubyCallNodeParameters callNodeParame
2828
}
2929

3030
@Specialization(
31-
guards = {
32-
"isRubyValue(self)",
33-
"lookupNode.lookupProtected(frame, self, METHOD) == coreMethods().KERNEL_IS_A",
34-
},
31+
guards = "lookupNode.lookupProtected(frame, self, METHOD) == coreMethods().KERNEL_IS_A",
3532
assumptions = "assumptions",
3633
limit = "1")
3734
protected boolean doIsA(VirtualFrame frame, Object self, RubyModule module,

src/main/java/org/truffleruby/core/inlined/InlinedIsNilNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ protected boolean nil(Nil self) {
3535
}
3636

3737
@Specialization(
38-
guards = {
39-
"isRubyValue(self)",
40-
"lookup.lookupProtected(frame, self, METHOD) == coreMethods().KERNEL_IS_NIL", },
38+
guards = "lookup.lookupProtected(frame, self, METHOD) == coreMethods().KERNEL_IS_NIL",
4139
assumptions = "assumptions",
4240
limit = "1")
4341
protected boolean notNil(VirtualFrame frame, Object self,

src/main/java/org/truffleruby/core/inlined/InlinedKindOfNode.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ public InlinedKindOfNode(RubyContext context, RubyCallNodeParameters callNodePar
2828
}
2929

3030
@Specialization(
31-
guards = {
32-
"isRubyValue(self)",
33-
"lookupNode.lookupProtected(frame, self, METHOD) == coreMethods().KERNEL_KIND_OF",
34-
},
31+
guards = "lookupNode.lookupProtected(frame, self, METHOD) == coreMethods().KERNEL_KIND_OF",
3532
assumptions = "assumptions",
3633
limit = "1")
3734
protected boolean doKindOf(VirtualFrame frame, Object self, RubyModule module,

src/main/java/org/truffleruby/language/methods/LookupMethodNode.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.truffleruby.language.arguments.RubyArguments;
2222
import org.truffleruby.language.dispatch.DispatchConfiguration;
2323
import org.truffleruby.language.objects.MetaClassNode;
24-
import org.truffleruby.utils.Utils;
2524

2625
import com.oracle.truffle.api.CompilerAsserts;
2726
import com.oracle.truffle.api.TruffleLanguage;
@@ -33,7 +32,6 @@
3332
import com.oracle.truffle.api.frame.Frame;
3433
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
3534
import com.oracle.truffle.api.frame.VirtualFrame;
36-
import com.oracle.truffle.api.profiles.BranchProfile;
3735
import com.oracle.truffle.api.profiles.ConditionProfile;
3836

3937
/** Caches {@link ModuleOperations#lookupMethodCached(RubyModule, String, DeclarationContext)} on an actual instance. */
@@ -85,7 +83,7 @@ protected InternalMethod lookupMethodUncached(
8583
@Cached MetaClassNode metaClassNode,
8684
@Cached ConditionProfile noCallerMethodProfile,
8785
@Cached ConditionProfile isSendProfile,
88-
@Cached BranchProfile foreignProfile,
86+
@Cached ConditionProfile foreignProfile,
8987
@Cached ConditionProfile noPrependedModulesProfile,
9088
@Cached ConditionProfile onMetaClassProfile,
9189
@Cached ConditionProfile hasRefinementsProfile,
@@ -98,9 +96,8 @@ protected InternalMethod lookupMethodUncached(
9896

9997
// Actual lookup
10098

101-
if (metaClass == context.getCoreLibrary().truffleInteropForeignClass) {
102-
foreignProfile.enter();
103-
throw Utils.unsupportedOperation("method lookup not supported on foreign objects");
99+
if (foreignProfile.profile(metaClass == context.getCoreLibrary().truffleInteropForeignClass)) {
100+
return null;
104101
}
105102

106103
final DeclarationContext declarationContext = RubyArguments.tryGetDeclarationContext(frame);
@@ -163,7 +160,7 @@ protected static MethodLookupResult lookupCached(RubyContext context, Frame call
163160
CompilerAsserts.neverPartOfCompilation("slow-path method lookup should not be compiled");
164161

165162
if (metaClass == context.getCoreLibrary().truffleInteropForeignClass) {
166-
throw new UnsupportedOperationException("method lookup not supported on foreign objects");
163+
return new MethodLookupResult(null);
167164
}
168165

169166
final DeclarationContext declarationContext = RubyArguments.tryGetDeclarationContext(callingFrame);

0 commit comments

Comments
 (0)