Skip to content

Commit e11dadd

Browse files
committed
Share gotState profiles
1 parent 10a23ff commit e11dadd

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,9 @@ public boolean isSequence(@CachedLibrary("this") PythonObjectLibrary plib,
643643

644644
@ExportMessage
645645
public int lengthWithState(ThreadState state,
646-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState,
647-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile hasLen,
648-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile ltZero,
646+
@Shared("gotState") @Cached ConditionProfile gotState,
647+
@Exclusive @Cached ConditionProfile hasLen,
648+
@Exclusive @Cached ConditionProfile ltZero,
649649
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic getLenNode,
650650
@Exclusive @Cached CallUnaryMethodNode callNode,
651651
@Exclusive @Cached PRaiseNode raiseNode,
@@ -737,9 +737,9 @@ public final boolean isCallable(@Exclusive @Cached LookupInheritedAttributeNode.
737737

738738
@ExportMessage
739739
public boolean isTrueWithState(ThreadState state,
740-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState,
741-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile hasBool,
742-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile hasLen,
740+
@Shared("gotState") @Cached ConditionProfile gotState,
741+
@Exclusive @Cached ConditionProfile hasBool,
742+
@Exclusive @Cached ConditionProfile hasLen,
743743
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupAttrs,
744744
@Exclusive @Cached CastToJavaBooleanNode castToBoolean,
745745
@Exclusive @Cached PRaiseNode raiseNode,
@@ -788,7 +788,7 @@ public final boolean isHashable(@Exclusive @Cached LookupInheritedAttributeNode.
788788

789789
@ExportMessage
790790
public long hashWithState(ThreadState state,
791-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState,
791+
@Shared("gotState") @Cached ConditionProfile gotState,
792792
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupHashAttributeNode,
793793
@Exclusive @Cached CallUnaryMethodNode callNode,
794794
@Exclusive @Cached PRaiseNode raise,
@@ -819,7 +819,7 @@ public boolean isSame(Object other,
819819
@ExportMessage
820820
public int equalsInternal(Object other, ThreadState state,
821821
@CachedLibrary(limit = "3") PythonObjectLibrary lib,
822-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState,
822+
@Shared("gotState") @Cached ConditionProfile gotState,
823823
@Shared("isNode") @Cached IsNode isNode,
824824
@Exclusive @Cached CallBinaryMethodNode callNode,
825825
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupEqAttrNode) {
@@ -869,7 +869,7 @@ public Object asIndexWithState(ThreadState state,
869869
@Shared("asIndexLookup") @Cached LookupInheritedAttributeNode.Dynamic lookupIndex,
870870
@Exclusive @Cached("createBinaryProfile()") ConditionProfile noIndex,
871871
@Exclusive @Cached("createBinaryProfile()") ConditionProfile resultProfile,
872-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
872+
@Shared("gotState") @Cached ConditionProfile gotState) {
873873
// n.b.: the CPython shortcut "if (PyLong_Check(item)) return item;" is
874874
// implemented in the specific Java classes PInt, PythonNativeVoidPtr,
875875
// and PythonAbstractNativeObject and dispatched polymorphically
@@ -897,7 +897,7 @@ public String asPathWithState(ThreadState state,
897897
@Exclusive @Cached CallUnaryMethodNode callNode,
898898
@Exclusive @Cached PRaiseNode raise,
899899
@Cached CastToJavaStringNode castToJavaStringNode,
900-
@Exclusive @Cached ConditionProfile gotState) {
900+
@Shared("gotState") @Cached ConditionProfile gotState) {
901901
Object func = lookup.execute(this, __FSPATH__);
902902
if (func == PNone.NO_VALUE) {
903903
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_STR_BYTE_OSPATHLIKE_OBJ, this);
@@ -922,7 +922,7 @@ public Object asPStringWithState(ThreadState state,
922922
@Exclusive @Cached CallUnaryMethodNode callNode,
923923
@Exclusive @Cached IsSubtypeNode isSubtypeNode,
924924
@Exclusive @Cached PRaiseNode raise,
925-
@Exclusive @Cached ConditionProfile gotState) {
925+
@Shared("gotState") @Cached ConditionProfile gotState) {
926926
return asPString(this, lookup, gotState, state, callNode, isSubtypeNode, lib, raise);
927927
}
928928

@@ -952,7 +952,7 @@ public int asFileDescriptorWithState(ThreadState state,
952952
@Exclusive @Cached PRaiseNode raiseNode,
953953
@Exclusive @Cached BranchProfile noFilenoMethodProfile,
954954
@Exclusive @Cached IsBuiltinClassProfile isIntProfile,
955-
@Exclusive @Cached ConditionProfile gotState,
955+
@Shared("gotState") @Cached ConditionProfile gotState,
956956
@Exclusive @Cached CastToJavaIntExactNode castToJavaIntNode,
957957
@Exclusive @Cached IsBuiltinClassProfile isAttrError) {
958958

@@ -1037,10 +1037,10 @@ public static Object lookupAttributeImpl(Object receiver, String name, boolean i
10371037

10381038
@ExportMessage
10391039
public Object callFunctionWithState(ThreadState state, Object[] arguments,
1040-
@Exclusive @Cached ConditionProfile hasStateProfile,
1040+
@Shared("gotState") @Cached ConditionProfile gotState,
10411041
@Exclusive @Cached CallNode callNode) {
10421042
VirtualFrame frame = null;
1043-
if (hasStateProfile.profile(state != null)) {
1043+
if (gotState.profile(state != null)) {
10441044
frame = PArguments.frameForCall(state);
10451045
}
10461046
return callNode.execute(frame, this, arguments);
@@ -1065,12 +1065,12 @@ public abstract static class CallUnboundMethodNode extends Node {
10651065
@Specialization(limit = "3")
10661066
Object getAndCall(ThreadState state, Object method, boolean ignoreGetException, Object receiver, Object[] arguments,
10671067
@CachedLibrary("receiver") PythonObjectLibrary plib,
1068-
@Cached ConditionProfile hasStateProfile,
1068+
@Cached ConditionProfile gotState,
10691069
@Cached LookupInheritedAttributeNode.Dynamic lookupGet,
10701070
@Cached CallNode callGet,
10711071
@Cached CallNode callMethod) {
10721072
VirtualFrame frame = null;
1073-
if (hasStateProfile.profile(state != null)) {
1073+
if (gotState.profile(state != null)) {
10741074
frame = PArguments.frameForCall(state);
10751075
}
10761076
Object get = lookupGet.execute(method, __GET__);
@@ -1115,7 +1115,7 @@ public Object asPIntWithState(ThreadState state,
11151115
@Shared("asPIntLookupAttr") @Cached LookupInheritedAttributeNode.Dynamic lookup,
11161116
@Exclusive @Cached CallUnaryMethodNode callNode,
11171117
@Exclusive @Cached PRaiseNode raise,
1118-
@Exclusive @Cached ConditionProfile gotState,
1118+
@Shared("gotState") @Cached ConditionProfile gotState,
11191119
@CachedLibrary("this") PythonObjectLibrary lib,
11201120
@Exclusive @Cached ConditionProfile hasIndexFunc,
11211121
@Exclusive @Cached ConditionProfile hasIntFunc) {
@@ -1186,7 +1186,7 @@ public double asJavaDoubleWithState(ThreadState state,
11861186
@Exclusive @Cached() ConditionProfile hasIndexFunc,
11871187
@Shared("asJavaLookup") @Cached LookupInheritedAttributeNode.Dynamic lookup,
11881188
@Exclusive @Cached CallUnaryMethodNode callNode,
1189-
@Exclusive @Cached ConditionProfile gotState,
1189+
@Shared("gotState") @Cached ConditionProfile gotState,
11901190
@Exclusive @Cached CastToJavaDoubleNode castToDouble,
11911191
@Exclusive @Cached() ConditionProfile hasFloatFunc,
11921192
@Exclusive @Cached PRaiseNode raise) {
@@ -1227,7 +1227,7 @@ public boolean canBeJavaLong(
12271227
public long asJavaLongWithState(ThreadState state,
12281228
@Shared("asJavaLongLookup") @Cached LookupInheritedAttributeNode.Dynamic lookup,
12291229
@Exclusive @Cached CallUnaryMethodNode callNode,
1230-
@Exclusive @Cached ConditionProfile gotState,
1230+
@Shared("gotState") @Cached ConditionProfile gotState,
12311231
@Exclusive @Cached CastToJavaLongExactNode castToLong,
12321232
@Exclusive @Cached PRaiseNode raise) {
12331233

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.truffle.api.RootCallTarget;
5151
import com.oracle.truffle.api.dsl.Cached;
5252
import com.oracle.truffle.api.dsl.Cached.Exclusive;
53+
import com.oracle.truffle.api.dsl.Cached.Shared;
5354
import com.oracle.truffle.api.dsl.GenerateUncached;
5455
import com.oracle.truffle.api.dsl.NodeFactory;
5556
import com.oracle.truffle.api.dsl.Specialization;
@@ -179,10 +180,10 @@ public Object getLazyPythonClass() {
179180

180181
@ExportMessage
181182
public Object callUnboundMethodWithState(ThreadState state, Object receiver, Object[] arguments,
182-
@Exclusive @Cached ConditionProfile hasStateProfile,
183+
@Shared("gotState") @Cached ConditionProfile gotState,
183184
@Exclusive @Cached CallUnboundMethodNode call) {
184185
VirtualFrame frame = null;
185-
if (hasStateProfile.profile(state != null)) {
186+
if (gotState.profile(state != null)) {
186187
frame = PArguments.frameForCall(state);
187188
}
188189
return call.execute(frame, this, receiver, arguments);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.truffle.api.Truffle;
4444
import com.oracle.truffle.api.dsl.Cached;
4545
import com.oracle.truffle.api.dsl.Cached.Exclusive;
46+
import com.oracle.truffle.api.dsl.Cached.Shared;
4647
import com.oracle.truffle.api.frame.VirtualFrame;
4748
import com.oracle.truffle.api.interop.UnsupportedMessageException;
4849
import com.oracle.truffle.api.library.ExportLibrary;
@@ -235,10 +236,10 @@ public Object getLazyPythonClass() {
235236

236237
@ExportMessage
237238
public Object callUnboundMethodWithState(ThreadState state, Object receiver, Object[] arguments,
238-
@Exclusive @Cached ConditionProfile hasStateProfile,
239+
@Shared("gotState") @Cached ConditionProfile gotState,
239240
@Exclusive @Cached CallNode call) {
240241
VirtualFrame frame = null;
241-
if (hasStateProfile.profile(state != null)) {
242+
if (gotState.profile(state != null)) {
242243
frame = PArguments.frameForCall(state);
243244
}
244245
return call.execute(frame, this, PositionalArgumentsNode.prependArgument(receiver, arguments));

0 commit comments

Comments
 (0)