Skip to content

Commit 24853d5

Browse files
committed
Migrate all the PException#expectAttributeError usages to the new inlined profile
1 parent 3052c41 commit 24853d5

File tree

10 files changed

+96
-72
lines changed

10 files changed

+96
-72
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
229229
import com.oracle.graal.python.nodes.object.GetClassNode;
230230
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
231-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
231+
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
232232
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
233233
import com.oracle.graal.python.nodes.util.CannotCastException;
234234
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
@@ -1303,15 +1303,16 @@ public Object getAttrDefault(VirtualFrame frame, Object primary, TruffleString n
13031303
@SuppressWarnings("unused")
13041304
@Specialization(limit = "getAttributeAccessInlineCacheMaxDepth()", guards = {"stringEquals(cachedName, name, equalNode, stringProfile)", "!isNoValue(defaultValue)"})
13051305
Object getAttr(VirtualFrame frame, Object primary, TruffleString name, Object defaultValue,
1306+
@Bind("this") Node inliningTarget,
13061307
@Cached ConditionProfile stringProfile,
13071308
@Cached TruffleString.EqualNode equalNode,
13081309
@Cached("name") TruffleString cachedName,
13091310
@Cached("create(name)") GetFixedAttributeNode getAttributeNode,
1310-
@Cached IsBuiltinClassProfile errorProfile) {
1311+
@Cached IsBuiltinObjectProfile errorProfile) {
13111312
try {
13121313
return getAttributeNode.executeObject(frame, primary);
13131314
} catch (PException e) {
1314-
e.expectAttributeError(errorProfile);
1315+
e.expectAttributeError(inliningTarget, errorProfile);
13151316
return defaultValue;
13161317
}
13171318
}
@@ -1324,12 +1325,13 @@ Object getAttrFromObject(VirtualFrame frame, Object primary, TruffleString name,
13241325

13251326
@Specialization(replaces = {"getAttr", "getAttrDefault"}, guards = "!isNoValue(defaultValue)")
13261327
Object getAttrFromObject(VirtualFrame frame, Object primary, TruffleString name, Object defaultValue,
1328+
@Bind("this") Node inliningTarget,
13271329
@Cached GetAnyAttributeNode getAttributeNode,
1328-
@Cached IsBuiltinClassProfile errorProfile) {
1330+
@Cached IsBuiltinObjectProfile errorProfile) {
13291331
try {
13301332
return getAttributeNode.executeObject(frame, primary, name);
13311333
} catch (PException e) {
1332-
e.expectAttributeError(errorProfile);
1334+
e.expectAttributeError(inliningTarget, errorProfile);
13331335
return defaultValue;
13341336
}
13351337
}
@@ -2457,18 +2459,19 @@ private static Object buildJavaClass(Object namespace, TruffleString name, Objec
24572459

24582460
@Specialization
24592461
protected Object doItNonFunction(VirtualFrame frame, Object function, Object[] arguments, PKeyword[] keywords,
2462+
@Bind("this") Node inliningTarget,
24602463
@Cached PythonObjectFactory factory,
24612464
@Cached CalculateMetaclassNode calculateMetaClass,
24622465
@Cached("create(T___PREPARE__)") GetAttributeNode getPrepare,
24632466
@Cached(parameters = "GetItem") LookupCallableSlotInMRONode getGetItem,
2464-
@Cached GetClassNode getGetItemClass,
2467+
@Cached InlinedGetClassNode getGetItemClass,
24652468
@Cached CallVarargsMethodNode callPrep,
24662469
@Cached CallVarargsMethodNode callType,
24672470
@Cached CallDispatchNode callBody,
24682471
@Cached UpdateBasesNode update,
24692472
@Cached PyObjectSetItem setOrigBases,
2470-
@Cached GetClassNode getClass,
2471-
@Cached IsBuiltinClassProfile noAttributeProfile) {
2473+
@Cached InlinedGetClassNode getClass,
2474+
@Cached IsBuiltinObjectProfile noAttributeProfile) {
24722475

24732476
if (arguments.length < 1) {
24742477
throw raise(PythonErrorType.TypeError, ErrorMessages.BUILD_CLS_NOT_ENOUGH_ARGS);
@@ -2528,7 +2531,7 @@ class InitializeBuildClass {
25282531
meta = PythonContext.get(update).lookupType(PythonBuiltinClassType.PythonClass);
25292532
} else {
25302533
// else get the type of the first base
2531-
meta = getClass.execute(bases.getSequenceStorage().getItemNormalized(0));
2534+
meta = getClass.execute(inliningTarget, bases.getSequenceStorage().getItemNormalized(0));
25322535
}
25332536
isClass = true; // meta is really a class
25342537
}
@@ -2555,10 +2558,10 @@ class InitializeBuildClass {
25552558
Object prep = getPrepare.executeObject(frame, init.meta);
25562559
ns = callPrep.execute(frame, prep, new Object[]{name, init.bases}, init.mkw);
25572560
} catch (PException p) {
2558-
p.expectAttributeError(noAttributeProfile);
2561+
p.expectAttributeError(inliningTarget, noAttributeProfile);
25592562
ns = factory().createDict(new DynamicObjectStorage(PythonLanguage.get(this)));
25602563
}
2561-
if (PGuards.isNoValue(getGetItem.execute(getGetItemClass.execute(ns)))) {
2564+
if (PGuards.isNoValue(getGetItem.execute(getGetItemClass.execute(inliningTarget, ns)))) {
25622565
if (init.isClass) {
25632566
throw raise(PythonErrorType.TypeError, ErrorMessages.N_PREPARE_MUST_RETURN_MAPPING, init.meta, ns);
25642567
} else {

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
122122
import com.oracle.graal.python.nodes.expression.CastToListExpressionNode.CastToListInteropNode;
123123
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
124+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
124125
import com.oracle.graal.python.nodes.object.GetClassNode;
125126
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
126127
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
@@ -136,6 +137,7 @@
136137
import com.oracle.truffle.api.CompilerDirectives;
137138
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
138139
import com.oracle.truffle.api.TruffleLanguage;
140+
import com.oracle.truffle.api.dsl.Bind;
139141
import com.oracle.truffle.api.dsl.Cached;
140142
import com.oracle.truffle.api.dsl.Cached.Exclusive;
141143
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -161,6 +163,7 @@
161163
import com.oracle.truffle.api.object.HiddenKey;
162164
import com.oracle.truffle.api.object.Shape;
163165
import com.oracle.truffle.api.profiles.ConditionProfile;
166+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
164167
import com.oracle.truffle.api.strings.TruffleString;
165168
import com.oracle.truffle.api.strings.TruffleString.RegionEqualNode;
166169
import com.oracle.truffle.api.utilities.TriState;
@@ -212,15 +215,16 @@ public final void clearNativeWrapper(ConditionProfile hasHandleValidAssumptionPr
212215

213216
@ExportMessage
214217
public void writeMember(String key, Object value,
218+
@Bind("$node") Node inliningTarget,
215219
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
216220
@Cached PInteropSetAttributeNode setAttributeNode,
217-
@Shared("attributeErrorProfile") @Cached IsBuiltinClassProfile attrErrorProfile,
221+
@Shared("attributeErrorProfile") @Cached IsBuiltinObjectProfile attrErrorProfile,
218222
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException, UnknownIdentifierException {
219223
boolean mustRelease = gil.acquire();
220224
try {
221225
setAttributeNode.execute(this, fromJavaStringNode.execute(key, TS_ENCODING), value);
222226
} catch (PException e) {
223-
e.expectAttributeError(attrErrorProfile);
227+
e.expectAttributeError(inliningTarget, attrErrorProfile);
224228
// TODO(fa) not accurate; distinguish between read-only and non-existing
225229
throw UnknownIdentifierException.create(key);
226230
} finally {
@@ -487,13 +491,14 @@ public boolean hasMemberWriteSideEffects(String member,
487491

488492
@ExportMessage
489493
public Object invokeMember(String member, Object[] arguments,
494+
@Bind("$node") Node inliningTarget,
490495
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode,
491496
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupGetattributeNode,
492497
@Exclusive @Cached CallBinaryMethodNode callGetattributeNode,
493498
@Exclusive @Cached PExecuteNode executeNode,
494499
@Exclusive @Cached ConditionProfile profileGetattribute,
495500
@Exclusive @Cached ConditionProfile profileMember,
496-
@Shared("attributeErrorProfile") @Cached IsBuiltinClassProfile attributeErrorProfile,
501+
@Shared("attributeErrorProfile") @Cached IsBuiltinObjectProfile attributeErrorProfile,
497502
@Exclusive @Cached GilNode gil)
498503
throws UnknownIdentifierException, UnsupportedMessageException {
499504
boolean mustRelease = gil.acquire();
@@ -509,7 +514,7 @@ public Object invokeMember(String member, Object[] arguments,
509514
throw UnknownIdentifierException.create(member);
510515
}
511516
} catch (PException e) {
512-
e.expect(AttributeError, attributeErrorProfile);
517+
e.expect(inliningTarget, AttributeError, attributeErrorProfile);
513518
throw UnknownIdentifierException.create(member);
514519
}
515520
return executeNode.execute(memberObj, arguments);
@@ -598,14 +603,15 @@ public Object getMembers(boolean includeInternal,
598603

599604
@ExportMessage
600605
public void removeMember(String member,
606+
@Bind("$node") Node inliningTarget,
601607
@Cached PInteropDeleteAttributeNode deleteAttributeNode,
602-
@Shared("attributeErrorProfile") @Cached IsBuiltinClassProfile attrErrorProfile,
608+
@Shared("attributeErrorProfile") @Cached IsBuiltinObjectProfile attrErrorProfile,
603609
@Exclusive @Cached GilNode gil) throws UnsupportedMessageException, UnknownIdentifierException {
604610
boolean mustRelease = gil.acquire();
605611
try {
606612
deleteAttributeNode.execute(this, member);
607613
} catch (PException e) {
608-
e.expectAttributeError(attrErrorProfile);
614+
e.expectAttributeError(inliningTarget, attrErrorProfile);
609615
// TODO(fa) not accurate; distinguish between read-only and non-existing
610616
throw UnknownIdentifierException.create(member);
611617
} finally {
@@ -1366,17 +1372,18 @@ public abstract static class PInteropSetAttributeNode extends Node {
13661372

13671373
@Specialization
13681374
public static void doSpecialObject(PythonAbstractObject primary, TruffleString attrName, Object value,
1375+
@Bind("this") Node inliningTarget,
13691376
@Cached PForeignToPTypeNode convert,
13701377
@Cached LookupInheritedAttributeNode.Dynamic lookupSetAttrNode,
13711378
@Cached CallTernaryMethodNode callSetAttrNode,
1372-
@Cached ConditionProfile profile,
1373-
@Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
1379+
@Cached InlinedConditionProfile profile,
1380+
@Cached IsBuiltinObjectProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
13741381
Object attrSetattr = lookupSetAttrNode.execute(primary, SpecialMethodNames.T___SETATTR__);
1375-
if (profile.profile(attrSetattr != PNone.NO_VALUE)) {
1382+
if (profile.profile(inliningTarget, attrSetattr != PNone.NO_VALUE)) {
13761383
try {
13771384
callSetAttrNode.execute(null, attrSetattr, primary, attrName, convert.executeConvert(value));
13781385
} catch (PException e) {
1379-
e.expectAttributeError(attrErrorProfile);
1386+
e.expectAttributeError(inliningTarget, attrErrorProfile);
13801387
// TODO(fa) not accurate; distinguish between read-only and non-existing
13811388
throw UnknownIdentifierException.create(attrName.toJavaStringUncached());
13821389
}
@@ -1428,17 +1435,18 @@ public abstract static class PInteropDeleteAttributeNode extends Node {
14281435

14291436
@Specialization
14301437
public void doSpecialObject(PythonAbstractObject primary, String attrName,
1438+
@Bind("this") Node inliningTarget,
14311439
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
14321440
@Cached LookupInheritedAttributeNode.Dynamic lookupSetAttrNode,
14331441
@Cached CallBinaryMethodNode callSetAttrNode,
1434-
@Cached ConditionProfile profile,
1435-
@Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
1442+
@Cached InlinedConditionProfile profile,
1443+
@Cached IsBuiltinObjectProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
14361444
Object attrDelattr = lookupSetAttrNode.execute(primary, SpecialMethodNames.T___DELATTR__);
1437-
if (profile.profile(attrDelattr != PNone.NO_VALUE)) {
1445+
if (profile.profile(inliningTarget, attrDelattr != PNone.NO_VALUE)) {
14381446
try {
14391447
callSetAttrNode.executeObject(attrDelattr, primary, fromJavaStringNode.execute(attrName, TS_ENCODING));
14401448
} catch (PException e) {
1441-
e.expectAttributeError(attrErrorProfile);
1449+
e.expectAttributeError(inliningTarget, attrErrorProfile);
14421450
// TODO(fa) not accurate; distinguish between read-only and non-existing
14431451
throw UnknownIdentifierException.create(attrName);
14441452
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2023, 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
@@ -72,17 +72,19 @@
7272
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
7373
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
7474
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
75-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
75+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
7676
import com.oracle.graal.python.runtime.exception.PException;
7777
import com.oracle.graal.python.util.PythonUtils;
7878
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
79+
import com.oracle.truffle.api.dsl.Bind;
7980
import com.oracle.truffle.api.dsl.Cached;
8081
import com.oracle.truffle.api.dsl.Cached.Shared;
8182
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8283
import com.oracle.truffle.api.dsl.ImportStatic;
8384
import com.oracle.truffle.api.dsl.NodeFactory;
8485
import com.oracle.truffle.api.dsl.Specialization;
8586
import com.oracle.truffle.api.frame.VirtualFrame;
87+
import com.oracle.truffle.api.nodes.Node;
8688
import com.oracle.truffle.api.strings.TruffleString;
8789

8890
@CoreFunctions(extendClasses = {PythonBuiltinClassType.PInstancemethod})
@@ -125,13 +127,14 @@ protected static Object func(PDecoratedMethod self) {
125127
public abstract static class GetattributeNode extends PythonBuiltinNode {
126128
@Specialization
127129
protected static Object doIt(VirtualFrame frame, PDecoratedMethod self, Object key,
130+
@Bind("this") Node inliningTarget,
128131
@Cached ObjectBuiltins.GetAttributeNode objectGetattrNode,
129132
@Cached PyObjectGetAttr getAttrNode,
130-
@Cached IsBuiltinClassProfile errorProfile) {
133+
@Cached IsBuiltinObjectProfile errorProfile) {
131134
try {
132135
return objectGetattrNode.execute(frame, self, key);
133136
} catch (PException e) {
134-
e.expectAttributeError(errorProfile);
137+
e.expectAttributeError(inliningTarget, errorProfile);
135138
return getAttrNode.execute(frame, self.getCallable(), key);
136139
}
137140
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -61,17 +61,19 @@
6161
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
6262
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6363
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
64+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
6465
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
65-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6666
import com.oracle.graal.python.nodes.util.CannotCastException;
6767
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
6868
import com.oracle.graal.python.runtime.exception.PException;
69+
import com.oracle.truffle.api.dsl.Bind;
6970
import com.oracle.truffle.api.dsl.Cached;
7071
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7172
import com.oracle.truffle.api.dsl.ImportStatic;
7273
import com.oracle.truffle.api.dsl.NodeFactory;
7374
import com.oracle.truffle.api.dsl.Specialization;
7475
import com.oracle.truffle.api.frame.VirtualFrame;
76+
import com.oracle.truffle.api.nodes.Node;
7577
import com.oracle.truffle.api.strings.TruffleString;
7678

7779
@CoreFunctions(extendClasses = PythonBuiltinClassType.PMethod)
@@ -117,8 +119,9 @@ protected Object doIt(PMethod self,
117119
public abstract static class GetattributeNode extends PythonBuiltinNode {
118120
@Specialization
119121
protected Object doIt(VirtualFrame frame, PMethod self, Object keyObj,
122+
@Bind("this") Node inliningTarget,
120123
@Cached ObjectBuiltins.GetAttributeNode objectGetattrNode,
121-
@Cached IsBuiltinClassProfile errorProfile,
124+
@Cached IsBuiltinObjectProfile errorProfile,
122125
@Cached CastToTruffleStringNode castKeyToStringNode) {
123126
TruffleString key;
124127
try {
@@ -130,7 +133,7 @@ protected Object doIt(VirtualFrame frame, PMethod self, Object keyObj,
130133
try {
131134
return objectGetattrNode.execute(frame, self, key);
132135
} catch (PException e) {
133-
e.expectAttributeError(errorProfile);
136+
e.expectAttributeError(inliningTarget, errorProfile);
134137
return objectGetattrNode.execute(frame, self.getFunction(), key);
135138
}
136139
}

0 commit comments

Comments
 (0)