Skip to content

Commit bd6246b

Browse files
committed
Address review feedback
1 parent c2b9c7e commit bd6246b

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMANodes.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,10 @@ HashingStorage fast(VirtualFrame frame, PDict dict,
236236
HashingStorage slow(VirtualFrame frame, Object object,
237237
@Shared("id") @Cached ConditionProfile idErrorProfile,
238238
@Shared("k") @Cached ConditionProfile hasKeyErrorProfile,
239-
@Cached ConditionProfile dictErrorProfile,
240239
@Shared("h") @CachedLibrary(limit = "2") HashingStorageLibrary hlib,
241240
@Cached GetDictIfExistsNode getDict) {
242241
PDict dict = getDict.execute(object);
243-
if (dictErrorProfile.profile(dict == null)) {
242+
if (dict == null) {
244243
throw raise(TypeError, FILTER_SPEC_MUST_BE_DICT);
245244
}
246245
return fast(frame, dict, idErrorProfile, hasKeyErrorProfile, hlib);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/ThreadLocalBuiltins.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ protected Object doIt(VirtualFrame frame, PThreadLocal object, Object keyObj,
126126
@Cached LookupAttributeInMRONode.Dynamic lookup,
127127
@Cached GetClassNode getClassNode,
128128
@Cached CastToJavaStringNode castKeyToStringNode) {
129+
// Note: getting thread local dict has potential side-effects, don't move
129130
PDict localDict = getThreadLocalDict.execute(frame, object);
130131
String key;
131132
try {
@@ -239,13 +240,14 @@ protected PNone doStringKey(VirtualFrame frame, PThreadLocal object, String keyO
239240
@Cached ThreadLocalNodes.GetThreadLocalDict getThreadLocalDict,
240241
@Cached GetClassNode getClassNode,
241242
@Cached LookupAttributeInMRONode.Dynamic getExisting) {
243+
// Note: getting thread local dict has potential side-effects, don't move
244+
PDict localDict = getThreadLocalDict.execute(frame, object);
242245
String key;
243246
try {
244247
key = castKeyToStringNode.execute(keyObject);
245248
} catch (CannotCastException e) {
246249
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObject);
247250
}
248-
PDict localDict = getThreadLocalDict.execute(frame, object);
249251
Object type = getClassNode.execute(object);
250252
Object descr = getExisting.execute(type, key);
251253
if (descr != PNone.NO_VALUE) {
@@ -314,13 +316,14 @@ protected PNone doIt(VirtualFrame frame, PThreadLocal object, Object keyObj,
314316
@Cached CallBinaryMethodNode callDelete,
315317
@CachedLibrary(limit = "3") HashingStorageLibrary hlib,
316318
@Cached CastToJavaStringNode castKeyToStringNode) {
319+
// Note: getting thread local dict has potential side-effects, don't move
320+
PDict localDict = getThreadLocalDict.execute(frame, object);
317321
String key;
318322
try {
319323
key = castKeyToStringNode.execute(keyObj);
320324
} catch (CannotCastException e) {
321325
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj);
322326
}
323-
PDict localDict = getThreadLocalDict.execute(frame, object);
324327
Object type = getClassNode.execute(object);
325328
Object descr = getExisting.execute(type, key);
326329
if (descr != PNone.NO_VALUE) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,13 @@ public final Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused"
353353

354354
@Specialization
355355
Object selfInArgs(VirtualFrame frame, @SuppressWarnings("unused") PNone self, Object[] arguments, PKeyword[] keywords,
356-
@Cached CallNodeHelper callNode) {
356+
@Shared("callNode") @Cached CallNodeHelper callNode) {
357357
return callNode.execute(frame, arguments[0], arguments, keywords, false);
358358
}
359359

360360
@Fallback
361361
Object selfSeparate(VirtualFrame frame, Object self, Object[] arguments, PKeyword[] keywords,
362-
@Cached CallNodeHelper callNode) {
362+
@Shared("callNode") @Cached CallNodeHelper callNode) {
363363
return callNode.execute(frame, self, arguments, keywords, true);
364364
}
365365
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,16 @@ public static ReadAttributeFromObjectNode getUncachedForceType() {
9898
static final int MAX_DICT_TYPES = 2;
9999

100100
// read from the DynamicObject store
101-
@Specialization(guards = "getDict.execute(object) == null || isHiddenKey(key)", limit = "1")
101+
@Specialization(guards = "isHiddenKey(key)")
102+
protected static Object readFromDynamicStorageHidden(PythonObject object, Object key,
103+
@Shared("readDynamic") @Cached ReadAttributeFromDynamicObjectNode readAttributeFromDynamicObjectNode) {
104+
return readAttributeFromDynamicObjectNode.execute(object.getStorage(), key);
105+
}
106+
107+
@Specialization(guards = "getDict.execute(object) == null", limit = "1")
102108
protected static Object readFromDynamicStorage(PythonObject object, Object key,
103109
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
104-
@Cached ReadAttributeFromDynamicObjectNode readAttributeFromDynamicObjectNode) {
110+
@Shared("readDynamic") @Cached ReadAttributeFromDynamicObjectNode readAttributeFromDynamicObjectNode) {
105111
return readAttributeFromDynamicObjectNode.execute(object.getStorage(), key);
106112
}
107113

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadGlobalOrBuiltinNode.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ protected Object readGlobal(@SuppressWarnings("unused") VirtualFrame frame,
9898
return returnGlobalOrBuiltin(result);
9999
}
100100

101-
protected static HashingStorage getStorage(Object cachedGlobals) {
102-
return ((PDict) cachedGlobals).getDictStorage();
101+
protected static HashingStorage getStorage(Object globals) {
102+
return ((PDict) globals).getDictStorage();
103103
}
104104

105105
@Specialization(guards = "isBuiltinDictUnchangedStorage(frame, builtinProfile, cachedGlobals, cachedStorage)", assumptions = "singleContextAssumption()", limit = "1")
@@ -130,15 +130,13 @@ protected Object readGlobalBuiltinDictCached(@SuppressWarnings("unused") Virtual
130130
return returnGlobalOrBuiltin(result == null ? PNone.NO_VALUE : result);
131131
}
132132

133-
public static HashingStorage getGlobalStorage(VirtualFrame frame) {
134-
return ((PDict) PArguments.getGlobals(frame)).getDictStorage();
135-
}
136-
137-
@Specialization(guards = "isBuiltinDict(getGlobals(frame), builtinProfile)", replaces = {"readGlobalBuiltinDictCached", "readGlobalBuiltinDictCachedUnchangedStorage"})
138-
protected Object readGlobalBuiltinDict(VirtualFrame frame,
139-
@CachedLibrary(limit = "3") HashingStorageLibrary hlib,
133+
@Specialization(guards = "isBuiltinDict(globals, builtinProfile)", replaces = {"readGlobalBuiltinDictCached", "readGlobalBuiltinDictCachedUnchangedStorage"}, limit = "3")
134+
protected Object readGlobalBuiltinDict(@SuppressWarnings("unused") VirtualFrame frame,
135+
@SuppressWarnings("unused") @Bind("getGlobals(frame)") Object globals,
136+
@Bind("getStorage(globals)") HashingStorage storage,
137+
@CachedLibrary("storage") HashingStorageLibrary hlib,
140138
@Cached @SuppressWarnings("unused") IsBuiltinClassProfile builtinProfile) {
141-
Object result = hlib.getItem(getGlobalStorage(frame), attributeId);
139+
Object result = hlib.getItem(storage, attributeId);
142140
return returnGlobalOrBuiltin(result == null ? PNone.NO_VALUE : result);
143141
}
144142

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetOrCreateDictNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.oracle.truffle.api.dsl.Fallback;
5454
import com.oracle.truffle.api.dsl.GenerateUncached;
5555
import com.oracle.truffle.api.dsl.Specialization;
56+
import com.oracle.truffle.api.profiles.BranchProfile;
5657

5758
@GenerateUncached
5859
public abstract class GetOrCreateDictNode extends PNodeWithContext {
@@ -62,9 +63,11 @@ public abstract class GetOrCreateDictNode extends PNodeWithContext {
6263
static PDict doPythonObject(PythonObject object,
6364
@Shared("getDict") @Cached GetDictIfExistsNode getDictIfExistsNode,
6465
@Cached SetDictNode setDictNode,
66+
@Cached BranchProfile createDict,
6567
@Cached PythonObjectFactory factory) {
6668
PDict dict = getDictIfExistsNode.execute(object);
6769
if (dict == null) {
70+
createDict.enter();
6871
dict = factory.createDictFixedStorage(object);
6972
setDictNode.execute(object, dict);
7073
}

0 commit comments

Comments
 (0)