@@ -74,9 +74,10 @@ final class PolyglotFastThreadLocals {
7474 private static final FinalIntMap LANGUAGE_INDEXES = new FinalIntMap ();
7575 private static final int RESERVED_NULL = -1 ; // never set
7676 private static final int THREAD_INDEX = 0 ;
77- static final int CONTEXT_INDEX = 1 ;
78- private static final int ENCAPSULATING_NODE_REFERENCE_INDEX = 2 ;
79- private static final int LANGUAGE_START = 3 ;
77+ static final int CONTEXT_THREAD_LOCALS_INDEX = 1 ;
78+ static final int CONTEXT_INDEX = 2 ;
79+ private static final int ENCAPSULATING_NODE_REFERENCE_INDEX = 3 ;
80+ private static final int LANGUAGE_START = 4 ;
8081
8182 static final int LANGUAGE_CONTEXT_OFFSET = 0 ;
8283 static final int LANGUAGE_SPI_OFFSET = 1 ;
@@ -92,6 +93,7 @@ static Object[] createFastThreadLocals(PolyglotThreadInfo thread) {
9293 assert Thread .holdsLock (context );
9394 Object [] data = createEmptyData (thread .context .engine );
9495 data [THREAD_INDEX ] = thread ;
96+ data [CONTEXT_THREAD_LOCALS_INDEX ] = thread .contextThreadLocals ;
9597 data [CONTEXT_INDEX ] = thread .context ;
9698 data [ENCAPSULATING_NODE_REFERENCE_INDEX ] = EngineAccessor .NODES .createEncapsulatingNodeReference (thread .getThread ());
9799 for (PolyglotLanguageContext languageContext : thread .context .contexts ) {
@@ -105,6 +107,7 @@ static Object[] createFastThreadLocals(PolyglotThreadInfo thread) {
105107 private static Object [] createFastThreadLocalsForLanguage (PolyglotLanguageInstance instance ) {
106108 Object [] data = createEmptyData (instance .language .engine );
107109 data [THREAD_INDEX ] = null ; // not available if only engine is entered
110+ data [CONTEXT_THREAD_LOCALS_INDEX ] = null ; // not available if only engine is entered
108111 data [CONTEXT_INDEX ] = null ; // not available if only engine is entered
109112
110113 // we take the first language we find. should we fail maybe if there is more than one?
@@ -142,7 +145,7 @@ public static <C> ContextReference<C> createContextReference(Class<? extends Tru
142145 }
143146
144147 public static boolean needsEnter (PolyglotContextImpl context ) {
145- return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , false ) != context ;
148+ return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , false , false ) != context ;
146149 }
147150
148151 public static Object [] enter (PolyglotThreadInfo threadInfo ) {
@@ -195,33 +198,33 @@ static EncapsulatingNodeReference getEncapsulatingNodeReference(boolean invalida
195198 * instead. So we do not bother here and trade a bit smaller code for fewer deoptimizations
196199 * and less footprint (no assumptions in use).
197200 */
198- return IMPL .fastGet (ENCAPSULATING_NODE_REFERENCE_INDEX , EncapsulatingNodeReference .class , invalidateOnNull );
201+ return IMPL .fastGet (ENCAPSULATING_NODE_REFERENCE_INDEX , EncapsulatingNodeReference .class , invalidateOnNull , false );
199202 }
200203
201- public static PolyglotThreadInfo getCurrentThread (PolyglotSharingLayer layer ) {
204+ public static Object [] getCurrentThreadContextThreadLocals (PolyglotSharingLayer layer ) {
202205 if (CompilerDirectives .inCompiledCode () && layer != null ) {
203206 PolyglotContextImpl singleContext = layer .getSingleConstantContext ();
204207 if (singleContext != null && CompilerDirectives .isPartialEvaluationConstant (singleContext )) {
205208 PolyglotThreadInfo constantThread = singleContext .singleThreadValue .getConstant ();
206209 if (constantThread != null ) {
207- return constantThread ;
210+ return constantThread . getThreadLocals ( layer . engine ) ;
208211 }
209212 }
210213 }
211- return IMPL .fastGet (THREAD_INDEX , PolyglotThreadInfo .class , true );
214+ return IMPL .fastGet (CONTEXT_THREAD_LOCALS_INDEX , Object [] .class , true , true );
212215 }
213216
214- public static PolyglotThreadInfo getCurrentThreadEngine (PolyglotEngineImpl engine ) {
217+ public static Object [] getCurrentThreadContextThreadLocalsEngine (PolyglotEngineImpl engine ) {
215218 if (CompilerDirectives .inCompiledCode () && engine != null ) {
216219 PolyglotContextImpl singleContext = engine .singleContextValue .getConstant ();
217220 if (singleContext != null ) {
218221 PolyglotThreadInfo constantThread = singleContext .singleThreadValue .getConstant ();
219222 if (constantThread != null ) {
220- return constantThread ;
223+ return constantThread . getThreadLocals ( engine ) ;
221224 }
222225 }
223226 }
224- return IMPL .fastGet (THREAD_INDEX , PolyglotThreadInfo .class , true );
227+ return IMPL .fastGet (CONTEXT_THREAD_LOCALS_INDEX , Object [] .class , true , true );
225228 }
226229
227230 public static PolyglotContextImpl getContext (PolyglotSharingLayer layer ) {
@@ -231,7 +234,7 @@ public static PolyglotContextImpl getContext(PolyglotSharingLayer layer) {
231234 return value ;
232235 }
233236 }
234- return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , true );
237+ return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , true , false );
235238 }
236239
237240 public static PolyglotContextImpl getContextWithEngine (PolyglotEngineImpl engine ) {
@@ -241,7 +244,7 @@ public static PolyglotContextImpl getContextWithEngine(PolyglotEngineImpl engine
241244 return context ;
242245 }
243246 }
244- return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , true );
247+ return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , true , false );
245248 }
246249
247250 public static PolyglotContextImpl getContextWithNode (Node node ) {
@@ -251,7 +254,7 @@ public static PolyglotContextImpl getContextWithNode(Node node) {
251254 return layer .getSingleConstantContext ();
252255 }
253256 }
254- return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , true );
257+ return IMPL .fastGet (CONTEXT_INDEX , PolyglotContextImpl .class , true , false );
255258 }
256259
257260 @ SuppressWarnings ("unchecked" )
@@ -263,7 +266,7 @@ public static TruffleLanguage<Object> getLanguage(Node node, int index, Class<?>
263266 return instance .spi ;
264267 }
265268 }
266- return (TruffleLanguage <Object >) IMPL .fastGet (index , languageClass , true );
269+ return (TruffleLanguage <Object >) IMPL .fastGet (index , languageClass , true , false );
267270 }
268271
269272 public static Object getLanguageContext (Node node , int index ) {
@@ -279,7 +282,7 @@ public static Object getLanguageContext(Node node, int index) {
279282 }
280283 contextClass = findContextClass (node , index );
281284 }
282- return IMPL .fastGet (index , contextClass , true );
285+ return IMPL .fastGet (index , contextClass , true , false );
283286 }
284287
285288 private static boolean validSharing (Node node ) {
0 commit comments