Skip to content

Commit b7f54b2

Browse files
committed
[GR-18397] Count method size at most once.
PullRequest: graalpython/666
2 parents 1cdae49 + d169894 commit b7f54b2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRootNode.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.oracle.truffle.api.TruffleLanguage;
4949
import com.oracle.truffle.api.frame.FrameDescriptor;
5050
import com.oracle.truffle.api.nodes.Node;
51+
import com.oracle.truffle.api.nodes.NodeUtil;
5152
import com.oracle.truffle.api.nodes.RootNode;
5253
import com.oracle.truffle.api.profiles.ConditionProfile;
5354

@@ -64,6 +65,8 @@ public abstract class PRootNode extends RootNode {
6465
*/
6566
@CompilationFinal private Assumption dontNeedExceptionState = createExceptionStateAssumption();
6667

68+
private int nodeCount = -1;
69+
6770
protected PRootNode(TruffleLanguage<?> language) {
6871
super(language);
6972
}
@@ -72,6 +75,15 @@ protected PRootNode(TruffleLanguage<?> language, FrameDescriptor frameDescriptor
7275
super(language, frameDescriptor);
7376
}
7477

78+
public final int getNodeCount() {
79+
CompilerAsserts.neverPartOfCompilation();
80+
int n = nodeCount;
81+
if (n != -1) {
82+
return n;
83+
}
84+
return nodeCount = NodeUtil.countNodes(this);
85+
}
86+
7587
public ConditionProfile getFrameEscapedProfile() {
7688
return frameEscaped;
7789
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallSpecialMethodNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.graal.python.builtins.objects.function.PFunction;
4646
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4747
import com.oracle.graal.python.builtins.objects.method.PMethod;
48+
import com.oracle.graal.python.nodes.PRootNode;
4849
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
4950
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5051
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -92,7 +93,8 @@ private <T extends PythonBuiltinBaseNode> T getBuiltin(PBuiltinFunction func, Cl
9293
private <T extends PythonBuiltinBaseNode> boolean callerExceedsMaxSize(T builtinNode) {
9394
CompilerAsserts.neverPartOfCompilation();
9495
if (!maxSizeExceeded) {
95-
int n = NodeUtil.countNodes(getRootNode());
96+
RootNode root = getRootNode();
97+
int n = root instanceof PRootNode ? ((PRootNode) root).getNodeCount() : NodeUtil.countNodes(root);
9698
// nb: option 'BuiltinsInliningMaxCallerSize' is defined as a compatible option, i.e.,
9799
// ASTs will only we shared between contexts that have the same value for this option.
98100
int maxSize = PythonOptions.getOption(lookupContextReference(PythonLanguage.class).get(), PythonOptions.BuiltinsInliningMaxCallerSize);

0 commit comments

Comments
 (0)