-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Use @cached for super and zsuper calls.
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
- 9.0.0.0
- 9.0.0.0.rc2
Showing
6 changed files
with
241 additions
and
152 deletions.
There are no files selected for viewing
114 changes: 0 additions & 114 deletions
114
truffle/src/main/java/org/jruby/truffle/nodes/supercall/AbstractGeneralSuperCallNode.java
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
truffle/src/main/java/org/jruby/truffle/nodes/supercall/CallMethodNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.nodes.supercall; | ||
|
||
import org.jruby.truffle.nodes.RubyNode; | ||
import org.jruby.truffle.nodes.dispatch.DispatchNode; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.methods.InternalMethod; | ||
|
||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.NodeChildren; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.DirectCallNode; | ||
import com.oracle.truffle.api.nodes.IndirectCallNode; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
|
||
@NodeChildren({ | ||
@NodeChild("method"), | ||
@NodeChild(value = "arguments", type = RubyNode[].class) | ||
}) | ||
public abstract class CallMethodNode extends RubyNode { | ||
|
||
public static int getCacheLimit() { | ||
return DispatchNode.DISPATCH_POLYMORPHIC_MAX; | ||
} | ||
|
||
public CallMethodNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public abstract Object executeCallMethod(VirtualFrame frame, InternalMethod method, Object[] arguments); | ||
|
||
@Specialization( | ||
guards = "method == cachedMethod", | ||
// TODO(eregon, 12 June 2015) we should maybe check an Assumption here to remove the cache entry when the lookup changes (redefined method, hierarchy changes) | ||
limit = "getCacheLimit()") | ||
protected Object callMethodCached(VirtualFrame frame, InternalMethod method, Object[] arguments, | ||
@Cached("method") InternalMethod cachedMethod, | ||
@Cached("create(cachedMethod.getCallTarget())") DirectCallNode callNode) { | ||
return callNode.call(frame, arguments); | ||
} | ||
|
||
@Specialization | ||
protected Object callMethodUncached(VirtualFrame frame, InternalMethod method, Object[] arguments, | ||
@Cached("create()") IndirectCallNode indirectCallNode) { | ||
return indirectCallNode.call(frame, method.getCallTarget(), arguments); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
truffle/src/main/java/org/jruby/truffle/nodes/supercall/LookupSuperMethodNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.nodes.supercall; | ||
|
||
import org.jruby.truffle.nodes.RubyNode; | ||
import org.jruby.truffle.nodes.dispatch.DispatchNode; | ||
import org.jruby.truffle.nodes.objects.MetaClassNode; | ||
import org.jruby.truffle.nodes.objects.MetaClassNodeGen; | ||
import org.jruby.truffle.runtime.ModuleOperations; | ||
import org.jruby.truffle.runtime.RubyArguments; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.core.RubyClass; | ||
import org.jruby.truffle.runtime.methods.InternalMethod; | ||
|
||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
|
||
@NodeChild("self") | ||
public abstract class LookupSuperMethodNode extends RubyNode { | ||
|
||
public static int getCacheLimit() { | ||
return DispatchNode.DISPATCH_POLYMORPHIC_MAX; | ||
} | ||
|
||
@Child MetaClassNode metaClassNode; | ||
|
||
public LookupSuperMethodNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
metaClassNode = MetaClassNodeGen.create(context, sourceSection, null); | ||
} | ||
|
||
public abstract InternalMethod executeLookupSuperMethod(VirtualFrame frame, Object self); | ||
|
||
// The check for same metaClass is overly restrictive, | ||
// but seems the be the only reasonable check in term of performance. | ||
// The ideal condition would be to check if both ancestor lists starting at | ||
// the current method's module are identical, which is non-trivial | ||
// if the current method's module is an (included) module and not a class. | ||
|
||
@Specialization( | ||
guards = { | ||
"getCurrentMethod(frame) == currentMethod", | ||
"metaClass(frame, self) == selfMetaClass" | ||
}, | ||
assumptions = "selfMetaClass.getUnmodifiedAssumption()", // guards against include/prepend/method redefinition | ||
limit = "getCacheLimit()") | ||
protected InternalMethod lookupSuperMethodCached(VirtualFrame frame, Object self, | ||
@Cached("getCurrentMethod(frame)") InternalMethod currentMethod, | ||
@Cached("metaClass(frame, self)") RubyClass selfMetaClass, | ||
@Cached("doLookup(currentMethod, selfMetaClass)") InternalMethod superMethod) { | ||
return superMethod; | ||
} | ||
|
||
@Specialization | ||
protected InternalMethod lookupSuperMethodUncached(VirtualFrame frame, Object self) { | ||
InternalMethod currentMethod = getCurrentMethod(frame); | ||
RubyClass selfMetaClass = metaClass(frame, self); | ||
return doLookup(currentMethod, selfMetaClass); | ||
} | ||
|
||
protected InternalMethod getCurrentMethod(VirtualFrame frame) { | ||
return RubyArguments.getMethod(frame.getArguments()); | ||
} | ||
|
||
protected RubyClass metaClass(VirtualFrame frame, Object object) { | ||
return metaClassNode.executeMetaClass(frame, object); | ||
} | ||
|
||
protected InternalMethod doLookup(InternalMethod currentMethod, RubyClass selfMetaClass) { | ||
InternalMethod superMethod = ModuleOperations.lookupSuperMethod(currentMethod, selfMetaClass); | ||
// TODO (eregon, 12 June 2015): Is this correct? | ||
if (superMethod != null && superMethod.isUndefined()) { | ||
superMethod = null; | ||
} | ||
return superMethod; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d78023f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this - the super call nodes were ancient and pretty bad.
d78023f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I figured it would be a nice way to approach normal call dispatch nodes at a smaller scale.
This is a bit different than Get/LookupConstantNode in that the composition is simply done with two calls in each node, like the RubyCall example in Graal.