@@ -69,7 +69,7 @@ public final class IsBuiltinClassProfile {
69
69
// context case, we just cache all classes, in the multi-context case, we
70
70
// only cache classes if they are builtin types that are shared across
71
71
// contexts.
72
- private final Assumption singleContextAssumption = PythonLanguage . getCurrent (). singleContextAssumption ;
72
+ private final Assumption singleContextAssumption ;
73
73
private static final int CLASS_CACHE_SIZE = 3 ;
74
74
@ CompilationFinal (dimensions = 1 ) private ClassCache [] classCache = new ClassCache [CLASS_CACHE_SIZE ];
75
75
@ CompilationFinal private boolean cacheUsedInSingleContext = false ;
@@ -84,17 +84,18 @@ private static final class ClassCache {
84
84
}
85
85
}
86
86
87
- private static final IsBuiltinClassProfile UNCACHED = new IsBuiltinClassProfile ();
87
+ private static final IsBuiltinClassProfile UNCACHED = new IsBuiltinClassProfile (null );
88
88
static {
89
89
UNCACHED .classCache = null ;
90
90
}
91
91
92
- private IsBuiltinClassProfile () {
93
- // private constructor
92
+ /* private constructor */
93
+ private IsBuiltinClassProfile (Assumption singleContextAssumption ) {
94
+ this .singleContextAssumption = singleContextAssumption ;
94
95
}
95
96
96
97
public static IsBuiltinClassProfile create () {
97
- return new IsBuiltinClassProfile ();
98
+ return new IsBuiltinClassProfile (PythonLanguage . getCurrent (). singleContextAssumption );
98
99
}
99
100
100
101
public static IsBuiltinClassProfile getUncached () {
@@ -105,7 +106,7 @@ public static IsBuiltinClassProfile getUncached() {
105
106
private LazyPythonClass getLazyPythonClass (PythonObject object ) {
106
107
if (classCache != null ) {
107
108
// we're still caching
108
- if (!singleContextAssumption .isValid () && cacheUsedInSingleContext ) {
109
+ if (!( singleContextAssumption != null && singleContextAssumption .isValid () ) && cacheUsedInSingleContext ) {
109
110
// we previously used this cache in a single context, now we're
110
111
// in a multi-context mode. Reset the cache.
111
112
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -120,7 +121,7 @@ private LazyPythonClass getLazyPythonClass(PythonObject object) {
120
121
LazyPythonClass klass = PythonObject .getLazyPythonClass (shape .getObjectType ());
121
122
if (klass instanceof PythonBuiltinClassType ) {
122
123
classCache [i ] = new ClassCache (shape , klass );
123
- } else if (singleContextAssumption .isValid ()) {
124
+ } else if (singleContextAssumption != null && singleContextAssumption .isValid ()) {
124
125
// we're caching a non-builtin type, so if we switch to
125
126
// a multi-context, the cache needs to be flushed.
126
127
cacheUsedInSingleContext = true ;
0 commit comments