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

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

Issue 112863002: Merge bleeding_edge 18021:18297 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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
« no previous file with comments | « src/mark-compact.h ('k') | src/math.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 return compacting_; 399 return compacting_;
400 } 400 }
401 401
402 402
403 void MarkCompactCollector::CollectGarbage() { 403 void MarkCompactCollector::CollectGarbage() {
404 // Make sure that Prepare() has been called. The individual steps below will 404 // Make sure that Prepare() has been called. The individual steps below will
405 // update the state as they proceed. 405 // update the state as they proceed.
406 ASSERT(state_ == PREPARE_GC); 406 ASSERT(state_ == PREPARE_GC);
407 ASSERT(encountered_weak_collections_ == Smi::FromInt(0)); 407 ASSERT(encountered_weak_collections_ == Smi::FromInt(0));
408 408
409 heap()->allocation_mementos_found_ = 0;
410
411 MarkLiveObjects(); 409 MarkLiveObjects();
412 ASSERT(heap_->incremental_marking()->IsStopped()); 410 ASSERT(heap_->incremental_marking()->IsStopped());
413 411
414 if (FLAG_collect_maps) ClearNonLiveReferences(); 412 if (FLAG_collect_maps) ClearNonLiveReferences();
415 413
416 ClearWeakCollections(); 414 ClearWeakCollections();
417 415
418 #ifdef VERIFY_HEAP 416 #ifdef VERIFY_HEAP
419 if (FLAG_verify_heap) { 417 if (FLAG_verify_heap) {
420 VerifyMarking(heap_); 418 VerifyMarking(heap_);
(...skipping 21 matching lines...) Expand all
442 440
443 Finish(); 441 Finish();
444 442
445 if (marking_parity_ == EVEN_MARKING_PARITY) { 443 if (marking_parity_ == EVEN_MARKING_PARITY) {
446 marking_parity_ = ODD_MARKING_PARITY; 444 marking_parity_ = ODD_MARKING_PARITY;
447 } else { 445 } else {
448 ASSERT(marking_parity_ == ODD_MARKING_PARITY); 446 ASSERT(marking_parity_ == ODD_MARKING_PARITY);
449 marking_parity_ = EVEN_MARKING_PARITY; 447 marking_parity_ = EVEN_MARKING_PARITY;
450 } 448 }
451 449
452 if (FLAG_trace_track_allocation_sites &&
453 heap()->allocation_mementos_found_ > 0) {
454 PrintF("AllocationMementos found during mark-sweep = %d\n",
455 heap()->allocation_mementos_found_);
456 }
457 tracer_ = NULL; 450 tracer_ = NULL;
458 } 451 }
459 452
460 453
461 #ifdef VERIFY_HEAP 454 #ifdef VERIFY_HEAP
462 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) { 455 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) {
463 PageIterator it(space); 456 PageIterator it(space);
464 457
465 while (it.has_next()) { 458 while (it.has_next()) {
466 Page* p = it.next(); 459 Page* p = it.next();
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 // Mark all the objects reachable from the map and body. May leave 1832 // Mark all the objects reachable from the map and body. May leave
1840 // overflowed objects in the heap. 1833 // overflowed objects in the heap.
1841 collector_->EmptyMarkingDeque(); 1834 collector_->EmptyMarkingDeque();
1842 } 1835 }
1843 1836
1844 MarkCompactCollector* collector_; 1837 MarkCompactCollector* collector_;
1845 }; 1838 };
1846 1839
1847 1840
1848 // Helper class for pruning the string table. 1841 // Helper class for pruning the string table.
1842 template<bool finalize_external_strings>
1849 class StringTableCleaner : public ObjectVisitor { 1843 class StringTableCleaner : public ObjectVisitor {
1850 public: 1844 public:
1851 explicit StringTableCleaner(Heap* heap) 1845 explicit StringTableCleaner(Heap* heap)
1852 : heap_(heap), pointers_removed_(0) { } 1846 : heap_(heap), pointers_removed_(0) { }
1853 1847
1854 virtual void VisitPointers(Object** start, Object** end) { 1848 virtual void VisitPointers(Object** start, Object** end) {
1855 // Visit all HeapObject pointers in [start, end). 1849 // Visit all HeapObject pointers in [start, end).
1856 for (Object** p = start; p < end; p++) { 1850 for (Object** p = start; p < end; p++) {
1857 Object* o = *p; 1851 Object* o = *p;
1858 if (o->IsHeapObject() && 1852 if (o->IsHeapObject() &&
1859 !Marking::MarkBitFrom(HeapObject::cast(o)).Get()) { 1853 !Marking::MarkBitFrom(HeapObject::cast(o)).Get()) {
1860 // Check if the internalized string being pruned is external. We need to 1854 if (finalize_external_strings) {
1861 // delete the associated external data as this string is going away. 1855 ASSERT(o->IsExternalString());
1862
1863 // Since no objects have yet been moved we can safely access the map of
1864 // the object.
1865 if (o->IsExternalString()) {
1866 heap_->FinalizeExternalString(String::cast(*p)); 1856 heap_->FinalizeExternalString(String::cast(*p));
1857 } else {
1858 pointers_removed_++;
1867 } 1859 }
1868 // Set the entry to the_hole_value (as deleted). 1860 // Set the entry to the_hole_value (as deleted).
1869 *p = heap_->the_hole_value(); 1861 *p = heap_->the_hole_value();
1870 pointers_removed_++;
1871 } 1862 }
1872 } 1863 }
1873 } 1864 }
1874 1865
1875 int PointersRemoved() { 1866 int PointersRemoved() {
1867 ASSERT(!finalize_external_strings);
1876 return pointers_removed_; 1868 return pointers_removed_;
1877 } 1869 }
1878 1870
1879 private: 1871 private:
1880 Heap* heap_; 1872 Heap* heap_;
1881 int pointers_removed_; 1873 int pointers_removed_;
1882 }; 1874 };
1883 1875
1884 1876
1877 typedef StringTableCleaner<false> InternalizedStringTableCleaner;
1878 typedef StringTableCleaner<true> ExternalStringTableCleaner;
1879
1880
1885 // Implementation of WeakObjectRetainer for mark compact GCs. All marked objects 1881 // Implementation of WeakObjectRetainer for mark compact GCs. All marked objects
1886 // are retained. 1882 // are retained.
1887 class MarkCompactWeakObjectRetainer : public WeakObjectRetainer { 1883 class MarkCompactWeakObjectRetainer : public WeakObjectRetainer {
1888 public: 1884 public:
1889 virtual Object* RetainAs(Object* object) { 1885 virtual Object* RetainAs(Object* object) {
1890 if (Marking::MarkBitFrom(HeapObject::cast(object)).Get()) { 1886 if (Marking::MarkBitFrom(HeapObject::cast(object)).Get()) {
1891 return object; 1887 return object;
1888 } else if (object->IsAllocationSite() &&
1889 !(AllocationSite::cast(object)->IsZombie())) {
1890 // "dead" AllocationSites need to live long enough for a traversal of new
1891 // space. These sites get a one-time reprieve.
1892 AllocationSite* site = AllocationSite::cast(object);
1893 site->MarkZombie();
1894 site->GetHeap()->mark_compact_collector()->MarkAllocationSite(site);
1895 return object;
1892 } else { 1896 } else {
1893 return NULL; 1897 return NULL;
1894 } 1898 }
1895 } 1899 }
1896 }; 1900 };
1897 1901
1898 1902
1899 // Fill the marking stack with overflowed objects returned by the given 1903 // Fill the marking stack with overflowed objects returned by the given
1900 // iterator. Stop when the marking stack is filled or the end of the space 1904 // iterator. Stop when the marking stack is filled or the end of the space
1901 // is reached, whichever comes first. 1905 // is reached, whichever comes first.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 while (current_cell != 0) { 1997 while (current_cell != 0) {
1994 int trailing_zeros = CompilerIntrinsics::CountTrailingZeros(current_cell); 1998 int trailing_zeros = CompilerIntrinsics::CountTrailingZeros(current_cell);
1995 current_cell >>= trailing_zeros; 1999 current_cell >>= trailing_zeros;
1996 offset += trailing_zeros; 2000 offset += trailing_zeros;
1997 Address address = cell_base + offset * kPointerSize; 2001 Address address = cell_base + offset * kPointerSize;
1998 HeapObject* object = HeapObject::FromAddress(address); 2002 HeapObject* object = HeapObject::FromAddress(address);
1999 2003
2000 int size = object->Size(); 2004 int size = object->Size();
2001 survivors_size += size; 2005 survivors_size += size;
2002 2006
2003 if (FLAG_trace_track_allocation_sites && object->IsJSObject()) { 2007 Heap::UpdateAllocationSiteFeedback(object);
2004 if (AllocationMemento::FindForJSObject(JSObject::cast(object), true)
2005 != NULL) {
2006 heap()->allocation_mementos_found_++;
2007 }
2008 }
2009 2008
2010 offset++; 2009 offset++;
2011 current_cell >>= 1; 2010 current_cell >>= 1;
2012 // Aggressively promote young survivors to the old space. 2011 // Aggressively promote young survivors to the old space.
2013 if (TryPromoteObject(object, size)) { 2012 if (TryPromoteObject(object, size)) {
2014 continue; 2013 continue;
2015 } 2014 }
2016 2015
2017 // Promotion failed. Just migrate object to another semispace. 2016 // Promotion failed. Just migrate object to another semispace.
2018 MaybeObject* allocation = new_space->AllocateRaw(size); 2017 MaybeObject* allocation = new_space->AllocateRaw(size);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 StringTable* string_table = heap()->string_table(); 2090 StringTable* string_table = heap()->string_table();
2092 // Mark the string table itself. 2091 // Mark the string table itself.
2093 MarkBit string_table_mark = Marking::MarkBitFrom(string_table); 2092 MarkBit string_table_mark = Marking::MarkBitFrom(string_table);
2094 SetMark(string_table, string_table_mark); 2093 SetMark(string_table, string_table_mark);
2095 // Explicitly mark the prefix. 2094 // Explicitly mark the prefix.
2096 string_table->IteratePrefix(visitor); 2095 string_table->IteratePrefix(visitor);
2097 ProcessMarkingDeque(); 2096 ProcessMarkingDeque();
2098 } 2097 }
2099 2098
2100 2099
2100 void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) {
2101 MarkBit mark_bit = Marking::MarkBitFrom(site);
2102 SetMark(site, mark_bit);
2103 }
2104
2105
2101 void MarkCompactCollector::MarkRoots(RootMarkingVisitor* visitor) { 2106 void MarkCompactCollector::MarkRoots(RootMarkingVisitor* visitor) {
2102 // Mark the heap roots including global variables, stack variables, 2107 // Mark the heap roots including global variables, stack variables,
2103 // etc., and all objects reachable from them. 2108 // etc., and all objects reachable from them.
2104 heap()->IterateStrongRoots(visitor, VISIT_ONLY_STRONG); 2109 heap()->IterateStrongRoots(visitor, VISIT_ONLY_STRONG);
2105 2110
2106 // Handle the string table specially. 2111 // Handle the string table specially.
2107 MarkStringTable(visitor); 2112 MarkStringTable(visitor);
2108 2113
2109 MarkWeakObjectToCodeTable(); 2114 MarkWeakObjectToCodeTable();
2110 2115
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 // Object literal map caches reference strings (cache keys) and maps 2394 // Object literal map caches reference strings (cache keys) and maps
2390 // (cache values). At this point still useful maps have already been 2395 // (cache values). At this point still useful maps have already been
2391 // marked. Mark the keys for the alive values before we process the 2396 // marked. Mark the keys for the alive values before we process the
2392 // string table. 2397 // string table.
2393 ProcessMapCaches(); 2398 ProcessMapCaches();
2394 2399
2395 // Prune the string table removing all strings only pointed to by the 2400 // Prune the string table removing all strings only pointed to by the
2396 // string table. Cannot use string_table() here because the string 2401 // string table. Cannot use string_table() here because the string
2397 // table is marked. 2402 // table is marked.
2398 StringTable* string_table = heap()->string_table(); 2403 StringTable* string_table = heap()->string_table();
2399 StringTableCleaner v(heap()); 2404 InternalizedStringTableCleaner internalized_visitor(heap());
2400 string_table->IterateElements(&v); 2405 string_table->IterateElements(&internalized_visitor);
2401 string_table->ElementsRemoved(v.PointersRemoved()); 2406 string_table->ElementsRemoved(internalized_visitor.PointersRemoved());
2402 heap()->external_string_table_.Iterate(&v); 2407
2408 ExternalStringTableCleaner external_visitor(heap());
2409 heap()->external_string_table_.Iterate(&external_visitor);
2403 heap()->external_string_table_.CleanUp(); 2410 heap()->external_string_table_.CleanUp();
2404 2411
2405 // Process the weak references. 2412 // Process the weak references.
2406 MarkCompactWeakObjectRetainer mark_compact_object_retainer; 2413 MarkCompactWeakObjectRetainer mark_compact_object_retainer;
2407 heap()->ProcessWeakReferences(&mark_compact_object_retainer); 2414 heap()->ProcessWeakReferences(&mark_compact_object_retainer);
2408 2415
2409 // Remove object groups after marking phase. 2416 // Remove object groups after marking phase.
2410 heap()->isolate()->global_handles()->RemoveObjectGroups(); 2417 heap()->isolate()->global_handles()->RemoveObjectGroups();
2411 heap()->isolate()->global_handles()->RemoveImplicitRefGroups(); 2418 heap()->isolate()->global_handles()->RemoveImplicitRefGroups();
2412 2419
2413 // Flush code from collected candidates. 2420 // Flush code from collected candidates.
2414 if (is_code_flushing_enabled()) { 2421 if (is_code_flushing_enabled()) {
2415 code_flusher_->ProcessCandidates(); 2422 code_flusher_->ProcessCandidates();
2416 // If incremental marker does not support code flushing, we need to 2423 // If incremental marker does not support code flushing, we need to
2417 // disable it before incremental marking steps for next cycle. 2424 // disable it before incremental marking steps for next cycle.
2418 if (FLAG_flush_code && !FLAG_flush_code_incrementally) { 2425 if (FLAG_flush_code && !FLAG_flush_code_incrementally) {
2419 EnableCodeFlushing(false); 2426 EnableCodeFlushing(false);
2420 } 2427 }
2421 } 2428 }
2422 2429
2423 if (!FLAG_watch_ic_patching) {
2424 // Clean up dead objects from the runtime profiler.
2425 heap()->isolate()->runtime_profiler()->RemoveDeadSamples();
2426 }
2427
2428 if (FLAG_track_gc_object_stats) { 2430 if (FLAG_track_gc_object_stats) {
2429 heap()->CheckpointObjectStats(); 2431 heap()->CheckpointObjectStats();
2430 } 2432 }
2431 } 2433 }
2432 2434
2433 2435
2434 void MarkCompactCollector::ProcessMapCaches() { 2436 void MarkCompactCollector::ProcessMapCaches() {
2435 Object* raw_context = heap()->native_contexts_list_; 2437 Object* raw_context = heap()->native_contexts_list_;
2436 while (raw_context != heap()->undefined_value()) { 2438 while (raw_context != heap()->undefined_value()) {
2437 Context* context = reinterpret_cast<Context*>(raw_context); 2439 Context* context = reinterpret_cast<Context*>(raw_context);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2759 // to encounter pointers to dead new space objects during traversal of pointers 2761 // to encounter pointers to dead new space objects during traversal of pointers
2760 // to new space. We should clear them to avoid encountering them during next 2762 // to new space. We should clear them to avoid encountering them during next
2761 // pointer iteration. This is an issue if the store buffer overflows and we 2763 // pointer iteration. This is an issue if the store buffer overflows and we
2762 // have to scan the entire old space, including dead objects, looking for 2764 // have to scan the entire old space, including dead objects, looking for
2763 // pointers to new space. 2765 // pointers to new space.
2764 void MarkCompactCollector::MigrateObject(Address dst, 2766 void MarkCompactCollector::MigrateObject(Address dst,
2765 Address src, 2767 Address src,
2766 int size, 2768 int size,
2767 AllocationSpace dest) { 2769 AllocationSpace dest) {
2768 HeapProfiler* heap_profiler = heap()->isolate()->heap_profiler(); 2770 HeapProfiler* heap_profiler = heap()->isolate()->heap_profiler();
2769 if (heap_profiler->is_profiling()) { 2771 if (heap_profiler->is_tracking_object_moves()) {
2770 heap_profiler->ObjectMoveEvent(src, dst, size); 2772 heap_profiler->ObjectMoveEvent(src, dst, size);
2771 } 2773 }
2772 ASSERT(heap()->AllowedToBeMigrated(HeapObject::FromAddress(src), dest)); 2774 ASSERT(heap()->AllowedToBeMigrated(HeapObject::FromAddress(src), dest));
2773 ASSERT(dest != LO_SPACE && size <= Page::kMaxNonCodeHeapObjectSize); 2775 ASSERT(dest != LO_SPACE && size <= Page::kMaxNonCodeHeapObjectSize);
2774 if (dest == OLD_POINTER_SPACE) { 2776 if (dest == OLD_POINTER_SPACE) {
2775 Address src_slot = src; 2777 Address src_slot = src;
2776 Address dst_slot = dst; 2778 Address dst_slot = dst;
2777 ASSERT(IsAligned(size, kPointerSize)); 2779 ASSERT(IsAligned(size, kPointerSize));
2778 2780
2779 for (int remaining = size / kPointerSize; remaining > 0; remaining--) { 2781 for (int remaining = size / kPointerSize; remaining > 0; remaining--) {
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
3505 WeakHashTable* table = 3507 WeakHashTable* table =
3506 WeakHashTable::cast(heap_->weak_object_to_code_table()); 3508 WeakHashTable::cast(heap_->weak_object_to_code_table());
3507 table->Iterate(&updating_visitor); 3509 table->Iterate(&updating_visitor);
3508 table->Rehash(heap_->undefined_value()); 3510 table->Rehash(heap_->undefined_value());
3509 } 3511 }
3510 3512
3511 // Update pointers from external string table. 3513 // Update pointers from external string table.
3512 heap_->UpdateReferencesInExternalStringTable( 3514 heap_->UpdateReferencesInExternalStringTable(
3513 &UpdateReferenceInExternalStringTableEntry); 3515 &UpdateReferenceInExternalStringTableEntry);
3514 3516
3515 if (!FLAG_watch_ic_patching) {
3516 // Update JSFunction pointers from the runtime profiler.
3517 heap()->isolate()->runtime_profiler()->UpdateSamplesAfterCompact(
3518 &updating_visitor);
3519 }
3520
3521 EvacuationWeakObjectRetainer evacuation_object_retainer; 3517 EvacuationWeakObjectRetainer evacuation_object_retainer;
3522 heap()->ProcessWeakReferences(&evacuation_object_retainer); 3518 heap()->ProcessWeakReferences(&evacuation_object_retainer);
3523 3519
3524 // Visit invalidated code (we ignored all slots on it) and clear mark-bits 3520 // Visit invalidated code (we ignored all slots on it) and clear mark-bits
3525 // under it. 3521 // under it.
3526 ProcessInvalidatedCode(&updating_visitor); 3522 ProcessInvalidatedCode(&updating_visitor);
3527 3523
3528 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); 3524 heap_->isolate()->inner_pointer_to_code_cache()->Flush();
3529 3525
3530 #ifdef VERIFY_HEAP 3526 #ifdef VERIFY_HEAP
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
4365 while (buffer != NULL) { 4361 while (buffer != NULL) {
4366 SlotsBuffer* next_buffer = buffer->next(); 4362 SlotsBuffer* next_buffer = buffer->next();
4367 DeallocateBuffer(buffer); 4363 DeallocateBuffer(buffer);
4368 buffer = next_buffer; 4364 buffer = next_buffer;
4369 } 4365 }
4370 *buffer_address = NULL; 4366 *buffer_address = NULL;
4371 } 4367 }
4372 4368
4373 4369
4374 } } // namespace v8::internal 4370 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mark-compact.h ('k') | src/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698