| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 return HeapObject::cast(first); | 937 return HeapObject::cast(first); |
| 938 } | 938 } |
| 939 | 939 |
| 940 | 940 |
| 941 class StaticMarkingVisitor : public StaticVisitorBase { | 941 class StaticMarkingVisitor : public StaticVisitorBase { |
| 942 public: | 942 public: |
| 943 static inline void IterateBody(Map* map, HeapObject* obj) { | 943 static inline void IterateBody(Map* map, HeapObject* obj) { |
| 944 table_.GetVisitor(map)(map, obj); | 944 table_.GetVisitor(map)(map, obj); |
| 945 } | 945 } |
| 946 | 946 |
| 947 static void ObjectStatsVisitBase(StaticVisitorBase::VisitorId id, | |
| 948 Map* map, HeapObject* obj); | |
| 949 | |
| 950 static void ObjectStatsCountFixedArray( | |
| 951 FixedArrayBase* fixed_array, | |
| 952 FixedArraySubInstanceType fast_type, | |
| 953 FixedArraySubInstanceType dictionary_type); | |
| 954 | |
| 955 template<StaticMarkingVisitor::VisitorId id> | |
| 956 class ObjectStatsTracker { | |
| 957 public: | |
| 958 static inline void Visit(Map* map, HeapObject* obj); | |
| 959 }; | |
| 960 | |
| 961 static void Initialize(); | 947 static void Initialize(); |
| 962 | 948 |
| 963 INLINE(static void VisitPointer(Heap* heap, Object** p)) { | 949 INLINE(static void VisitPointer(Heap* heap, Object** p)) { |
| 964 MarkObjectByPointer(heap->mark_compact_collector(), p, p); | 950 MarkObjectByPointer(heap->mark_compact_collector(), p, p); |
| 965 } | 951 } |
| 966 | 952 |
| 967 INLINE(static void VisitPointers(Heap* heap, Object** start, Object** end)) { | 953 INLINE(static void VisitPointers(Heap* heap, Object** start, Object** end)) { |
| 968 // Mark all objects pointed to in [start, end). | 954 // Mark all objects pointed to in [start, end). |
| 969 const int kMinRangeForMarkingRecursion = 64; | 955 const int kMinRangeForMarkingRecursion = 64; |
| 970 if (end - start >= kMinRangeForMarkingRecursion) { | 956 if (end - start >= kMinRangeForMarkingRecursion) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 }; | 1075 }; |
| 1090 | 1076 |
| 1091 typedef FlexibleBodyVisitor<StaticMarkingVisitor, | 1077 typedef FlexibleBodyVisitor<StaticMarkingVisitor, |
| 1092 JSObject::BodyDescriptor, | 1078 JSObject::BodyDescriptor, |
| 1093 void> JSObjectVisitor; | 1079 void> JSObjectVisitor; |
| 1094 | 1080 |
| 1095 typedef FlexibleBodyVisitor<StaticMarkingVisitor, | 1081 typedef FlexibleBodyVisitor<StaticMarkingVisitor, |
| 1096 StructBodyDescriptor, | 1082 StructBodyDescriptor, |
| 1097 void> StructObjectVisitor; | 1083 void> StructObjectVisitor; |
| 1098 | 1084 |
| 1085 template<StaticVisitorBase::VisitorId id> |
| 1086 static inline void TrackObjectStatsAndVisit(Map* map, HeapObject* obj); |
| 1087 |
| 1088 static inline void TrackObjectStatsAndVisitBase( |
| 1089 StaticVisitorBase::VisitorId id, Map* map, HeapObject* obj); |
| 1090 |
| 1099 static void VisitJSWeakMap(Map* map, HeapObject* object) { | 1091 static void VisitJSWeakMap(Map* map, HeapObject* object) { |
| 1100 MarkCompactCollector* collector = map->GetHeap()->mark_compact_collector(); | 1092 MarkCompactCollector* collector = map->GetHeap()->mark_compact_collector(); |
| 1101 JSWeakMap* weak_map = reinterpret_cast<JSWeakMap*>(object); | 1093 JSWeakMap* weak_map = reinterpret_cast<JSWeakMap*>(object); |
| 1102 | 1094 |
| 1103 // Enqueue weak map in linked list of encountered weak maps. | 1095 // Enqueue weak map in linked list of encountered weak maps. |
| 1104 if (weak_map->next() == Smi::FromInt(0)) { | 1096 if (weak_map->next() == Smi::FromInt(0)) { |
| 1105 weak_map->set_next(collector->encountered_weak_maps()); | 1097 weak_map->set_next(collector->encountered_weak_maps()); |
| 1106 collector->set_encountered_weak_maps(weak_map); | 1098 collector->set_encountered_weak_maps(weak_map); |
| 1107 } | 1099 } |
| 1108 | 1100 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 | 1492 |
| 1501 #undef SLOT_ADDR | 1493 #undef SLOT_ADDR |
| 1502 | 1494 |
| 1503 typedef void (*Callback)(Map* map, HeapObject* object); | 1495 typedef void (*Callback)(Map* map, HeapObject* object); |
| 1504 | 1496 |
| 1505 static VisitorDispatchTable<Callback> table_; | 1497 static VisitorDispatchTable<Callback> table_; |
| 1506 static VisitorDispatchTable<Callback> non_count_table_; | 1498 static VisitorDispatchTable<Callback> non_count_table_; |
| 1507 }; | 1499 }; |
| 1508 | 1500 |
| 1509 | 1501 |
| 1510 void StaticMarkingVisitor::ObjectStatsCountFixedArray( | 1502 static void ObjectStatsCountFixedArray( |
| 1511 FixedArrayBase* fixed_array, | 1503 FixedArrayBase* fixed_array, |
| 1512 FixedArraySubInstanceType fast_type, | 1504 FixedArraySubInstanceType fast_type, |
| 1513 FixedArraySubInstanceType dictionary_type) { | 1505 FixedArraySubInstanceType dictionary_type) { |
| 1514 Heap* heap = fixed_array->map()->GetHeap(); | 1506 Heap* heap = fixed_array->map()->GetHeap(); |
| 1515 if (fixed_array->map() != heap->fixed_cow_array_map() && | 1507 if (fixed_array->map() != heap->fixed_cow_array_map() && |
| 1516 fixed_array->map() != heap->fixed_double_array_map() && | 1508 fixed_array->map() != heap->fixed_double_array_map() && |
| 1517 fixed_array != heap->empty_fixed_array()) { | 1509 fixed_array != heap->empty_fixed_array()) { |
| 1518 if (fixed_array->IsDictionary()) { | 1510 if (fixed_array->IsDictionary()) { |
| 1519 heap->RecordObjectStats(FIXED_ARRAY_TYPE, | 1511 heap->RecordObjectStats(FIXED_ARRAY_TYPE, |
| 1520 dictionary_type, | 1512 dictionary_type, |
| 1521 fixed_array->Size()); | 1513 fixed_array->Size()); |
| 1522 } else { | 1514 } else { |
| 1523 heap->RecordObjectStats(FIXED_ARRAY_TYPE, | 1515 heap->RecordObjectStats(FIXED_ARRAY_TYPE, |
| 1524 fast_type, | 1516 fast_type, |
| 1525 fixed_array->Size()); | 1517 fixed_array->Size()); |
| 1526 } | 1518 } |
| 1527 } | 1519 } |
| 1528 } | 1520 } |
| 1529 | 1521 |
| 1530 | 1522 |
| 1531 void StaticMarkingVisitor::ObjectStatsVisitBase( | 1523 void StaticMarkingVisitor::TrackObjectStatsAndVisitBase( |
| 1532 StaticVisitorBase::VisitorId id, Map* map, HeapObject* obj) { | 1524 StaticVisitorBase::VisitorId id, Map* map, HeapObject* obj) { |
| 1533 Heap* heap = map->GetHeap(); | 1525 Heap* heap = map->GetHeap(); |
| 1534 int object_size = obj->Size(); | 1526 int object_size = obj->Size(); |
| 1535 heap->RecordObjectStats(map->instance_type(), -1, object_size); | 1527 heap->RecordObjectStats(map->instance_type(), -1, object_size); |
| 1536 non_count_table_.GetVisitorById(id)(map, obj); | 1528 non_count_table_.GetVisitorById(id)(map, obj); |
| 1537 if (obj->IsJSObject()) { | 1529 if (obj->IsJSObject()) { |
| 1538 JSObject* object = JSObject::cast(obj); | 1530 JSObject* object = JSObject::cast(obj); |
| 1539 ObjectStatsCountFixedArray(object->elements(), | 1531 ObjectStatsCountFixedArray(object->elements(), |
| 1540 DICTIONARY_ELEMENTS_SUB_TYPE, | 1532 DICTIONARY_ELEMENTS_SUB_TYPE, |
| 1541 FAST_ELEMENTS_SUB_TYPE); | 1533 FAST_ELEMENTS_SUB_TYPE); |
| 1542 ObjectStatsCountFixedArray(object->properties(), | 1534 ObjectStatsCountFixedArray(object->properties(), |
| 1543 DICTIONARY_PROPERTIES_SUB_TYPE, | 1535 DICTIONARY_PROPERTIES_SUB_TYPE, |
| 1544 FAST_PROPERTIES_SUB_TYPE); | 1536 FAST_PROPERTIES_SUB_TYPE); |
| 1545 } | 1537 } |
| 1546 } | 1538 } |
| 1547 | 1539 |
| 1548 | 1540 |
| 1549 template<StaticMarkingVisitor::VisitorId id> | 1541 template<StaticVisitorBase::VisitorId id> |
| 1550 void StaticMarkingVisitor::ObjectStatsTracker<id>::Visit( | 1542 void StaticMarkingVisitor::TrackObjectStatsAndVisit(Map* map, HeapObject* obj) { |
| 1551 Map* map, HeapObject* obj) { | 1543 TrackObjectStatsAndVisitBase(id, map, obj); |
| 1552 ObjectStatsVisitBase(id, map, obj); | |
| 1553 } | 1544 } |
| 1554 | 1545 |
| 1555 | 1546 |
| 1556 template<> | 1547 template<> |
| 1557 class StaticMarkingVisitor::ObjectStatsTracker< | 1548 void StaticMarkingVisitor::TrackObjectStatsAndVisit< |
| 1558 StaticMarkingVisitor::kVisitMap> { | 1549 StaticMarkingVisitor::kVisitMap>(Map* map, HeapObject* obj) { |
| 1559 public: | 1550 Heap* heap = map->GetHeap(); |
| 1560 static inline void Visit(Map* map, HeapObject* obj) { | 1551 Map* map_obj = Map::cast(obj); |
| 1561 Heap* heap = map->GetHeap(); | 1552 ASSERT(map->instance_type() == MAP_TYPE); |
| 1562 Map* map_obj = Map::cast(obj); | 1553 DescriptorArray* array = map_obj->instance_descriptors(); |
| 1563 ASSERT(map->instance_type() == MAP_TYPE); | 1554 if (array != heap->empty_descriptor_array()) { |
| 1564 DescriptorArray* array = map_obj->instance_descriptors(); | 1555 int fixed_array_size = array->Size(); |
| 1565 if (array != heap->empty_descriptor_array()) { | 1556 heap->RecordObjectStats(FIXED_ARRAY_TYPE, |
| 1566 int fixed_array_size = array->Size(); | 1557 DESCRIPTOR_ARRAY_SUB_TYPE, |
| 1567 heap->RecordObjectStats(FIXED_ARRAY_TYPE, | 1558 fixed_array_size); |
| 1568 DESCRIPTOR_ARRAY_SUB_TYPE, | |
| 1569 fixed_array_size); | |
| 1570 } | |
| 1571 if (map_obj->HasTransitionArray()) { | |
| 1572 int fixed_array_size = map_obj->transitions()->Size(); | |
| 1573 heap->RecordObjectStats(FIXED_ARRAY_TYPE, | |
| 1574 TRANSITION_ARRAY_SUB_TYPE, | |
| 1575 fixed_array_size); | |
| 1576 } | |
| 1577 if (map_obj->code_cache() != heap->empty_fixed_array()) { | |
| 1578 heap->RecordObjectStats( | |
| 1579 FIXED_ARRAY_TYPE, | |
| 1580 MAP_CODE_CACHE_SUB_TYPE, | |
| 1581 FixedArray::cast(map_obj->code_cache())->Size()); | |
| 1582 } | |
| 1583 ObjectStatsVisitBase(kVisitMap, map, obj); | |
| 1584 } | 1559 } |
| 1585 }; | 1560 if (map_obj->HasTransitionArray()) { |
| 1561 int fixed_array_size = map_obj->transitions()->Size(); |
| 1562 heap->RecordObjectStats(FIXED_ARRAY_TYPE, |
| 1563 TRANSITION_ARRAY_SUB_TYPE, |
| 1564 fixed_array_size); |
| 1565 } |
| 1566 if (map_obj->code_cache() != heap->empty_fixed_array()) { |
| 1567 heap->RecordObjectStats( |
| 1568 FIXED_ARRAY_TYPE, |
| 1569 MAP_CODE_CACHE_SUB_TYPE, |
| 1570 FixedArray::cast(map_obj->code_cache())->Size()); |
| 1571 } |
| 1572 TrackObjectStatsAndVisitBase(kVisitMap, map, obj); |
| 1573 } |
| 1586 | 1574 |
| 1587 | 1575 |
| 1588 template<> | 1576 template<> |
| 1589 class StaticMarkingVisitor::ObjectStatsTracker< | 1577 void StaticMarkingVisitor::TrackObjectStatsAndVisit< |
| 1590 StaticMarkingVisitor::kVisitCode> { | 1578 StaticMarkingVisitor::kVisitCode>(Map* map, HeapObject* obj) { |
| 1591 public: | 1579 Heap* heap = map->GetHeap(); |
| 1592 static inline void Visit(Map* map, HeapObject* obj) { | 1580 int object_size = obj->Size(); |
| 1593 Heap* heap = map->GetHeap(); | 1581 ASSERT(map->instance_type() == CODE_TYPE); |
| 1594 int object_size = obj->Size(); | 1582 heap->RecordObjectStats(CODE_TYPE, Code::cast(obj)->kind(), object_size); |
| 1595 ASSERT(map->instance_type() == CODE_TYPE); | 1583 TrackObjectStatsAndVisitBase(kVisitCode, map, obj); |
| 1596 heap->RecordObjectStats(CODE_TYPE, Code::cast(obj)->kind(), object_size); | 1584 } |
| 1597 ObjectStatsVisitBase(kVisitCode, map, obj); | |
| 1598 } | |
| 1599 }; | |
| 1600 | 1585 |
| 1601 | 1586 |
| 1602 template<> | 1587 template<> |
| 1603 class StaticMarkingVisitor::ObjectStatsTracker< | 1588 void StaticMarkingVisitor::TrackObjectStatsAndVisit< |
| 1604 StaticMarkingVisitor::kVisitSharedFunctionInfo> { | 1589 StaticMarkingVisitor::kVisitSharedFunctionInfo>(Map* map, HeapObject* obj) { |
| 1605 public: | 1590 Heap* heap = map->GetHeap(); |
| 1606 static inline void Visit(Map* map, HeapObject* obj) { | 1591 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj); |
| 1607 Heap* heap = map->GetHeap(); | 1592 if (sfi->scope_info() != heap->empty_fixed_array()) { |
| 1608 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj); | 1593 heap->RecordObjectStats( |
| 1609 if (sfi->scope_info() != heap->empty_fixed_array()) { | 1594 FIXED_ARRAY_TYPE, |
| 1610 heap->RecordObjectStats( | 1595 SCOPE_INFO_SUB_TYPE, |
| 1611 FIXED_ARRAY_TYPE, | 1596 FixedArray::cast(sfi->scope_info())->Size()); |
| 1612 SCOPE_INFO_SUB_TYPE, | |
| 1613 FixedArray::cast(sfi->scope_info())->Size()); | |
| 1614 } | |
| 1615 ObjectStatsVisitBase(kVisitSharedFunctionInfo, map, obj); | |
| 1616 } | 1597 } |
| 1617 }; | 1598 TrackObjectStatsAndVisitBase(kVisitSharedFunctionInfo, map, obj); |
| 1599 } |
| 1618 | 1600 |
| 1619 | 1601 |
| 1620 template<> | 1602 template<> |
| 1621 class StaticMarkingVisitor::ObjectStatsTracker< | 1603 void StaticMarkingVisitor::TrackObjectStatsAndVisit< |
| 1622 StaticMarkingVisitor::kVisitFixedArray> { | 1604 StaticMarkingVisitor::kVisitFixedArray>(Map* map, HeapObject* obj) { |
| 1623 public: | 1605 Heap* heap = map->GetHeap(); |
| 1624 static inline void Visit(Map* map, HeapObject* obj) { | 1606 FixedArray* fixed_array = FixedArray::cast(obj); |
| 1625 Heap* heap = map->GetHeap(); | 1607 if (fixed_array == heap->symbol_table()) { |
| 1626 FixedArray* fixed_array = FixedArray::cast(obj); | 1608 heap->RecordObjectStats( |
| 1627 if (fixed_array == heap->symbol_table()) { | 1609 FIXED_ARRAY_TYPE, |
| 1628 heap->RecordObjectStats( | 1610 SYMBOL_TABLE_SUB_TYPE, |
| 1629 FIXED_ARRAY_TYPE, | 1611 fixed_array->Size()); |
| 1630 SYMBOL_TABLE_SUB_TYPE, | |
| 1631 fixed_array->Size()); | |
| 1632 } | |
| 1633 ObjectStatsVisitBase(kVisitFixedArray, map, obj); | |
| 1634 } | 1612 } |
| 1635 }; | 1613 TrackObjectStatsAndVisitBase(kVisitFixedArray, map, obj); |
| 1614 } |
| 1636 | 1615 |
| 1637 | 1616 |
| 1638 void StaticMarkingVisitor::Initialize() { | 1617 void StaticMarkingVisitor::Initialize() { |
| 1639 table_.Register(kVisitShortcutCandidate, | 1618 table_.Register(kVisitShortcutCandidate, |
| 1640 &FixedBodyVisitor<StaticMarkingVisitor, | 1619 &FixedBodyVisitor<StaticMarkingVisitor, |
| 1641 ConsString::BodyDescriptor, | 1620 ConsString::BodyDescriptor, |
| 1642 void>::Visit); | 1621 void>::Visit); |
| 1643 | 1622 |
| 1644 table_.Register(kVisitConsString, | 1623 table_.Register(kVisitConsString, |
| 1645 &FixedBodyVisitor<StaticMarkingVisitor, | 1624 &FixedBodyVisitor<StaticMarkingVisitor, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 kVisitJSObjectGeneric>(); | 1680 kVisitJSObjectGeneric>(); |
| 1702 | 1681 |
| 1703 table_.RegisterSpecializations<StructObjectVisitor, | 1682 table_.RegisterSpecializations<StructObjectVisitor, |
| 1704 kVisitStruct, | 1683 kVisitStruct, |
| 1705 kVisitStructGeneric>(); | 1684 kVisitStructGeneric>(); |
| 1706 | 1685 |
| 1707 if (FLAG_track_gc_object_stats) { | 1686 if (FLAG_track_gc_object_stats) { |
| 1708 // Copy the visitor table to make call-through possible. | 1687 // Copy the visitor table to make call-through possible. |
| 1709 non_count_table_.CopyFrom(&table_); | 1688 non_count_table_.CopyFrom(&table_); |
| 1710 #define VISITOR_ID_COUNT_FUNCTION(id) \ | 1689 #define VISITOR_ID_COUNT_FUNCTION(id) \ |
| 1711 table_.Register(kVisit##id, ObjectStatsTracker<kVisit##id>::Visit); | 1690 table_.Register(kVisit##id, TrackObjectStatsAndVisit<kVisit##id>); |
| 1712 VISITOR_ID_LIST(VISITOR_ID_COUNT_FUNCTION) | 1691 VISITOR_ID_LIST(VISITOR_ID_COUNT_FUNCTION) |
| 1713 #undef VISITOR_ID_COUNT_FUNCTION | 1692 #undef VISITOR_ID_COUNT_FUNCTION |
| 1714 } | 1693 } |
| 1715 } | 1694 } |
| 1716 | 1695 |
| 1717 | 1696 |
| 1718 VisitorDispatchTable<StaticMarkingVisitor::Callback> | 1697 VisitorDispatchTable<StaticMarkingVisitor::Callback> |
| 1719 StaticMarkingVisitor::table_; | 1698 StaticMarkingVisitor::table_; |
| 1720 VisitorDispatchTable<StaticMarkingVisitor::Callback> | 1699 VisitorDispatchTable<StaticMarkingVisitor::Callback> |
| 1721 StaticMarkingVisitor::non_count_table_; | 1700 StaticMarkingVisitor::non_count_table_; |
| (...skipping 2557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4279 while (buffer != NULL) { | 4258 while (buffer != NULL) { |
| 4280 SlotsBuffer* next_buffer = buffer->next(); | 4259 SlotsBuffer* next_buffer = buffer->next(); |
| 4281 DeallocateBuffer(buffer); | 4260 DeallocateBuffer(buffer); |
| 4282 buffer = next_buffer; | 4261 buffer = next_buffer; |
| 4283 } | 4262 } |
| 4284 *buffer_address = NULL; | 4263 *buffer_address = NULL; |
| 4285 } | 4264 } |
| 4286 | 4265 |
| 4287 | 4266 |
| 4288 } } // namespace v8::internal | 4267 } } // namespace v8::internal |
| OLD | NEW |