52
52
import com .oracle .truffle .api .dsl .Cached ;
53
53
import com .oracle .truffle .api .dsl .Specialization ;
54
54
import com .oracle .truffle .api .frame .VirtualFrame ;
55
+ import com .oracle .truffle .api .profiles .ConditionProfile ;
55
56
56
57
/**
57
58
* Equivalent of CPython's {@code PyImport_Import}.
@@ -61,6 +62,8 @@ public abstract class PyImportImport extends PNodeWithState {
61
62
62
63
@ Specialization
63
64
Object doGeneric (VirtualFrame frame , Object moduleName ,
65
+ @ Cached ConditionProfile noGlobalsProfile ,
66
+ @ Cached ConditionProfile dictBuiltinsProfile ,
64
67
@ Cached PyImportGetModule importGetModule ,
65
68
@ Cached PyObjectGetItem getItemNode ,
66
69
@ Cached PyObjectGetAttr getAttrNode ,
@@ -70,7 +73,7 @@ Object doGeneric(VirtualFrame frame, Object moduleName,
70
73
// Get the builtins from current globals
71
74
Object globals = getGlobals .execute (frame );
72
75
Object builtins ;
73
- if (globals != null ) {
76
+ if (noGlobalsProfile . profile ( globals != null ) ) {
74
77
builtins = getItemNode .execute (frame , globals , __BUILTINS__ );
75
78
} else {
76
79
// No globals -- use standard builtins, and fake globals
@@ -80,7 +83,7 @@ Object doGeneric(VirtualFrame frame, Object moduleName,
80
83
81
84
// Get the __import__ function from the builtins
82
85
Object importFunc ;
83
- if (builtins instanceof PDict ) {
86
+ if (dictBuiltinsProfile . profile ( builtins instanceof PDict ) ) {
84
87
importFunc = getItemNode .execute (frame , builtins , __IMPORT__ );
85
88
} else {
86
89
importFunc = getAttrNode .execute (frame , builtins , __IMPORT__ );
0 commit comments