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

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

Issue 2638173002: Compact the symbol table when creating core snapshots or JIT app snapshots. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/symbols.h" 5 #include "vm/symbols.h"
6 6
7 #include "vm/handles.h" 7 #include "vm/handles.h"
8 #include "vm/hash_table.h" 8 #include "vm/hash_table.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 ASSERT(!symbol.IsNull()); 347 ASSERT(!symbol.IsNull());
348 bool present = unified_table.Insert(symbol); 348 bool present = unified_table.Insert(symbol);
349 ASSERT(!present); 349 ASSERT(!present);
350 } 350 }
351 table.Release(); 351 table.Release();
352 352
353 return unified_table.Release().raw(); 353 return unified_table.Release().raw();
354 } 354 }
355 355
356 356
357 #if defined(DART_PRECOMPILER)
358 void Symbols::Compact(Isolate* isolate) { 357 void Symbols::Compact(Isolate* isolate) {
359 ASSERT(isolate != Dart::vm_isolate()); 358 ASSERT(isolate != Dart::vm_isolate());
360 Zone* zone = Thread::Current()->zone(); 359 Zone* zone = Thread::Current()->zone();
361 360
362 // 1. Drop the symbol table and do a full garbage collection. 361 // 1. Drop the symbol table and do a full garbage collection.
363 isolate->object_store()->set_symbol_table(Object::empty_array()); 362 isolate->object_store()->set_symbol_table(Object::empty_array());
364 isolate->heap()->CollectAllGarbage(); 363 isolate->heap()->CollectAllGarbage();
365 364
366 // 2. Walk the heap to find surviving symbols. 365 // 2. Walk the heap to find surviving symbols.
367 GrowableArray<String*> symbols; 366 GrowableArray<String*> symbols;
(...skipping 22 matching lines...) Expand all
390 SymbolTable table(zone, array.raw()); 389 SymbolTable table(zone, array.raw());
391 for (intptr_t i = 0; i < symbols.length(); i++) { 390 for (intptr_t i = 0; i < symbols.length(); i++) {
392 String& symbol = *symbols[i]; 391 String& symbol = *symbols[i];
393 ASSERT(symbol.IsString()); 392 ASSERT(symbol.IsString());
394 ASSERT(symbol.IsCanonical()); 393 ASSERT(symbol.IsCanonical());
395 bool present = table.Insert(symbol); 394 bool present = table.Insert(symbol);
396 ASSERT(!present); 395 ASSERT(!present);
397 } 396 }
398 isolate->object_store()->set_symbol_table(table.Release()); 397 isolate->object_store()->set_symbol_table(table.Release());
399 } 398 }
400 #endif // DART_PRECOMPILER
401 399
402 400
403 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) { 401 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) {
404 ASSERT(isolate != NULL); 402 ASSERT(isolate != NULL);
405 SymbolTable table(isolate->object_store()->symbol_table()); 403 SymbolTable table(isolate->object_store()->symbol_table());
406 *size = table.NumOccupied(); 404 *size = table.NumOccupied();
407 *capacity = table.NumEntries(); 405 *capacity = table.NumEntries();
408 table.Release(); 406 table.Release();
409 } 407 }
410 408
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 693
696 694
697 RawString* Symbols::FromCharCode(Thread* thread, int32_t char_code) { 695 RawString* Symbols::FromCharCode(Thread* thread, int32_t char_code) {
698 if (char_code > kMaxOneCharCodeSymbol) { 696 if (char_code > kMaxOneCharCodeSymbol) {
699 return FromUTF32(thread, &char_code, 1); 697 return FromUTF32(thread, &char_code, 1);
700 } 698 }
701 return predefined_[char_code]; 699 return predefined_[char_code];
702 } 700 }
703 701
704 702
705 void Symbols::DumpStats() { 703 void Symbols::DumpStats(Isolate* isolate) {
706 if (FLAG_dump_symbol_stats) { 704 intptr_t size = -1;
707 intptr_t size = -1; 705 intptr_t capacity = -1;
708 intptr_t capacity = -1; 706 // First dump VM symbol table stats.
709 // First dump VM symbol table stats. 707 GetStats(Dart::vm_isolate(), &size, &capacity);
710 GetStats(Dart::vm_isolate(), &size, &capacity); 708 OS::Print("VM Isolate: Number of symbols : %" Pd "\n", size);
711 OS::Print("VM Isolate: Number of symbols : %" Pd "\n", size); 709 OS::Print("VM Isolate: Symbol table capacity : %" Pd "\n", capacity);
712 OS::Print("VM Isolate: Symbol table capacity : %" Pd "\n", capacity); 710 // Now dump regular isolate symbol table stats.
713 // Now dump regular isolate symbol table stats. 711 GetStats(isolate, &size, &capacity);
714 GetStats(Isolate::Current(), &size, &capacity); 712 OS::Print("Isolate: Number of symbols : %" Pd "\n", size);
715 OS::Print("Isolate: Number of symbols : %" Pd "\n", size); 713 OS::Print("Isolate: Symbol table capacity : %" Pd "\n", capacity);
716 OS::Print("Isolate: Symbol table capacity : %" Pd "\n", capacity); 714 // TODO(koda): Consider recording growth and collision stats in HashTable,
717 // TODO(koda): Consider recording growth and collision stats in HashTable, 715 // in DEBUG mode.
718 // in DEBUG mode.
719 }
720 } 716 }
721 717
722 718
723 intptr_t Symbols::LookupPredefinedSymbol(RawObject* obj) { 719 intptr_t Symbols::LookupPredefinedSymbol(RawObject* obj) {
724 for (intptr_t i = 1; i < Symbols::kMaxPredefinedId; i++) { 720 for (intptr_t i = 1; i < Symbols::kMaxPredefinedId; i++) {
725 if (symbol_handles_[i]->raw() == obj) { 721 if (symbol_handles_[i]->raw() == obj) {
726 return (i + kMaxPredefinedObjectIds); 722 return (i + kMaxPredefinedObjectIds);
727 } 723 }
728 } 724 }
729 return kInvalidIndex; 725 return kInvalidIndex;
730 } 726 }
731 727
732 728
733 RawObject* Symbols::GetPredefinedSymbol(intptr_t object_id) { 729 RawObject* Symbols::GetPredefinedSymbol(intptr_t object_id) {
734 ASSERT(IsPredefinedSymbolId(object_id)); 730 ASSERT(IsPredefinedSymbolId(object_id));
735 intptr_t i = (object_id - kMaxPredefinedObjectIds); 731 intptr_t i = (object_id - kMaxPredefinedObjectIds);
736 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { 732 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) {
737 return symbol_handles_[i]->raw(); 733 return symbol_handles_[i]->raw();
738 } 734 }
739 return Object::null(); 735 return Object::null();
740 } 736 }
741 737
742 } // namespace dart 738 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698