Skip to content

Commit 6c0d9a6

Browse files
committed
avoid loading builtin patches only during native image build time
1 parent 262c2c7 commit 6c0d9a6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.oracle.truffle.api.TruffleFile;
6262
import com.oracle.truffle.api.TruffleLanguage;
6363
import com.oracle.truffle.api.TruffleLogger;
64+
import com.oracle.truffle.api.TruffleOptions;
6465
import com.oracle.truffle.api.debug.DebuggerTags;
6566
import com.oracle.truffle.api.frame.Frame;
6667
import com.oracle.truffle.api.frame.MaterializedFrame;
@@ -86,6 +87,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
8687
public static final String MIME_TYPE = "text/x-python";
8788
public static final String EXTENSION = ".py";
8889

90+
@CompilationFinal private boolean nativeBuildTime = TruffleOptions.AOT;
8991
@CompilationFinal private PythonCore sharedCore;
9092
private final NodeFactory nodeFactory;
9193

@@ -105,6 +107,7 @@ protected void finalizeContext(PythonContext context) {
105107

106108
@Override
107109
protected boolean patchContext(PythonContext context, Env newEnv) {
110+
nativeBuildTime = false; // now we're running
108111
ensureSysExecutable(context);
109112
ensureHomeInOptions(newEnv);
110113
if (!optionsAllowPreInitializedContext(context, newEnv)) {
@@ -115,6 +118,7 @@ protected boolean patchContext(PythonContext context, Env newEnv) {
115118
context.setOut(newEnv.out());
116119
context.setErr(newEnv.err());
117120
context.initialize();
121+
context.getCore().postInitialize();
118122
return true;
119123
}
120124

@@ -419,4 +423,8 @@ private static <E1 extends Exception, E2 extends Exception, E3 extends Exception
419423
}
420424
return newBuilder.build();
421425
}
426+
427+
public boolean isNativeBuildTime() {
428+
return nativeBuildTime;
429+
}
422430
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ public boolean isInitialized() {
346346
return initialized;
347347
}
348348

349+
@Override
349350
public void initialize() {
350351
String coreHome = PythonCore.getCoreHomeOrFail();
351352
loadFile("builtins", coreHome);
@@ -355,10 +356,19 @@ public void initialize() {
355356
}
356357
exportCInterface(getContext());
357358
currentException = null;
358-
loadFile(__BUILTINS_PATCHES__, PythonCore.getCoreHomeOrFail());
359+
postInitialize();
359360
initialized = true;
360361
}
361362

363+
@Override
364+
public void postInitialize() {
365+
if (!getLanguage().isNativeBuildTime()) {
366+
initialized = false;
367+
loadFile(__BUILTINS_PATCHES__, PythonCore.getCoreHomeOrFail());
368+
initialized = true;
369+
}
370+
}
371+
362372
public Object duplicate(Map<Object, Object> replacements, Object value) {
363373
Object replacement = replacements.get(value);
364374
if (replacement != null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonCore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public interface PythonCore {
6767
*/
6868
public void initialize();
6969

70+
public void postInitialize();
71+
7072
public boolean isInitialized();
7173

7274
public PythonModule lookupBuiltinModule(String name);

0 commit comments

Comments
 (0)