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

Side by Side Diff: src/mark-compact.cc

Issue 149324: * Move almost all roots into an array ready for use by a constant-pool... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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 | Annotate | Revision Log
« src/heap.cc ('K') | « src/heap-inl.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // (ConsString::cast(object)->second() == Heap::empty_string()) 217 // (ConsString::cast(object)->second() == Heap::empty_string())
218 // except the maps for the object and its possible substrings might be 218 // except the maps for the object and its possible substrings might be
219 // marked. 219 // marked.
220 HeapObject* object = HeapObject::cast(*p); 220 HeapObject* object = HeapObject::cast(*p);
221 MapWord map_word = object->map_word(); 221 MapWord map_word = object->map_word();
222 map_word.ClearMark(); 222 map_word.ClearMark();
223 InstanceType type = map_word.ToMap()->instance_type(); 223 InstanceType type = map_word.ToMap()->instance_type();
224 if ((type & kShortcutTypeMask) != kShortcutTypeTag) return object; 224 if ((type & kShortcutTypeMask) != kShortcutTypeTag) return object;
225 225
226 Object* second = reinterpret_cast<ConsString*>(object)->unchecked_second(); 226 Object* second = reinterpret_cast<ConsString*>(object)->unchecked_second();
227 if (reinterpret_cast<String*>(second) != Heap::empty_string()) return object; 227 if (reinterpret_cast<String*>(second) !=
Kasper Lund 2009/07/08 12:42:37 Why is the reinterpret_cast necessary here? It's r
Erik Corry 2009/07/08 14:19:50 It wasn't necessary.
228 Heap::raw_unchecked_empty_string()) {
229 return object;
230 }
228 231
229 // Since we don't have the object's start, it is impossible to update the 232 // Since we don't have the object's start, it is impossible to update the
230 // remembered set. Therefore, we only replace the string with its left 233 // remembered set. Therefore, we only replace the string with its left
231 // substring when the remembered set does not change. 234 // substring when the remembered set does not change.
232 Object* first = reinterpret_cast<ConsString*>(object)->unchecked_first(); 235 Object* first = reinterpret_cast<ConsString*>(object)->unchecked_first();
233 if (!Heap::InNewSpace(object) && Heap::InNewSpace(first)) return object; 236 if (!Heap::InNewSpace(object) && Heap::InNewSpace(first)) return object;
234 237
235 *p = first; 238 *p = first;
236 return HeapObject::cast(first); 239 return HeapObject::cast(first);
237 } 240 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } else { 417 } else {
415 v8::String::ExternalAsciiStringResource** resource = 418 v8::String::ExternalAsciiStringResource** resource =
416 reinterpret_cast<v8::String::ExternalAsciiStringResource**> 419 reinterpret_cast<v8::String::ExternalAsciiStringResource**>
417 (resource_addr); 420 (resource_addr);
418 delete *resource; 421 delete *resource;
419 // Clear the resource pointer in the symbol. 422 // Clear the resource pointer in the symbol.
420 *resource = NULL; 423 *resource = NULL;
421 } 424 }
422 } 425 }
423 // Set the entry to null_value (as deleted). 426 // Set the entry to null_value (as deleted).
424 *p = Heap::null_value(); 427 *p = Heap::raw_unchecked_null_value();
425 pointers_removed_++; 428 pointers_removed_++;
426 } 429 }
427 } 430 }
428 } 431 }
429 432
430 int PointersRemoved() { 433 int PointersRemoved() {
431 return pointers_removed_; 434 return pointers_removed_;
432 } 435 }
433 private: 436 private:
434 int pointers_removed_; 437 int pointers_removed_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 MarkingVisitor visitor; // Has no state or contents. 471 MarkingVisitor visitor; // Has no state or contents.
469 visitor.VisitPointers(HeapObject::RawField(map, Map::kPrototypeOffset), 472 visitor.VisitPointers(HeapObject::RawField(map, Map::kPrototypeOffset),
470 HeapObject::RawField(map, Map::kSize)); 473 HeapObject::RawField(map, Map::kSize));
471 } 474 }
472 475
473 476
474 void MarkCompactCollector::MarkDescriptorArray( 477 void MarkCompactCollector::MarkDescriptorArray(
475 DescriptorArray* descriptors) { 478 DescriptorArray* descriptors) {
476 if (descriptors->IsMarked()) return; 479 if (descriptors->IsMarked()) return;
477 // Empty descriptor array is marked as a root before any maps are marked. 480 // Empty descriptor array is marked as a root before any maps are marked.
478 ASSERT(descriptors != Heap::empty_descriptor_array()); 481 ASSERT(descriptors != Heap::raw_unchecked_empty_descriptor_array());
479 SetMark(descriptors); 482 SetMark(descriptors);
480 483
481 FixedArray* contents = reinterpret_cast<FixedArray*>( 484 FixedArray* contents = reinterpret_cast<FixedArray*>(
482 descriptors->get(DescriptorArray::kContentArrayIndex)); 485 descriptors->get(DescriptorArray::kContentArrayIndex));
483 ASSERT(contents->IsHeapObject()); 486 ASSERT(contents->IsHeapObject());
484 ASSERT(!contents->IsMarked()); 487 ASSERT(!contents->IsMarked());
485 ASSERT(contents->IsFixedArray()); 488 ASSERT(contents->IsFixedArray());
486 ASSERT(contents->length() >= 2); 489 ASSERT(contents->length() >= 2);
487 SetMark(contents); 490 SetMark(contents);
488 // Contents contains (value, details) pairs. If the details say 491 // Contents contains (value, details) pairs. If the details say
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } 586 }
584 }; 587 };
585 588
586 589
587 void MarkCompactCollector::MarkSymbolTable() { 590 void MarkCompactCollector::MarkSymbolTable() {
588 // Objects reachable from symbols are marked as live so as to ensure 591 // Objects reachable from symbols are marked as live so as to ensure
589 // that if the symbol itself remains alive after GC for any reason, 592 // that if the symbol itself remains alive after GC for any reason,
590 // and if it is a sliced string or a cons string backed by an 593 // and if it is a sliced string or a cons string backed by an
591 // external string (even indirectly), then the external string does 594 // external string (even indirectly), then the external string does
592 // not receive a weak reference callback. 595 // not receive a weak reference callback.
593 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table()); 596 SymbolTable* symbol_table =
597 reinterpret_cast<SymbolTable*>(Heap::raw_unchecked_symbol_table());
Kasper Lund 2009/07/08 12:42:37 Doesn't raw_unchecked_symbol_table return somethin
594 // Mark the symbol table itself. 598 // Mark the symbol table itself.
595 SetMark(symbol_table); 599 SetMark(symbol_table);
596 // Explicitly mark the prefix. 600 // Explicitly mark the prefix.
597 MarkingVisitor marker; 601 MarkingVisitor marker;
598 symbol_table->IteratePrefix(&marker); 602 symbol_table->IteratePrefix(&marker);
599 ProcessMarkingStack(&marker); 603 ProcessMarkingStack(&marker);
600 // Mark subparts of the symbols but not the symbols themselves 604 // Mark subparts of the symbols but not the symbols themselves
601 // (unless reachable from another symbol). 605 // (unless reachable from another symbol).
602 SymbolMarkingVisitor symbol_marker; 606 SymbolMarkingVisitor symbol_marker;
603 symbol_table->IterateElements(&symbol_marker); 607 symbol_table->IterateElements(&symbol_marker);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 } 780 }
777 781
778 // Repeat the object groups to mark unmarked groups reachable from the 782 // Repeat the object groups to mark unmarked groups reachable from the
779 // weak roots. 783 // weak roots.
780 ProcessObjectGroups(root_visitor.stack_visitor()); 784 ProcessObjectGroups(root_visitor.stack_visitor());
781 785
782 // Prune the symbol table removing all symbols only pointed to by the 786 // Prune the symbol table removing all symbols only pointed to by the
783 // symbol table. Cannot use SymbolTable::cast here because the symbol 787 // symbol table. Cannot use SymbolTable::cast here because the symbol
784 // table is marked. 788 // table is marked.
785 SymbolTable* symbol_table = 789 SymbolTable* symbol_table =
786 reinterpret_cast<SymbolTable*>(Heap::symbol_table()); 790 reinterpret_cast<SymbolTable*>(Heap::raw_unchecked_symbol_table());
Kasper Lund 2009/07/08 12:42:37 Do you need reinterpret_cast here?
787 SymbolTableCleaner v; 791 SymbolTableCleaner v;
788 symbol_table->IterateElements(&v); 792 symbol_table->IterateElements(&v);
789 symbol_table->ElementsRemoved(v.PointersRemoved()); 793 symbol_table->ElementsRemoved(v.PointersRemoved());
790 794
791 // Remove object groups after marking phase. 795 // Remove object groups after marking phase.
792 GlobalHandles::RemoveObjectGroups(); 796 GlobalHandles::RemoveObjectGroups();
793 } 797 }
794 798
795 799
796 static int CountMarkedCallback(HeapObject* obj) { 800 static int CountMarkedCallback(HeapObject* obj) {
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 current += object->Size()) { 1139 current += object->Size()) {
1136 object = HeapObject::FromAddress(current); 1140 object = HeapObject::FromAddress(current);
1137 if (object->IsMarked()) { 1141 if (object->IsMarked()) {
1138 object->ClearMark(); 1142 object->ClearMark();
1139 MarkCompactCollector::tracer()->decrement_marked_count(); 1143 MarkCompactCollector::tracer()->decrement_marked_count();
1140 } else { 1144 } else {
1141 // We give non-live objects a map that will correctly give their size, 1145 // We give non-live objects a map that will correctly give their size,
1142 // since their existing map might not be live after the collection. 1146 // since their existing map might not be live after the collection.
1143 int size = object->Size(); 1147 int size = object->Size();
1144 if (size >= ByteArray::kHeaderSize) { 1148 if (size >= ByteArray::kHeaderSize) {
1145 object->set_map(Heap::byte_array_map()); 1149 object->set_map(Heap::raw_unchecked_byte_array_map());
1146 ByteArray::cast(object)->set_length(ByteArray::LengthFor(size)); 1150 ByteArray::cast(object)->set_length(ByteArray::LengthFor(size));
1147 } else { 1151 } else {
1148 ASSERT(size == kPointerSize); 1152 ASSERT(size == kPointerSize);
1149 object->set_map(Heap::one_word_filler_map()); 1153 object->set_map(Heap::raw_unchecked_one_word_filler_map());
1150 } 1154 }
1151 ASSERT(object->Size() == size); 1155 ASSERT(object->Size() == size);
1152 } 1156 }
1153 // The object is now unmarked for the call to Size() at the top of the 1157 // The object is now unmarked for the call to Size() at the top of the
1154 // loop. 1158 // loop.
1155 } 1159 }
1156 } 1160 }
1157 1161
1158 1162
1159 static void SweepSpace(PagedSpace* space, DeallocateFunction dealloc) { 1163 static void SweepSpace(PagedSpace* space, DeallocateFunction dealloc) {
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 1804
1801 void MarkCompactCollector::RebuildRSets() { 1805 void MarkCompactCollector::RebuildRSets() {
1802 #ifdef DEBUG 1806 #ifdef DEBUG
1803 ASSERT(state_ == RELOCATE_OBJECTS); 1807 ASSERT(state_ == RELOCATE_OBJECTS);
1804 state_ = REBUILD_RSETS; 1808 state_ = REBUILD_RSETS;
1805 #endif 1809 #endif
1806 Heap::RebuildRSets(); 1810 Heap::RebuildRSets();
1807 } 1811 }
1808 1812
1809 } } // namespace v8::internal 1813 } } // namespace v8::internal
OLDNEW
« src/heap.cc ('K') | « src/heap-inl.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698