OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 V(closure_symbol, "(closure)") | 199 V(closure_symbol, "(closure)") |
200 | 200 |
201 | 201 |
202 // Forward declaration of the GCTracer class. | 202 // Forward declaration of the GCTracer class. |
203 class GCTracer; | 203 class GCTracer; |
204 class HeapStats; | 204 class HeapStats; |
205 | 205 |
206 | 206 |
207 typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); | 207 typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); |
208 | 208 |
| 209 typedef bool (*DirtyRegionCallback)(Address start, |
| 210 Address end, |
| 211 ObjectSlotCallback copy_object_func); |
| 212 |
209 | 213 |
210 // The all static Heap captures the interface to the global object heap. | 214 // The all static Heap captures the interface to the global object heap. |
211 // All JavaScript contexts by this process share the same object heap. | 215 // All JavaScript contexts by this process share the same object heap. |
212 | 216 |
213 class Heap : public AllStatic { | 217 class Heap : public AllStatic { |
214 public: | 218 public: |
215 // Configure heap size before setup. Return false if the heap has been | 219 // Configure heap size before setup. Return false if the heap has been |
216 // setup already. | 220 // setup already. |
217 static bool ConfigureHeap(int max_semispace_size, int max_old_gen_size); | 221 static bool ConfigureHeap(int max_semispace_size, int max_old_gen_size); |
218 static bool ConfigureHeapDefault(); | 222 static bool ConfigureHeapDefault(); |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 // not match the empty string. | 737 // not match the empty string. |
734 static String* hidden_symbol() { return hidden_symbol_; } | 738 static String* hidden_symbol() { return hidden_symbol_; } |
735 | 739 |
736 // Iterates over all roots in the heap. | 740 // Iterates over all roots in the heap. |
737 static void IterateRoots(ObjectVisitor* v, VisitMode mode); | 741 static void IterateRoots(ObjectVisitor* v, VisitMode mode); |
738 // Iterates over all strong roots in the heap. | 742 // Iterates over all strong roots in the heap. |
739 static void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); | 743 static void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); |
740 // Iterates over all the other roots in the heap. | 744 // Iterates over all the other roots in the heap. |
741 static void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); | 745 static void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); |
742 | 746 |
743 // Iterates remembered set of an old space. | 747 enum ExpectedPageWatermarkState { |
744 static void IterateRSet(PagedSpace* space, ObjectSlotCallback callback); | 748 WATERMARK_SHOULD_BE_VALID, |
| 749 WATERMARK_CAN_BE_INVALID |
| 750 }; |
745 | 751 |
746 // Iterates a range of remembered set addresses starting with rset_start | 752 // For each dirty region on a page in use from an old space call |
747 // corresponding to the range of allocated pointers | 753 // visit_dirty_region callback. |
748 // [object_start, object_end). | 754 // If either visit_dirty_region or callback can cause an allocation |
749 // Returns the number of bits that were set. | 755 // in old space and changes in allocation watermark then |
750 static int IterateRSetRange(Address object_start, | 756 // can_preallocate_during_iteration should be set to true. |
751 Address object_end, | 757 // All pages will be marked as having invalid watermark upon |
752 Address rset_start, | 758 // iteration completion. |
753 ObjectSlotCallback copy_object_func); | 759 static void IterateDirtyRegions( |
| 760 PagedSpace* space, |
| 761 DirtyRegionCallback visit_dirty_region, |
| 762 ObjectSlotCallback callback, |
| 763 ExpectedPageWatermarkState expected_page_watermark_state); |
| 764 |
| 765 // Interpret marks as a bitvector of dirty marks for regions of size |
| 766 // Page::kRegionSize aligned by Page::kRegionAlignmentMask and covering |
| 767 // memory interval from start to top. For each dirty region call a |
| 768 // visit_dirty_region callback. Return updated bitvector of dirty marks. |
| 769 static uint32_t IterateDirtyRegions(uint32_t marks, |
| 770 Address start, |
| 771 Address end, |
| 772 DirtyRegionCallback visit_dirty_region, |
| 773 ObjectSlotCallback callback); |
| 774 |
| 775 // Iterate pointers to new space found in memory interval from start to end. |
| 776 // Update dirty marks for page containing start address. |
| 777 static void IterateAndMarkPointersToNewSpace(Address start, |
| 778 Address end, |
| 779 ObjectSlotCallback callback); |
| 780 |
| 781 // Iterate pointers to new space found in memory interval from start to end. |
| 782 // Return true if pointers to new space was found. |
| 783 static bool IteratePointersInDirtyRegion(Address start, |
| 784 Address end, |
| 785 ObjectSlotCallback callback); |
| 786 |
| 787 |
| 788 // Iterate pointers to new space found in memory interval from start to end. |
| 789 // This interval is considered to belong to the map space. |
| 790 // Return true if pointers to new space was found. |
| 791 static bool IteratePointersInDirtyMapsRegion(Address start, |
| 792 Address end, |
| 793 ObjectSlotCallback callback); |
| 794 |
754 | 795 |
755 // Returns whether the object resides in new space. | 796 // Returns whether the object resides in new space. |
756 static inline bool InNewSpace(Object* object); | 797 static inline bool InNewSpace(Object* object); |
757 static inline bool InFromSpace(Object* object); | 798 static inline bool InFromSpace(Object* object); |
758 static inline bool InToSpace(Object* object); | 799 static inline bool InToSpace(Object* object); |
759 | 800 |
760 // Checks whether an address/object in the heap (including auxiliary | 801 // Checks whether an address/object in the heap (including auxiliary |
761 // area and unused area). | 802 // area and unused area). |
762 static bool Contains(Address addr); | 803 static bool Contains(Address addr); |
763 static bool Contains(HeapObject* value); | 804 static bool Contains(HeapObject* value); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 static void TracePathToGlobal(); | 886 static void TracePathToGlobal(); |
846 #endif | 887 #endif |
847 | 888 |
848 // Callback function passed to Heap::Iterate etc. Copies an object if | 889 // Callback function passed to Heap::Iterate etc. Copies an object if |
849 // necessary, the object might be promoted to an old space. The caller must | 890 // necessary, the object might be promoted to an old space. The caller must |
850 // ensure the precondition that the object is (a) a heap object and (b) in | 891 // ensure the precondition that the object is (a) a heap object and (b) in |
851 // the heap's from space. | 892 // the heap's from space. |
852 static void ScavengePointer(HeapObject** p); | 893 static void ScavengePointer(HeapObject** p); |
853 static inline void ScavengeObject(HeapObject** p, HeapObject* object); | 894 static inline void ScavengeObject(HeapObject** p, HeapObject* object); |
854 | 895 |
855 // Clear a range of remembered set addresses corresponding to the object | |
856 // area address 'start' with size 'size_in_bytes', eg, when adding blocks | |
857 // to the free list. | |
858 static void ClearRSetRange(Address start, int size_in_bytes); | |
859 | |
860 // Rebuild remembered set in old and map spaces. | |
861 static void RebuildRSets(); | |
862 | |
863 // Update an old object's remembered set | |
864 static int UpdateRSet(HeapObject* obj); | |
865 | |
866 // Commits from space if it is uncommitted. | 896 // Commits from space if it is uncommitted. |
867 static void EnsureFromSpaceIsCommitted(); | 897 static void EnsureFromSpaceIsCommitted(); |
868 | 898 |
869 // Support for partial snapshots. After calling this we can allocate a | 899 // Support for partial snapshots. After calling this we can allocate a |
870 // certain number of bytes using only linear allocation (with a | 900 // certain number of bytes using only linear allocation (with a |
871 // LinearAllocationScope and an AlwaysAllocateScope) without using freelists | 901 // LinearAllocationScope and an AlwaysAllocateScope) without using freelists |
872 // or causing a GC. It returns true of space was reserved or false if a GC is | 902 // or causing a GC. It returns true of space was reserved or false if a GC is |
873 // needed. For paged spaces the space requested must include the space wasted | 903 // needed. For paged spaces the space requested must include the space wasted |
874 // at the end of each page when allocating linearly. | 904 // at the end of each page when allocating linearly. |
875 static void ReserveSpace( | 905 static void ReserveSpace( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 bool check_number_string_cache = true); | 978 bool check_number_string_cache = true); |
949 | 979 |
950 static Map* MapForExternalArrayType(ExternalArrayType array_type); | 980 static Map* MapForExternalArrayType(ExternalArrayType array_type); |
951 static RootListIndex RootIndexForExternalArrayType( | 981 static RootListIndex RootIndexForExternalArrayType( |
952 ExternalArrayType array_type); | 982 ExternalArrayType array_type); |
953 | 983 |
954 static void RecordStats(HeapStats* stats); | 984 static void RecordStats(HeapStats* stats); |
955 | 985 |
956 // Copy block of memory from src to dst. Size of block should be aligned | 986 // Copy block of memory from src to dst. Size of block should be aligned |
957 // by pointer size. | 987 // by pointer size. |
958 static inline void CopyBlock(Object** dst, Object** src, int byte_size); | 988 static inline void CopyBlock(Address dst, Address src, int byte_size); |
| 989 |
| 990 static inline void CopyBlockToOldSpaceAndUpdateRegionMarks(Address dst, |
| 991 Address src, |
| 992 int byte_size); |
959 | 993 |
960 // Optimized version of memmove for blocks with pointer size aligned sizes and | 994 // Optimized version of memmove for blocks with pointer size aligned sizes and |
961 // pointer size aligned addresses. | 995 // pointer size aligned addresses. |
962 static inline void MoveBlock(Object** dst, Object** src, int byte_size); | 996 static inline void MoveBlock(Address dst, Address src, int byte_size); |
| 997 |
| 998 static inline void MoveBlockToOldSpaceAndUpdateRegionMarks(Address dst, |
| 999 Address src, |
| 1000 int byte_size); |
963 | 1001 |
964 // Check new space expansion criteria and expand semispaces if it was hit. | 1002 // Check new space expansion criteria and expand semispaces if it was hit. |
965 static void CheckNewSpaceExpansionCriteria(); | 1003 static void CheckNewSpaceExpansionCriteria(); |
966 | 1004 |
967 static inline void IncrementYoungSurvivorsCounter(int survived) { | 1005 static inline void IncrementYoungSurvivorsCounter(int survived) { |
968 survived_since_last_expansion_ += survived; | 1006 survived_since_last_expansion_ += survived; |
969 } | 1007 } |
970 | 1008 |
971 static void UpdateNewSpaceReferencesInExternalStringTable( | 1009 static void UpdateNewSpaceReferencesInExternalStringTable( |
972 ExternalStringTableUpdaterCallback updater_func); | 1010 ExternalStringTableUpdaterCallback updater_func); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 | 1238 |
1201 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | 1239 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) |
1202 // Record the copy of an object in the NewSpace's statistics. | 1240 // Record the copy of an object in the NewSpace's statistics. |
1203 static void RecordCopiedObject(HeapObject* obj); | 1241 static void RecordCopiedObject(HeapObject* obj); |
1204 | 1242 |
1205 // Record statistics before and after garbage collection. | 1243 // Record statistics before and after garbage collection. |
1206 static void ReportStatisticsBeforeGC(); | 1244 static void ReportStatisticsBeforeGC(); |
1207 static void ReportStatisticsAfterGC(); | 1245 static void ReportStatisticsAfterGC(); |
1208 #endif | 1246 #endif |
1209 | 1247 |
1210 // Rebuild remembered set in an old space. | |
1211 static void RebuildRSets(PagedSpace* space); | |
1212 | |
1213 // Rebuild remembered set in the large object space. | |
1214 static void RebuildRSets(LargeObjectSpace* space); | |
1215 | |
1216 // Slow part of scavenge object. | 1248 // Slow part of scavenge object. |
1217 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); | 1249 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); |
1218 | 1250 |
1219 // Initializes a function with a shared part and prototype. | 1251 // Initializes a function with a shared part and prototype. |
1220 // Returns the function. | 1252 // Returns the function. |
1221 // Note: this code was factored out of AllocateFunction such that | 1253 // Note: this code was factored out of AllocateFunction such that |
1222 // other parts of the VM could use it. Specifically, a function that creates | 1254 // other parts of the VM could use it. Specifically, a function that creates |
1223 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. | 1255 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. |
1224 // Please note this does not perform a garbage collection. | 1256 // Please note this does not perform a garbage collection. |
1225 static inline Object* InitializeFunction(JSFunction* function, | 1257 static inline Object* InitializeFunction(JSFunction* function, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 } | 1326 } |
1295 | 1327 |
1296 ~LinearAllocationScope() { | 1328 ~LinearAllocationScope() { |
1297 Heap::linear_allocation_scope_depth_--; | 1329 Heap::linear_allocation_scope_depth_--; |
1298 ASSERT(Heap::linear_allocation_scope_depth_ >= 0); | 1330 ASSERT(Heap::linear_allocation_scope_depth_ >= 0); |
1299 } | 1331 } |
1300 }; | 1332 }; |
1301 | 1333 |
1302 | 1334 |
1303 #ifdef DEBUG | 1335 #ifdef DEBUG |
1304 // Visitor class to verify interior pointers that do not have remembered set | 1336 // Visitor class to verify interior pointers in spaces that do not contain |
1305 // bits. All heap object pointers have to point into the heap to a location | 1337 // or care about intergenerational references. All heap object pointers have to |
1306 // that has a map pointer at its first word. Caveat: Heap::Contains is an | 1338 // point into the heap to a location that has a map pointer at its first word. |
1307 // approximation because it can return true for objects in a heap space but | 1339 // Caveat: Heap::Contains is an approximation because it can return true for |
1308 // above the allocation pointer. | 1340 // objects in a heap space but above the allocation pointer. |
1309 class VerifyPointersVisitor: public ObjectVisitor { | 1341 class VerifyPointersVisitor: public ObjectVisitor { |
1310 public: | 1342 public: |
1311 void VisitPointers(Object** start, Object** end) { | 1343 void VisitPointers(Object** start, Object** end) { |
1312 for (Object** current = start; current < end; current++) { | 1344 for (Object** current = start; current < end; current++) { |
1313 if ((*current)->IsHeapObject()) { | 1345 if ((*current)->IsHeapObject()) { |
1314 HeapObject* object = HeapObject::cast(*current); | 1346 HeapObject* object = HeapObject::cast(*current); |
1315 ASSERT(Heap::Contains(object)); | 1347 ASSERT(Heap::Contains(object)); |
1316 ASSERT(object->map()->IsMap()); | 1348 ASSERT(object->map()->IsMap()); |
1317 } | 1349 } |
1318 } | 1350 } |
1319 } | 1351 } |
1320 }; | 1352 }; |
1321 | 1353 |
1322 | 1354 |
1323 // Visitor class to verify interior pointers that have remembered set bits. | 1355 // Visitor class to verify interior pointers in spaces that use region marks |
1324 // As VerifyPointersVisitor but also checks that remembered set bits are | 1356 // to keep track of intergenerational references. |
1325 // always set for pointers into new space. | 1357 // As VerifyPointersVisitor but also checks that dirty marks are set |
1326 class VerifyPointersAndRSetVisitor: public ObjectVisitor { | 1358 // for regions covering intergenerational references. |
| 1359 class VerifyPointersAndDirtyRegionsVisitor: public ObjectVisitor { |
1327 public: | 1360 public: |
1328 void VisitPointers(Object** start, Object** end) { | 1361 void VisitPointers(Object** start, Object** end) { |
1329 for (Object** current = start; current < end; current++) { | 1362 for (Object** current = start; current < end; current++) { |
1330 if ((*current)->IsHeapObject()) { | 1363 if ((*current)->IsHeapObject()) { |
1331 HeapObject* object = HeapObject::cast(*current); | 1364 HeapObject* object = HeapObject::cast(*current); |
1332 ASSERT(Heap::Contains(object)); | 1365 ASSERT(Heap::Contains(object)); |
1333 ASSERT(object->map()->IsMap()); | 1366 ASSERT(object->map()->IsMap()); |
1334 if (Heap::InNewSpace(object)) { | 1367 if (Heap::InNewSpace(object)) { |
1335 ASSERT(Page::IsRSetSet(reinterpret_cast<Address>(current), 0)); | 1368 ASSERT(Heap::InToSpace(object)); |
| 1369 Address addr = reinterpret_cast<Address>(current); |
| 1370 ASSERT(Page::FromAddress(addr)->IsRegionDirty(addr)); |
1336 } | 1371 } |
1337 } | 1372 } |
1338 } | 1373 } |
1339 } | 1374 } |
1340 }; | 1375 }; |
1341 #endif | 1376 #endif |
1342 | 1377 |
1343 | 1378 |
1344 // Space iterator for iterating over all spaces of the heap. | 1379 // Space iterator for iterating over all spaces of the heap. |
1345 // Returns each space in turn, and null when it is done. | 1380 // Returns each space in turn, and null when it is done. |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1893 | 1928 |
1894 // To speed up scavenge collections new space string are kept | 1929 // To speed up scavenge collections new space string are kept |
1895 // separate from old space strings. | 1930 // separate from old space strings. |
1896 static List<Object*> new_space_strings_; | 1931 static List<Object*> new_space_strings_; |
1897 static List<Object*> old_space_strings_; | 1932 static List<Object*> old_space_strings_; |
1898 }; | 1933 }; |
1899 | 1934 |
1900 } } // namespace v8::internal | 1935 } } // namespace v8::internal |
1901 | 1936 |
1902 #endif // V8_HEAP_H_ | 1937 #endif // V8_HEAP_H_ |
OLD | NEW |