6969import com .oracle .truffle .api .frame .Frame ;
7070import com .oracle .truffle .api .frame .VirtualFrame ;
7171import com .oracle .truffle .api .nodes .Node ;
72+ import com .oracle .truffle .api .profiles .ConditionProfile ;
7273
7374/**
7475 * Equivalent to use for the various PyObject_LookupAttr* functions available in CPython. Note that
@@ -148,11 +149,13 @@ static final Object doBuiltinModule(VirtualFrame frame, Object object, String na
148149 @ Cached ReadAttributeFromObjectNode readNode ,
149150 @ Cached ReadAttributeFromObjectNode readGetattr ,
150151 @ Shared ("errorProfile" ) @ Cached IsBuiltinClassProfile errorProfile ,
152+ @ Cached ConditionProfile noValueFound ,
151153 @ Cached CallNode callGetattr ) {
152154 Object value = readNode .execute (object , cachedName );
153- if (value == PNone .NO_VALUE ) {
155+ if (noValueFound . profile ( value == PNone .NO_VALUE ) ) {
154156 Object getAttr = readGetattr .execute (object , SpecialMethodNames .__GETATTR__ );
155157 if (getAttr != PNone .NO_VALUE ) {
158+ // (tfel): I'm not profiling this, since modules with __getattr__ are kind of rare
156159 try {
157160 return callGetattr .execute (frame , getAttr , name );
158161 } catch (PException e ) {
@@ -179,15 +182,15 @@ static final Object doBuiltinType(VirtualFrame frame, Object object, String name
179182 @ Cached ("create(name)" ) LookupAttributeInMRONode lookupName ,
180183 @ Bind ("lookupName.execute(type)" ) Object descr ,
181184 @ Cached ReadAttributeFromObjectNode readNode ,
182- @ Cached ReadAttributeFromObjectNode readGetattr ,
185+ @ Cached ConditionProfile valueFound ,
183186 @ Cached ("create(__GET__)" ) LookupInheritedAttributeNode lookupValueGet ,
187+ @ Cached ConditionProfile noGetMethod ,
184188 @ Cached CallTernaryMethodNode invokeValueGet ,
185- @ Shared ("errorProfile" ) @ Cached IsBuiltinClassProfile errorProfile ,
186- @ Cached CallNode callGetattr ) {
189+ @ Shared ("errorProfile" ) @ Cached IsBuiltinClassProfile errorProfile ) {
187190 Object value = readNode .execute (object , cachedName );
188- if (value != PNone .NO_VALUE ) {
191+ if (valueFound . profile ( value != PNone .NO_VALUE ) ) {
189192 Object valueGet = lookupValueGet .execute (value );
190- if (valueGet == PNone .NO_VALUE ) {
193+ if (noGetMethod . profile ( valueGet == PNone .NO_VALUE ) ) {
191194 return value ;
192195 } else if (PGuards .isCallable (valueGet )) {
193196 try {
0 commit comments