@@ -1279,79 +1279,70 @@ DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 0, 2) {
12791279}
12801280
12811281static void EnsureThreadLocalsTableExistsAndBigEnough (Thread* thread,
1282- intptr_t index) {
1283- GrowableObjectArray& locals =
1284- GrowableObjectArray::Handle (thread->thread_locals ());
1285- if (locals.IsNull ()) {
1286- locals = GrowableObjectArray::New ();
1287- thread->set_thread_locals (locals);
1288- }
1289- if (index >= locals.Length ()) {
1290- locals.Grow (index + 1 );
1291- intptr_t old_length = locals.Length ();
1292- locals.SetLength (locals.Capacity ());
1293- for (intptr_t i = old_length; i < locals.Capacity (); i++) {
1294- locals.SetAt (i, Object::sentinel ());
1282+ intptr_t id) {
1283+ Array& locals = Array::Handle (thread->thread_locals ());
1284+ if (id >= locals.Length ()) {
1285+ intptr_t new_length = id + 1 ;
1286+ const Array& new_array =
1287+ Array::Handle (Array::Grow (locals, new_length, Heap::kOld ));
1288+ for (intptr_t i = locals.Length (); i < new_length; i++) {
1289+ new_array.SetAt (i, Object::sentinel ());
12951290 }
1291+ thread->set_thread_locals (new_array);
12961292 }
12971293}
12981294
1299- DEFINE_NATIVE_ENTRY (ScopedThreadLocal_allocateId , 0 , 0 ) {
1295+ DEFINE_NATIVE_ENTRY (ThreadLocal_allocateId , 0 , 0 ) {
13001296 auto isolate_group = thread->isolate_group ();
1301- isolate_group->increment_scoped_thread_locals_count ();
1302- intptr_t new_index = isolate_group->scoped_thread_locals_count () - 1 ;
1297+ isolate_group->increment_thread_locals_count ();
1298+ intptr_t new_index = isolate_group->thread_locals_count () - 1 ;
13031299 EnsureThreadLocalsTableExistsAndBigEnough (thread, new_index);
1304- GrowableObjectArray& locals =
1305- GrowableObjectArray::Handle (thread->thread_locals ());
1300+ Array& locals = Array::Handle (thread->thread_locals ());
13061301 locals.SetAt (new_index, Object::sentinel ());
13071302 return Integer::New (new_index);
13081303}
13091304
13101305static void ValidateScopedThreadLocalId (Thread* thread, intptr_t id) {
1311- if (id < 0 || id >= thread->isolate_group ()->scoped_thread_locals_count ()) {
1306+ if (id < 0 || id >= thread->isolate_group ()->thread_locals_count ()) {
13121307 const String& msg = String::Handle (String::New (" Invalid local id." ));
13131308 Exceptions::ThrowStateError (msg);
13141309 UNREACHABLE ();
13151310 }
13161311 EnsureThreadLocalsTableExistsAndBigEnough (thread, id);
13171312}
13181313
1319- DEFINE_NATIVE_ENTRY (ScopedThreadLocal_hasValue , 0 , 1 ) {
1314+ DEFINE_NATIVE_ENTRY (ThreadLocal_hasValue , 0 , 1 ) {
13201315 GET_NON_NULL_NATIVE_ARGUMENT (Integer, id_obj, arguments->NativeArgAt (0 ));
13211316 intptr_t id = id_obj.Value ();
13221317 ValidateScopedThreadLocalId (thread, id);
1323- GrowableObjectArray& locals =
1324- GrowableObjectArray::Handle (thread->thread_locals ());
1318+ Array& locals = Array::Handle (thread->thread_locals ());
13251319 return locals.At (id) == Object::sentinel ().ptr () ? Bool::False ().ptr ()
13261320 : Bool::True ().ptr ();
13271321}
13281322
1329- DEFINE_NATIVE_ENTRY (ScopedThreadLocal_getValue , 0 , 1 ) {
1323+ DEFINE_NATIVE_ENTRY (ThreadLocal_getValue , 0 , 1 ) {
13301324 GET_NON_NULL_NATIVE_ARGUMENT (Integer, id_obj, arguments->NativeArgAt (0 ));
13311325 intptr_t id = id_obj.Value ();
13321326 ValidateScopedThreadLocalId (thread, id);
1333- GrowableObjectArray& locals =
1334- GrowableObjectArray::Handle (thread->thread_locals ());
1327+ Array& locals = Array::Handle (thread->thread_locals ());
13351328 return locals.At (id);
13361329}
13371330
1338- DEFINE_NATIVE_ENTRY (ScopedThreadLocal_setValue , 0 , 2 ) {
1331+ DEFINE_NATIVE_ENTRY (ThreadLocal_setValue , 0 , 2 ) {
13391332 GET_NON_NULL_NATIVE_ARGUMENT (Integer, id_obj, arguments->NativeArgAt (0 ));
13401333 intptr_t id = id_obj.Value ();
13411334 ValidateScopedThreadLocalId (thread, id);
13421335 GET_NON_NULL_NATIVE_ARGUMENT (Instance, value, arguments->NativeArgAt (1 ));
1343- GrowableObjectArray& locals =
1344- GrowableObjectArray::Handle (thread->thread_locals ());
1336+ Array& locals = Array::Handle (thread->thread_locals ());
13451337 locals.SetAt (id, value);
13461338 return Object::null ();
13471339}
13481340
1349- DEFINE_NATIVE_ENTRY (ScopedThreadLocal_clearValue , 0 , 1 ) {
1341+ DEFINE_NATIVE_ENTRY (ThreadLocal_clearValue , 0 , 1 ) {
13501342 GET_NON_NULL_NATIVE_ARGUMENT (Integer, id_obj, arguments->NativeArgAt (0 ));
13511343 intptr_t id = id_obj.Value ();
13521344 ValidateScopedThreadLocalId (thread, id);
1353- GrowableObjectArray& locals =
1354- GrowableObjectArray::Handle (thread->thread_locals ());
1345+ Array& locals = Array::Handle (thread->thread_locals ());
13551346 locals.SetAt (id, Object::sentinel ());
13561347 return Object::null ();
13571348}
0 commit comments