Skip to content

Commit 2278b6c

Browse files
committed
Use cached nodes in PyImport_GetModule
1 parent 1334701 commit 2278b6c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,32 +121,40 @@ abstract static class PyImport_GetModule extends CApiUnaryBuiltinNode {
121121
private static final TruffleString T__LOCK_UNLOCK_MODULE = tsLiteral("_lock_unlock_module");
122122

123123
@Specialization
124-
@TruffleBoundary
125-
Object getModule(Object name) {
126-
PythonContext context = PythonContext.get(null);
124+
Object getModule(Object name,
125+
@Bind("this") Node inliningTarget,
126+
@Cached PyObjectGetItem getItem,
127+
@Cached PyObjectGetAttr getAttr,
128+
@Cached PyObjectIsTrueNode isTrueNode) {
129+
PythonContext context = PythonContext.get(inliningTarget);
127130
PDict modules = context.getSysModules();
128131
Object m;
129132
try {
130-
m = PyObjectGetItem.executeUncached(modules, name);
133+
m = getItem.execute(null, inliningTarget, modules, name);
131134
} catch (PException e) {
132135
return context.getNativeNull();
133136
}
134137
if (m != PNone.NONE) {
135138
boolean initializing = false;
136139
try {
137-
Object spec = PyObjectGetAttr.executeUncached(m, T___SPEC__);
138-
Object initializingObj = PyObjectGetAttr.executeUncached(spec, T___INITIALIZING__);
139-
if (PyObjectIsTrueNode.executeUncached(initializingObj)) {
140+
Object spec = getAttr.execute(null, inliningTarget, m, T___SPEC__);
141+
Object initializingObj = getAttr.execute(null, inliningTarget, spec, T___INITIALIZING__);
142+
if (isTrueNode.execute(null, inliningTarget, initializingObj)) {
140143
initializing = true;
141144
}
142145
} catch (PException e) {
143146
// ignore
144147
}
145148
if (initializing) {
146-
PyObjectCallMethodObjArgs.executeUncached(context.getImportlib(), T__LOCK_UNLOCK_MODULE, name);
149+
waitForInitialization(name, context);
147150
}
148151
}
149152
return m;
150153
}
154+
155+
@TruffleBoundary
156+
private static void waitForInitialization(Object name, PythonContext context) {
157+
PyObjectCallMethodObjArgs.executeUncached(context.getImportlib(), T__LOCK_UNLOCK_MODULE, name);
158+
}
151159
}
152160
}

0 commit comments

Comments
 (0)