Skip to content

Commit ca439ce

Browse files
fangereransalond
authored andcommitted
Fix: Do not use singleContextAssumption in a static instance.
(cherry picked from commit 1f663e9)
1 parent e21558e commit ca439ce

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsBuiltinClassProfile.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public final class IsBuiltinClassProfile {
6969
// context case, we just cache all classes, in the multi-context case, we
7070
// only cache classes if they are builtin types that are shared across
7171
// contexts.
72-
private final Assumption singleContextAssumption = PythonLanguage.getCurrent().singleContextAssumption;
72+
private final Assumption singleContextAssumption;
7373
private static final int CLASS_CACHE_SIZE = 3;
7474
@CompilationFinal(dimensions = 1) private ClassCache[] classCache = new ClassCache[CLASS_CACHE_SIZE];
7575
@CompilationFinal private boolean cacheUsedInSingleContext = false;
@@ -84,17 +84,18 @@ private static final class ClassCache {
8484
}
8585
}
8686

87-
private static final IsBuiltinClassProfile UNCACHED = new IsBuiltinClassProfile();
87+
private static final IsBuiltinClassProfile UNCACHED = new IsBuiltinClassProfile(null);
8888
static {
8989
UNCACHED.classCache = null;
9090
}
9191

92-
private IsBuiltinClassProfile() {
93-
// private constructor
92+
/* private constructor */
93+
private IsBuiltinClassProfile(Assumption singleContextAssumption) {
94+
this.singleContextAssumption = singleContextAssumption;
9495
}
9596

9697
public static IsBuiltinClassProfile create() {
97-
return new IsBuiltinClassProfile();
98+
return new IsBuiltinClassProfile(PythonLanguage.getCurrent().singleContextAssumption);
9899
}
99100

100101
public static IsBuiltinClassProfile getUncached() {
@@ -105,7 +106,7 @@ public static IsBuiltinClassProfile getUncached() {
105106
private LazyPythonClass getLazyPythonClass(PythonObject object) {
106107
if (classCache != null) {
107108
// we're still caching
108-
if (!singleContextAssumption.isValid() && cacheUsedInSingleContext) {
109+
if (!(singleContextAssumption != null && singleContextAssumption.isValid()) && cacheUsedInSingleContext) {
109110
// we previously used this cache in a single context, now we're
110111
// in a multi-context mode. Reset the cache.
111112
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -120,7 +121,7 @@ private LazyPythonClass getLazyPythonClass(PythonObject object) {
120121
LazyPythonClass klass = PythonObject.getLazyPythonClass(shape.getObjectType());
121122
if (klass instanceof PythonBuiltinClassType) {
122123
classCache[i] = new ClassCache(shape, klass);
123-
} else if (singleContextAssumption.isValid()) {
124+
} else if (singleContextAssumption != null && singleContextAssumption.isValid()) {
124125
// we're caching a non-builtin type, so if we switch to
125126
// a multi-context, the cache needs to be flushed.
126127
cacheUsedInSingleContext = true;

0 commit comments

Comments
 (0)