Skip to content

Commit 2c5a029

Browse files
committed
getting the node factory is now on the fast path
1 parent 8d76a8a commit 2c5a029

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public RootNode getFunctionRootNode() {
8282
}
8383

8484
public NodeFactory<? extends PythonBuiltinBaseNode> getBuiltinNodeFactory() {
85-
CompilerAsserts.neverPartOfCompilation();
8685
RootNode functionRootNode = getFunctionRootNode();
8786
if (functionRootNode instanceof BuiltinFunctionRootNode) {
8887
return ((BuiltinFunctionRootNode) functionRootNode).getFactory();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupAttributeInMRONode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@
6161
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
6262
import com.oracle.truffle.api.dsl.Cached;
6363
import com.oracle.truffle.api.dsl.ImportStatic;
64+
import com.oracle.truffle.api.dsl.ReportPolymorphism;
6465
import com.oracle.truffle.api.dsl.Specialization;
6566
import com.oracle.truffle.api.nodes.ExplodeLoop;
6667

6768
@ImportStatic(PythonOptions.class)
69+
@ReportPolymorphism
6870
public abstract class LookupAttributeInMRONode extends PNodeWithContext {
6971
public abstract static class Dynamic extends PNodeWithContext {
7072
private static final DynamicUncached UNCACHED = new DynamicUncached();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapTpNew.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4545
import com.oracle.graal.python.builtins.objects.function.PArguments;
4646
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
47-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassesNode;
4847
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
4948
import com.oracle.graal.python.nodes.PRaiseNode;
5049
import com.oracle.graal.python.nodes.SpecialMethodNames;
@@ -56,16 +55,17 @@
5655
import com.oracle.truffle.api.dsl.NodeFactory;
5756
import com.oracle.truffle.api.frame.VirtualFrame;
5857
import com.oracle.truffle.api.nodes.NodeCost;
58+
import com.oracle.truffle.api.profiles.ValueProfile;
5959

6060
/**
6161
* Implements cpython://Objects/typeobject.c#tp_new_wrapper.
6262
*/
6363
public final class WrapTpNew extends SlotWrapper {
6464
@Child IsTypeNode isType;
6565
@Child IsSubtypeNode isSubtype;
66-
@Child GetBaseClassesNode getBases;
6766
@Child PRaiseNode raiseNode;
6867
@Child LookupAttributeInMRONode lookupNewNode;
68+
@CompilationFinal ValueProfile builtinProfile;
6969
@CompilationFinal byte state = 0;
7070
@CompilationFinal PythonBuiltinClassType owner;
7171

@@ -122,12 +122,17 @@ public Object execute(VirtualFrame frame) {
122122
// we're in. We have our optimizations for this lookup that the compiler can then
123123
// (hopefully) merge with the initial lookup of the new method before entering it.
124124
if (lookupNewNode == null) {
125+
reportPolymorphicSpecialize();
125126
CompilerDirectives.transferToInterpreterAndInvalidate();
126127
lookupNewNode = insert(LookupAttributeInMRONode.createForLookupOfUnmanagedClasses(SpecialMethodNames.__NEW__));
127128
}
128129
Object newMethod = lookupNewNode.execute(arg0);
129130
if (newMethod instanceof PBuiltinFunction) {
130-
NodeFactory<? extends PythonBuiltinBaseNode> factory = ((PBuiltinFunction) newMethod).getBuiltinNodeFactory();
131+
if (builtinProfile == null) {
132+
CompilerDirectives.transferToInterpreterAndInvalidate();
133+
builtinProfile = ValueProfile.createIdentityProfile();
134+
}
135+
NodeFactory<? extends PythonBuiltinBaseNode> factory = ((PBuiltinFunction) builtinProfile.profile(newMethod)).getBuiltinNodeFactory();
131136
if (factory != null) {
132137
if (!factory.getNodeClass().isAssignableFrom(getNode().getClass())) {
133138
if ((state & IS_UNSAFE_STATE) == 0) {

0 commit comments

Comments
 (0)