OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 | 208 |
209 // Forward declarations. | 209 // Forward declarations. |
210 class GCTracer; | 210 class GCTracer; |
211 class HeapStats; | 211 class HeapStats; |
212 class WeakObjectRetainer; | 212 class WeakObjectRetainer; |
213 | 213 |
214 | 214 |
215 typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); | 215 typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); |
216 | 216 |
217 typedef bool (*DirtyRegionCallback)(Address start, | 217 typedef void (*PointerRegionCallback)(Address start, |
218 Address end, | 218 Address end, |
219 ObjectSlotCallback copy_object_func); | 219 ObjectSlotCallback copy_object_func); |
220 | 220 |
221 | 221 |
222 // The all static Heap captures the interface to the global object heap. | 222 // The all static Heap captures the interface to the global object heap. |
223 // All JavaScript contexts by this process share the same object heap. | 223 // All JavaScript contexts by this process share the same object heap. |
224 | 224 |
225 class Heap : public AllStatic { | 225 class Heap : public AllStatic { |
226 public: | 226 public: |
227 // Configure heap size before setup. Return false if the heap has been | 227 // Configure heap size before setup. Return false if the heap has been |
228 // setup already. | 228 // setup already. |
229 static bool ConfigureHeap(intptr_t max_semispace_size, | 229 static bool ConfigureHeap(intptr_t max_semispace_size, |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 // Iterates over all strong roots in the heap. | 814 // Iterates over all strong roots in the heap. |
815 static void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); | 815 static void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); |
816 // Iterates over all the other roots in the heap. | 816 // Iterates over all the other roots in the heap. |
817 static void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); | 817 static void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); |
818 | 818 |
819 enum ExpectedPageWatermarkState { | 819 enum ExpectedPageWatermarkState { |
820 WATERMARK_SHOULD_BE_VALID, | 820 WATERMARK_SHOULD_BE_VALID, |
821 WATERMARK_CAN_BE_INVALID | 821 WATERMARK_CAN_BE_INVALID |
822 }; | 822 }; |
823 | 823 |
824 // For each dirty region on a page in use from an old space call | 824 // For each region of pointers on a page in use from an old space call |
825 // visit_dirty_region callback. | 825 // visit_pointer_region callback. |
826 // If either visit_dirty_region or callback can cause an allocation | 826 // If either visit_pointer_region or callback can cause an allocation |
827 // in old space and changes in allocation watermark then | 827 // in old space and changes in allocation watermark then |
828 // can_preallocate_during_iteration should be set to true. | 828 // can_preallocate_during_iteration should be set to true. |
829 // All pages will be marked as having invalid watermark upon | 829 // All pages will be marked as having invalid watermark upon |
830 // iteration completion. | 830 // iteration completion. |
831 static void IterateDirtyRegions( | 831 static void IteratePointers( |
832 PagedSpace* space, | 832 PagedSpace* space, |
833 DirtyRegionCallback visit_dirty_region, | 833 PointerRegionCallback visit_pointer_region, |
834 ObjectSlotCallback callback, | 834 ObjectSlotCallback callback, |
835 ExpectedPageWatermarkState expected_page_watermark_state); | 835 ExpectedPageWatermarkState expected_page_watermark_state); |
836 | 836 |
837 // Interpret marks as a bitvector of dirty marks for regions of size | |
838 // Page::kRegionSize aligned by Page::kRegionAlignmentMask and covering | |
839 // memory interval from start to top. For each dirty region call a | |
840 // visit_dirty_region callback. Return updated bitvector of dirty marks. | |
841 static uint32_t IterateDirtyRegions(uint32_t marks, | |
842 Address start, | |
843 Address end, | |
844 DirtyRegionCallback visit_dirty_region, | |
845 ObjectSlotCallback callback); | |
846 | |
847 // Iterate pointers to from semispace of new space found in memory interval | 837 // Iterate pointers to from semispace of new space found in memory interval |
848 // from start to end. | 838 // from start to end. |
849 // Update dirty marks for page containing start address. | |
850 static void IterateAndMarkPointersToFromSpace(Address start, | 839 static void IterateAndMarkPointersToFromSpace(Address start, |
851 Address end, | 840 Address end, |
852 ObjectSlotCallback callback); | 841 ObjectSlotCallback callback); |
853 | 842 |
854 // Iterate pointers to new space found in memory interval from start to end. | 843 // Iterate pointers to new space found in memory interval from start to end. |
855 // Return true if pointers to new space was found. | 844 static void IteratePointersToNewSpace(Address start, |
856 static bool IteratePointersInDirtyRegion(Address start, | 845 Address end, |
857 Address end, | 846 ObjectSlotCallback callback); |
858 ObjectSlotCallback callback); | |
859 | 847 |
860 | 848 |
861 // Iterate pointers to new space found in memory interval from start to end. | 849 // Iterate pointers to new space found in memory interval from start to end. |
862 // This interval is considered to belong to the map space. | 850 // This interval is considered to belong to the map space. |
863 // Return true if pointers to new space was found. | 851 static void IteratePointersFromMapsToNewSpace(Address start, |
864 static bool IteratePointersInDirtyMapsRegion(Address start, | 852 Address end, |
865 Address end, | 853 ObjectSlotCallback callback); |
866 ObjectSlotCallback callback); | |
867 | 854 |
868 | 855 |
869 // Returns whether the object resides in new space. | 856 // Returns whether the object resides in new space. |
870 static inline bool InNewSpace(Object* object); | 857 static inline bool InNewSpace(Object* object); |
871 static inline bool InNewSpace(Address addr); | 858 static inline bool InNewSpace(Address addr); |
872 static inline bool InFromSpace(Object* object); | 859 static inline bool InFromSpace(Object* object); |
873 static inline bool InToSpace(Object* object); | 860 static inline bool InToSpace(Object* object); |
874 | 861 |
875 // Checks whether an address/object in the heap (including auxiliary | 862 // Checks whether an address/object in the heap (including auxiliary |
876 // area and unused area). | 863 // area and unused area). |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 void VisitPointers(Object** start, Object** end) { | 1498 void VisitPointers(Object** start, Object** end) { |
1512 for (Object** current = start; current < end; current++) { | 1499 for (Object** current = start; current < end; current++) { |
1513 if ((*current)->IsHeapObject()) { | 1500 if ((*current)->IsHeapObject()) { |
1514 HeapObject* object = HeapObject::cast(*current); | 1501 HeapObject* object = HeapObject::cast(*current); |
1515 ASSERT(Heap::Contains(object)); | 1502 ASSERT(Heap::Contains(object)); |
1516 ASSERT(object->map()->IsMap()); | 1503 ASSERT(object->map()->IsMap()); |
1517 } | 1504 } |
1518 } | 1505 } |
1519 } | 1506 } |
1520 }; | 1507 }; |
1521 | |
1522 | |
1523 #ifdef ENABLE_CARDMARKING_WRITE_BARRIER | |
1524 // Visitor class to verify interior pointers in spaces that use region marks | |
1525 // to keep track of intergenerational references. | |
1526 // As VerifyPointersVisitor but also checks that dirty marks are set | |
1527 // for regions covering intergenerational references. | |
1528 class VerifyPointersAndDirtyRegionsVisitor: public ObjectVisitor { | |
1529 public: | |
1530 void VisitPointers(Object** start, Object** end) { | |
1531 for (Object** current = start; current < end; current++) { | |
1532 if ((*current)->IsHeapObject()) { | |
1533 HeapObject* object = HeapObject::cast(*current); | |
1534 ASSERT(Heap::Contains(object)); | |
1535 ASSERT(object->map()->IsMap()); | |
1536 if (Heap::InNewSpace(object)) { | |
1537 ASSERT(Heap::InToSpace(object)); | |
1538 Address addr = reinterpret_cast<Address>(current); | |
1539 ASSERT(Page::FromAddress(addr)->IsRegionDirty(addr)); | |
1540 } | |
1541 } | |
1542 } | |
1543 } | |
1544 }; | |
1545 #endif | 1508 #endif |
1546 #endif | |
1547 | 1509 |
1548 | 1510 |
1549 // Space iterator for iterating over all spaces of the heap. | 1511 // Space iterator for iterating over all spaces of the heap. |
1550 // Returns each space in turn, and null when it is done. | 1512 // Returns each space in turn, and null when it is done. |
1551 class AllSpaces BASE_EMBEDDED { | 1513 class AllSpaces BASE_EMBEDDED { |
1552 public: | 1514 public: |
1553 Space* next(); | 1515 Space* next(); |
1554 AllSpaces() { counter_ = FIRST_SPACE; } | 1516 AllSpaces() { counter_ = FIRST_SPACE; } |
1555 private: | 1517 private: |
1556 int counter_; | 1518 int counter_; |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2167 | 2129 |
2168 private: | 2130 private: |
2169 static const uintptr_t kNotMarkedBit = 0x1; | 2131 static const uintptr_t kNotMarkedBit = 0x1; |
2170 STATIC_ASSERT((kHeapObjectTag & kNotMarkedBit) != 0); | 2132 STATIC_ASSERT((kHeapObjectTag & kNotMarkedBit) != 0); |
2171 }; | 2133 }; |
2172 | 2134 |
2173 | 2135 |
2174 } } // namespace v8::internal | 2136 } } // namespace v8::internal |
2175 | 2137 |
2176 #endif // V8_HEAP_H_ | 2138 #endif // V8_HEAP_H_ |
OLD | NEW |