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

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

Issue 2644523002: [heap] Provide ObjectMarking with marking transitions (Closed)
Patch Set: Rebase Created 3 years, 11 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
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/mark-compact-inl.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 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 static void VerifyMarking(Heap* heap, Address bottom, Address top) { 101 static void VerifyMarking(Heap* heap, Address bottom, Address top) {
102 VerifyMarkingVisitor visitor(heap); 102 VerifyMarkingVisitor visitor(heap);
103 HeapObject* object; 103 HeapObject* object;
104 Address next_object_must_be_here_or_later = bottom; 104 Address next_object_must_be_here_or_later = bottom;
105 for (Address current = bottom; current < top;) { 105 for (Address current = bottom; current < top;) {
106 object = HeapObject::FromAddress(current); 106 object = HeapObject::FromAddress(current);
107 // One word fillers at the end of a black area can be grey. 107 // One word fillers at the end of a black area can be grey.
108 if (MarkCompactCollector::IsMarked(object) && 108 if (MarkCompactCollector::IsMarked(object) &&
109 object->map() != heap->one_pointer_filler_map()) { 109 object->map() != heap->one_pointer_filler_map()) {
110 CHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(object))); 110 CHECK(ObjectMarking::IsBlack(object));
111 CHECK(current >= next_object_must_be_here_or_later); 111 CHECK(current >= next_object_must_be_here_or_later);
112 object->Iterate(&visitor); 112 object->Iterate(&visitor);
113 next_object_must_be_here_or_later = current + object->Size(); 113 next_object_must_be_here_or_later = current + object->Size();
114 // The object is either part of a black area of black allocation or a 114 // The object is either part of a black area of black allocation or a
115 // regular black object 115 // regular black object
116 Page* page = Page::FromAddress(current); 116 Page* page = Page::FromAddress(current);
117 CHECK( 117 CHECK(
118 page->markbits()->AllBitsSetInRange( 118 page->markbits()->AllBitsSetInRange(
119 page->AddressToMarkbitIndex(current), 119 page->AddressToMarkbitIndex(current),
120 page->AddressToMarkbitIndex(next_object_must_be_here_or_later)) || 120 page->AddressToMarkbitIndex(next_object_must_be_here_or_later)) ||
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 341
342 342
343 void MarkCompactCollector::VerifyMarkbitsAreClean() { 343 void MarkCompactCollector::VerifyMarkbitsAreClean() {
344 VerifyMarkbitsAreClean(heap_->old_space()); 344 VerifyMarkbitsAreClean(heap_->old_space());
345 VerifyMarkbitsAreClean(heap_->code_space()); 345 VerifyMarkbitsAreClean(heap_->code_space());
346 VerifyMarkbitsAreClean(heap_->map_space()); 346 VerifyMarkbitsAreClean(heap_->map_space());
347 VerifyMarkbitsAreClean(heap_->new_space()); 347 VerifyMarkbitsAreClean(heap_->new_space());
348 348
349 LargeObjectIterator it(heap_->lo_space()); 349 LargeObjectIterator it(heap_->lo_space());
350 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { 350 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
351 MarkBit mark_bit = ObjectMarking::MarkBitFrom(obj); 351 CHECK(ObjectMarking::IsWhite(obj));
352 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 void MarkCompactCollector::VerifyWeakEmbeddedObjectsInCode() { 356 void MarkCompactCollector::VerifyWeakEmbeddedObjectsInCode() {
358 HeapObjectIterator code_iterator(heap()->code_space()); 357 HeapObjectIterator code_iterator(heap()->code_space());
359 for (HeapObject* obj = code_iterator.Next(); obj != NULL; 358 for (HeapObject* obj = code_iterator.Next(); obj != NULL;
360 obj = code_iterator.Next()) { 359 obj = code_iterator.Next()) {
361 Code* code = Code::cast(obj); 360 Code* code = Code::cast(obj);
362 if (!code->is_optimized_code()) continue; 361 if (!code->is_optimized_code()) continue;
(...skipping 28 matching lines...) Expand all
391 390
392 391
393 void MarkCompactCollector::ClearMarkbits() { 392 void MarkCompactCollector::ClearMarkbits() {
394 ClearMarkbitsInPagedSpace(heap_->code_space()); 393 ClearMarkbitsInPagedSpace(heap_->code_space());
395 ClearMarkbitsInPagedSpace(heap_->map_space()); 394 ClearMarkbitsInPagedSpace(heap_->map_space());
396 ClearMarkbitsInPagedSpace(heap_->old_space()); 395 ClearMarkbitsInPagedSpace(heap_->old_space());
397 ClearMarkbitsInNewSpace(heap_->new_space()); 396 ClearMarkbitsInNewSpace(heap_->new_space());
398 397
399 LargeObjectIterator it(heap_->lo_space()); 398 LargeObjectIterator it(heap_->lo_space());
400 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { 399 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
401 Marking::MarkWhite(ObjectMarking::MarkBitFrom(obj)); 400 ObjectMarking::ClearMarkBit(obj);
402 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); 401 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address());
403 chunk->ResetProgressBar(); 402 chunk->ResetProgressBar();
404 chunk->ResetLiveBytes(); 403 chunk->ResetLiveBytes();
405 } 404 }
406 } 405 }
407 406
408 class MarkCompactCollector::Sweeper::SweeperTask : public v8::Task { 407 class MarkCompactCollector::Sweeper::SweeperTask : public v8::Task {
409 public: 408 public:
410 SweeperTask(Sweeper* sweeper, base::Semaphore* pending_sweeper_tasks, 409 SweeperTask(Sweeper* sweeper, base::Semaphore* pending_sweeper_tasks,
411 AllocationSpace space_to_start) 410 AllocationSpace space_to_start)
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 901
903 JSFunction* candidate = jsfunction_candidates_head_; 902 JSFunction* candidate = jsfunction_candidates_head_;
904 JSFunction* next_candidate; 903 JSFunction* next_candidate;
905 while (candidate != NULL) { 904 while (candidate != NULL) {
906 next_candidate = GetNextCandidate(candidate); 905 next_candidate = GetNextCandidate(candidate);
907 ClearNextCandidate(candidate, undefined); 906 ClearNextCandidate(candidate, undefined);
908 907
909 SharedFunctionInfo* shared = candidate->shared(); 908 SharedFunctionInfo* shared = candidate->shared();
910 909
911 Code* code = shared->code(); 910 Code* code = shared->code();
912 MarkBit code_mark = ObjectMarking::MarkBitFrom(code); 911 if (ObjectMarking::IsWhite(code)) {
913 if (Marking::IsWhite(code_mark)) {
914 if (FLAG_trace_code_flushing && shared->is_compiled()) { 912 if (FLAG_trace_code_flushing && shared->is_compiled()) {
915 PrintF("[code-flushing clears: "); 913 PrintF("[code-flushing clears: ");
916 shared->ShortPrint(); 914 shared->ShortPrint();
917 PrintF(" - age: %d]\n", code->GetAge()); 915 PrintF(" - age: %d]\n", code->GetAge());
918 } 916 }
919 // Always flush the optimized code map if there is one. 917 // Always flush the optimized code map if there is one.
920 if (!shared->OptimizedCodeMapIsCleared()) { 918 if (!shared->OptimizedCodeMapIsCleared()) {
921 shared->ClearOptimizedCodeMap(); 919 shared->ClearOptimizedCodeMap();
922 } 920 }
923 if (shared->HasBytecodeArray()) { 921 if (shared->HasBytecodeArray()) {
924 shared->set_code(interpreter_entry_trampoline); 922 shared->set_code(interpreter_entry_trampoline);
925 candidate->set_code(interpreter_entry_trampoline); 923 candidate->set_code(interpreter_entry_trampoline);
926 } else { 924 } else {
927 shared->set_code(lazy_compile); 925 shared->set_code(lazy_compile);
928 candidate->set_code(lazy_compile); 926 candidate->set_code(lazy_compile);
929 } 927 }
930 } else { 928 } else {
931 DCHECK(Marking::IsBlack(code_mark)); 929 DCHECK(ObjectMarking::IsBlack(code));
932 candidate->set_code(code); 930 candidate->set_code(code);
933 } 931 }
934 932
935 // We are in the middle of a GC cycle so the write barrier in the code 933 // We are in the middle of a GC cycle so the write barrier in the code
936 // setter did not record the slot update and we have to do that manually. 934 // setter did not record the slot update and we have to do that manually.
937 Address slot = candidate->address() + JSFunction::kCodeEntryOffset; 935 Address slot = candidate->address() + JSFunction::kCodeEntryOffset;
938 Code* target = Code::cast(Code::GetObjectFromEntryAddress(slot)); 936 Code* target = Code::cast(Code::GetObjectFromEntryAddress(slot));
939 isolate_->heap()->mark_compact_collector()->RecordCodeEntrySlot( 937 isolate_->heap()->mark_compact_collector()->RecordCodeEntrySlot(
940 candidate, slot, target); 938 candidate, slot, target);
941 939
(...skipping 13 matching lines...) Expand all
955 Code* lazy_compile = isolate_->builtins()->builtin(Builtins::kCompileLazy); 953 Code* lazy_compile = isolate_->builtins()->builtin(Builtins::kCompileLazy);
956 Code* interpreter_entry_trampoline = 954 Code* interpreter_entry_trampoline =
957 isolate_->builtins()->builtin(Builtins::kInterpreterEntryTrampoline); 955 isolate_->builtins()->builtin(Builtins::kInterpreterEntryTrampoline);
958 SharedFunctionInfo* candidate = shared_function_info_candidates_head_; 956 SharedFunctionInfo* candidate = shared_function_info_candidates_head_;
959 SharedFunctionInfo* next_candidate; 957 SharedFunctionInfo* next_candidate;
960 while (candidate != NULL) { 958 while (candidate != NULL) {
961 next_candidate = GetNextCandidate(candidate); 959 next_candidate = GetNextCandidate(candidate);
962 ClearNextCandidate(candidate); 960 ClearNextCandidate(candidate);
963 961
964 Code* code = candidate->code(); 962 Code* code = candidate->code();
965 MarkBit code_mark = ObjectMarking::MarkBitFrom(code); 963 if (ObjectMarking::IsWhite(code)) {
966 if (Marking::IsWhite(code_mark)) {
967 if (FLAG_trace_code_flushing && candidate->is_compiled()) { 964 if (FLAG_trace_code_flushing && candidate->is_compiled()) {
968 PrintF("[code-flushing clears: "); 965 PrintF("[code-flushing clears: ");
969 candidate->ShortPrint(); 966 candidate->ShortPrint();
970 PrintF(" - age: %d]\n", code->GetAge()); 967 PrintF(" - age: %d]\n", code->GetAge());
971 } 968 }
972 // Always flush the optimized code map if there is one. 969 // Always flush the optimized code map if there is one.
973 if (!candidate->OptimizedCodeMapIsCleared()) { 970 if (!candidate->OptimizedCodeMapIsCleared()) {
974 candidate->ClearOptimizedCodeMap(); 971 candidate->ClearOptimizedCodeMap();
975 } 972 }
976 if (candidate->HasBytecodeArray()) { 973 if (candidate->HasBytecodeArray()) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 inline static void PushOnMarkingDeque(Heap* heap, Object* obj) { 1093 inline static void PushOnMarkingDeque(Heap* heap, Object* obj) {
1097 HeapObject* object = HeapObject::cast(obj); 1094 HeapObject* object = HeapObject::cast(obj);
1098 MarkBit mark_bit = ObjectMarking::MarkBitFrom(object); 1095 MarkBit mark_bit = ObjectMarking::MarkBitFrom(object);
1099 heap->mark_compact_collector()->MarkObject(object, mark_bit); 1096 heap->mark_compact_collector()->MarkObject(object, mark_bit);
1100 } 1097 }
1101 1098
1102 inline static bool MarkRecursively(Heap* heap, HeapObject* object) { 1099 inline static bool MarkRecursively(Heap* heap, HeapObject* object) {
1103 StackLimitCheck check(heap->isolate()); 1100 StackLimitCheck check(heap->isolate());
1104 if (check.HasOverflowed()) return false; 1101 if (check.HasOverflowed()) return false;
1105 1102
1106 MarkBit mark = ObjectMarking::MarkBitFrom(object); 1103 if (ObjectMarking::IsBlackOrGrey(object)) return true;
1107 if (Marking::IsBlackOrGrey(mark)) return true; 1104 heap->mark_compact_collector()->SetMark(object);
1108 heap->mark_compact_collector()->SetMark(object, mark);
1109 IterateBody(object->map(), object); 1105 IterateBody(object->map(), object);
1110 return true; 1106 return true;
1111 } 1107 }
1112 }; 1108 };
1113 1109
1114 class MarkCompactMarkingVisitor 1110 class MarkCompactMarkingVisitor
1115 : public StaticMarkingVisitor<MarkCompactMarkingVisitor> { 1111 : public StaticMarkingVisitor<MarkCompactMarkingVisitor> {
1116 public: 1112 public:
1117 static void Initialize(); 1113 static void Initialize();
1118 1114
(...skipping 17 matching lines...) Expand all
1136 1132
1137 // Marks the object black and pushes it on the marking stack. 1133 // Marks the object black and pushes it on the marking stack.
1138 INLINE(static void MarkObject(Heap* heap, HeapObject* object)) { 1134 INLINE(static void MarkObject(Heap* heap, HeapObject* object)) {
1139 MarkBit mark = ObjectMarking::MarkBitFrom(object); 1135 MarkBit mark = ObjectMarking::MarkBitFrom(object);
1140 heap->mark_compact_collector()->MarkObject(object, mark); 1136 heap->mark_compact_collector()->MarkObject(object, mark);
1141 } 1137 }
1142 1138
1143 // Marks the object black without pushing it on the marking stack. 1139 // Marks the object black without pushing it on the marking stack.
1144 // Returns true if object needed marking and false otherwise. 1140 // Returns true if object needed marking and false otherwise.
1145 INLINE(static bool MarkObjectWithoutPush(Heap* heap, HeapObject* object)) { 1141 INLINE(static bool MarkObjectWithoutPush(Heap* heap, HeapObject* object)) {
1146 MarkBit mark_bit = ObjectMarking::MarkBitFrom(object); 1142 if (ObjectMarking::IsWhite(object)) {
1147 if (Marking::IsWhite(mark_bit)) { 1143 heap->mark_compact_collector()->SetMark(object);
1148 heap->mark_compact_collector()->SetMark(object, mark_bit);
1149 return true; 1144 return true;
1150 } 1145 }
1151 return false; 1146 return false;
1152 } 1147 }
1153 1148
1154 // Mark object pointed to by p. 1149 // Mark object pointed to by p.
1155 INLINE(static void MarkObjectByPointer(MarkCompactCollector* collector, 1150 INLINE(static void MarkObjectByPointer(MarkCompactCollector* collector,
1156 HeapObject* object, Object** p)) { 1151 HeapObject* object, Object** p)) {
1157 if (!(*p)->IsHeapObject()) return; 1152 if (!(*p)->IsHeapObject()) return;
1158 HeapObject* target_object = HeapObject::cast(*p); 1153 HeapObject* target_object = HeapObject::cast(*p);
1159 collector->RecordSlot(object, p, target_object); 1154 collector->RecordSlot(object, p, target_object);
1160 MarkBit mark = ObjectMarking::MarkBitFrom(target_object); 1155 MarkBit mark = ObjectMarking::MarkBitFrom(target_object);
1161 collector->MarkObject(target_object, mark); 1156 collector->MarkObject(target_object, mark);
1162 } 1157 }
1163 1158
1164 1159
1165 // Visit an unmarked object. 1160 // Visit an unmarked object.
1166 INLINE(static void VisitUnmarkedObject(MarkCompactCollector* collector, 1161 INLINE(static void VisitUnmarkedObject(MarkCompactCollector* collector,
1167 HeapObject* obj)) { 1162 HeapObject* obj)) {
1168 #ifdef DEBUG 1163 #ifdef DEBUG
1169 DCHECK(collector->heap()->Contains(obj)); 1164 DCHECK(collector->heap()->Contains(obj));
1170 DCHECK(!collector->heap()->mark_compact_collector()->IsMarked(obj)); 1165 DCHECK(!collector->heap()->mark_compact_collector()->IsMarked(obj));
1171 #endif 1166 #endif
1172 Map* map = obj->map(); 1167 Map* map = obj->map();
1173 Heap* heap = obj->GetHeap(); 1168 Heap* heap = obj->GetHeap();
1174 MarkBit mark = ObjectMarking::MarkBitFrom(obj); 1169 heap->mark_compact_collector()->SetMark(obj);
1175 heap->mark_compact_collector()->SetMark(obj, mark);
1176 // Mark the map pointer and the body. 1170 // Mark the map pointer and the body.
1177 MarkBit map_mark = ObjectMarking::MarkBitFrom(map); 1171 MarkBit map_mark = ObjectMarking::MarkBitFrom(map);
1178 heap->mark_compact_collector()->MarkObject(map, map_mark); 1172 heap->mark_compact_collector()->MarkObject(map, map_mark);
1179 IterateBody(map, obj); 1173 IterateBody(map, obj);
1180 } 1174 }
1181 1175
1182 // Visit all unmarked objects pointed to by [start, end). 1176 // Visit all unmarked objects pointed to by [start, end).
1183 // Returns false if the operation fails (lack of stack space). 1177 // Returns false if the operation fails (lack of stack space).
1184 INLINE(static bool VisitUnmarkedObjects(Heap* heap, HeapObject* object, 1178 INLINE(static bool VisitUnmarkedObjects(Heap* heap, HeapObject* object,
1185 Object** start, Object** end)) { 1179 Object** start, Object** end)) {
1186 // Return false is we are close to the stack limit. 1180 // Return false is we are close to the stack limit.
1187 StackLimitCheck check(heap->isolate()); 1181 StackLimitCheck check(heap->isolate());
1188 if (check.HasOverflowed()) return false; 1182 if (check.HasOverflowed()) return false;
1189 1183
1190 MarkCompactCollector* collector = heap->mark_compact_collector(); 1184 MarkCompactCollector* collector = heap->mark_compact_collector();
1191 // Visit the unmarked objects. 1185 // Visit the unmarked objects.
1192 for (Object** p = start; p < end; p++) { 1186 for (Object** p = start; p < end; p++) {
1193 Object* o = *p; 1187 Object* o = *p;
1194 if (!o->IsHeapObject()) continue; 1188 if (!o->IsHeapObject()) continue;
1195 collector->RecordSlot(object, p, o); 1189 collector->RecordSlot(object, p, o);
1196 HeapObject* obj = HeapObject::cast(o); 1190 HeapObject* obj = HeapObject::cast(o);
1197 MarkBit mark = ObjectMarking::MarkBitFrom(obj); 1191 if (ObjectMarking::IsBlackOrGrey(obj)) continue;
1198 if (Marking::IsBlackOrGrey(mark)) continue;
1199 VisitUnmarkedObject(collector, obj); 1192 VisitUnmarkedObject(collector, obj);
1200 } 1193 }
1201 return true; 1194 return true;
1202 } 1195 }
1203 1196
1204 private: 1197 private:
1205 // Code flushing support. 1198 // Code flushing support.
1206 1199
1207 static const int kRegExpCodeThreshold = 5; 1200 static const int kRegExpCodeThreshold = 5;
1208 1201
(...skipping 12 matching lines...) Expand all
1221 if (!code->IsSmi() && 1214 if (!code->IsSmi() &&
1222 HeapObject::cast(code)->map()->instance_type() == CODE_TYPE) { 1215 HeapObject::cast(code)->map()->instance_type() == CODE_TYPE) {
1223 // Save a copy that can be reinstated if we need the code again. 1216 // Save a copy that can be reinstated if we need the code again.
1224 re->SetDataAt(JSRegExp::saved_code_index(is_one_byte), code); 1217 re->SetDataAt(JSRegExp::saved_code_index(is_one_byte), code);
1225 1218
1226 // Saving a copy might create a pointer into compaction candidate 1219 // Saving a copy might create a pointer into compaction candidate
1227 // that was not observed by marker. This might happen if JSRegExp data 1220 // that was not observed by marker. This might happen if JSRegExp data
1228 // was marked through the compilation cache before marker reached JSRegExp 1221 // was marked through the compilation cache before marker reached JSRegExp
1229 // object. 1222 // object.
1230 FixedArray* data = FixedArray::cast(re->data()); 1223 FixedArray* data = FixedArray::cast(re->data());
1231 if (Marking::IsBlackOrGrey(ObjectMarking::MarkBitFrom(data))) { 1224 if (ObjectMarking::IsBlackOrGrey(data)) {
1232 Object** slot = 1225 Object** slot =
1233 data->data_start() + JSRegExp::saved_code_index(is_one_byte); 1226 data->data_start() + JSRegExp::saved_code_index(is_one_byte);
1234 heap->mark_compact_collector()->RecordSlot(data, slot, code); 1227 heap->mark_compact_collector()->RecordSlot(data, slot, code);
1235 } 1228 }
1236 1229
1237 // Set a number in the 0-255 range to guarantee no smi overflow. 1230 // Set a number in the 0-255 range to guarantee no smi overflow.
1238 re->SetDataAt(JSRegExp::code_index(is_one_byte), 1231 re->SetDataAt(JSRegExp::code_index(is_one_byte),
1239 Smi::FromInt(heap->ms_count() & 0xff)); 1232 Smi::FromInt(heap->ms_count() & 0xff));
1240 } else if (code->IsSmi()) { 1233 } else if (code->IsSmi()) {
1241 int value = Smi::cast(code)->value(); 1234 int value = Smi::cast(code)->value();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 private: 1380 private:
1388 void MarkObjectByPointer(Object** p) { 1381 void MarkObjectByPointer(Object** p) {
1389 if (!(*p)->IsHeapObject()) return; 1382 if (!(*p)->IsHeapObject()) return;
1390 1383
1391 HeapObject* object = HeapObject::cast(*p); 1384 HeapObject* object = HeapObject::cast(*p);
1392 1385
1393 if (mode == MarkCompactMode::YOUNG_GENERATION && 1386 if (mode == MarkCompactMode::YOUNG_GENERATION &&
1394 !collector_->heap()->InNewSpace(object)) 1387 !collector_->heap()->InNewSpace(object))
1395 return; 1388 return;
1396 1389
1397 MarkBit mark_bit = ObjectMarking::MarkBitFrom(object); 1390 if (ObjectMarking::IsBlackOrGrey(object)) return;
1398 if (Marking::IsBlackOrGrey(mark_bit)) return;
1399 1391
1400 Map* map = object->map(); 1392 Map* map = object->map();
1401 // Mark the object. 1393 // Mark the object.
1402 collector_->SetMark(object, mark_bit); 1394 collector_->SetMark(object);
1403 1395
1404 switch (mode) { 1396 switch (mode) {
1405 case MarkCompactMode::FULL: { 1397 case MarkCompactMode::FULL: {
1406 // Mark the map pointer and body, and push them on the marking stack. 1398 // Mark the map pointer and body, and push them on the marking stack.
1407 MarkBit map_mark = ObjectMarking::MarkBitFrom(map); 1399 MarkBit map_mark = ObjectMarking::MarkBitFrom(map);
1408 collector_->MarkObject(map, map_mark); 1400 collector_->MarkObject(map, map_mark);
1409 MarkCompactMarkingVisitor::IterateBody(map, object); 1401 MarkCompactMarkingVisitor::IterateBody(map, object);
1410 } break; 1402 } break;
1411 case MarkCompactMode::YOUNG_GENERATION: 1403 case MarkCompactMode::YOUNG_GENERATION:
1412 StaticYoungGenerationMarkingVisitor::IterateBody(map, object); 1404 StaticYoungGenerationMarkingVisitor::IterateBody(map, object);
(...skipping 17 matching lines...) Expand all
1430 : heap_(heap), pointers_removed_(0), table_(table) { 1422 : heap_(heap), pointers_removed_(0), table_(table) {
1431 DCHECK(!record_slots || table != nullptr); 1423 DCHECK(!record_slots || table != nullptr);
1432 } 1424 }
1433 1425
1434 void VisitPointers(Object** start, Object** end) override { 1426 void VisitPointers(Object** start, Object** end) override {
1435 // Visit all HeapObject pointers in [start, end). 1427 // Visit all HeapObject pointers in [start, end).
1436 MarkCompactCollector* collector = heap_->mark_compact_collector(); 1428 MarkCompactCollector* collector = heap_->mark_compact_collector();
1437 for (Object** p = start; p < end; p++) { 1429 for (Object** p = start; p < end; p++) {
1438 Object* o = *p; 1430 Object* o = *p;
1439 if (o->IsHeapObject()) { 1431 if (o->IsHeapObject()) {
1440 if (Marking::IsWhite(ObjectMarking::MarkBitFrom(HeapObject::cast(o)))) { 1432 if (ObjectMarking::IsWhite(HeapObject::cast(o))) {
1441 if (finalize_external_strings) { 1433 if (finalize_external_strings) {
1442 if (o->IsExternalString()) { 1434 if (o->IsExternalString()) {
1443 heap_->FinalizeExternalString(String::cast(*p)); 1435 heap_->FinalizeExternalString(String::cast(*p));
1444 } else { 1436 } else {
1445 // The original external string may have been internalized. 1437 // The original external string may have been internalized.
1446 DCHECK(o->IsThinString()); 1438 DCHECK(o->IsThinString());
1447 } 1439 }
1448 } else { 1440 } else {
1449 pointers_removed_++; 1441 pointers_removed_++;
1450 } 1442 }
(...skipping 20 matching lines...) Expand all
1471 }; 1463 };
1472 1464
1473 typedef StringTableCleaner<false, true> InternalizedStringTableCleaner; 1465 typedef StringTableCleaner<false, true> InternalizedStringTableCleaner;
1474 typedef StringTableCleaner<true, false> ExternalStringTableCleaner; 1466 typedef StringTableCleaner<true, false> ExternalStringTableCleaner;
1475 1467
1476 // Implementation of WeakObjectRetainer for mark compact GCs. All marked objects 1468 // Implementation of WeakObjectRetainer for mark compact GCs. All marked objects
1477 // are retained. 1469 // are retained.
1478 class MarkCompactWeakObjectRetainer : public WeakObjectRetainer { 1470 class MarkCompactWeakObjectRetainer : public WeakObjectRetainer {
1479 public: 1471 public:
1480 virtual Object* RetainAs(Object* object) { 1472 virtual Object* RetainAs(Object* object) {
1481 MarkBit mark_bit = ObjectMarking::MarkBitFrom(HeapObject::cast(object)); 1473 DCHECK(!ObjectMarking::IsGrey(HeapObject::cast(object)));
1482 DCHECK(!Marking::IsGrey(mark_bit)); 1474 if (ObjectMarking::IsBlack(HeapObject::cast(object))) {
1483 if (Marking::IsBlack(mark_bit)) {
1484 return object; 1475 return object;
1485 } else if (object->IsAllocationSite() && 1476 } else if (object->IsAllocationSite() &&
1486 !(AllocationSite::cast(object)->IsZombie())) { 1477 !(AllocationSite::cast(object)->IsZombie())) {
1487 // "dead" AllocationSites need to live long enough for a traversal of new 1478 // "dead" AllocationSites need to live long enough for a traversal of new
1488 // space. These sites get a one-time reprieve. 1479 // space. These sites get a one-time reprieve.
1489 AllocationSite* site = AllocationSite::cast(object); 1480 AllocationSite* site = AllocationSite::cast(object);
1490 site->MarkZombie(); 1481 site->MarkZombie();
1491 site->GetHeap()->mark_compact_collector()->MarkAllocationSite(site); 1482 site->GetHeap()->mark_compact_collector()->MarkAllocationSite(site);
1492 return object; 1483 return object;
1493 } else { 1484 } else {
1494 return NULL; 1485 return NULL;
1495 } 1486 }
1496 } 1487 }
1497 }; 1488 };
1498 1489
1499 1490
1500 // Fill the marking stack with overflowed objects returned by the given 1491 // Fill the marking stack with overflowed objects returned by the given
1501 // iterator. Stop when the marking stack is filled or the end of the space 1492 // iterator. Stop when the marking stack is filled or the end of the space
1502 // is reached, whichever comes first. 1493 // is reached, whichever comes first.
1503 template <class T> 1494 template <class T>
1504 void MarkCompactCollector::DiscoverGreyObjectsWithIterator(T* it) { 1495 void MarkCompactCollector::DiscoverGreyObjectsWithIterator(T* it) {
1505 // The caller should ensure that the marking stack is initially not full, 1496 // The caller should ensure that the marking stack is initially not full,
1506 // so that we don't waste effort pointlessly scanning for objects. 1497 // so that we don't waste effort pointlessly scanning for objects.
1507 DCHECK(!marking_deque()->IsFull()); 1498 DCHECK(!marking_deque()->IsFull());
1508 1499
1509 Map* filler_map = heap()->one_pointer_filler_map(); 1500 Map* filler_map = heap()->one_pointer_filler_map();
1510 for (HeapObject* object = it->Next(); object != NULL; object = it->Next()) { 1501 for (HeapObject* object = it->Next(); object != NULL; object = it->Next()) {
1511 MarkBit markbit = ObjectMarking::MarkBitFrom(object); 1502 if ((object->map() != filler_map) && ObjectMarking::IsGrey(object)) {
1512 if ((object->map() != filler_map) && Marking::IsGrey(markbit)) { 1503 ObjectMarking::GreyToBlack(object);
1513 Marking::GreyToBlack(markbit);
1514 PushBlack(object); 1504 PushBlack(object);
1515 if (marking_deque()->IsFull()) return; 1505 if (marking_deque()->IsFull()) return;
1516 } 1506 }
1517 } 1507 }
1518 } 1508 }
1519 1509
1520 void MarkCompactCollector::DiscoverGreyObjectsOnPage(MemoryChunk* p) { 1510 void MarkCompactCollector::DiscoverGreyObjectsOnPage(MemoryChunk* p) {
1521 DCHECK(!marking_deque()->IsFull()); 1511 DCHECK(!marking_deque()->IsFull());
1522 LiveObjectIterator<kGreyObjects> it(p); 1512 LiveObjectIterator<kGreyObjects> it(p);
1523 HeapObject* object = NULL; 1513 HeapObject* object = NULL;
1524 while ((object = it.Next()) != NULL) { 1514 while ((object = it.Next()) != NULL) {
1525 MarkBit markbit = ObjectMarking::MarkBitFrom(object); 1515 DCHECK(ObjectMarking::IsGrey(object));
1526 DCHECK(Marking::IsGrey(markbit)); 1516 ObjectMarking::GreyToBlack(object);
1527 Marking::GreyToBlack(markbit);
1528 PushBlack(object); 1517 PushBlack(object);
1529 if (marking_deque()->IsFull()) return; 1518 if (marking_deque()->IsFull()) return;
1530 } 1519 }
1531 } 1520 }
1532 1521
1533 class RecordMigratedSlotVisitor final : public ObjectVisitor { 1522 class RecordMigratedSlotVisitor final : public ObjectVisitor {
1534 public: 1523 public:
1535 explicit RecordMigratedSlotVisitor(MarkCompactCollector* collector) 1524 explicit RecordMigratedSlotVisitor(MarkCompactCollector* collector)
1536 : collector_(collector) {} 1525 : collector_(collector) {}
1537 1526
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 for (Page* page : PageRange(space->bottom(), space->top())) { 1956 for (Page* page : PageRange(space->bottom(), space->top())) {
1968 DiscoverGreyObjectsOnPage(page); 1957 DiscoverGreyObjectsOnPage(page);
1969 if (marking_deque()->IsFull()) return; 1958 if (marking_deque()->IsFull()) return;
1970 } 1959 }
1971 } 1960 }
1972 1961
1973 1962
1974 bool MarkCompactCollector::IsUnmarkedHeapObject(Object** p) { 1963 bool MarkCompactCollector::IsUnmarkedHeapObject(Object** p) {
1975 Object* o = *p; 1964 Object* o = *p;
1976 if (!o->IsHeapObject()) return false; 1965 if (!o->IsHeapObject()) return false;
1977 HeapObject* heap_object = HeapObject::cast(o); 1966 return ObjectMarking::IsWhite(HeapObject::cast(o));
1978 MarkBit mark = ObjectMarking::MarkBitFrom(heap_object);
1979 return Marking::IsWhite(mark);
1980 } 1967 }
1981 1968
1982 1969
1983 bool MarkCompactCollector::IsUnmarkedHeapObjectWithHeap(Heap* heap, 1970 bool MarkCompactCollector::IsUnmarkedHeapObjectWithHeap(Heap* heap,
1984 Object** p) { 1971 Object** p) {
1985 Object* o = *p; 1972 Object* o = *p;
1986 DCHECK(o->IsHeapObject()); 1973 DCHECK(o->IsHeapObject());
1987 HeapObject* heap_object = HeapObject::cast(o); 1974 return ObjectMarking::IsWhite(HeapObject::cast(o));
1988 MarkBit mark = ObjectMarking::MarkBitFrom(heap_object);
1989 return Marking::IsWhite(mark);
1990 } 1975 }
1991 1976
1992 void MarkCompactCollector::MarkStringTable( 1977 void MarkCompactCollector::MarkStringTable(
1993 RootMarkingVisitor<MarkCompactMode::FULL>* visitor) { 1978 RootMarkingVisitor<MarkCompactMode::FULL>* visitor) {
1994 StringTable* string_table = heap()->string_table(); 1979 StringTable* string_table = heap()->string_table();
1995 // Mark the string table itself. 1980 // Mark the string table itself.
1996 MarkBit string_table_mark = ObjectMarking::MarkBitFrom(string_table); 1981 if (ObjectMarking::IsWhite(string_table)) {
1997 if (Marking::IsWhite(string_table_mark)) {
1998 // String table could have already been marked by visiting the handles list. 1982 // String table could have already been marked by visiting the handles list.
1999 SetMark(string_table, string_table_mark); 1983 SetMark(string_table);
2000 } 1984 }
2001 // Explicitly mark the prefix. 1985 // Explicitly mark the prefix.
2002 string_table->IteratePrefix(visitor); 1986 string_table->IteratePrefix(visitor);
2003 ProcessMarkingDeque<MarkCompactMode::FULL>(); 1987 ProcessMarkingDeque<MarkCompactMode::FULL>();
2004 } 1988 }
2005 1989
2006 1990
2007 void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) { 1991 void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) {
2008 MarkBit mark_bit = ObjectMarking::MarkBitFrom(site); 1992 SetMark(site);
2009 SetMark(site, mark_bit);
2010 } 1993 }
2011 1994
2012 void MarkCompactCollector::MarkRoots( 1995 void MarkCompactCollector::MarkRoots(
2013 RootMarkingVisitor<MarkCompactMode::FULL>* visitor) { 1996 RootMarkingVisitor<MarkCompactMode::FULL>* visitor) {
2014 // Mark the heap roots including global variables, stack variables, 1997 // Mark the heap roots including global variables, stack variables,
2015 // etc., and all objects reachable from them. 1998 // etc., and all objects reachable from them.
2016 heap()->IterateStrongRoots(visitor, VISIT_ONLY_STRONG); 1999 heap()->IterateStrongRoots(visitor, VISIT_ONLY_STRONG);
2017 2000
2018 // Handle the string table specially. 2001 // Handle the string table specially.
2019 MarkStringTable(visitor); 2002 MarkStringTable(visitor);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 // After: the marking stack is empty, and all objects reachable from the 2045 // After: the marking stack is empty, and all objects reachable from the
2063 // marking stack have been marked, or are overflowed in the heap. 2046 // marking stack have been marked, or are overflowed in the heap.
2064 template <MarkCompactMode mode> 2047 template <MarkCompactMode mode>
2065 void MarkCompactCollector::EmptyMarkingDeque() { 2048 void MarkCompactCollector::EmptyMarkingDeque() {
2066 while (!marking_deque()->IsEmpty()) { 2049 while (!marking_deque()->IsEmpty()) {
2067 HeapObject* object = marking_deque()->Pop(); 2050 HeapObject* object = marking_deque()->Pop();
2068 2051
2069 DCHECK(!object->IsFiller()); 2052 DCHECK(!object->IsFiller());
2070 DCHECK(object->IsHeapObject()); 2053 DCHECK(object->IsHeapObject());
2071 DCHECK(heap()->Contains(object)); 2054 DCHECK(heap()->Contains(object));
2072 DCHECK(!Marking::IsWhite(ObjectMarking::MarkBitFrom(object))); 2055 DCHECK(!ObjectMarking::IsWhite(object));
2073 2056
2074 Map* map = object->map(); 2057 Map* map = object->map();
2075 switch (mode) { 2058 switch (mode) {
2076 case MarkCompactMode::FULL: { 2059 case MarkCompactMode::FULL: {
2077 MarkBit map_mark = ObjectMarking::MarkBitFrom(map); 2060 MarkBit map_mark = ObjectMarking::MarkBitFrom(map);
2078 MarkObject(map, map_mark); 2061 MarkObject(map, map_mark);
2079 MarkCompactMarkingVisitor::IterateBody(map, object); 2062 MarkCompactMarkingVisitor::IterateBody(map, object);
2080 } break; 2063 } break;
2081 case MarkCompactMode::YOUNG_GENERATION: { 2064 case MarkCompactMode::YOUNG_GENERATION: {
2082 DCHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(object))); 2065 DCHECK(ObjectMarking::IsBlack(object));
2083 StaticYoungGenerationMarkingVisitor::IterateBody(map, object); 2066 StaticYoungGenerationMarkingVisitor::IterateBody(map, object);
2084 } break; 2067 } break;
2085 } 2068 }
2086 } 2069 }
2087 } 2070 }
2088 2071
2089 2072
2090 // Sweep the heap for overflowed objects, clear their overflow bits, and 2073 // Sweep the heap for overflowed objects, clear their overflow bits, and
2091 // push them on the marking stack. Stop early if the marking stack fills 2074 // push them on the marking stack. Stop early if the marking stack fills
2092 // before sweeping completes. If sweeping completes, there are no remaining 2075 // before sweeping completes. If sweeping completes, there are no remaining
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2273 ObjectStatsVisitor(Heap* heap, ObjectStats* live_stats, 2256 ObjectStatsVisitor(Heap* heap, ObjectStats* live_stats,
2274 ObjectStats* dead_stats) 2257 ObjectStats* dead_stats)
2275 : live_collector_(heap, live_stats), dead_collector_(heap, dead_stats) { 2258 : live_collector_(heap, live_stats), dead_collector_(heap, dead_stats) {
2276 DCHECK_NOT_NULL(live_stats); 2259 DCHECK_NOT_NULL(live_stats);
2277 DCHECK_NOT_NULL(dead_stats); 2260 DCHECK_NOT_NULL(dead_stats);
2278 // Global objects are roots and thus recorded as live. 2261 // Global objects are roots and thus recorded as live.
2279 live_collector_.CollectGlobalStatistics(); 2262 live_collector_.CollectGlobalStatistics();
2280 } 2263 }
2281 2264
2282 bool Visit(HeapObject* obj) override { 2265 bool Visit(HeapObject* obj) override {
2283 if (Marking::IsBlack(ObjectMarking::MarkBitFrom(obj))) { 2266 if (ObjectMarking::IsBlack(obj)) {
2284 live_collector_.CollectStatistics(obj); 2267 live_collector_.CollectStatistics(obj);
2285 } else { 2268 } else {
2286 DCHECK(!Marking::IsGrey(ObjectMarking::MarkBitFrom(obj))); 2269 DCHECK(!ObjectMarking::IsGrey(obj));
2287 dead_collector_.CollectStatistics(obj); 2270 dead_collector_.CollectStatistics(obj);
2288 } 2271 }
2289 return true; 2272 return true;
2290 } 2273 }
2291 2274
2292 private: 2275 private:
2293 ObjectStatsCollector live_collector_; 2276 ObjectStatsCollector live_collector_;
2294 ObjectStatsCollector dead_collector_; 2277 ObjectStatsCollector dead_collector_;
2295 }; 2278 };
2296 2279
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 } 2315 }
2333 2316
2334 SlotCallbackResult MarkCompactCollector::CheckAndMarkObject( 2317 SlotCallbackResult MarkCompactCollector::CheckAndMarkObject(
2335 Heap* heap, Address slot_address) { 2318 Heap* heap, Address slot_address) {
2336 Object* object = *reinterpret_cast<Object**>(slot_address); 2319 Object* object = *reinterpret_cast<Object**>(slot_address);
2337 if (heap->InNewSpace(object)) { 2320 if (heap->InNewSpace(object)) {
2338 // Marking happens before flipping the young generation, so the object 2321 // Marking happens before flipping the young generation, so the object
2339 // has to be in ToSpace. 2322 // has to be in ToSpace.
2340 DCHECK(heap->InToSpace(object)); 2323 DCHECK(heap->InToSpace(object));
2341 HeapObject* heap_object = reinterpret_cast<HeapObject*>(object); 2324 HeapObject* heap_object = reinterpret_cast<HeapObject*>(object);
2342 MarkBit mark_bit = ObjectMarking::MarkBitFrom(heap_object); 2325 if (ObjectMarking::IsBlackOrGrey(heap_object)) {
2343 if (Marking::IsBlackOrGrey(mark_bit)) {
2344 return KEEP_SLOT; 2326 return KEEP_SLOT;
2345 } 2327 }
2346 heap->mark_compact_collector()->SetMark(heap_object, mark_bit); 2328 heap->mark_compact_collector()->SetMark(heap_object);
2347 StaticYoungGenerationMarkingVisitor::IterateBody(heap_object->map(), 2329 StaticYoungGenerationMarkingVisitor::IterateBody(heap_object->map(),
2348 heap_object); 2330 heap_object);
2349 return KEEP_SLOT; 2331 return KEEP_SLOT;
2350 } 2332 }
2351 return REMOVE_SLOT; 2333 return REMOVE_SLOT;
2352 } 2334 }
2353 2335
2354 static bool IsUnmarkedObject(Heap* heap, Object** p) { 2336 static bool IsUnmarkedObject(Heap* heap, Object** p) {
2355 DCHECK_IMPLIES(heap->InNewSpace(*p), heap->InToSpace(*p)); 2337 DCHECK_IMPLIES(heap->InNewSpace(*p), heap->InToSpace(*p));
2356 return heap->InNewSpace(*p) && 2338 return heap->InNewSpace(*p) && !ObjectMarking::IsBlack(HeapObject::cast(*p));
2357 !Marking::IsBlack(ObjectMarking::MarkBitFrom(HeapObject::cast(*p)));
2358 } 2339 }
2359 2340
2360 void MarkCompactCollector::MarkLiveObjectsInYoungGeneration() { 2341 void MarkCompactCollector::MarkLiveObjectsInYoungGeneration() {
2361 TRACE_GC(heap()->tracer(), GCTracer::Scope::MINOR_MC_MARK); 2342 TRACE_GC(heap()->tracer(), GCTracer::Scope::MINOR_MC_MARK);
2362 2343
2363 PostponeInterruptsScope postpone(isolate()); 2344 PostponeInterruptsScope postpone(isolate());
2364 2345
2365 StaticYoungGenerationMarkingVisitor::Initialize(heap()); 2346 StaticYoungGenerationMarkingVisitor::Initialize(heap());
2366 RootMarkingVisitor<MarkCompactMode::YOUNG_GENERATION> root_visitor(heap()); 2347 RootMarkingVisitor<MarkCompactMode::YOUNG_GENERATION> root_visitor(heap());
2367 2348
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
2629 } 2610 }
2630 2611
2631 2612
2632 void MarkCompactCollector::ClearSimpleMapTransitions( 2613 void MarkCompactCollector::ClearSimpleMapTransitions(
2633 Object* non_live_map_list) { 2614 Object* non_live_map_list) {
2634 Object* the_hole_value = heap()->the_hole_value(); 2615 Object* the_hole_value = heap()->the_hole_value();
2635 Object* weak_cell_obj = non_live_map_list; 2616 Object* weak_cell_obj = non_live_map_list;
2636 while (weak_cell_obj != Smi::kZero) { 2617 while (weak_cell_obj != Smi::kZero) {
2637 WeakCell* weak_cell = WeakCell::cast(weak_cell_obj); 2618 WeakCell* weak_cell = WeakCell::cast(weak_cell_obj);
2638 Map* map = Map::cast(weak_cell->value()); 2619 Map* map = Map::cast(weak_cell->value());
2639 DCHECK(Marking::IsWhite(ObjectMarking::MarkBitFrom(map))); 2620 DCHECK(ObjectMarking::IsWhite(map));
2640 Object* potential_parent = map->constructor_or_backpointer(); 2621 Object* potential_parent = map->constructor_or_backpointer();
2641 if (potential_parent->IsMap()) { 2622 if (potential_parent->IsMap()) {
2642 Map* parent = Map::cast(potential_parent); 2623 Map* parent = Map::cast(potential_parent);
2643 if (Marking::IsBlackOrGrey(ObjectMarking::MarkBitFrom(parent)) && 2624 if (ObjectMarking::IsBlackOrGrey(parent) &&
2644 parent->raw_transitions() == weak_cell) { 2625 parent->raw_transitions() == weak_cell) {
2645 ClearSimpleMapTransition(parent, map); 2626 ClearSimpleMapTransition(parent, map);
2646 } 2627 }
2647 } 2628 }
2648 weak_cell->clear(); 2629 weak_cell->clear();
2649 weak_cell_obj = weak_cell->next(); 2630 weak_cell_obj = weak_cell->next();
2650 weak_cell->clear_next(the_hole_value); 2631 weak_cell->clear_next(the_hole_value);
2651 } 2632 }
2652 } 2633 }
2653 2634
(...skipping 18 matching lines...) Expand all
2672 void MarkCompactCollector::ClearFullMapTransitions() { 2653 void MarkCompactCollector::ClearFullMapTransitions() {
2673 HeapObject* undefined = heap()->undefined_value(); 2654 HeapObject* undefined = heap()->undefined_value();
2674 Object* obj = heap()->encountered_transition_arrays(); 2655 Object* obj = heap()->encountered_transition_arrays();
2675 while (obj != Smi::kZero) { 2656 while (obj != Smi::kZero) {
2676 TransitionArray* array = TransitionArray::cast(obj); 2657 TransitionArray* array = TransitionArray::cast(obj);
2677 int num_transitions = array->number_of_entries(); 2658 int num_transitions = array->number_of_entries();
2678 DCHECK_EQ(TransitionArray::NumberOfTransitions(array), num_transitions); 2659 DCHECK_EQ(TransitionArray::NumberOfTransitions(array), num_transitions);
2679 if (num_transitions > 0) { 2660 if (num_transitions > 0) {
2680 Map* map = array->GetTarget(0); 2661 Map* map = array->GetTarget(0);
2681 Map* parent = Map::cast(map->constructor_or_backpointer()); 2662 Map* parent = Map::cast(map->constructor_or_backpointer());
2682 bool parent_is_alive = 2663 bool parent_is_alive = ObjectMarking::IsBlackOrGrey(parent);
2683 Marking::IsBlackOrGrey(ObjectMarking::MarkBitFrom(parent));
2684 DescriptorArray* descriptors = 2664 DescriptorArray* descriptors =
2685 parent_is_alive ? parent->instance_descriptors() : nullptr; 2665 parent_is_alive ? parent->instance_descriptors() : nullptr;
2686 bool descriptors_owner_died = 2666 bool descriptors_owner_died =
2687 CompactTransitionArray(parent, array, descriptors); 2667 CompactTransitionArray(parent, array, descriptors);
2688 if (descriptors_owner_died) { 2668 if (descriptors_owner_died) {
2689 TrimDescriptorArray(parent, descriptors); 2669 TrimDescriptorArray(parent, descriptors);
2690 } 2670 }
2691 } 2671 }
2692 obj = array->next_link(); 2672 obj = array->next_link();
2693 array->set_next_link(undefined, SKIP_WRITE_BARRIER); 2673 array->set_next_link(undefined, SKIP_WRITE_BARRIER);
2694 } 2674 }
2695 heap()->set_encountered_transition_arrays(Smi::kZero); 2675 heap()->set_encountered_transition_arrays(Smi::kZero);
2696 } 2676 }
2697 2677
2698 2678
2699 bool MarkCompactCollector::CompactTransitionArray( 2679 bool MarkCompactCollector::CompactTransitionArray(
2700 Map* map, TransitionArray* transitions, DescriptorArray* descriptors) { 2680 Map* map, TransitionArray* transitions, DescriptorArray* descriptors) {
2701 int num_transitions = transitions->number_of_entries(); 2681 int num_transitions = transitions->number_of_entries();
2702 bool descriptors_owner_died = false; 2682 bool descriptors_owner_died = false;
2703 int transition_index = 0; 2683 int transition_index = 0;
2704 // Compact all live transitions to the left. 2684 // Compact all live transitions to the left.
2705 for (int i = 0; i < num_transitions; ++i) { 2685 for (int i = 0; i < num_transitions; ++i) {
2706 Map* target = transitions->GetTarget(i); 2686 Map* target = transitions->GetTarget(i);
2707 DCHECK_EQ(target->constructor_or_backpointer(), map); 2687 DCHECK_EQ(target->constructor_or_backpointer(), map);
2708 if (Marking::IsWhite(ObjectMarking::MarkBitFrom(target))) { 2688 if (ObjectMarking::IsWhite(target)) {
2709 if (descriptors != nullptr && 2689 if (descriptors != nullptr &&
2710 target->instance_descriptors() == descriptors) { 2690 target->instance_descriptors() == descriptors) {
2711 descriptors_owner_died = true; 2691 descriptors_owner_died = true;
2712 } 2692 }
2713 } else { 2693 } else {
2714 if (i != transition_index) { 2694 if (i != transition_index) {
2715 Name* key = transitions->GetKey(i); 2695 Name* key = transitions->GetKey(i);
2716 transitions->SetKey(transition_index, key); 2696 transitions->SetKey(transition_index, key);
2717 Object** key_slot = transitions->GetKeySlot(transition_index); 2697 Object** key_slot = transitions->GetKeySlot(transition_index);
2718 RecordSlot(transitions, key_slot, key); 2698 RecordSlot(transitions, key_slot, key);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2873 // Cells for new-space objects embedded in optimized code are wrapped in 2853 // Cells for new-space objects embedded in optimized code are wrapped in
2874 // WeakCell and put into Heap::weak_object_to_code_table. 2854 // WeakCell and put into Heap::weak_object_to_code_table.
2875 // Such cells do not have any strong references but we want to keep them 2855 // Such cells do not have any strong references but we want to keep them
2876 // alive as long as the cell value is alive. 2856 // alive as long as the cell value is alive.
2877 // TODO(ulan): remove this once we remove Heap::weak_object_to_code_table. 2857 // TODO(ulan): remove this once we remove Heap::weak_object_to_code_table.
2878 if (value->IsCell()) { 2858 if (value->IsCell()) {
2879 Object* cell_value = Cell::cast(value)->value(); 2859 Object* cell_value = Cell::cast(value)->value();
2880 if (cell_value->IsHeapObject() && 2860 if (cell_value->IsHeapObject() &&
2881 MarkCompactCollector::IsMarked(HeapObject::cast(cell_value))) { 2861 MarkCompactCollector::IsMarked(HeapObject::cast(cell_value))) {
2882 // Resurrect the cell. 2862 // Resurrect the cell.
2883 MarkBit mark = ObjectMarking::MarkBitFrom(value); 2863 SetMark(value);
2884 SetMark(value, mark);
2885 Object** slot = HeapObject::RawField(value, Cell::kValueOffset); 2864 Object** slot = HeapObject::RawField(value, Cell::kValueOffset);
2886 RecordSlot(value, slot, *slot); 2865 RecordSlot(value, slot, *slot);
2887 slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset); 2866 slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
2888 RecordSlot(weak_cell, slot, *slot); 2867 RecordSlot(weak_cell, slot, *slot);
2889 clear_value = false; 2868 clear_value = false;
2890 } 2869 }
2891 } 2870 }
2892 if (value->IsMap()) { 2871 if (value->IsMap()) {
2893 // The map is non-live. 2872 // The map is non-live.
2894 Map* map = Map::cast(value); 2873 Map* map = Map::cast(value);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
3416 } 3395 }
3417 3396
3418 intptr_t freed_bytes = 0; 3397 intptr_t freed_bytes = 0;
3419 intptr_t max_freed_bytes = 0; 3398 intptr_t max_freed_bytes = 0;
3420 int curr_region = -1; 3399 int curr_region = -1;
3421 3400
3422 LiveObjectIterator<kBlackObjects> it(p); 3401 LiveObjectIterator<kBlackObjects> it(p);
3423 HeapObject* object = NULL; 3402 HeapObject* object = NULL;
3424 3403
3425 while ((object = it.Next()) != NULL) { 3404 while ((object = it.Next()) != NULL) {
3426 DCHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(object))); 3405 DCHECK(ObjectMarking::IsBlack(object));
3427 Address free_end = object->address(); 3406 Address free_end = object->address();
3428 if (free_end != free_start) { 3407 if (free_end != free_start) {
3429 CHECK_GT(free_end, free_start); 3408 CHECK_GT(free_end, free_start);
3430 size_t size = static_cast<size_t>(free_end - free_start); 3409 size_t size = static_cast<size_t>(free_end - free_start);
3431 if (free_space_mode == ZAP_FREE_SPACE) { 3410 if (free_space_mode == ZAP_FREE_SPACE) {
3432 memset(free_start, 0xcc, size); 3411 memset(free_start, 0xcc, size);
3433 } 3412 }
3434 if (free_list_mode == REBUILD_FREE_LIST) { 3413 if (free_list_mode == REBUILD_FREE_LIST) {
3435 freed_bytes = reinterpret_cast<PagedSpace*>(space)->UnaccountedFree( 3414 freed_bytes = reinterpret_cast<PagedSpace*>(space)->UnaccountedFree(
3436 free_start, size); 3415 free_start, size);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3506 Address start = code->instruction_start(); 3485 Address start = code->instruction_start();
3507 Address end = code->address() + code->Size(); 3486 Address end = code->address() + code->Size();
3508 3487
3509 RememberedSet<OLD_TO_NEW>::RemoveRangeTyped(page, start, end); 3488 RememberedSet<OLD_TO_NEW>::RemoveRangeTyped(page, start, end);
3510 3489
3511 if (heap_->incremental_marking()->IsCompacting() && 3490 if (heap_->incremental_marking()->IsCompacting() &&
3512 !ShouldSkipEvacuationSlotRecording(code)) { 3491 !ShouldSkipEvacuationSlotRecording(code)) {
3513 DCHECK(compacting_); 3492 DCHECK(compacting_);
3514 3493
3515 // If the object is white than no slots were recorded on it yet. 3494 // If the object is white than no slots were recorded on it yet.
3516 MarkBit mark_bit = ObjectMarking::MarkBitFrom(code); 3495 if (ObjectMarking::IsWhite(code)) return;
3517 if (Marking::IsWhite(mark_bit)) return;
3518 3496
3519 // Ignore all slots that might have been recorded in the body of the 3497 // Ignore all slots that might have been recorded in the body of the
3520 // deoptimized code object. Assumption: no slots will be recorded for 3498 // deoptimized code object. Assumption: no slots will be recorded for
3521 // this object after invalidating it. 3499 // this object after invalidating it.
3522 RememberedSet<OLD_TO_OLD>::RemoveRangeTyped(page, start, end); 3500 RememberedSet<OLD_TO_OLD>::RemoveRangeTyped(page, start, end);
3523 } 3501 }
3524 } 3502 }
3525 3503
3526 3504
3527 // Return true if the given code is deoptimized or will be deoptimized. 3505 // Return true if the given code is deoptimized or will be deoptimized.
3528 bool MarkCompactCollector::WillBeDeoptimized(Code* code) { 3506 bool MarkCompactCollector::WillBeDeoptimized(Code* code) {
3529 return code->is_optimized_code() && code->marked_for_deoptimization(); 3507 return code->is_optimized_code() && code->marked_for_deoptimization();
3530 } 3508 }
3531 3509
3532 3510
3533 #ifdef VERIFY_HEAP 3511 #ifdef VERIFY_HEAP
3534 static void VerifyAllBlackObjects(MemoryChunk* page) { 3512 static void VerifyAllBlackObjects(MemoryChunk* page) {
3535 LiveObjectIterator<kAllLiveObjects> it(page); 3513 LiveObjectIterator<kAllLiveObjects> it(page);
3536 HeapObject* object = NULL; 3514 HeapObject* object = NULL;
3537 while ((object = it.Next()) != NULL) { 3515 while ((object = it.Next()) != NULL) {
3538 CHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(object))); 3516 CHECK(ObjectMarking::IsBlack(object));
3539 } 3517 }
3540 } 3518 }
3541 #endif // VERIFY_HEAP 3519 #endif // VERIFY_HEAP
3542 3520
3543 template <class Visitor> 3521 template <class Visitor>
3544 bool MarkCompactCollector::VisitLiveObjects(MemoryChunk* page, Visitor* visitor, 3522 bool MarkCompactCollector::VisitLiveObjects(MemoryChunk* page, Visitor* visitor,
3545 IterationMode mode) { 3523 IterationMode mode) {
3546 #ifdef VERIFY_HEAP 3524 #ifdef VERIFY_HEAP
3547 VerifyAllBlackObjects(page); 3525 VerifyAllBlackObjects(page);
3548 #endif // VERIFY_HEAP 3526 #endif // VERIFY_HEAP
3549 3527
3550 LiveObjectIterator<kBlackObjects> it(page); 3528 LiveObjectIterator<kBlackObjects> it(page);
3551 HeapObject* object = nullptr; 3529 HeapObject* object = nullptr;
3552 while ((object = it.Next()) != nullptr) { 3530 while ((object = it.Next()) != nullptr) {
3553 DCHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(object))); 3531 DCHECK(ObjectMarking::IsBlack(object));
3554 if (!visitor->Visit(object)) { 3532 if (!visitor->Visit(object)) {
3555 if (mode == kClearMarkbits) { 3533 if (mode == kClearMarkbits) {
3556 page->markbits()->ClearRange( 3534 page->markbits()->ClearRange(
3557 page->AddressToMarkbitIndex(page->area_start()), 3535 page->AddressToMarkbitIndex(page->area_start()),
3558 page->AddressToMarkbitIndex(object->address())); 3536 page->AddressToMarkbitIndex(object->address()));
3559 if (page->old_to_new_slots() != nullptr) { 3537 if (page->old_to_new_slots() != nullptr) {
3560 page->old_to_new_slots()->RemoveRange( 3538 page->old_to_new_slots()->RemoveRange(
3561 0, static_cast<int>(object->address() - page->address()), 3539 0, static_cast<int>(object->address() - page->address()),
3562 SlotSet::PREFREE_EMPTY_BUCKETS); 3540 SlotSet::PREFREE_EMPTY_BUCKETS);
3563 } 3541 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
3740 // Unfortunately, we do not know about the slot. It could be in a 3718 // Unfortunately, we do not know about the slot. It could be in a
3741 // just freed free space object. 3719 // just freed free space object.
3742 if (heap->InToSpace(slot->Value())) { 3720 if (heap->InToSpace(slot->Value())) {
3743 return KEEP_SLOT; 3721 return KEEP_SLOT;
3744 } 3722 }
3745 } else if (heap->InToSpace(slot_reference)) { 3723 } else if (heap->InToSpace(slot_reference)) {
3746 // Slots can point to "to" space if the page has been moved, or if the 3724 // Slots can point to "to" space if the page has been moved, or if the
3747 // slot has been recorded multiple times in the remembered set. Since 3725 // slot has been recorded multiple times in the remembered set. Since
3748 // there is no forwarding information present we need to check the 3726 // there is no forwarding information present we need to check the
3749 // markbits to determine liveness. 3727 // markbits to determine liveness.
3750 if (Marking::IsBlack(ObjectMarking::MarkBitFrom( 3728 if (ObjectMarking::IsBlack(reinterpret_cast<HeapObject*>(slot_reference)))
3751 reinterpret_cast<HeapObject*>(slot_reference))))
3752 return KEEP_SLOT; 3729 return KEEP_SLOT;
3753 } else { 3730 } else {
3754 DCHECK(!heap->InNewSpace(slot_reference)); 3731 DCHECK(!heap->InNewSpace(slot_reference));
3755 } 3732 }
3756 return REMOVE_SLOT; 3733 return REMOVE_SLOT;
3757 } 3734 }
3758 }; 3735 };
3759 3736
3760 int NumberOfPointerUpdateTasks(int pages) { 3737 int NumberOfPointerUpdateTasks(int pages) {
3761 if (!FLAG_parallel_pointer_update) return 1; 3738 if (!FLAG_parallel_pointer_update) return 1;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
4075 } 4052 }
4076 } 4053 }
4077 4054
4078 4055
4079 void MarkCompactCollector::RecordCodeTargetPatch(Address pc, Code* target) { 4056 void MarkCompactCollector::RecordCodeTargetPatch(Address pc, Code* target) {
4080 DCHECK(heap()->gc_state() == Heap::MARK_COMPACT); 4057 DCHECK(heap()->gc_state() == Heap::MARK_COMPACT);
4081 if (is_compacting()) { 4058 if (is_compacting()) {
4082 Code* host = 4059 Code* host =
4083 isolate()->inner_pointer_to_code_cache()->GcSafeFindCodeForInnerPointer( 4060 isolate()->inner_pointer_to_code_cache()->GcSafeFindCodeForInnerPointer(
4084 pc); 4061 pc);
4085 MarkBit mark_bit = ObjectMarking::MarkBitFrom(host); 4062 if (ObjectMarking::IsBlack(host)) {
4086 if (Marking::IsBlack(mark_bit)) {
4087 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); 4063 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host);
4088 // The target is always in old space, we don't have to record the slot in 4064 // The target is always in old space, we don't have to record the slot in
4089 // the old-to-new remembered set. 4065 // the old-to-new remembered set.
4090 DCHECK(!heap()->InNewSpace(target)); 4066 DCHECK(!heap()->InNewSpace(target));
4091 RecordRelocSlot(host, &rinfo, target); 4067 RecordRelocSlot(host, &rinfo, target);
4092 } 4068 }
4093 } 4069 }
4094 } 4070 }
4095 4071
4096 } // namespace internal 4072 } // namespace internal
4097 } // namespace v8 4073 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/mark-compact-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698