OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/heap/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 315 } |
316 #endif | 316 #endif |
317 | 317 |
318 StartSweepSpaces(); | 318 StartSweepSpaces(); |
319 | 319 |
320 EvacuateNewSpaceAndCandidates(); | 320 EvacuateNewSpaceAndCandidates(); |
321 | 321 |
322 Finish(); | 322 Finish(); |
323 } | 323 } |
324 | 324 |
325 | |
326 #ifdef VERIFY_HEAP | 325 #ifdef VERIFY_HEAP |
327 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) { | 326 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) { |
328 for (Page* p : *space) { | 327 for (Page* p : *space) { |
329 CHECK(p->markbits()->IsClean()); | 328 CHECK(p->markbits()->IsClean()); |
330 CHECK_EQ(0, p->LiveBytes()); | 329 CHECK_EQ(0, p->LiveBytes()); |
331 } | 330 } |
332 } | 331 } |
333 | 332 |
334 | 333 |
335 void MarkCompactCollector::VerifyMarkbitsAreClean(NewSpace* space) { | 334 void MarkCompactCollector::VerifyMarkbitsAreClean(NewSpace* space) { |
(...skipping 11 matching lines...) Expand all Loading... |
347 VerifyMarkbitsAreClean(heap_->new_space()); | 346 VerifyMarkbitsAreClean(heap_->new_space()); |
348 | 347 |
349 LargeObjectIterator it(heap_->lo_space()); | 348 LargeObjectIterator it(heap_->lo_space()); |
350 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { | 349 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { |
351 MarkBit mark_bit = ObjectMarking::MarkBitFrom(obj); | 350 MarkBit mark_bit = ObjectMarking::MarkBitFrom(obj); |
352 CHECK(Marking::IsWhite(mark_bit)); | 351 CHECK(Marking::IsWhite(mark_bit)); |
353 CHECK_EQ(0, Page::FromAddress(obj->address())->LiveBytes()); | 352 CHECK_EQ(0, Page::FromAddress(obj->address())->LiveBytes()); |
354 } | 353 } |
355 } | 354 } |
356 | 355 |
357 | |
358 void MarkCompactCollector::VerifyWeakEmbeddedObjectsInCode() { | 356 void MarkCompactCollector::VerifyWeakEmbeddedObjectsInCode() { |
359 HeapObjectIterator code_iterator(heap()->code_space()); | 357 HeapObjectIterator code_iterator(heap()->code_space()); |
360 for (HeapObject* obj = code_iterator.Next(); obj != NULL; | 358 for (HeapObject* obj = code_iterator.Next(); obj != NULL; |
361 obj = code_iterator.Next()) { | 359 obj = code_iterator.Next()) { |
362 Code* code = Code::cast(obj); | 360 Code* code = Code::cast(obj); |
363 if (!code->is_optimized_code()) continue; | 361 if (!code->is_optimized_code()) continue; |
364 if (WillBeDeoptimized(code)) continue; | 362 if (WillBeDeoptimized(code)) continue; |
365 code->VerifyEmbeddedObjectsDependency(); | 363 code->VerifyEmbeddedObjectsDependency(); |
366 } | 364 } |
367 } | 365 } |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 JSFunction* candidate = jsfunction_candidates_head_; | 1074 JSFunction* candidate = jsfunction_candidates_head_; |
1077 while (candidate != NULL) { | 1075 while (candidate != NULL) { |
1078 if (heap->InFromSpace(candidate)) { | 1076 if (heap->InFromSpace(candidate)) { |
1079 v->VisitPointer(reinterpret_cast<Object**>(slot)); | 1077 v->VisitPointer(reinterpret_cast<Object**>(slot)); |
1080 } | 1078 } |
1081 candidate = GetNextCandidate(*slot); | 1079 candidate = GetNextCandidate(*slot); |
1082 slot = GetNextCandidateSlot(*slot); | 1080 slot = GetNextCandidateSlot(*slot); |
1083 } | 1081 } |
1084 } | 1082 } |
1085 | 1083 |
| 1084 class StaticYoungGenerationMarkingVisitor |
| 1085 : public StaticNewSpaceVisitor<StaticYoungGenerationMarkingVisitor> { |
| 1086 public: |
| 1087 static void Initialize(Heap* heap) { |
| 1088 StaticNewSpaceVisitor<StaticYoungGenerationMarkingVisitor>::Initialize(); |
| 1089 } |
| 1090 |
| 1091 inline static void VisitPointer(Heap* heap, HeapObject* object, Object** p) { |
| 1092 Object* target = *p; |
| 1093 if (heap->InNewSpace(target)) { |
| 1094 if (MarkRecursively(heap, HeapObject::cast(target))) return; |
| 1095 PushOnMarkingDeque(heap, target); |
| 1096 } |
| 1097 } |
| 1098 |
| 1099 protected: |
| 1100 inline static void PushOnMarkingDeque(Heap* heap, Object* obj) { |
| 1101 HeapObject* object = HeapObject::cast(obj); |
| 1102 MarkBit mark_bit = ObjectMarking::MarkBitFrom(object); |
| 1103 heap->mark_compact_collector()->MarkObject(object, mark_bit); |
| 1104 } |
| 1105 |
| 1106 inline static bool MarkRecursively(Heap* heap, HeapObject* object) { |
| 1107 StackLimitCheck check(heap->isolate()); |
| 1108 if (check.HasOverflowed()) return false; |
| 1109 |
| 1110 MarkBit mark = ObjectMarking::MarkBitFrom(object); |
| 1111 if (Marking::IsBlackOrGrey(mark)) return true; |
| 1112 heap->mark_compact_collector()->SetMark(object, mark); |
| 1113 IterateBody(object->map(), object); |
| 1114 return true; |
| 1115 } |
| 1116 }; |
1086 | 1117 |
1087 class MarkCompactMarkingVisitor | 1118 class MarkCompactMarkingVisitor |
1088 : public StaticMarkingVisitor<MarkCompactMarkingVisitor> { | 1119 : public StaticMarkingVisitor<MarkCompactMarkingVisitor> { |
1089 public: | 1120 public: |
1090 static void Initialize(); | 1121 static void Initialize(); |
1091 | 1122 |
1092 INLINE(static void VisitPointer(Heap* heap, HeapObject* object, Object** p)) { | 1123 INLINE(static void VisitPointer(Heap* heap, HeapObject* object, Object** p)) { |
1093 MarkObjectByPointer(heap->mark_compact_collector(), object, p); | 1124 MarkObjectByPointer(heap->mark_compact_collector(), object, p); |
1094 } | 1125 } |
1095 | 1126 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 // Iterate the archived stacks in all threads to check if | 1360 // Iterate the archived stacks in all threads to check if |
1330 // the code is referenced. | 1361 // the code is referenced. |
1331 CodeMarkingVisitor code_marking_visitor(this); | 1362 CodeMarkingVisitor code_marking_visitor(this); |
1332 heap()->isolate()->thread_manager()->IterateArchivedThreads( | 1363 heap()->isolate()->thread_manager()->IterateArchivedThreads( |
1333 &code_marking_visitor); | 1364 &code_marking_visitor); |
1334 | 1365 |
1335 SharedFunctionInfoMarkingVisitor visitor(this); | 1366 SharedFunctionInfoMarkingVisitor visitor(this); |
1336 heap()->isolate()->compilation_cache()->IterateFunctions(&visitor); | 1367 heap()->isolate()->compilation_cache()->IterateFunctions(&visitor); |
1337 heap()->isolate()->handle_scope_implementer()->Iterate(&visitor); | 1368 heap()->isolate()->handle_scope_implementer()->Iterate(&visitor); |
1338 | 1369 |
1339 ProcessMarkingDeque(); | 1370 ProcessMarkingDeque<MarkCompactMode::FULL>(); |
1340 } | 1371 } |
1341 | 1372 |
1342 | 1373 |
1343 // Visitor class for marking heap roots. | 1374 // Visitor class for marking heap roots. |
| 1375 template <MarkCompactMode mode> |
1344 class RootMarkingVisitor : public ObjectVisitor { | 1376 class RootMarkingVisitor : public ObjectVisitor { |
1345 public: | 1377 public: |
1346 explicit RootMarkingVisitor(Heap* heap) | 1378 explicit RootMarkingVisitor(Heap* heap) |
1347 : collector_(heap->mark_compact_collector()) {} | 1379 : collector_(heap->mark_compact_collector()) {} |
1348 | 1380 |
1349 void VisitPointer(Object** p) override { MarkObjectByPointer(p); } | 1381 void VisitPointer(Object** p) override { MarkObjectByPointer(p); } |
1350 | 1382 |
1351 void VisitPointers(Object** start, Object** end) override { | 1383 void VisitPointers(Object** start, Object** end) override { |
1352 for (Object** p = start; p < end; p++) MarkObjectByPointer(p); | 1384 for (Object** p = start; p < end; p++) MarkObjectByPointer(p); |
1353 } | 1385 } |
1354 | 1386 |
1355 // Skip the weak next code link in a code object, which is visited in | 1387 // Skip the weak next code link in a code object, which is visited in |
1356 // ProcessTopOptimizedFrame. | 1388 // ProcessTopOptimizedFrame. |
1357 void VisitNextCodeLink(Object** p) override {} | 1389 void VisitNextCodeLink(Object** p) override {} |
1358 | 1390 |
1359 private: | 1391 private: |
1360 void MarkObjectByPointer(Object** p) { | 1392 void MarkObjectByPointer(Object** p) { |
1361 if (!(*p)->IsHeapObject()) return; | 1393 if (!(*p)->IsHeapObject()) return; |
1362 | 1394 |
1363 HeapObject* object = HeapObject::cast(*p); | 1395 HeapObject* object = HeapObject::cast(*p); |
1364 | 1396 |
| 1397 if (mode == MarkCompactMode::YOUNG_GENERATION && |
| 1398 !collector_->heap()->InNewSpace(object)) |
| 1399 return; |
| 1400 |
1365 MarkBit mark_bit = ObjectMarking::MarkBitFrom(object); | 1401 MarkBit mark_bit = ObjectMarking::MarkBitFrom(object); |
1366 if (Marking::IsBlackOrGrey(mark_bit)) return; | 1402 if (Marking::IsBlackOrGrey(mark_bit)) return; |
1367 | 1403 |
1368 Map* map = object->map(); | 1404 Map* map = object->map(); |
1369 // Mark the object. | 1405 // Mark the object. |
1370 collector_->SetMark(object, mark_bit); | 1406 collector_->SetMark(object, mark_bit); |
1371 | 1407 |
1372 // Mark the map pointer and body, and push them on the marking stack. | 1408 switch (mode) { |
1373 MarkBit map_mark = ObjectMarking::MarkBitFrom(map); | 1409 case MarkCompactMode::FULL: { |
1374 collector_->MarkObject(map, map_mark); | 1410 // Mark the map pointer and body, and push them on the marking stack. |
1375 MarkCompactMarkingVisitor::IterateBody(map, object); | 1411 MarkBit map_mark = ObjectMarking::MarkBitFrom(map); |
| 1412 collector_->MarkObject(map, map_mark); |
| 1413 MarkCompactMarkingVisitor::IterateBody(map, object); |
| 1414 } break; |
| 1415 case MarkCompactMode::YOUNG_GENERATION: |
| 1416 StaticYoungGenerationMarkingVisitor::IterateBody(map, object); |
| 1417 break; |
| 1418 } |
1376 | 1419 |
1377 // Mark all the objects reachable from the map and body. May leave | 1420 // Mark all the objects reachable from the map and body. May leave |
1378 // overflowed objects in the heap. | 1421 // overflowed objects in the heap. |
1379 collector_->EmptyMarkingDeque(); | 1422 collector_->EmptyMarkingDeque<mode>(); |
1380 } | 1423 } |
1381 | 1424 |
1382 MarkCompactCollector* collector_; | 1425 MarkCompactCollector* collector_; |
1383 }; | 1426 }; |
1384 | 1427 |
1385 | 1428 |
1386 // Helper class for pruning the string table. | 1429 // Helper class for pruning the string table. |
1387 template <bool finalize_external_strings, bool record_slots> | 1430 template <bool finalize_external_strings, bool record_slots> |
1388 class StringTableCleaner : public ObjectVisitor { | 1431 class StringTableCleaner : public ObjectVisitor { |
1389 public: | 1432 public: |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 | 1982 |
1940 bool MarkCompactCollector::IsUnmarkedHeapObjectWithHeap(Heap* heap, | 1983 bool MarkCompactCollector::IsUnmarkedHeapObjectWithHeap(Heap* heap, |
1941 Object** p) { | 1984 Object** p) { |
1942 Object* o = *p; | 1985 Object* o = *p; |
1943 DCHECK(o->IsHeapObject()); | 1986 DCHECK(o->IsHeapObject()); |
1944 HeapObject* heap_object = HeapObject::cast(o); | 1987 HeapObject* heap_object = HeapObject::cast(o); |
1945 MarkBit mark = ObjectMarking::MarkBitFrom(heap_object); | 1988 MarkBit mark = ObjectMarking::MarkBitFrom(heap_object); |
1946 return Marking::IsWhite(mark); | 1989 return Marking::IsWhite(mark); |
1947 } | 1990 } |
1948 | 1991 |
1949 | 1992 void MarkCompactCollector::MarkStringTable( |
1950 void MarkCompactCollector::MarkStringTable(RootMarkingVisitor* visitor) { | 1993 RootMarkingVisitor<MarkCompactMode::FULL>* visitor) { |
1951 StringTable* string_table = heap()->string_table(); | 1994 StringTable* string_table = heap()->string_table(); |
1952 // Mark the string table itself. | 1995 // Mark the string table itself. |
1953 MarkBit string_table_mark = ObjectMarking::MarkBitFrom(string_table); | 1996 MarkBit string_table_mark = ObjectMarking::MarkBitFrom(string_table); |
1954 if (Marking::IsWhite(string_table_mark)) { | 1997 if (Marking::IsWhite(string_table_mark)) { |
1955 // String table could have already been marked by visiting the handles list. | 1998 // String table could have already been marked by visiting the handles list. |
1956 SetMark(string_table, string_table_mark); | 1999 SetMark(string_table, string_table_mark); |
1957 } | 2000 } |
1958 // Explicitly mark the prefix. | 2001 // Explicitly mark the prefix. |
1959 string_table->IteratePrefix(visitor); | 2002 string_table->IteratePrefix(visitor); |
1960 ProcessMarkingDeque(); | 2003 ProcessMarkingDeque<MarkCompactMode::FULL>(); |
1961 } | 2004 } |
1962 | 2005 |
1963 | 2006 |
1964 void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) { | 2007 void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) { |
1965 MarkBit mark_bit = ObjectMarking::MarkBitFrom(site); | 2008 MarkBit mark_bit = ObjectMarking::MarkBitFrom(site); |
1966 SetMark(site, mark_bit); | 2009 SetMark(site, mark_bit); |
1967 } | 2010 } |
1968 | 2011 |
1969 | 2012 void MarkCompactCollector::MarkRoots( |
1970 void MarkCompactCollector::MarkRoots(RootMarkingVisitor* visitor) { | 2013 RootMarkingVisitor<MarkCompactMode::FULL>* visitor) { |
1971 // Mark the heap roots including global variables, stack variables, | 2014 // Mark the heap roots including global variables, stack variables, |
1972 // etc., and all objects reachable from them. | 2015 // etc., and all objects reachable from them. |
1973 heap()->IterateStrongRoots(visitor, VISIT_ONLY_STRONG); | 2016 heap()->IterateStrongRoots(visitor, VISIT_ONLY_STRONG); |
1974 | 2017 |
1975 // Handle the string table specially. | 2018 // Handle the string table specially. |
1976 MarkStringTable(visitor); | 2019 MarkStringTable(visitor); |
1977 | 2020 |
1978 // There may be overflowed objects in the heap. Visit them now. | 2021 // There may be overflowed objects in the heap. Visit them now. |
1979 while (marking_deque()->overflowed()) { | 2022 while (marking_deque()->overflowed()) { |
1980 RefillMarkingDeque(); | 2023 RefillMarkingDeque<MarkCompactMode::FULL>(); |
1981 EmptyMarkingDeque(); | 2024 EmptyMarkingDeque<MarkCompactMode::FULL>(); |
1982 } | 2025 } |
1983 } | 2026 } |
1984 | 2027 |
1985 | 2028 |
1986 void MarkCompactCollector::MarkImplicitRefGroups( | 2029 void MarkCompactCollector::MarkImplicitRefGroups( |
1987 MarkObjectFunction mark_object) { | 2030 MarkObjectFunction mark_object) { |
1988 List<ImplicitRefGroup*>* ref_groups = | 2031 List<ImplicitRefGroup*>* ref_groups = |
1989 isolate()->global_handles()->implicit_ref_groups(); | 2032 isolate()->global_handles()->implicit_ref_groups(); |
1990 | 2033 |
1991 int last = 0; | 2034 int last = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
2011 delete entry; | 2054 delete entry; |
2012 } | 2055 } |
2013 ref_groups->Rewind(last); | 2056 ref_groups->Rewind(last); |
2014 } | 2057 } |
2015 | 2058 |
2016 | 2059 |
2017 // Mark all objects reachable from the objects on the marking stack. | 2060 // Mark all objects reachable from the objects on the marking stack. |
2018 // Before: the marking stack contains zero or more heap object pointers. | 2061 // Before: the marking stack contains zero or more heap object pointers. |
2019 // After: the marking stack is empty, and all objects reachable from the | 2062 // After: the marking stack is empty, and all objects reachable from the |
2020 // marking stack have been marked, or are overflowed in the heap. | 2063 // marking stack have been marked, or are overflowed in the heap. |
| 2064 template <MarkCompactMode mode> |
2021 void MarkCompactCollector::EmptyMarkingDeque() { | 2065 void MarkCompactCollector::EmptyMarkingDeque() { |
2022 while (!marking_deque()->IsEmpty()) { | 2066 while (!marking_deque()->IsEmpty()) { |
2023 HeapObject* object = marking_deque()->Pop(); | 2067 HeapObject* object = marking_deque()->Pop(); |
2024 | 2068 |
2025 DCHECK(!object->IsFiller()); | 2069 DCHECK(!object->IsFiller()); |
2026 DCHECK(object->IsHeapObject()); | 2070 DCHECK(object->IsHeapObject()); |
2027 DCHECK(heap()->Contains(object)); | 2071 DCHECK(heap()->Contains(object)); |
2028 DCHECK(!Marking::IsWhite(ObjectMarking::MarkBitFrom(object))); | 2072 DCHECK(!Marking::IsWhite(ObjectMarking::MarkBitFrom(object))); |
2029 | 2073 |
2030 Map* map = object->map(); | 2074 Map* map = object->map(); |
2031 MarkBit map_mark = ObjectMarking::MarkBitFrom(map); | 2075 switch (mode) { |
2032 MarkObject(map, map_mark); | 2076 case MarkCompactMode::FULL: { |
2033 | 2077 MarkBit map_mark = ObjectMarking::MarkBitFrom(map); |
2034 MarkCompactMarkingVisitor::IterateBody(map, object); | 2078 MarkObject(map, map_mark); |
| 2079 MarkCompactMarkingVisitor::IterateBody(map, object); |
| 2080 } break; |
| 2081 case MarkCompactMode::YOUNG_GENERATION: { |
| 2082 DCHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(object))); |
| 2083 StaticYoungGenerationMarkingVisitor::IterateBody(map, object); |
| 2084 } break; |
| 2085 } |
2035 } | 2086 } |
2036 } | 2087 } |
2037 | 2088 |
2038 | 2089 |
2039 // Sweep the heap for overflowed objects, clear their overflow bits, and | 2090 // Sweep the heap for overflowed objects, clear their overflow bits, and |
2040 // push them on the marking stack. Stop early if the marking stack fills | 2091 // push them on the marking stack. Stop early if the marking stack fills |
2041 // before sweeping completes. If sweeping completes, there are no remaining | 2092 // before sweeping completes. If sweeping completes, there are no remaining |
2042 // overflowed objects in the heap so the overflow flag on the markings stack | 2093 // overflowed objects in the heap so the overflow flag on the markings stack |
2043 // is cleared. | 2094 // is cleared. |
| 2095 template <MarkCompactMode mode> |
2044 void MarkCompactCollector::RefillMarkingDeque() { | 2096 void MarkCompactCollector::RefillMarkingDeque() { |
2045 isolate()->CountUsage(v8::Isolate::UseCounterFeature::kMarkDequeOverflow); | 2097 isolate()->CountUsage(v8::Isolate::UseCounterFeature::kMarkDequeOverflow); |
2046 DCHECK(marking_deque()->overflowed()); | 2098 DCHECK(marking_deque()->overflowed()); |
2047 | 2099 |
2048 DiscoverGreyObjectsInNewSpace(); | 2100 DiscoverGreyObjectsInNewSpace(); |
2049 if (marking_deque()->IsFull()) return; | 2101 if (marking_deque()->IsFull()) return; |
2050 | 2102 |
2051 DiscoverGreyObjectsInSpace(heap()->old_space()); | 2103 if (mode == MarkCompactMode::FULL) { |
2052 if (marking_deque()->IsFull()) return; | 2104 DiscoverGreyObjectsInSpace(heap()->old_space()); |
2053 | 2105 if (marking_deque()->IsFull()) return; |
2054 DiscoverGreyObjectsInSpace(heap()->code_space()); | 2106 DiscoverGreyObjectsInSpace(heap()->code_space()); |
2055 if (marking_deque()->IsFull()) return; | 2107 if (marking_deque()->IsFull()) return; |
2056 | 2108 DiscoverGreyObjectsInSpace(heap()->map_space()); |
2057 DiscoverGreyObjectsInSpace(heap()->map_space()); | 2109 if (marking_deque()->IsFull()) return; |
2058 if (marking_deque()->IsFull()) return; | 2110 LargeObjectIterator lo_it(heap()->lo_space()); |
2059 | 2111 DiscoverGreyObjectsWithIterator(&lo_it); |
2060 LargeObjectIterator lo_it(heap()->lo_space()); | 2112 if (marking_deque()->IsFull()) return; |
2061 DiscoverGreyObjectsWithIterator(&lo_it); | 2113 } |
2062 if (marking_deque()->IsFull()) return; | |
2063 | 2114 |
2064 marking_deque()->ClearOverflowed(); | 2115 marking_deque()->ClearOverflowed(); |
2065 } | 2116 } |
2066 | 2117 |
2067 | 2118 |
2068 // Mark all objects reachable (transitively) from objects on the marking | 2119 // Mark all objects reachable (transitively) from objects on the marking |
2069 // stack. Before: the marking stack contains zero or more heap object | 2120 // stack. Before: the marking stack contains zero or more heap object |
2070 // pointers. After: the marking stack is empty and there are no overflowed | 2121 // pointers. After: the marking stack is empty and there are no overflowed |
2071 // objects in the heap. | 2122 // objects in the heap. |
| 2123 template <MarkCompactMode mode> |
2072 void MarkCompactCollector::ProcessMarkingDeque() { | 2124 void MarkCompactCollector::ProcessMarkingDeque() { |
2073 EmptyMarkingDeque(); | 2125 EmptyMarkingDeque<mode>(); |
2074 while (marking_deque()->overflowed()) { | 2126 while (marking_deque()->overflowed()) { |
2075 RefillMarkingDeque(); | 2127 RefillMarkingDeque<mode>(); |
2076 EmptyMarkingDeque(); | 2128 EmptyMarkingDeque<mode>(); |
2077 } | 2129 } |
| 2130 DCHECK(marking_deque()->IsEmpty()); |
2078 } | 2131 } |
2079 | 2132 |
2080 // Mark all objects reachable (transitively) from objects on the marking | 2133 // Mark all objects reachable (transitively) from objects on the marking |
2081 // stack including references only considered in the atomic marking pause. | 2134 // stack including references only considered in the atomic marking pause. |
2082 void MarkCompactCollector::ProcessEphemeralMarking( | 2135 void MarkCompactCollector::ProcessEphemeralMarking( |
2083 ObjectVisitor* visitor, bool only_process_harmony_weak_collections) { | 2136 ObjectVisitor* visitor, bool only_process_harmony_weak_collections) { |
2084 DCHECK(marking_deque()->IsEmpty() && !marking_deque()->overflowed()); | 2137 DCHECK(marking_deque()->IsEmpty() && !marking_deque()->overflowed()); |
2085 bool work_to_do = true; | 2138 bool work_to_do = true; |
2086 while (work_to_do) { | 2139 while (work_to_do) { |
2087 if (heap_->UsingEmbedderHeapTracer()) { | 2140 if (heap_->UsingEmbedderHeapTracer()) { |
2088 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_WRAPPER_TRACING); | 2141 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_WRAPPER_TRACING); |
2089 heap_->RegisterWrappersWithEmbedderHeapTracer(); | 2142 heap_->RegisterWrappersWithEmbedderHeapTracer(); |
2090 heap_->embedder_heap_tracer()->AdvanceTracing( | 2143 heap_->embedder_heap_tracer()->AdvanceTracing( |
2091 0, EmbedderHeapTracer::AdvanceTracingActions( | 2144 0, EmbedderHeapTracer::AdvanceTracingActions( |
2092 EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); | 2145 EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); |
2093 } | 2146 } |
2094 if (!only_process_harmony_weak_collections) { | 2147 if (!only_process_harmony_weak_collections) { |
2095 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_OBJECT_GROUPING); | 2148 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_OBJECT_GROUPING); |
2096 isolate()->global_handles()->IterateObjectGroups( | 2149 isolate()->global_handles()->IterateObjectGroups( |
2097 visitor, &IsUnmarkedHeapObjectWithHeap); | 2150 visitor, &IsUnmarkedHeapObjectWithHeap); |
2098 MarkImplicitRefGroups(&MarkCompactMarkingVisitor::MarkObject); | 2151 MarkImplicitRefGroups(&MarkCompactMarkingVisitor::MarkObject); |
2099 } | 2152 } |
2100 ProcessWeakCollections(); | 2153 ProcessWeakCollections(); |
2101 work_to_do = !marking_deque()->IsEmpty(); | 2154 work_to_do = !marking_deque()->IsEmpty(); |
2102 ProcessMarkingDeque(); | 2155 ProcessMarkingDeque<MarkCompactMode::FULL>(); |
2103 } | 2156 } |
2104 } | 2157 } |
2105 | 2158 |
2106 void MarkCompactCollector::ProcessTopOptimizedFrame(ObjectVisitor* visitor) { | 2159 void MarkCompactCollector::ProcessTopOptimizedFrame(ObjectVisitor* visitor) { |
2107 for (StackFrameIterator it(isolate(), isolate()->thread_local_top()); | 2160 for (StackFrameIterator it(isolate(), isolate()->thread_local_top()); |
2108 !it.done(); it.Advance()) { | 2161 !it.done(); it.Advance()) { |
2109 if (it.frame()->type() == StackFrame::JAVA_SCRIPT) { | 2162 if (it.frame()->type() == StackFrame::JAVA_SCRIPT) { |
2110 return; | 2163 return; |
2111 } | 2164 } |
2112 if (it.frame()->type() == StackFrame::OPTIMIZED) { | 2165 if (it.frame()->type() == StackFrame::OPTIMIZED) { |
2113 Code* code = it.frame()->LookupCode(); | 2166 Code* code = it.frame()->LookupCode(); |
2114 if (!code->CanDeoptAt(it.frame()->pc())) { | 2167 if (!code->CanDeoptAt(it.frame()->pc())) { |
2115 Code::BodyDescriptor::IterateBody(code, visitor); | 2168 Code::BodyDescriptor::IterateBody(code, visitor); |
2116 } | 2169 } |
2117 ProcessMarkingDeque(); | 2170 ProcessMarkingDeque<MarkCompactMode::FULL>(); |
2118 return; | 2171 return; |
2119 } | 2172 } |
2120 } | 2173 } |
2121 } | 2174 } |
2122 | 2175 |
2123 void MarkingDeque::SetUp() { | 2176 void MarkingDeque::SetUp() { |
2124 backing_store_ = new base::VirtualMemory(kMaxSize); | 2177 backing_store_ = new base::VirtualMemory(kMaxSize); |
2125 backing_store_committed_size_ = 0; | 2178 backing_store_committed_size_ = 0; |
2126 if (backing_store_ == nullptr) { | 2179 if (backing_store_ == nullptr) { |
2127 V8::FatalProcessOutOfMemory("MarkingDeque::SetUp"); | 2180 V8::FatalProcessOutOfMemory("MarkingDeque::SetUp"); |
(...skipping 19 matching lines...) Expand all Loading... |
2147 : backing_store_committed_size_; | 2200 : backing_store_committed_size_; |
2148 DCHECK( | 2201 DCHECK( |
2149 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(size / kPointerSize))); | 2202 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(size / kPointerSize))); |
2150 mask_ = static_cast<int>((size / kPointerSize) - 1); | 2203 mask_ = static_cast<int>((size / kPointerSize) - 1); |
2151 top_ = bottom_ = 0; | 2204 top_ = bottom_ = 0; |
2152 overflowed_ = false; | 2205 overflowed_ = false; |
2153 } | 2206 } |
2154 | 2207 |
2155 void MarkingDeque::StopUsing() { | 2208 void MarkingDeque::StopUsing() { |
2156 base::LockGuard<base::Mutex> guard(&mutex_); | 2209 base::LockGuard<base::Mutex> guard(&mutex_); |
| 2210 if (!in_use_) return; |
2157 DCHECK(IsEmpty()); | 2211 DCHECK(IsEmpty()); |
2158 DCHECK(!overflowed_); | 2212 DCHECK(!overflowed_); |
2159 top_ = bottom_ = mask_ = 0; | 2213 top_ = bottom_ = mask_ = 0; |
2160 in_use_ = false; | 2214 in_use_ = false; |
2161 if (FLAG_concurrent_sweeping) { | 2215 if (FLAG_concurrent_sweeping) { |
2162 StartUncommitTask(); | 2216 StartUncommitTask(); |
2163 } else { | 2217 } else { |
2164 Uncommit(); | 2218 Uncommit(); |
2165 } | 2219 } |
2166 } | 2220 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2260 } | 2314 } |
2261 if (FLAG_trace_gc_object_stats) { | 2315 if (FLAG_trace_gc_object_stats) { |
2262 heap()->live_object_stats_->PrintJSON("live"); | 2316 heap()->live_object_stats_->PrintJSON("live"); |
2263 heap()->dead_object_stats_->PrintJSON("dead"); | 2317 heap()->dead_object_stats_->PrintJSON("dead"); |
2264 } | 2318 } |
2265 heap()->live_object_stats_->CheckpointObjectStats(); | 2319 heap()->live_object_stats_->CheckpointObjectStats(); |
2266 heap()->dead_object_stats_->ClearObjectStats(); | 2320 heap()->dead_object_stats_->ClearObjectStats(); |
2267 } | 2321 } |
2268 } | 2322 } |
2269 | 2323 |
| 2324 SlotCallbackResult MarkCompactCollector::CheckAndMarkObject( |
| 2325 Heap* heap, Address slot_address) { |
| 2326 Object* object = *reinterpret_cast<Object**>(slot_address); |
| 2327 if (heap->InNewSpace(object)) { |
| 2328 // Marking happens before flipping the young generation, so the object |
| 2329 // has to be in ToSpace. |
| 2330 DCHECK(heap->InToSpace(object)); |
| 2331 HeapObject* heap_object = reinterpret_cast<HeapObject*>(object); |
| 2332 MarkBit mark_bit = ObjectMarking::MarkBitFrom(heap_object); |
| 2333 if (Marking::IsBlackOrGrey(mark_bit)) { |
| 2334 return KEEP_SLOT; |
| 2335 } |
| 2336 heap->mark_compact_collector()->SetMark(heap_object, mark_bit); |
| 2337 StaticYoungGenerationMarkingVisitor::IterateBody(heap_object->map(), |
| 2338 heap_object); |
| 2339 return KEEP_SLOT; |
| 2340 } |
| 2341 return REMOVE_SLOT; |
| 2342 } |
| 2343 |
| 2344 static bool IsUnmarkedObject(Heap* heap, Object** p) { |
| 2345 DCHECK_IMPLIES(heap->InNewSpace(*p), heap->InToSpace(*p)); |
| 2346 return heap->InNewSpace(*p) && |
| 2347 !Marking::IsBlack(ObjectMarking::MarkBitFrom(HeapObject::cast(*p))); |
| 2348 } |
| 2349 |
| 2350 void MarkCompactCollector::MarkLiveObjectsInYoungGeneration() { |
| 2351 TRACE_GC(heap()->tracer(), GCTracer::Scope::MINOR_MC_MARK); |
| 2352 |
| 2353 PostponeInterruptsScope postpone(isolate()); |
| 2354 |
| 2355 StaticYoungGenerationMarkingVisitor::Initialize(heap()); |
| 2356 RootMarkingVisitor<MarkCompactMode::YOUNG_GENERATION> root_visitor(heap()); |
| 2357 |
| 2358 marking_deque()->StartUsing(); |
| 2359 |
| 2360 isolate()->global_handles()->IdentifyWeakUnmodifiedObjects( |
| 2361 &Heap::IsUnmodifiedHeapObject); |
| 2362 |
| 2363 { |
| 2364 TRACE_GC(heap()->tracer(), GCTracer::Scope::MINOR_MC_MARK_ROOTS); |
| 2365 heap()->IterateRoots(&root_visitor, VISIT_ALL_IN_SCAVENGE); |
| 2366 ProcessMarkingDeque<MarkCompactMode::YOUNG_GENERATION>(); |
| 2367 } |
| 2368 |
| 2369 { |
| 2370 TRACE_GC(heap()->tracer(), |
| 2371 GCTracer::Scope::MINOR_MC_MARK_OLD_TO_NEW_POINTERS); |
| 2372 RememberedSet<OLD_TO_NEW>::Iterate(heap(), [this](Address addr) { |
| 2373 return CheckAndMarkObject(heap(), addr); |
| 2374 }); |
| 2375 RememberedSet<OLD_TO_NEW>::IterateTyped( |
| 2376 heap(), [this](SlotType type, Address host_addr, Address addr) { |
| 2377 return UpdateTypedSlotHelper::UpdateTypedSlot( |
| 2378 isolate(), type, addr, [this](Object** addr) { |
| 2379 return CheckAndMarkObject(heap(), |
| 2380 reinterpret_cast<Address>(addr)); |
| 2381 }); |
| 2382 }); |
| 2383 ProcessMarkingDeque<MarkCompactMode::YOUNG_GENERATION>(); |
| 2384 } |
| 2385 |
| 2386 { |
| 2387 TRACE_GC(heap()->tracer(), GCTracer::Scope::MINOR_MC_MARK_WEAK); |
| 2388 heap()->VisitEncounteredWeakCollections(&root_visitor); |
| 2389 ProcessMarkingDeque<MarkCompactMode::YOUNG_GENERATION>(); |
| 2390 } |
| 2391 |
| 2392 if (is_code_flushing_enabled()) { |
| 2393 TRACE_GC(heap()->tracer(), |
| 2394 GCTracer::Scope::MINOR_MC_MARK_CODE_FLUSH_CANDIDATES); |
| 2395 code_flusher()->IteratePointersToFromSpace(&root_visitor); |
| 2396 ProcessMarkingDeque<MarkCompactMode::YOUNG_GENERATION>(); |
| 2397 } |
| 2398 |
| 2399 { |
| 2400 TRACE_GC(heap()->tracer(), GCTracer::Scope::MINOR_MC_MARK_GLOBAL_HANDLES); |
| 2401 isolate()->global_handles()->MarkNewSpaceWeakUnmodifiedObjectsPending( |
| 2402 &IsUnmarkedObject); |
| 2403 isolate() |
| 2404 ->global_handles() |
| 2405 ->IterateNewSpaceWeakUnmodifiedRoots<GlobalHandles::VISIT_OTHERS>( |
| 2406 &root_visitor); |
| 2407 ProcessMarkingDeque<MarkCompactMode::YOUNG_GENERATION>(); |
| 2408 } |
| 2409 |
| 2410 marking_deque()->StopUsing(); |
| 2411 } |
| 2412 |
2270 void MarkCompactCollector::MarkLiveObjects() { | 2413 void MarkCompactCollector::MarkLiveObjects() { |
2271 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK); | 2414 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK); |
2272 // The recursive GC marker detects when it is nearing stack overflow, | 2415 // The recursive GC marker detects when it is nearing stack overflow, |
2273 // and switches to a different marking system. JS interrupts interfere | 2416 // and switches to a different marking system. JS interrupts interfere |
2274 // with the C stack limit check. | 2417 // with the C stack limit check. |
2275 PostponeInterruptsScope postpone(isolate()); | 2418 PostponeInterruptsScope postpone(isolate()); |
2276 | 2419 |
2277 { | 2420 { |
2278 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_FINISH_INCREMENTAL); | 2421 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_FINISH_INCREMENTAL); |
2279 IncrementalMarking* incremental_marking = heap_->incremental_marking(); | 2422 IncrementalMarking* incremental_marking = heap_->incremental_marking(); |
2280 if (was_marked_incrementally_) { | 2423 if (was_marked_incrementally_) { |
2281 incremental_marking->Finalize(); | 2424 incremental_marking->Finalize(); |
2282 } else { | 2425 } else { |
2283 CHECK(incremental_marking->IsStopped()); | 2426 CHECK(incremental_marking->IsStopped()); |
2284 } | 2427 } |
2285 } | 2428 } |
2286 | 2429 |
2287 #ifdef DEBUG | 2430 #ifdef DEBUG |
2288 DCHECK(state_ == PREPARE_GC); | 2431 DCHECK(state_ == PREPARE_GC); |
2289 state_ = MARK_LIVE_OBJECTS; | 2432 state_ = MARK_LIVE_OBJECTS; |
2290 #endif | 2433 #endif |
2291 | 2434 |
2292 marking_deque()->StartUsing(); | 2435 marking_deque()->StartUsing(); |
2293 | 2436 |
2294 { | 2437 { |
2295 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_PREPARE_CODE_FLUSH); | 2438 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_PREPARE_CODE_FLUSH); |
2296 PrepareForCodeFlushing(); | 2439 PrepareForCodeFlushing(); |
2297 } | 2440 } |
2298 | 2441 |
2299 RootMarkingVisitor root_visitor(heap()); | 2442 RootMarkingVisitor<MarkCompactMode::FULL> root_visitor(heap()); |
2300 | 2443 |
2301 { | 2444 { |
2302 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_ROOTS); | 2445 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_ROOTS); |
2303 MarkRoots(&root_visitor); | 2446 MarkRoots(&root_visitor); |
2304 ProcessTopOptimizedFrame(&root_visitor); | 2447 ProcessTopOptimizedFrame(&root_visitor); |
2305 } | 2448 } |
2306 | 2449 |
2307 { | 2450 { |
2308 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_WEAK_CLOSURE); | 2451 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_WEAK_CLOSURE); |
2309 | 2452 |
(...skipping 11 matching lines...) Expand all Loading... |
2321 // immediately reclaimed. Instead, we have to mark them as pending and mark | 2464 // immediately reclaimed. Instead, we have to mark them as pending and mark |
2322 // objects reachable from them. | 2465 // objects reachable from them. |
2323 // | 2466 // |
2324 // First we identify nonlive weak handles and mark them as pending | 2467 // First we identify nonlive weak handles and mark them as pending |
2325 // destruction. | 2468 // destruction. |
2326 { | 2469 { |
2327 TRACE_GC(heap()->tracer(), | 2470 TRACE_GC(heap()->tracer(), |
2328 GCTracer::Scope::MC_MARK_WEAK_CLOSURE_WEAK_HANDLES); | 2471 GCTracer::Scope::MC_MARK_WEAK_CLOSURE_WEAK_HANDLES); |
2329 heap()->isolate()->global_handles()->IdentifyWeakHandles( | 2472 heap()->isolate()->global_handles()->IdentifyWeakHandles( |
2330 &IsUnmarkedHeapObject); | 2473 &IsUnmarkedHeapObject); |
2331 ProcessMarkingDeque(); | 2474 ProcessMarkingDeque<MarkCompactMode::FULL>(); |
2332 } | 2475 } |
2333 // Then we mark the objects. | 2476 // Then we mark the objects. |
2334 | 2477 |
2335 { | 2478 { |
2336 TRACE_GC(heap()->tracer(), | 2479 TRACE_GC(heap()->tracer(), |
2337 GCTracer::Scope::MC_MARK_WEAK_CLOSURE_WEAK_ROOTS); | 2480 GCTracer::Scope::MC_MARK_WEAK_CLOSURE_WEAK_ROOTS); |
2338 heap()->isolate()->global_handles()->IterateWeakRoots(&root_visitor); | 2481 heap()->isolate()->global_handles()->IterateWeakRoots(&root_visitor); |
2339 ProcessMarkingDeque(); | 2482 ProcessMarkingDeque<MarkCompactMode::FULL>(); |
2340 } | 2483 } |
2341 | 2484 |
2342 // Repeat Harmony weak maps marking to mark unmarked objects reachable from | 2485 // Repeat Harmony weak maps marking to mark unmarked objects reachable from |
2343 // the weak roots we just marked as pending destruction. | 2486 // the weak roots we just marked as pending destruction. |
2344 // | 2487 // |
2345 // We only process harmony collections, as all object groups have been fully | 2488 // We only process harmony collections, as all object groups have been fully |
2346 // processed and no weakly reachable node can discover new objects groups. | 2489 // processed and no weakly reachable node can discover new objects groups. |
2347 { | 2490 { |
2348 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_WEAK_CLOSURE_HARMONY); | 2491 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_WEAK_CLOSURE_HARMONY); |
2349 ProcessEphemeralMarking(&root_visitor, true); | 2492 ProcessEphemeralMarking(&root_visitor, true); |
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3935 // The target is always in old space, we don't have to record the slot in | 4078 // The target is always in old space, we don't have to record the slot in |
3936 // the old-to-new remembered set. | 4079 // the old-to-new remembered set. |
3937 DCHECK(!heap()->InNewSpace(target)); | 4080 DCHECK(!heap()->InNewSpace(target)); |
3938 RecordRelocSlot(host, &rinfo, target); | 4081 RecordRelocSlot(host, &rinfo, target); |
3939 } | 4082 } |
3940 } | 4083 } |
3941 } | 4084 } |
3942 | 4085 |
3943 } // namespace internal | 4086 } // namespace internal |
3944 } // namespace v8 | 4087 } // namespace v8 |
OLD | NEW |