Skip to content

Commit a84deba

Browse files
committed
Reduce footprint of WriteAttributeToObject
1 parent d481a70 commit a84deba

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

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

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ static boolean writeToDynamicStorageNoType(PythonObject object, Object key, Obje
153153
@Specialization(guards = {"isAttrWritable(klass, key)", "!isHiddenKey(key)", "getDict.execute(klass) == null"}, limit = "1")
154154
boolean writeToDynamicStorageBuiltinType(PythonBuiltinClass klass, Object key, Object value,
155155
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
156-
@Cached CastToJavaStringNode castToStrNode,
157-
@Cached BranchProfile callAttrUpdate,
158-
@CachedLibrary(limit = "getAttributeAccessInlineCacheMaxDepth()") DynamicObjectLibrary dylib) {
156+
@Shared("castToStr") @Cached CastToJavaStringNode castToStrNode,
157+
@Shared("callAttrUpdate") @Cached BranchProfile callAttrUpdate,
158+
@Shared("dylib") @CachedLibrary(limit = "getAttributeAccessInlineCacheMaxDepth()") DynamicObjectLibrary dylib) {
159159
if (PythonContext.get(this).isInitialized()) {
160160
throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTES_OF_TYPE_S, klass);
161161
} else {
@@ -166,10 +166,10 @@ boolean writeToDynamicStorageBuiltinType(PythonBuiltinClass klass, Object key, O
166166
@Specialization(guards = {"isAttrWritable(klass, key)", "!isHiddenKey(key)", "getDict.execute(klass) == null"}, limit = "1")
167167
static boolean writeToDynamicStoragePythonClass(PythonClass klass, Object key, Object value,
168168
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
169-
@Cached CastToJavaStringNode castToStrNode,
170-
@Cached BranchProfile callAttrUpdate,
169+
@Shared("castToStr") @Cached CastToJavaStringNode castToStrNode,
170+
@Shared("callAttrUpdate") @Cached BranchProfile callAttrUpdate,
171171
@Cached BranchProfile updateFlags,
172-
@CachedLibrary(limit = "getAttributeAccessInlineCacheMaxDepth()") DynamicObjectLibrary dylib) {
172+
@Shared("dylib") @CachedLibrary(limit = "getAttributeAccessInlineCacheMaxDepth()") DynamicObjectLibrary dylib) {
173173
if (value == PNone.NO_VALUE) {
174174
updateFlags.enter();
175175
dylib.setShapeFlags(klass, dylib.getShapeFlags(klass) | HAS_NO_VALUE_PROPERTIES);
@@ -197,8 +197,8 @@ private static boolean writeToDynamicStorageManagedClass(PythonManagedClass klas
197197
static boolean writeToDictNoType(@SuppressWarnings("unused") PythonObject object, Object key, Object value,
198198
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
199199
@Bind("getDict.execute(object)") PDict dict,
200-
@Cached BranchProfile updateStorage,
201-
@CachedLibrary(limit = "1") HashingStorageLibrary hlib) {
200+
@Shared("updateStorage") @Cached BranchProfile updateStorage,
201+
@Shared("hlib") @CachedLibrary(limit = "1") HashingStorageLibrary hlib) {
202202
return writeToDict(dict, key, value, updateStorage, hlib);
203203
}
204204

@@ -207,10 +207,10 @@ static boolean writeToDictNoType(@SuppressWarnings("unused") PythonObject object
207207
boolean writeToDictBuiltinType(PythonBuiltinClass klass, Object key, Object value,
208208
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
209209
@Bind("getDict.execute(klass)") PDict dict,
210-
@Cached CastToJavaStringNode castToStrNode,
211-
@Cached BranchProfile callAttrUpdate,
212-
@Cached BranchProfile updateStorage,
213-
@CachedLibrary(limit = "1") HashingStorageLibrary hlib) {
210+
@Shared("castToStr") @Cached CastToJavaStringNode castToStrNode,
211+
@Shared("callAttrUpdate") @Cached BranchProfile callAttrUpdate,
212+
@Shared("updateStorage") @Cached BranchProfile updateStorage,
213+
@Shared("hlib") @CachedLibrary(limit = "1") HashingStorageLibrary hlib) {
214214
if (PythonContext.get(this).isInitialized()) {
215215
throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTES_OF_TYPE_S, klass);
216216
} else {
@@ -222,10 +222,10 @@ boolean writeToDictBuiltinType(PythonBuiltinClass klass, Object key, Object valu
222222
static boolean writeToDictClass(PythonClass klass, Object key, Object value,
223223
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
224224
@Bind("getDict.execute(klass)") PDict dict,
225-
@Cached CastToJavaStringNode castToStrNode,
226-
@Cached BranchProfile callAttrUpdate,
227-
@Cached BranchProfile updateStorage,
228-
@CachedLibrary(limit = "1") HashingStorageLibrary hlib) {
225+
@Shared("castToStr") @Cached CastToJavaStringNode castToStrNode,
226+
@Shared("callAttrUpdate") @Cached BranchProfile callAttrUpdate,
227+
@Shared("updateStorage") @Cached BranchProfile updateStorage,
228+
@Shared("hlib") @CachedLibrary(limit = "1") HashingStorageLibrary hlib) {
229229
return writeToDictManagedClass(klass, dict, key, value, castToStrNode, callAttrUpdate, updateStorage, hlib);
230230
}
231231

@@ -256,13 +256,6 @@ static boolean writeToDict(PDict dict, Object key, Object value,
256256
return true;
257257
}
258258

259-
@Specialization(guards = "isErrorCase(getDict, object, key)", limit = "1")
260-
static boolean doError(Object object, Object key, @SuppressWarnings("unused") Object value,
261-
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
262-
@Cached PRaiseNode raiseNode) {
263-
throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
264-
}
265-
266259
@Specialization
267260
static boolean doPBCT(PythonBuiltinClassType object, Object key, Object value,
268261
@Cached WriteAttributeToObjectNode recursive) {
@@ -292,10 +285,10 @@ protected static boolean isErrorCase(GetDictIfExistsNode getDict, Object object,
292285
protected abstract static class WriteAttributeToObjectNotTypeNode extends WriteAttributeToObjectNode {
293286
@Specialization(guards = {"!isHiddenKey(key)"})
294287
static boolean writeNativeObject(PythonAbstractNativeObject object, Object key, Object value,
295-
@Cached GetDictIfExistsNode getDict,
296-
@CachedLibrary(limit = "1") HashingStorageLibrary hlib,
297-
@Cached BranchProfile updateStorage,
298-
@Cached PRaiseNode raiseNode) {
288+
@Shared("getDict") @Cached GetDictIfExistsNode getDict,
289+
@Shared("hlib") @CachedLibrary(limit = "1") HashingStorageLibrary hlib,
290+
@Shared("updateStorage") @Cached BranchProfile updateStorage,
291+
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
299292
/*
300293
* The dict of native objects that stores the object attributes is located at 'objectPtr
301294
* + Py_TYPE(objectPtr)->tp_dictoffset'. 'PythonObjectLibrary.getDict' will exactly load
@@ -307,6 +300,13 @@ static boolean writeNativeObject(PythonAbstractNativeObject object, Object key,
307300
}
308301
throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
309302
}
303+
304+
@Specialization(guards = "isErrorCase(getDict, object, key)", limit = "1")
305+
static boolean doError(Object object, Object key, @SuppressWarnings("unused") Object value,
306+
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
307+
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
308+
throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
309+
}
310310
}
311311

312312
@GenerateUncached
@@ -342,7 +342,7 @@ static boolean writeNativeClassGeneric(PythonAbstractNativeObject object, Object
342342
@Shared("hlib") @CachedLibrary(limit = "1") HashingStorageLibrary hlib,
343343
@Shared("updateStorage") @Cached BranchProfile updateStorage,
344344
@Cached BranchProfile canBeSpecialSlot,
345-
@Cached CastToJavaStringNode castKeyNode,
345+
@Shared("castToStr") @Cached CastToJavaStringNode castKeyNode,
346346
@Cached IsTypeNode isTypeNode,
347347
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
348348
try {
@@ -372,5 +372,12 @@ static boolean writeNativeClassGeneric(PythonAbstractNativeObject object, Object
372372
}
373373
}
374374
}
375+
376+
@Specialization(guards = "isErrorCase(getDict, object, key)", limit = "1")
377+
static boolean doError(Object object, Object key, @SuppressWarnings("unused") Object value,
378+
@SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict,
379+
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
380+
throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
381+
}
375382
}
376383
}

0 commit comments

Comments
 (0)