Index: src/mark-compact.cc |
diff --git a/src/mark-compact.cc b/src/mark-compact.cc |
index 4bf00aa031eff05a831f8c328c866f0ba5b1b758..feec2e116c3de3312a91d9ec9486c048ebbf4f6a 100644 |
--- a/src/mark-compact.cc |
+++ b/src/mark-compact.cc |
@@ -938,18 +938,9 @@ static inline HeapObject* ShortCircuitConsString(Object** p) { |
} |
-class StaticMarkingVisitor : public StaticVisitorBase { |
+class MarkCompactMarkingVisitor |
+ : public StaticMarkingVisitor<MarkCompactMarkingVisitor> { |
public: |
- static inline void IterateBody(Map* map, HeapObject* obj) { |
- table_.GetVisitor(map)(map, obj); |
- } |
- |
- template<int id> |
- class ObjectStatsTracker { |
- public: |
- static inline void Visit(Map* map, HeapObject* obj); |
- }; |
- |
static void Initialize(); |
INLINE(static void VisitPointer(Heap* heap, Object** p)) { |
@@ -969,12 +960,9 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
} |
} |
- static void VisitGlobalPropertyCell(Heap* heap, RelocInfo* rinfo) { |
- ASSERT(rinfo->rmode() == RelocInfo::GLOBAL_PROPERTY_CELL); |
- JSGlobalPropertyCell* cell = |
- JSGlobalPropertyCell::cast(rinfo->target_cell()); |
- MarkBit mark = Marking::MarkBitFrom(cell); |
- heap->mark_compact_collector()->MarkObject(cell, mark); |
+ INLINE(static void MarkObject(Heap* heap, HeapObject* object)) { |
+ MarkBit mark = Marking::MarkBitFrom(object); |
+ heap->mark_compact_collector()->MarkObject(object, mark); |
} |
static inline void VisitEmbeddedPointer(Heap* heap, RelocInfo* rinfo) { |
@@ -983,8 +971,7 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
// that there can be no such embedded pointers and add assertion here. |
HeapObject* object = HeapObject::cast(rinfo->target_object()); |
heap->mark_compact_collector()->RecordRelocSlot(rinfo, object); |
- MarkBit mark = Marking::MarkBitFrom(object); |
- heap->mark_compact_collector()->MarkObject(object, mark); |
+ MarkObject(heap, object); |
} |
static inline void VisitCodeTarget(Heap* heap, RelocInfo* rinfo) { |
@@ -997,20 +984,8 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
IC::Clear(rinfo->pc()); |
target = Code::GetCodeFromTargetAddress(rinfo->target_address()); |
} |
- MarkBit code_mark = Marking::MarkBitFrom(target); |
- heap->mark_compact_collector()->MarkObject(target, code_mark); |
- heap->mark_compact_collector()->RecordRelocSlot(rinfo, target); |
- } |
- |
- static inline void VisitDebugTarget(Heap* heap, RelocInfo* rinfo) { |
- ASSERT((RelocInfo::IsJSReturn(rinfo->rmode()) && |
- rinfo->IsPatchedReturnSequence()) || |
- (RelocInfo::IsDebugBreakSlot(rinfo->rmode()) && |
- rinfo->IsPatchedDebugBreakSlotSequence())); |
- Code* target = Code::GetCodeFromTargetAddress(rinfo->call_address()); |
- MarkBit code_mark = Marking::MarkBitFrom(target); |
- heap->mark_compact_collector()->MarkObject(target, code_mark); |
heap->mark_compact_collector()->RecordRelocSlot(rinfo, target); |
+ MarkObject(heap, target); |
} |
// Mark object pointed to by p. |
@@ -1065,28 +1040,14 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
return true; |
} |
- static inline void VisitExternalReference(Address* p) { } |
- static inline void VisitExternalReference(RelocInfo* rinfo) { } |
- static inline void VisitRuntimeEntry(RelocInfo* rinfo) { } |
- |
- private: |
- class DataObjectVisitor { |
- public: |
- template<int size> |
- static void VisitSpecialized(Map* map, HeapObject* object) { |
- } |
- |
- static void Visit(Map* map, HeapObject* object) { |
+ static void VisitCode(Map* map, HeapObject* object) { |
+ Heap* heap = map->GetHeap(); |
+ Code* code = reinterpret_cast<Code*>(object); |
+ if (FLAG_cleanup_code_caches_at_gc) { |
+ code->ClearTypeFeedbackCells(heap); |
} |
- }; |
- |
- typedef FlexibleBodyVisitor<StaticMarkingVisitor, |
- JSObject::BodyDescriptor, |
- void> JSObjectVisitor; |
- |
- typedef FlexibleBodyVisitor<StaticMarkingVisitor, |
- StructBodyDescriptor, |
- void> StructObjectVisitor; |
+ code->CodeIterateBody<MarkCompactMarkingVisitor>(heap); |
+ } |
static void VisitJSWeakMap(Map* map, HeapObject* object) { |
MarkCompactCollector* collector = map->GetHeap()->mark_compact_collector(); |
@@ -1100,12 +1061,12 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
// Skip visiting the backing hash table containing the mappings. |
int object_size = JSWeakMap::BodyDescriptor::SizeOf(map, object); |
- BodyVisitorBase<StaticMarkingVisitor>::IteratePointers( |
+ BodyVisitorBase<MarkCompactMarkingVisitor>::IteratePointers( |
map->GetHeap(), |
object, |
JSWeakMap::BodyDescriptor::kStartOffset, |
JSWeakMap::kTableOffset); |
- BodyVisitorBase<StaticMarkingVisitor>::IteratePointers( |
+ BodyVisitorBase<MarkCompactMarkingVisitor>::IteratePointers( |
map->GetHeap(), |
object, |
JSWeakMap::kTableOffset + kPointerSize, |
@@ -1125,14 +1086,9 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
ASSERT(MarkCompactCollector::IsMarked(table->map())); |
} |
- static void VisitCode(Map* map, HeapObject* object) { |
- Heap* heap = map->GetHeap(); |
- Code* code = reinterpret_cast<Code*>(object); |
- if (FLAG_cleanup_code_caches_at_gc) { |
- code->ClearTypeFeedbackCells(heap); |
- } |
- code->CodeIterateBody<StaticMarkingVisitor>(heap); |
- } |
+ private: |
+ template<int id> |
+ static inline void TrackObjectStatsAndVisit(Map* map, HeapObject* obj); |
// Code flushing support. |
@@ -1247,7 +1203,7 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
static void VisitSharedFunctionInfoGeneric(Map* map, HeapObject* object) { |
SharedFunctionInfo::cast(object)->BeforeVisitingPointers(); |
- FixedBodyVisitor<StaticMarkingVisitor, |
+ FixedBodyVisitor<MarkCompactMarkingVisitor, |
SharedFunctionInfo::BodyDescriptor, |
void>::Visit(map, object); |
} |
@@ -1315,7 +1271,7 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
Heap* heap = map->GetHeap(); |
MarkCompactCollector* collector = heap->mark_compact_collector(); |
if (!collector->is_code_flushing_enabled()) { |
- VisitJSRegExpFields(map, object); |
+ VisitJSRegExp(map, object); |
return; |
} |
JSRegExp* re = reinterpret_cast<JSRegExp*>(object); |
@@ -1323,7 +1279,7 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
UpdateRegExpCodeAgeAndFlush(heap, re, true); |
UpdateRegExpCodeAgeAndFlush(heap, re, false); |
// Visit the fields of the RegExp, including the updated FixedArray. |
- VisitJSRegExpFields(map, object); |
+ VisitJSRegExp(map, object); |
} |
@@ -1362,29 +1318,6 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
} |
- static void VisitCodeEntry(Heap* heap, Address entry_address) { |
- Code* code = Code::cast(Code::GetObjectFromEntryAddress(entry_address)); |
- MarkBit mark = Marking::MarkBitFrom(code); |
- heap->mark_compact_collector()->MarkObject(code, mark); |
- heap->mark_compact_collector()-> |
- RecordCodeEntrySlot(entry_address, code); |
- } |
- |
- static void VisitGlobalContext(Map* map, HeapObject* object) { |
- FixedBodyVisitor<StaticMarkingVisitor, |
- Context::MarkCompactBodyDescriptor, |
- void>::Visit(map, object); |
- |
- MarkCompactCollector* collector = map->GetHeap()->mark_compact_collector(); |
- for (int idx = Context::FIRST_WEAK_SLOT; |
- idx < Context::GLOBAL_CONTEXT_SLOTS; |
- ++idx) { |
- Object** slot = |
- HeapObject::RawField(object, FixedArray::OffsetOfElementAt(idx)); |
- collector->RecordSlot(slot, slot, *slot); |
- } |
- } |
- |
static void VisitJSFunctionAndFlushCode(Map* map, HeapObject* object) { |
Heap* heap = map->GetHeap(); |
MarkCompactCollector* collector = heap->mark_compact_collector(); |
@@ -1466,15 +1399,6 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
JSFunction::kNonWeakFieldsEndOffset)); |
} |
- static inline void VisitJSRegExpFields(Map* map, |
- HeapObject* object) { |
- int last_property_offset = |
- JSRegExp::kSize + kPointerSize * map->inobject_properties(); |
- VisitPointers(map->GetHeap(), |
- SLOT_ADDR(object, JSRegExp::kPropertiesOffset), |
- SLOT_ADDR(object, last_property_offset)); |
- } |
- |
static void VisitSharedFunctionInfoFields(Heap* heap, |
HeapObject* object, |
@@ -1492,16 +1416,13 @@ class StaticMarkingVisitor : public StaticVisitorBase { |
#undef SLOT_ADDR |
- typedef void (*Callback)(Map* map, HeapObject* object); |
- |
- static VisitorDispatchTable<Callback> table_; |
static VisitorDispatchTable<Callback> non_count_table_; |
}; |
template<int id> |
-void StaticMarkingVisitor::ObjectStatsTracker<id>::Visit( |
- Map* map, HeapObject* obj) { |
+void MarkCompactMarkingVisitor::TrackObjectStatsAndVisit(Map* map, |
+ HeapObject* obj) { |
Heap* heap = map->GetHeap(); |
int object_size = obj->Size(); |
heap->RecordObjectStats(map->instance_type(), -1, object_size); |
@@ -1510,63 +1431,19 @@ void StaticMarkingVisitor::ObjectStatsTracker<id>::Visit( |
template<> |
-class StaticMarkingVisitor::ObjectStatsTracker< |
- StaticMarkingVisitor::kVisitCode> { |
- public: |
- static inline void Visit(Map* map, HeapObject* obj) { |
- Heap* heap = map->GetHeap(); |
- int object_size = obj->Size(); |
- ASSERT(map->instance_type() == CODE_TYPE); |
- heap->RecordObjectStats(CODE_TYPE, -1, object_size); |
- heap->RecordObjectStats(CODE_TYPE, Code::cast(obj)->kind(), object_size); |
- non_count_table_.GetVisitorById( |
- static_cast<VisitorId>(kVisitCode))(map, obj); |
- } |
-}; |
- |
- |
-void StaticMarkingVisitor::Initialize() { |
- table_.Register(kVisitShortcutCandidate, |
- &FixedBodyVisitor<StaticMarkingVisitor, |
- ConsString::BodyDescriptor, |
- void>::Visit); |
- |
- table_.Register(kVisitConsString, |
- &FixedBodyVisitor<StaticMarkingVisitor, |
- ConsString::BodyDescriptor, |
- void>::Visit); |
- |
- table_.Register(kVisitSlicedString, |
- &FixedBodyVisitor<StaticMarkingVisitor, |
- SlicedString::BodyDescriptor, |
- void>::Visit); |
- |
- table_.Register(kVisitFixedArray, |
- &FlexibleBodyVisitor<StaticMarkingVisitor, |
- FixedArray::BodyDescriptor, |
- void>::Visit); |
- |
- table_.Register(kVisitGlobalContext, &VisitGlobalContext); |
- |
- table_.Register(kVisitFixedDoubleArray, DataObjectVisitor::Visit); |
- |
- table_.Register(kVisitByteArray, &DataObjectVisitor::Visit); |
- table_.Register(kVisitFreeSpace, &DataObjectVisitor::Visit); |
- table_.Register(kVisitSeqAsciiString, &DataObjectVisitor::Visit); |
- table_.Register(kVisitSeqTwoByteString, &DataObjectVisitor::Visit); |
- |
- table_.Register(kVisitJSWeakMap, &VisitJSWeakMap); |
+void MarkCompactMarkingVisitor::TrackObjectStatsAndVisit< |
+ MarkCompactMarkingVisitor::kVisitCode>(Map* map, HeapObject* obj) { |
+ Heap* heap = map->GetHeap(); |
+ int object_size = obj->Size(); |
+ ASSERT(map->instance_type() == CODE_TYPE); |
+ heap->RecordObjectStats(CODE_TYPE, -1, object_size); |
+ heap->RecordObjectStats(CODE_TYPE, Code::cast(obj)->kind(), object_size); |
+ non_count_table_.GetVisitorById(static_cast<VisitorId>(kVisitCode))(map, obj); |
+} |
- table_.Register(kVisitOddball, |
- &FixedBodyVisitor<StaticMarkingVisitor, |
- Oddball::BodyDescriptor, |
- void>::Visit); |
- table_.Register(kVisitMap, |
- &FixedBodyVisitor<StaticMarkingVisitor, |
- Map::BodyDescriptor, |
- void>::Visit); |
- table_.Register(kVisitCode, &VisitCode); |
+void MarkCompactMarkingVisitor::Initialize() { |
+ StaticMarkingVisitor<MarkCompactMarkingVisitor>::Initialize(); |
table_.Register(kVisitSharedFunctionInfo, |
&VisitSharedFunctionInfoAndFlushCode); |
@@ -1577,38 +1454,19 @@ void StaticMarkingVisitor::Initialize() { |
table_.Register(kVisitJSRegExp, |
&VisitRegExpAndFlushCode); |
- table_.Register(kVisitPropertyCell, |
- &FixedBodyVisitor<StaticMarkingVisitor, |
- JSGlobalPropertyCell::BodyDescriptor, |
- void>::Visit); |
- |
- table_.RegisterSpecializations<DataObjectVisitor, |
- kVisitDataObject, |
- kVisitDataObjectGeneric>(); |
- |
- table_.RegisterSpecializations<JSObjectVisitor, |
- kVisitJSObject, |
- kVisitJSObjectGeneric>(); |
- |
- table_.RegisterSpecializations<StructObjectVisitor, |
- kVisitStruct, |
- kVisitStructGeneric>(); |
- |
if (FLAG_track_gc_object_stats) { |
// Copy the visitor table to make call-through possible. |
non_count_table_.CopyFrom(&table_); |
#define VISITOR_ID_COUNT_FUNCTION(id) \ |
- table_.Register(kVisit##id, ObjectStatsTracker<kVisit##id>::Visit); |
+ table_.Register(kVisit##id, TrackObjectStatsAndVisit<kVisit##id>); |
VISITOR_ID_LIST(VISITOR_ID_COUNT_FUNCTION) |
#undef VISITOR_ID_COUNT_FUNCTION |
} |
} |
-VisitorDispatchTable<StaticMarkingVisitor::Callback> |
- StaticMarkingVisitor::table_; |
-VisitorDispatchTable<StaticMarkingVisitor::Callback> |
- StaticMarkingVisitor::non_count_table_; |
+VisitorDispatchTable<MarkCompactMarkingVisitor::Callback> |
+ MarkCompactMarkingVisitor::non_count_table_; |
class MarkingVisitor : public ObjectVisitor { |
@@ -1616,11 +1474,11 @@ class MarkingVisitor : public ObjectVisitor { |
explicit MarkingVisitor(Heap* heap) : heap_(heap) { } |
void VisitPointer(Object** p) { |
- StaticMarkingVisitor::VisitPointer(heap_, p); |
+ MarkCompactMarkingVisitor::VisitPointer(heap_, p); |
} |
void VisitPointers(Object** start, Object** end) { |
- StaticMarkingVisitor::VisitPointers(heap_, start, end); |
+ MarkCompactMarkingVisitor::VisitPointers(heap_, start, end); |
} |
private: |
@@ -1779,7 +1637,7 @@ class RootMarkingVisitor : public ObjectVisitor { |
// Mark the map pointer and body, and push them on the marking stack. |
MarkBit map_mark = Marking::MarkBitFrom(map); |
collector_->MarkObject(map, map_mark); |
- StaticMarkingVisitor::IterateBody(map, object); |
+ MarkCompactMarkingVisitor::IterateBody(map, object); |
// Mark all the objects reachable from the map and body. May leave |
// overflowed objects in the heap. |
@@ -2249,7 +2107,7 @@ void MarkCompactCollector::EmptyMarkingDeque() { |
MarkBit map_mark = Marking::MarkBitFrom(map); |
MarkObject(map, map_mark); |
- StaticMarkingVisitor::IterateBody(map, object); |
+ MarkCompactMarkingVisitor::IterateBody(map, object); |
} |
// Process encountered weak maps, mark objects only reachable by those |
@@ -2388,7 +2246,7 @@ void MarkCompactCollector::MarkLiveObjects() { |
ASSERT(cell->IsJSGlobalPropertyCell()); |
if (IsMarked(cell)) { |
int offset = JSGlobalPropertyCell::kValueOffset; |
- StaticMarkingVisitor::VisitPointer( |
+ MarkCompactMarkingVisitor::VisitPointer( |
heap(), |
reinterpret_cast<Object**>(cell->address() + offset)); |
} |
@@ -2647,7 +2505,7 @@ void MarkCompactCollector::ProcessWeakMaps() { |
Object** value_slot = |
HeapObject::RawField(table, FixedArray::OffsetOfElementAt( |
ObjectHashTable::EntryToValueIndex(i))); |
- StaticMarkingVisitor::MarkObjectByPointer(this, anchor, value_slot); |
+ MarkCompactMarkingVisitor::MarkObjectByPointer(this, anchor, value_slot); |
} |
} |
weak_map_obj = weak_map->next(); |
@@ -4046,7 +3904,8 @@ void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj, |
void MarkCompactCollector::Initialize() { |
- StaticMarkingVisitor::Initialize(); |
+ MarkCompactMarkingVisitor::Initialize(); |
+ IncrementalMarking::Initialize(); |
} |