Skip to content

Commit d2d8d08

Browse files
committed
introduce string profiles
1 parent 11b90ef commit d2d8d08

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,16 +845,18 @@ public static GetAttrNode create() {
845845
public abstract Object executeWithArgs(VirtualFrame frame, Object primary, String name, Object defaultValue);
846846

847847
@SuppressWarnings("unused")
848-
@Specialization(limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", guards = {"name.equals(cachedName)", "isNoValue(defaultValue)"})
848+
@Specialization(limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", guards = {"stringEquals(cachedName, name, stringProfile)", "isNoValue(defaultValue)"})
849849
public Object getAttrDefault(VirtualFrame frame, Object primary, String name, PNone defaultValue,
850+
@Cached("createBinaryProfile()") ConditionProfile stringProfile,
850851
@Cached("name") String cachedName,
851852
@Cached("create(name)") GetFixedAttributeNode getAttributeNode) {
852853
return getAttributeNode.executeObject(frame, primary);
853854
}
854855

855856
@SuppressWarnings("unused")
856-
@Specialization(limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", guards = {"name.equals(cachedName)", "!isNoValue(defaultValue)"})
857+
@Specialization(limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", guards = {"stringEquals(cachedName, name, stringProfile)", "!isNoValue(defaultValue)"})
857858
Object getAttr(VirtualFrame frame, Object primary, String name, Object defaultValue,
859+
@Cached("createBinaryProfile()") ConditionProfile stringProfile,
858860
@Cached("name") String cachedName,
859861
@Cached("create(name)") GetFixedAttributeNode getAttributeNode,
860862
@Cached("create()") IsBuiltinClassProfile errorProfile) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,21 @@
8484
import com.oracle.truffle.api.frame.VirtualFrame;
8585
import com.oracle.truffle.api.interop.TruffleObject;
8686
import com.oracle.truffle.api.nodes.UnexpectedResultException;
87+
import com.oracle.truffle.api.profiles.ConditionProfile;
8788

8889
public abstract class PGuards {
8990

9091
/**
9192
* Specialization guards.
9293
*/
9394

95+
public static boolean stringEquals(String expected, String other, ConditionProfile profile) {
96+
if (profile.profile(expected == other)) {
97+
return true;
98+
}
99+
return expected.equals(other);
100+
}
101+
94102
public static boolean isSameObject(Object left, Object right) {
95103
return left == right;
96104
}

0 commit comments

Comments
 (0)