Skip to content

Commit ef52b5e

Browse files
committed
Inline ReadAttributeFromPythonObjectNode
1 parent dcf15ca commit ef52b5e

12 files changed

Lines changed: 53 additions & 41 deletions

File tree

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -250,9 +250,9 @@ abstract static class GraalPyPrivate_Module_AddFunctionToModule extends CApi7Bui
250250
static Object moduleFunction(Object methodDefPtr, PythonModule mod, TruffleString name, Object cfunc, int flags, int wrapper, Object doc,
251251
@Bind Node inliningTarget,
252252
@Cached ObjectBuiltins.SetattrNode setattrNode,
253-
@Cached ReadAttributeFromPythonObjectNode readAttrNode,
253+
@Cached(inline = true) ReadAttributeFromPythonObjectNode readAttrNode,
254254
@Cached CFunctionNewExMethodNode cFunctionNewExMethodNode) {
255-
Object modName = readAttrNode.execute(mod, T___NAME__, null);
255+
Object modName = readAttrNode.execute(inliningTarget, mod, T___NAME__, null);
256256
assert modName != null : "module name is missing!";
257257
Object func = cFunctionNewExMethodNode.execute(inliningTarget, methodDefPtr, name, cfunc, flags, wrapper, mod, modName, doc);
258258
setattrNode.executeSetAttr(null, mod, name, func);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public abstract static class LengthNode extends Node {
126126
static int cachedLen(DynamicObjectStorage self,
127127
@SuppressWarnings("unused") @Cached("self.store.getShape()") Shape cachedShape,
128128
@Cached(value = "keyArray(self)", dimensions = 1) Object[] keys,
129-
@Shared @Cached ReadAttributeFromPythonObjectNode readNode) {
129+
@Shared @Cached(inline = false) ReadAttributeFromPythonObjectNode readNode) {
130130
int len = 0;
131131
for (Object key : keys) {
132132
len = incrementLen(self, readNode, len, key);
@@ -136,7 +136,7 @@ static int cachedLen(DynamicObjectStorage self,
136136

137137
@Specialization(replaces = "cachedLen")
138138
static int length(DynamicObjectStorage self,
139-
@Shared @Cached ReadAttributeFromPythonObjectNode readNode,
139+
@Shared @Cached(inline = false) ReadAttributeFromPythonObjectNode readNode,
140140
@Cached DynamicObject.GetKeyArrayNode keyArrayNode) {
141141
Object[] keys = keyArrayNode.execute(self.store);
142142
int len = 0;
@@ -175,19 +175,19 @@ abstract static class GetItemNode extends Node {
175175

176176
@Specialization
177177
static Object string(Node inliningTarget, DynamicObjectStorage self, TruffleString key, @SuppressWarnings("unused") long keyHash,
178-
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
179-
@Exclusive @Cached InlinedConditionProfile noValueProfile) {
180-
Object result = readKey.execute(self.store, key, PNone.NO_VALUE);
178+
@Shared @Cached ReadAttributeFromPythonObjectNode readKey,
179+
@Shared @Cached InlinedConditionProfile noValueProfile) {
180+
Object result = readKey.execute(inliningTarget, self.store, key, PNone.NO_VALUE);
181181
return noValueProfile.profile(inliningTarget, result == PNone.NO_VALUE) ? null : result;
182182
}
183183

184-
@Specialization(guards = "isBuiltinString.execute(inliningTarget, key)", limit = "1")
184+
@Specialization(guards = "isBuiltinString.execute(inliningTarget, key)")
185185
@InliningCutoff
186186
static Object pstring(Node inliningTarget, DynamicObjectStorage self, PString key, @SuppressWarnings("unused") long keyHash,
187-
@SuppressWarnings("unused") @Cached PyUnicodeCheckExactNode isBuiltinString,
188-
@Cached CastToTruffleStringNode castStr,
189-
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
190-
@Exclusive @Cached InlinedConditionProfile noValueProfile) {
187+
@SuppressWarnings("unused") @Shared @Cached PyUnicodeCheckExactNode isBuiltinString,
188+
@Cached(inline = false) CastToTruffleStringNode castStr,
189+
@Shared @Cached ReadAttributeFromPythonObjectNode readKey,
190+
@Shared @Cached InlinedConditionProfile noValueProfile) {
191191
return string(inliningTarget, self, castStr.execute(inliningTarget, key), -1, readKey, noValueProfile);
192192
}
193193

@@ -208,7 +208,7 @@ abstract static class GetItemNoStringKeyNode extends Node {
208208
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN)
209209
static Object notString(Frame frame, DynamicObjectStorage self, Object key, long hashIn,
210210
@Bind Node inliningTarget,
211-
@Shared("readKey") @Cached ReadAttributeFromPythonObjectNode readKey,
211+
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
212212
@Exclusive @Cached("self.store.getShape()") Shape cachedShape,
213213
@Exclusive @Cached(value = "keyArray(self)", dimensions = 1) Object[] keyList,
214214
@Shared("eqNode") @Cached PyObjectRichCompareBool eqNode,
@@ -229,7 +229,7 @@ static Object notString(Frame frame, DynamicObjectStorage self, Object key, long
229229
@Specialization(replaces = "notString")
230230
static Object notStringLoop(Frame frame, DynamicObjectStorage self, Object key, long hashIn,
231231
@Bind Node inliningTarget,
232-
@Shared("readKey") @Cached ReadAttributeFromPythonObjectNode readKey,
232+
@Shared("readKey") @Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
233233
@Shared("eqNode") @Cached PyObjectRichCompareBool eqNode,
234234
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
235235
@Shared("noValueProfile") @Cached InlinedConditionProfile noValueProfile) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static Object economicMap(Node inliningTarget, EconomicMapStorage self, TruffleS
162162

163163
@Specialization
164164
static Object dom(Node inliningTarget, DynamicObjectStorage self, TruffleString key,
165-
@Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
165+
@Cached ReadAttributeFromPythonObjectNode readKey,
166166
@Cached InlinedConditionProfile noValueProfile) {
167167
return DynamicObjectStorage.GetItemNode.string(inliningTarget, self, key, -1, readKey, noValueProfile);
168168
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PBaseException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -360,15 +360,15 @@ int getExceptionExitStatus(
360360
@Cached CastToJavaIntExactNode castToInt,
361361
@Bind Node inliningTarget,
362362
@Exclusive @Cached GetClassNode getClassNode,
363-
@Cached ReadAttributeFromPythonObjectNode readNode,
363+
@Cached(inline = true) ReadAttributeFromPythonObjectNode readNode,
364364
@Exclusive @Cached InlinedBranchProfile unsupportedProfile,
365365
@Shared("gil") @Cached GilNode gil) throws UnsupportedMessageException {
366366
boolean mustRelease = gil.acquire();
367367
try {
368368
if (getExceptionType(inliningTarget, getClassNode, gil) == ExceptionType.EXIT) {
369369
try {
370370
// Avoiding getattr because this message shouldn't have side-effects
371-
Object code = readNode.execute(this, T_CODE);
371+
Object code = readNode.execute(inliningTarget, this, T_CODE);
372372
if (code == PNone.NO_VALUE) {
373373
return 1;
374374
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ static Object getModule(VirtualFrame frame, PBuiltinMethod self, @SuppressWarnin
224224
@Bind Node inliningTarget,
225225
@Cached("createFor($node)") BoundaryCallData boundaryCallData,
226226
@Cached PyObjectLookupAttr lookup,
227-
@Cached ReadAttributeFromPythonObjectNode readAttrNode) {
227+
@Cached(inline = true) ReadAttributeFromPythonObjectNode readAttrNode) {
228228
// No profiling, performance here is not very important
229-
Object module = readAttrNode.execute(self, T___MODULE__, PNone.NO_VALUE);
229+
Object module = readAttrNode.execute(inliningTarget, self, T___MODULE__, PNone.NO_VALUE);
230230
if (module != PNone.NO_VALUE) {
231231
return module;
232232
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static Object lookupConstantMROEquals(Object klass, TruffleString key,
114114
static Object lookupGeneric(Object klass, TruffleString key,
115115
@Bind Node inliningTarget,
116116
@Cached InlinedConditionProfile pbctProfile,
117-
@Cached ReadAttributeFromPythonObjectNode readPBCTAttrNode,
117+
@Cached(inline = false) ReadAttributeFromPythonObjectNode readPBCTAttrNode,
118118
@Cached GetMroStorageNode getMroNode,
119119
@Cached ReadAttributeFromObjectNode readAttrNode) {
120120
if (pbctProfile.profile(inliningTarget, klass instanceof PythonBuiltinClassType)) {
@@ -287,7 +287,7 @@ static PythonBuiltinClassType findOwnerInMro(Python3Core core, PythonBuiltinClas
287287
Object lookupPBCTCachedOwner(PythonBuiltinClassType klass, TruffleString key, boolean skipNonStaticBases,
288288
@Cached("klass") PythonBuiltinClassType cachedKlass,
289289
@Cached("findOwnerInMro(getContext(), cachedKlass, key)") PythonBuiltinClassType ownerKlass,
290-
@Shared @Cached ReadAttributeFromPythonObjectNode readAttrNode) {
290+
@Shared @Cached(inline = false) ReadAttributeFromPythonObjectNode readAttrNode) {
291291
if (ownerKlass == null) {
292292
return PNone.NO_VALUE;
293293
} else {
@@ -297,7 +297,7 @@ Object lookupPBCTCachedOwner(PythonBuiltinClassType klass, TruffleString key, bo
297297

298298
@Specialization(replaces = "lookupPBCTCachedOwner")
299299
Object lookupPBCTGeneric(PythonBuiltinClassType klass, TruffleString key, boolean skipNonStaticBases,
300-
@Shared @Cached ReadAttributeFromPythonObjectNode readAttrNode) {
300+
@Shared @Cached(inline = false) ReadAttributeFromPythonObjectNode readAttrNode) {
301301
return findAttr(PythonContext.get(this), klass, key, readAttrNode);
302302
}
303303

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ static Object doIt(VirtualFrame frame, Node inliningTarget, Object object, Truff
100100
@Cached("slots.tp_getattro()") TpSlot cachedSlot,
101101
// Common
102102
@Cached GetObjectSlotsNode getDescrSlotsNode,
103-
@Cached("create(key)") LookupAttributeInMRONode lookup,
103+
@Cached(value = "create(key)", inline = false) LookupAttributeInMRONode lookup,
104104
@Cached InlinedConditionProfile hasDescProfile,
105105
@Cached InlinedConditionProfile hasDescrGetProfile,
106106
@Cached InlinedConditionProfile hasValueProfile,
107107
@Cached PRaiseNode raiseNode,
108108
@Cached CallSlotDescrGet.Lazy callSlotDescrGet,
109109
// Specific to a given tp_getattro, some should probably be lazy
110110
@Cached ReadAttributeFromObjectNode readAttributeOfObjectNode,
111-
@Cached("create(key)") LookupAttributeInMRONode readAttributeOfClassNode,
111+
@Cached(value = "create(key)", inline = false) LookupAttributeInMRONode readAttributeOfClassNode,
112112
@Cached GetObjectSlotsNode getValueSlotsNode,
113113
@Cached InlinedBranchProfile hasNonDescriptorValueProfile,
114114
@Cached CallSlotDescrGet.Lazy callSlotValueGet,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
*/
6565
@ReportPolymorphism
6666
@GenerateUncached
67-
@GenerateInline(false) // footprint reduction 64 -> 47
67+
@GenerateInline(false)
6868
public abstract class ReadAttributeFromObjectNode extends PNodeWithContext {
6969

7070
@NeverDefault
@@ -88,11 +88,11 @@ static Object readObjectAttribute(PythonObject object, TruffleString key,
8888
@Bind Node inliningTarget,
8989
@Shared @Cached InlinedConditionProfile profileHasDict,
9090
@Shared @Cached GetDictIfExistsNode getDict,
91-
@Cached ReadAttributeFromPythonObjectNode readAttributeFromPythonObjectNode,
91+
@Shared @Cached(inline = true) ReadAttributeFromPythonObjectNode readAttributeFromPythonObjectNode,
9292
@Shared @Cached HashingStorageGetItemStringKey getItem) {
9393
var dict = getDict.execute(object);
9494
if (profileHasDict.profile(inliningTarget, dict == null)) {
95-
return readAttributeFromPythonObjectNode.execute(object, key);
95+
return readAttributeFromPythonObjectNode.execute(inliningTarget, object, key);
9696
} else {
9797
Object value = getItem.execute(inliningTarget, dict.getDictStorage(), key);
9898
if (value == null) {

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
* object has dict, also bypasses any other additional logic in {@link ReadAttributeFromObjectNode}.
6262
*/
6363
@GenerateUncached
64-
@GenerateInline(false) // footprint reduction 44 -> 25
64+
@GenerateInline
6565
public abstract class ReadAttributeFromPythonObjectNode extends PNodeWithContext {
6666
@NeverDefault
6767
public static ReadAttributeFromPythonObjectNode create() {
@@ -73,24 +73,36 @@ public static ReadAttributeFromPythonObjectNode getUncached() {
7373
}
7474

7575
public static Object executeUncached(PythonObject object, TruffleString key, Object defaultValue) {
76-
return getUncached().execute(object, key, defaultValue);
76+
return getUncached().execute(getUncached(), object, key, defaultValue);
7777
}
7878

79-
public abstract Object execute(PythonObject object, TruffleString key, Object defaultValue);
79+
public final Object execute(PythonObject object, TruffleString key, Object defaultValue) {
80+
return execute(this, object, key, defaultValue);
81+
}
8082

8183
public final Object execute(PythonObject object, TruffleString key) {
82-
return execute(object, key, PNone.NO_VALUE);
84+
return execute(this, object, key, PNone.NO_VALUE);
8385
}
8486

8587
// used only by DynamicObjectStorage, which will be removed during the transition from
8688
// DynamicObject to ObjectHashMap
87-
public abstract Object execute(DynamicObject object, TruffleString key, Object defaultValue);
89+
public final Object execute(DynamicObject object, TruffleString key, Object defaultValue) {
90+
return execute(this, object, key, defaultValue);
91+
}
92+
93+
public abstract Object execute(Node inliningTarget, PythonObject object, TruffleString key, Object defaultValue);
94+
95+
public final Object execute(Node inliningTarget, PythonObject object, TruffleString key) {
96+
return execute(inliningTarget, object, key, PNone.NO_VALUE);
97+
}
98+
99+
public abstract Object execute(Node inliningTarget, DynamicObject object, TruffleString key, Object defaultValue);
88100

89101
@Specialization
90-
protected final Object read(DynamicObject dynamicObject, TruffleString key, Object defaultValue,
102+
protected static Object read(Node inliningTarget, DynamicObject dynamicObject, TruffleString key, Object defaultValue,
91103
@Cached ReceiverCast receiverCast,
92104
@Cached DynamicObject.GetNode getNode) {
93-
return getNode.execute(receiverCast.execute(this, dynamicObject), key, defaultValue);
105+
return getNode.execute(receiverCast.execute(inliningTarget, dynamicObject), key, defaultValue);
94106
}
95107

96108
@GenerateCached(false)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ static Object readFromLocalsFastPath(VirtualFrame frame, TruffleString attribute
12591259
@ForceQuickening
12601260
@Specialization(guards = "!isNoValue(result)", limit = "1")
12611261
public static Object doLocalFastPath(VirtualFrame frame, TruffleString name,
1262-
@Cached ReadAttributeFromPythonObjectNode readAttrNode,
1262+
@Cached(inline = false) ReadAttributeFromPythonObjectNode readAttrNode,
12631263
@Bind("readFromLocalsFastPath(frame, name, readAttrNode)") Object result) {
12641264
return result;
12651265
}

0 commit comments

Comments
 (0)