Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: runtime/vm/isolate_reload.cc

Issue 2126393003: Cache compile-time constants on the script object, sometimes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: cleanups Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/isolate_reload.h" 5 #include "vm/isolate_reload.h"
6 6
7 #include "vm/become.h" 7 #include "vm/become.h"
8 #include "vm/code_generator.h" 8 #include "vm/code_generator.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 : start_time_micros_(OS::GetCurrentMonotonicMicros()), 177 : start_time_micros_(OS::GetCurrentMonotonicMicros()),
178 isolate_(isolate), 178 isolate_(isolate),
179 test_mode_(test_mode), 179 test_mode_(test_mode),
180 has_error_(false), 180 has_error_(false),
181 saved_num_cids_(-1), 181 saved_num_cids_(-1),
182 saved_class_table_(NULL), 182 saved_class_table_(NULL),
183 num_saved_libs_(-1), 183 num_saved_libs_(-1),
184 script_uri_(String::null()), 184 script_uri_(String::null()),
185 error_(Error::null()), 185 error_(Error::null()),
186 clean_scripts_set_storage_(Array::null()), 186 clean_scripts_set_storage_(Array::null()),
187 compile_time_constants_(Array::null()),
188 old_classes_set_storage_(Array::null()), 187 old_classes_set_storage_(Array::null()),
189 class_map_storage_(Array::null()), 188 class_map_storage_(Array::null()),
190 old_libraries_set_storage_(Array::null()), 189 old_libraries_set_storage_(Array::null()),
191 library_map_storage_(Array::null()), 190 library_map_storage_(Array::null()),
192 become_map_storage_(Array::null()), 191 become_map_storage_(Array::null()),
193 saved_root_library_(Library::null()), 192 saved_root_library_(Library::null()),
194 saved_libraries_(GrowableObjectArray::null()) { 193 saved_libraries_(GrowableObjectArray::null()) {
195 // Preallocate storage for maps. 194 // Preallocate storage for maps.
196 clean_scripts_set_storage_ = 195 clean_scripts_set_storage_ =
197 HashTables::New<UnorderedHashSet<ScriptUrlSetTraits> >(4); 196 HashTables::New<UnorderedHashSet<ScriptUrlSetTraits> >(4);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 ASSERT(!script_url.IsNull()); 499 ASSERT(!script_url.IsNull());
501 bool already_present = clean_scripts_set.Insert(script_url); 500 bool already_present = clean_scripts_set.Insert(script_url);
502 ASSERT(!already_present); 501 ASSERT(!already_present);
503 } 502 }
504 } 503 }
505 504
506 clean_scripts_set_storage_ = clean_scripts_set.Release().raw(); 505 clean_scripts_set_storage_ = clean_scripts_set.Release().raw();
507 } 506 }
508 507
509 508
510 void IsolateReloadContext::FilterCompileTimeConstants() {
511 // Save the compile time constants array.
512 compile_time_constants_ = I->object_store()->compile_time_constants();
513 // Clear the compile time constants array. This will be repopulated
514 // in the loop below.
515 I->object_store()->set_compile_time_constants(Array::Handle());
516
517 if (compile_time_constants_ == Array::null()) {
518 // Nothing to do.
519 return;
520 }
521
522 // Iterate over the saved compile time constants map.
523 ConstantsMap old_constants(compile_time_constants_);
524 ConstantsMap::Iterator it(&old_constants);
525
526 Array& key = Array::Handle();
527 String& url = String::Handle();
528 Smi& token_pos = Smi::Handle();
529 Instance& value = Instance::Handle();
530
531 // We filter the compile time constants map so that after it only contains
532 // constants from scripts contained in this set.
533 UnorderedHashSet<ScriptUrlSetTraits>
534 clean_scripts_set(clean_scripts_set_storage_);
535
536 while (it.MoveNext()) {
537 const intptr_t entry = it.Current();
538 ASSERT(entry != -1);
539 key = Array::RawCast(old_constants.GetKey(entry));
540 ASSERT(!key.IsNull());
541 url = String::RawCast(key.At(0));
542 ASSERT(!url.IsNull());
543 if (clean_scripts_set.ContainsKey(url)) {
544 // We've found a cached constant from a clean script, add it to the
545 // compile time constants map again.
546 token_pos = Smi::RawCast(key.At(1));
547 TokenPosition tp(token_pos.Value());
548 // Use ^= because this might be null.
549 value ^= old_constants.GetPayload(entry, 0);
550 Parser::InsertCachedConstantValue(url, tp, value);
551 }
552 }
553
554 old_constants.Release();
555 clean_scripts_set.Release();
556 }
557
558
559 // While reloading everything we do must be reversible so that we can abort 509 // While reloading everything we do must be reversible so that we can abort
560 // safely if the reload fails. This function stashes things to the side and 510 // safely if the reload fails. This function stashes things to the side and
561 // prepares the isolate for the reload attempt. 511 // prepares the isolate for the reload attempt.
562 void IsolateReloadContext::Checkpoint() { 512 void IsolateReloadContext::Checkpoint() {
563 TIMELINE_SCOPE(Checkpoint); 513 TIMELINE_SCOPE(Checkpoint);
564 CheckpointClasses(); 514 CheckpointClasses();
565 CheckpointLibraries(); 515 CheckpointLibraries();
566 BuildCleanScriptSet(); 516 BuildCleanScriptSet();
567 FilterCompileTimeConstants();
568 } 517 }
569 518
570 519
571 void IsolateReloadContext::RollbackClasses() { 520 void IsolateReloadContext::RollbackClasses() {
572 TIR_Print("---- ROLLING BACK CLASS TABLE\n"); 521 TIR_Print("---- ROLLING BACK CLASS TABLE\n");
573 ASSERT(saved_num_cids_ > 0); 522 ASSERT(saved_num_cids_ > 0);
574 ASSERT(saved_class_table_ != NULL); 523 ASSERT(saved_class_table_ != NULL);
575 ClassTable* class_table = I->class_table(); 524 ClassTable* class_table = I->class_table();
576 class_table->SetNumCids(saved_num_cids_); 525 class_table->SetNumCids(saved_num_cids_);
577 // Overwrite classes in class table with the saved classes. 526 // Overwrite classes in class table with the saved classes.
(...skipping 29 matching lines...) Expand all
607 if (!saved_root_lib.IsNull()) { 556 if (!saved_root_lib.IsNull()) {
608 object_store()->set_root_library(saved_root_lib); 557 object_store()->set_root_library(saved_root_lib);
609 } 558 }
610 559
611 set_saved_root_library(Library::Handle()); 560 set_saved_root_library(Library::Handle());
612 set_saved_libraries(GrowableObjectArray::Handle()); 561 set_saved_libraries(GrowableObjectArray::Handle());
613 } 562 }
614 563
615 564
616 void IsolateReloadContext::Rollback() { 565 void IsolateReloadContext::Rollback() {
617 I->object_store()->set_compile_time_constants(
618 Array::Handle(compile_time_constants_));
619 RollbackClasses(); 566 RollbackClasses();
620 RollbackLibraries(); 567 RollbackLibraries();
621 } 568 }
622 569
623 570
624 #ifdef DEBUG 571 #ifdef DEBUG
625 void IsolateReloadContext::VerifyMaps() { 572 void IsolateReloadContext::VerifyMaps() {
626 TIMELINE_SCOPE(VerifyMaps); 573 TIMELINE_SCOPE(VerifyMaps);
627 Class& cls = Class::Handle(); 574 Class& cls = Class::Handle();
628 Class& new_cls = Class::Handle(); 575 Class& new_cls = Class::Handle();
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 ASSERT(!super_cls.IsNull()); 1105 ASSERT(!super_cls.IsNull());
1159 super_cls.AddDirectSubclass(cls); 1106 super_cls.AddDirectSubclass(cls);
1160 } 1107 }
1161 } 1108 }
1162 } 1109 }
1163 } 1110 }
1164 1111
1165 #endif // !PRODUCT 1112 #endif // !PRODUCT
1166 1113
1167 } // namespace dart 1114 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698