Index: runtime/vm/symbols.cc |
diff --git a/runtime/vm/symbols.cc b/runtime/vm/symbols.cc |
index a138437c23d4e3739df28e0f96bb4b2f530df4e5..4147abb68bb0f6638c45e938dcebb0229c57c8d9 100644 |
--- a/runtime/vm/symbols.cc |
+++ b/runtime/vm/symbols.cc |
@@ -307,41 +307,6 @@ void Symbols::InitOnceFromSnapshot(Isolate* vm_isolate) { |
} |
-void Symbols::AddPredefinedSymbolsToIsolate() { |
- // Should only be run by regular Dart isolates. |
- Thread* thread = Thread::Current(); |
- Isolate* isolate = thread->isolate(); |
- Zone* zone = thread->zone(); |
- ASSERT(isolate != Dart::vm_isolate()); |
- String& str = String::Handle(zone); |
- |
- SymbolTable table(zone, isolate->object_store()->symbol_table()); |
- |
- // Set up all the predefined string symbols and create symbols for |
- // language keywords. |
- for (intptr_t i = 1; i < Symbols::kNullCharId; i++) { |
- str = OneByteString::New(names[i], Heap::kOld); |
- str.Hash(); |
- str ^= table.InsertOrGet(str); |
- str.SetCanonical(); // Make canonical once entered. |
- } |
- |
- // Add Latin1 characters as Symbols, so that Symbols::FromCharCode is fast. |
- for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) { |
- intptr_t idx = (kNullCharId + c); |
- ASSERT(idx < kMaxPredefinedId); |
- ASSERT(Utf::IsLatin1(c)); |
- uint8_t ch = static_cast<uint8_t>(c); |
- str = OneByteString::New(&ch, 1, Heap::kOld); |
- str.Hash(); |
- str ^= table.InsertOrGet(str); |
- str.SetCanonical(); // Make canonical once entered. |
- } |
- |
- isolate->object_store()->set_symbol_table(table.Release()); |
-} |
- |
- |
void Symbols::SetupSymbolTable(Isolate* isolate) { |
ASSERT(isolate != NULL); |
@@ -354,6 +319,41 @@ void Symbols::SetupSymbolTable(Isolate* isolate) { |
} |
+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.
|
+ Thread* thread = Thread::Current(); |
+ Isolate* isolate = thread->isolate(); |
+ Zone* zone = thread->zone(); |
+ SymbolTable vm_table(zone, |
+ Dart::vm_isolate()->object_store()->symbol_table()); |
+ SymbolTable table(zone, isolate->object_store()->symbol_table()); |
+ intptr_t unified_size = vm_table.NumOccupied() + table.NumOccupied(); |
+ SymbolTable unified_table(zone, HashTables::New<SymbolTable>(unified_size, |
+ Heap::kOld)); |
+ String& symbol = String::Handle(zone); |
+ |
+ SymbolTable::Iterator vm_iter(&vm_table); |
+ while (vm_iter.MoveNext()) { |
+ symbol ^= vm_table.GetKey(vm_iter.Current()); |
+ ASSERT(!symbol.IsNull()); |
+ bool present = unified_table.Insert(symbol); |
+ ASSERT(!present); |
+ } |
+ vm_table.Release(); |
+ |
+ SymbolTable::Iterator iter(&table); |
+ while (iter.MoveNext()) { |
+ symbol ^= table.GetKey(iter.Current()); |
+ ASSERT(!symbol.IsNull()); |
+ bool present = unified_table.Insert(symbol); |
+ ASSERT(!present); |
+ } |
+ table.Release(); |
+ |
+ return unified_table.Release().raw(); |
+} |
+ |
+ |
+#if defined(DART_PRECOMPILER) |
intptr_t Symbols::Compact(Isolate* isolate) { |
ASSERT(isolate != Dart::vm_isolate()); |
@@ -361,41 +361,17 @@ intptr_t Symbols::Compact(Isolate* isolate) { |
intptr_t initial_size = -1; |
intptr_t final_size = -1; |
- // 1. Build a collection of all the predefined symbols so they are |
- // strongly referenced (the read only handles are not traced). |
{ |
SymbolTable table(zone, isolate->object_store()->symbol_table()); |
initial_size = table.NumOccupied(); |
- |
- if (Object::vm_isolate_snapshot_object_table().Length() == 0) { |
- GrowableObjectArray& predefined_symbols = GrowableObjectArray::Handle( |
- GrowableObjectArray::New(kMaxPredefinedId)); |
- String& symbol = String::Handle(); |
- for (intptr_t i = 1; i < Symbols::kNullCharId; i++) { |
- const unsigned char* name = |
- reinterpret_cast<const unsigned char*>(names[i]); |
- symbol ^= table.GetOrNull(Latin1Array(name, strlen(names[i]))); |
- ASSERT(!symbol.IsNull()); |
- predefined_symbols.Add(symbol); |
- } |
- for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) { |
- intptr_t idx = (kNullCharId + c); |
- ASSERT(idx < kMaxPredefinedId); |
- ASSERT(Utf::IsLatin1(c)); |
- uint8_t ch = static_cast<uint8_t>(c); |
- symbol ^= table.GetOrNull(Latin1Array(&ch, 1)); |
- ASSERT(!symbol.IsNull()); |
- predefined_symbols.Add(symbol); |
- } |
- } |
table.Release(); |
} |
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
|
- // 2. Knock out the symbol table and do a full garbage collection. |
+ // 1. Drop the symbol table and do a full garbage collection. |
isolate->object_store()->set_symbol_table(Object::empty_array()); |
isolate->heap()->CollectAllGarbage(); |
- // 3. Walk the heap and build a new table from surviving symbols. |
+ // 2. Walk the heap to find surviving symbols. |
GrowableArray<String*> symbols; |
class SymbolCollector : public ObjectVisitor { |
public: |
@@ -418,6 +394,7 @@ intptr_t Symbols::Compact(Isolate* isolate) { |
SymbolCollector visitor(Thread::Current(), &symbols); |
isolate->heap()->IterateObjects(&visitor); |
+ // 3. Build a new table from the surviving symbols. |
{ |
Array& array = |
Array::Handle(HashTables::New<SymbolTable>(symbols.length() * 4 / 3, |
@@ -430,12 +407,18 @@ intptr_t Symbols::Compact(Isolate* isolate) { |
bool present = table.Insert(symbol); |
ASSERT(!present); |
} |
- final_size = table.NumOccupied(); |
isolate->object_store()->set_symbol_table(table.Release()); |
} |
+ { |
+ SymbolTable table(zone, isolate->object_store()->symbol_table()); |
+ final_size = table.NumOccupied(); |
+ table.Release(); |
+ } |
siva
2016/05/05 00:50:05
Ditto comment about this size computation, probabl
|
+ |
return initial_size - final_size; |
} |
+#endif // DART_PRECOMPILER |
void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) { |
@@ -655,7 +638,6 @@ RawString* Symbols::Lookup(Thread* thread, const StringType& str) { |
symbol ^= table.GetOrNull(str); |
table.Release(); |
} |
- |
ASSERT(symbol.IsNull() || symbol.IsSymbol()); |
ASSERT(symbol.IsNull() || symbol.HasHash()); |
return symbol.raw(); |