Skip to content

Commit 9aaa0ec

Browse files
committed
use a counting profile instead of just a branch profile for custom locals to avoid path duplication if there are always custom locals
1 parent 4ce74c8 commit 9aaa0ec

File tree

8 files changed

+18
-20
lines changed

8 files changed

+18
-20
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TestParserTranslator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import java.util.Set;
5353
import java.util.stream.Collectors;
5454

55-
import org.junit.Test;
56-
5755
import com.oracle.graal.python.PythonLanguage;
5856
import com.oracle.graal.python.builtins.objects.PNone;
5957
import com.oracle.graal.python.builtins.objects.complex.PComplex;
@@ -119,9 +117,11 @@
119117
import com.oracle.truffle.api.nodes.Node;
120118
import com.oracle.truffle.api.nodes.NodeUtil;
121119
import com.oracle.truffle.api.nodes.RootNode;
122-
import com.oracle.truffle.api.profiles.BranchProfile;
120+
import com.oracle.truffle.api.profiles.ConditionProfile;
123121
import com.oracle.truffle.api.source.Source;
124122

123+
import org.junit.Test;
124+
125125
public class TestParserTranslator {
126126
PythonContext context;
127127

@@ -131,7 +131,7 @@ public TestParserTranslator() {
131131
}
132132

133133
private static class JUnitRootNode extends PRootNode {
134-
private final BranchProfile profile = BranchProfile.create();
134+
private final ConditionProfile profile = ConditionProfile.createCountingProfile();
135135
@Child private ExpressionNode body;
136136
@Child private CalleeContext calleeContext = CalleeContext.create();
137137

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ public TruffleObject getCallable() {
743743

744744
@Specialization
745745
Object doIt(VirtualFrame frame,
746-
@Cached BranchProfile customLocalsProfile,
746+
@Cached("createCountingProfile()") ConditionProfile customLocalsProfile,
747747
@Cached CExtNodes.AsPythonObjectNode asPythonObjectNode,
748748
@CachedContext(PythonLanguage.class) PythonContext ctx,
749749
@Cached PRaiseNode raiseNode) {
@@ -1475,7 +1475,7 @@ abstract static class MethodDescriptorRoot extends PRootNode {
14751475
@Child protected ReadIndexedArgumentNode readSelfNode;
14761476
@Child private CalleeContext calleeContext = CalleeContext.create();
14771477

1478-
private final BranchProfile customLocalsProfile = BranchProfile.create();
1478+
private final ConditionProfile customLocalsProfile = ConditionProfile.createCountingProfile();
14791479
protected final PythonObjectFactory factory;
14801480

14811481
@TruffleBoundary

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PThreadState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
import com.oracle.truffle.api.library.CachedLibrary;
8585
import com.oracle.truffle.api.library.ExportLibrary;
8686
import com.oracle.truffle.api.library.ExportMessage;
87-
import com.oracle.truffle.api.profiles.BranchProfile;
87+
import com.oracle.truffle.api.profiles.ConditionProfile;
8888
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
8989

9090
@ExportLibrary(InteropLibrary.class)
@@ -481,7 +481,7 @@ protected GetTracebackRootNode(TruffleLanguage<?> language) {
481481
@Child private GetTracebackNode getTracebackNode;
482482
@Child private CalleeContext calleeContext = CalleeContext.create();
483483

484-
private final BranchProfile profile = BranchProfile.create();
484+
private final ConditionProfile profile = ConditionProfile.createCountingProfile();
485485

486486
@Override
487487
public Object execute(VirtualFrame frame) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
import com.oracle.truffle.api.frame.FrameDescriptor;
3939
import com.oracle.truffle.api.frame.FrameSlot;
4040
import com.oracle.truffle.api.frame.VirtualFrame;
41-
import com.oracle.truffle.api.profiles.BranchProfile;
41+
import com.oracle.truffle.api.profiles.ConditionProfile;
4242
import com.oracle.truffle.api.source.SourceSection;
4343

4444
public class ModuleRootNode extends PClosureRootNode {
4545
private static final Signature SIGNATURE = new Signature(false, -1, false, new String[0], new String[0]);
4646
private final String name;
4747
private final String doc;
48-
private final BranchProfile customLocalsProfile = BranchProfile.create();
48+
private final ConditionProfile customLocalsProfile = ConditionProfile.createCountingProfile();
4949
@Child private ExpressionNode body;
5050
@Child private WriteGlobalNode writeModuleDoc;
5151
@Child private CalleeContext calleeContext = CalleeContext.create();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/BuiltinFunctionRootNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
import com.oracle.truffle.api.dsl.NodeFactory;
4949
import com.oracle.truffle.api.frame.VirtualFrame;
5050
import com.oracle.truffle.api.nodes.Node;
51-
import com.oracle.truffle.api.profiles.BranchProfile;
51+
import com.oracle.truffle.api.profiles.ConditionProfile;
5252

5353
public final class BuiltinFunctionRootNode extends PRootNode {
5454
private final Signature signature;
5555
private final Builtin builtin;
5656
private final String name;
5757
private final NodeFactory<? extends PythonBuiltinBaseNode> factory;
5858
private final boolean declaresExplicitSelf;
59-
private final BranchProfile customLocalsProfile = BranchProfile.create();
59+
private final ConditionProfile customLocalsProfile = ConditionProfile.createCountingProfile();
6060
@Child private BuiltinCallNode body;
6161
@Child private CalleeContext calleeContext = CalleeContext.create();
6262

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/FunctionRootNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import com.oracle.truffle.api.frame.VirtualFrame;
4545
import com.oracle.truffle.api.nodes.ExplodeLoop;
4646
import com.oracle.truffle.api.nodes.NodeUtil;
47-
import com.oracle.truffle.api.profiles.BranchProfile;
47+
import com.oracle.truffle.api.profiles.ConditionProfile;
4848
import com.oracle.truffle.api.profiles.ValueProfile;
4949
import com.oracle.truffle.api.source.SourceSection;
5050

@@ -59,7 +59,7 @@ public class FunctionRootNode extends PClosureFunctionRootNode {
5959
private final SourceSection sourceSection;
6060
private final boolean isGenerator;
6161
private final ValueProfile generatorFrameProfile;
62-
private final BranchProfile customLocalsProfile = BranchProfile.create();
62+
private final ConditionProfile customLocalsProfile = ConditionProfile.createCountingProfile();
6363

6464
@Child private ExpressionNode body;
6565
@Child private CalleeContext calleeContext = CalleeContext.create();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import com.oracle.truffle.api.frame.VirtualFrame;
6868
import com.oracle.truffle.api.nodes.Node;
6969
import com.oracle.truffle.api.nodes.Node.Child;
70-
import com.oracle.truffle.api.profiles.BranchProfile;
70+
import com.oracle.truffle.api.profiles.ConditionProfile;
7171

7272
/**
7373
* A handler for asynchronous actions events that need to be handled on a main thread of execution,
@@ -142,7 +142,7 @@ private static class CallRootNode extends PRootNode {
142142
@Child private ReadCallerFrameNode readCallerFrameNode = ReadCallerFrameNode.create();
143143
@Child private CalleeContext calleeContext = CalleeContext.create();
144144

145-
private final BranchProfile profile = BranchProfile.create();
145+
private final ConditionProfile profile = ConditionProfile.createCountingProfile();
146146

147147
protected CallRootNode(TruffleLanguage<?> language) {
148148
super(language);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import com.oracle.truffle.api.frame.FrameInstance;
5959
import com.oracle.truffle.api.frame.VirtualFrame;
6060
import com.oracle.truffle.api.nodes.Node;
61-
import com.oracle.truffle.api.profiles.BranchProfile;
6261
import com.oracle.truffle.api.profiles.ConditionProfile;
6362

6463
/**
@@ -179,16 +178,15 @@ public static final class CalleeContext extends Node {
179178
/**
180179
* Wrap the execution of a Python callee called from a Python frame.
181180
*/
182-
public static void enter(VirtualFrame frame, BranchProfile profile) {
181+
public static void enter(VirtualFrame frame, ConditionProfile profile) {
183182
// tfel: Create our frame reference here and store it so that
184183
// there's no reference to it from the caller side.
185184
PFrame.Reference thisFrameRef = new PFrame.Reference(PArguments.getCallerFrameInfo(frame));
186185
Object customLocals = PArguments.getCustomLocals(frame);
187186
PArguments.setCurrentFrameInfo(frame, thisFrameRef);
188187
// tfel: If there are custom locals, write them into an (incomplete)
189188
// PFrame here
190-
if (customLocals != null && !(customLocals instanceof PFrame.Reference)) {
191-
profile.enter();
189+
if (profile.profile(customLocals != null && !(customLocals instanceof PFrame.Reference))) {
192190
thisFrameRef.setCustomLocals(customLocals);
193191
}
194192
}

0 commit comments

Comments
 (0)