Skip to content

Commit 19d6928

Browse files
committed
Ensure classloading for builtins happens at context initialize, not context create
1 parent 2cc2926 commit 19d6928

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ protected boolean patchContext(PythonContext context, Env newEnv) {
460460
@Override
461461
protected PythonContext createContext(Env env) {
462462
final PythonContext context = new PythonContext(this, env);
463-
context.initializeHomeAndPrefixPaths(env, getLanguageHome());
464463

465464
Object[] engineOptionsUnroll = this.engineOptionsStorage;
466465
if (engineOptionsUnroll == null) {
@@ -476,13 +475,6 @@ protected PythonContext createContext(Env env) {
476475
assert areOptionsCompatible(options, PythonOptions.createEngineOptions(env)) : "invalid engine options";
477476
}
478477

479-
if (allocationReporter == null) {
480-
allocationReporter = env.lookup(AllocationReporter.class);
481-
} else {
482-
// GR-61960
483-
// assert allocationReporter == env.lookup(AllocationReporter.class);
484-
}
485-
486478
return context;
487479
}
488480

@@ -509,8 +501,15 @@ protected OptionDescriptors getOptionDescriptors() {
509501
@Override
510502
protected void initializeContext(PythonContext context) {
511503
if (!isLanguageInitialized) {
504+
if (allocationReporter == null) {
505+
allocationReporter = context.getEnv().lookup(AllocationReporter.class);
506+
} else {
507+
// GR-61960
508+
// assert allocationReporter == env.lookup(AllocationReporter.class);
509+
}
512510
initializeLanguage();
513511
}
512+
context.initializeHomeAndPrefixPaths(context.getEnv(), getLanguageHome());
514513
context.initialize();
515514
}
516515

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,8 @@ public abstract class Python3Core {
430430
private static final TruffleString T__FROZEN_IMPORTLIB_EXTERNAL = tsLiteral("_frozen_importlib_external");
431431
private static final TruffleString T__FROZEN_IMPORTLIB = tsLiteral("_frozen_importlib");
432432
private static final TruffleString T_IMPORTLIB_BOOTSTRAP = tsLiteral("importlib._bootstrap");
433-
private final TruffleString[] coreFiles;
434433

435-
private static TruffleString[] initializeCoreFiles() {
434+
private static TruffleString[] getCoreFiles() {
436435
// Order matters!
437436
List<TruffleString> coreFiles = List.of(
438437
T___GRAALPYTHON__,
@@ -450,7 +449,7 @@ private static TruffleString[] initializeCoreFiles() {
450449
return coreFiles.toArray(new TruffleString[0]);
451450
}
452451

453-
private final PythonBuiltins[] builtins;
452+
private PythonBuiltins[] builtins;
454453

455454
public static final boolean HAS_PROFILER_TOOL;
456455
static {
@@ -865,8 +864,6 @@ private static PythonBuiltins[] initializeBuiltins(TruffleLanguage.Env env) {
865864

866865
public Python3Core(PythonLanguage language, TruffleLanguage.Env env) {
867866
this.language = language;
868-
this.builtins = initializeBuiltins(env);
869-
this.coreFiles = initializeCoreFiles();
870867
}
871868

872869
@CompilerDirectives.ValueType
@@ -944,6 +941,8 @@ public final boolean isCoreInitialized() {
944941
* Load the core library and prepare all builtin classes and modules.
945942
*/
946943
public final void initialize(PythonContext context) {
944+
assert this.builtins == null;
945+
this.builtins = initializeBuiltins(context.getEnv());
947946
initializeJavaCore();
948947
initializeImportlib();
949948
context.applyModuleOptions();
@@ -1042,7 +1041,7 @@ private void initializeImportlib() {
10421041
}
10431042

10441043
private void initializePython3Core(TruffleString coreHome) {
1045-
for (TruffleString s : coreFiles) {
1044+
for (TruffleString s : getCoreFiles()) {
10461045
loadFile(s, coreHome);
10471046
}
10481047
initialized = true;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,9 +2730,12 @@ public Thread getMainThread() {
27302730
return null;
27312731
}
27322732

2733-
private int dlopenFlags = PosixConstants.RTLD_NOW.value;
2733+
private Integer dlopenFlags = null;
27342734

27352735
public int getDlopenFlags() {
2736+
if (dlopenFlags == null) {
2737+
dlopenFlags = PosixConstants.RTLD_NOW.value;
2738+
}
27362739
return dlopenFlags;
27372740
}
27382741

0 commit comments

Comments
 (0)