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

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

Issue 1944213002: Support for taking full snapshots from 'dart', not just 'dart_bootstrap'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
« runtime/vm/snapshot.cc ('K') | « 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/handles_impl.h" 8 #include "vm/handles_impl.h"
9 #include "vm/hash_table.h" 9 #include "vm/hash_table.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 ASSERT(str->HasHash()); 300 ASSERT(str->HasHash());
301 ASSERT(str->IsCanonical()); 301 ASSERT(str->IsCanonical());
302 predefined_[c] = str->raw(); 302 predefined_[c] = str->raw();
303 symbol_handles_[idx] = str; 303 symbol_handles_[idx] = str;
304 } 304 }
305 305
306 vm_isolate->object_store()->set_symbol_table(table.Release()); 306 vm_isolate->object_store()->set_symbol_table(table.Release());
307 } 307 }
308 308
309 309
310 void Symbols::AddPredefinedSymbolsToIsolate() {
311 // Should only be run by regular Dart isolates.
312 Thread* thread = Thread::Current();
313 Isolate* isolate = thread->isolate();
314 Zone* zone = thread->zone();
315 ASSERT(isolate != Dart::vm_isolate());
316 String& str = String::Handle(zone);
317
318 SymbolTable table(zone, isolate->object_store()->symbol_table());
319
320 // Set up all the predefined string symbols and create symbols for
321 // language keywords.
322 for (intptr_t i = 1; i < Symbols::kNullCharId; i++) {
323 str = OneByteString::New(names[i], Heap::kOld);
324 str.Hash();
325 str ^= table.InsertOrGet(str);
326 str.SetCanonical(); // Make canonical once entered.
327 }
328
329 // Add Latin1 characters as Symbols, so that Symbols::FromCharCode is fast.
330 for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) {
331 intptr_t idx = (kNullCharId + c);
332 ASSERT(idx < kMaxPredefinedId);
333 ASSERT(Utf::IsLatin1(c));
334 uint8_t ch = static_cast<uint8_t>(c);
335 str = OneByteString::New(&ch, 1, Heap::kOld);
336 str.Hash();
337 str ^= table.InsertOrGet(str);
338 str.SetCanonical(); // Make canonical once entered.
339 }
340
341 isolate->object_store()->set_symbol_table(table.Release());
342 }
343
344
345 void Symbols::SetupSymbolTable(Isolate* isolate) { 310 void Symbols::SetupSymbolTable(Isolate* isolate) {
346 ASSERT(isolate != NULL); 311 ASSERT(isolate != NULL);
347 312
348 // Setup the symbol table used within the String class. 313 // Setup the symbol table used within the String class.
349 const intptr_t initial_size = (isolate == Dart::vm_isolate()) ? 314 const intptr_t initial_size = (isolate == Dart::vm_isolate()) ?
350 kInitialVMIsolateSymtabSize : kInitialSymtabSize; 315 kInitialVMIsolateSymtabSize : kInitialSymtabSize;
351 Array& array = 316 Array& array =
352 Array::Handle(HashTables::New<SymbolTable>(initial_size, Heap::kOld)); 317 Array::Handle(HashTables::New<SymbolTable>(initial_size, Heap::kOld));
353 isolate->object_store()->set_symbol_table(array); 318 isolate->object_store()->set_symbol_table(array);
354 } 319 }
355 320
356 321
322 RawArray* Symbols::UnifiedSymbolTable() {
siva 2016/05/05 00:50:05 ASSERT that this should only be called by the muta
rmacnak 2016/05/05 20:40:57 Done.
323 Thread* thread = Thread::Current();
324 Isolate* isolate = thread->isolate();
325 Zone* zone = thread->zone();
326 SymbolTable vm_table(zone,
327 Dart::vm_isolate()->object_store()->symbol_table());
328 SymbolTable table(zone, isolate->object_store()->symbol_table());
329 intptr_t unified_size = vm_table.NumOccupied() + table.NumOccupied();
330 SymbolTable unified_table(zone, HashTables::New<SymbolTable>(unified_size,
331 Heap::kOld));
332 String& symbol = String::Handle(zone);
333
334 SymbolTable::Iterator vm_iter(&vm_table);
335 while (vm_iter.MoveNext()) {
336 symbol ^= vm_table.GetKey(vm_iter.Current());
337 ASSERT(!symbol.IsNull());
338 bool present = unified_table.Insert(symbol);
339 ASSERT(!present);
340 }
341 vm_table.Release();
342
343 SymbolTable::Iterator iter(&table);
344 while (iter.MoveNext()) {
345 symbol ^= table.GetKey(iter.Current());
346 ASSERT(!symbol.IsNull());
347 bool present = unified_table.Insert(symbol);
348 ASSERT(!present);
349 }
350 table.Release();
351
352 return unified_table.Release().raw();
353 }
354
355
356 #if defined(DART_PRECOMPILER)
357 intptr_t Symbols::Compact(Isolate* isolate) { 357 intptr_t Symbols::Compact(Isolate* isolate) {
358 ASSERT(isolate != Dart::vm_isolate()); 358 ASSERT(isolate != Dart::vm_isolate());
359 359
360 Zone* zone = Thread::Current()->zone(); 360 Zone* zone = Thread::Current()->zone();
361 intptr_t initial_size = -1; 361 intptr_t initial_size = -1;
362 intptr_t final_size = -1; 362 intptr_t final_size = -1;
363 363
364 // 1. Build a collection of all the predefined symbols so they are
365 // strongly referenced (the read only handles are not traced).
366 { 364 {
367 SymbolTable table(zone, isolate->object_store()->symbol_table()); 365 SymbolTable table(zone, isolate->object_store()->symbol_table());
368 initial_size = table.NumOccupied(); 366 initial_size = table.NumOccupied();
369
370 if (Object::vm_isolate_snapshot_object_table().Length() == 0) {
371 GrowableObjectArray& predefined_symbols = GrowableObjectArray::Handle(
372 GrowableObjectArray::New(kMaxPredefinedId));
373 String& symbol = String::Handle();
374 for (intptr_t i = 1; i < Symbols::kNullCharId; i++) {
375 const unsigned char* name =
376 reinterpret_cast<const unsigned char*>(names[i]);
377 symbol ^= table.GetOrNull(Latin1Array(name, strlen(names[i])));
378 ASSERT(!symbol.IsNull());
379 predefined_symbols.Add(symbol);
380 }
381 for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) {
382 intptr_t idx = (kNullCharId + c);
383 ASSERT(idx < kMaxPredefinedId);
384 ASSERT(Utf::IsLatin1(c));
385 uint8_t ch = static_cast<uint8_t>(c);
386 symbol ^= table.GetOrNull(Latin1Array(&ch, 1));
387 ASSERT(!symbol.IsNull());
388 predefined_symbols.Add(symbol);
389 }
390 }
391 table.Release(); 367 table.Release();
392 } 368 }
siva 2016/05/05 00:50:05 This size computation seems to be needed only if F
rmacnak 2016/05/05 20:40:57 Pushed to precompiler.cc
393 369
394 // 2. Knock out the symbol table and do a full garbage collection. 370 // 1. Drop the symbol table and do a full garbage collection.
395 isolate->object_store()->set_symbol_table(Object::empty_array()); 371 isolate->object_store()->set_symbol_table(Object::empty_array());
396 isolate->heap()->CollectAllGarbage(); 372 isolate->heap()->CollectAllGarbage();
397 373
398 // 3. Walk the heap and build a new table from surviving symbols. 374 // 2. Walk the heap to find surviving symbols.
399 GrowableArray<String*> symbols; 375 GrowableArray<String*> symbols;
400 class SymbolCollector : public ObjectVisitor { 376 class SymbolCollector : public ObjectVisitor {
401 public: 377 public:
402 SymbolCollector(Thread* thread, 378 SymbolCollector(Thread* thread,
403 GrowableArray<String*>* symbols) 379 GrowableArray<String*>* symbols)
404 : symbols_(symbols), 380 : symbols_(symbols),
405 zone_(thread->zone()) {} 381 zone_(thread->zone()) {}
406 382
407 void VisitObject(RawObject* obj) { 383 void VisitObject(RawObject* obj) {
408 if (obj->IsString() && obj->IsCanonical()) { 384 if (obj->IsString() && obj->IsCanonical()) {
409 symbols_->Add(&String::ZoneHandle(zone_, String::RawCast(obj))); 385 symbols_->Add(&String::ZoneHandle(zone_, String::RawCast(obj)));
410 } 386 }
411 } 387 }
412 388
413 private: 389 private:
414 GrowableArray<String*>* symbols_; 390 GrowableArray<String*>* symbols_;
415 Zone* zone_; 391 Zone* zone_;
416 }; 392 };
417 393
418 SymbolCollector visitor(Thread::Current(), &symbols); 394 SymbolCollector visitor(Thread::Current(), &symbols);
419 isolate->heap()->IterateObjects(&visitor); 395 isolate->heap()->IterateObjects(&visitor);
420 396
397 // 3. Build a new table from the surviving symbols.
421 { 398 {
422 Array& array = 399 Array& array =
423 Array::Handle(HashTables::New<SymbolTable>(symbols.length() * 4 / 3, 400 Array::Handle(HashTables::New<SymbolTable>(symbols.length() * 4 / 3,
424 Heap::kOld)); 401 Heap::kOld));
425 SymbolTable table(zone, array.raw()); 402 SymbolTable table(zone, array.raw());
426 for (intptr_t i = 0; i < symbols.length(); i++) { 403 for (intptr_t i = 0; i < symbols.length(); i++) {
427 String& symbol = *symbols[i]; 404 String& symbol = *symbols[i];
428 ASSERT(symbol.IsString()); 405 ASSERT(symbol.IsString());
429 ASSERT(symbol.IsCanonical()); 406 ASSERT(symbol.IsCanonical());
430 bool present = table.Insert(symbol); 407 bool present = table.Insert(symbol);
431 ASSERT(!present); 408 ASSERT(!present);
432 } 409 }
410 isolate->object_store()->set_symbol_table(table.Release());
411 }
412
413 {
414 SymbolTable table(zone, isolate->object_store()->symbol_table());
433 final_size = table.NumOccupied(); 415 final_size = table.NumOccupied();
434 isolate->object_store()->set_symbol_table(table.Release()); 416 table.Release();
435 } 417 }
siva 2016/05/05 00:50:05 Ditto comment about this size computation, probabl
436 418
437 return initial_size - final_size; 419 return initial_size - final_size;
438 } 420 }
421 #endif // DART_PRECOMPILER
439 422
440 423
441 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) { 424 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) {
442 ASSERT(isolate != NULL); 425 ASSERT(isolate != NULL);
443 SymbolTable table(isolate->object_store()->symbol_table()); 426 SymbolTable table(isolate->object_store()->symbol_table());
444 *size = table.NumOccupied(); 427 *size = table.NumOccupied();
445 *capacity = table.NumEntries(); 428 *capacity = table.NumEntries();
446 table.Release(); 429 table.Release();
447 } 430 }
448 431
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 table.Release(); 631 table.Release();
649 } 632 }
650 if (symbol.IsNull()) { 633 if (symbol.IsNull()) {
651 Isolate* isolate = thread->isolate(); 634 Isolate* isolate = thread->isolate();
652 SafepointMutexLocker ml(isolate->symbols_mutex()); 635 SafepointMutexLocker ml(isolate->symbols_mutex());
653 data ^= isolate->object_store()->symbol_table(); 636 data ^= isolate->object_store()->symbol_table();
654 SymbolTable table(&key, &value, &data); 637 SymbolTable table(&key, &value, &data);
655 symbol ^= table.GetOrNull(str); 638 symbol ^= table.GetOrNull(str);
656 table.Release(); 639 table.Release();
657 } 640 }
658
659 ASSERT(symbol.IsNull() || symbol.IsSymbol()); 641 ASSERT(symbol.IsNull() || symbol.IsSymbol());
660 ASSERT(symbol.IsNull() || symbol.HasHash()); 642 ASSERT(symbol.IsNull() || symbol.HasHash());
661 return symbol.raw(); 643 return symbol.raw();
662 } 644 }
663 645
664 646
665 RawString* Symbols::LookupFromConcat( 647 RawString* Symbols::LookupFromConcat(
666 Thread* thread, const String& str1, const String& str2) { 648 Thread* thread, const String& str1, const String& str2) {
667 if (str1.Length() == 0) { 649 if (str1.Length() == 0) {
668 return Lookup(thread, str2); 650 return Lookup(thread, str2);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 753 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
772 ASSERT(IsVMSymbolId(object_id)); 754 ASSERT(IsVMSymbolId(object_id));
773 intptr_t i = (object_id - kMaxPredefinedObjectIds); 755 intptr_t i = (object_id - kMaxPredefinedObjectIds);
774 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { 756 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) {
775 return symbol_handles_[i]->raw(); 757 return symbol_handles_[i]->raw();
776 } 758 }
777 return Object::null(); 759 return Object::null();
778 } 760 }
779 761
780 } // namespace dart 762 } // namespace dart
OLDNEW
« runtime/vm/snapshot.cc ('K') | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698