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

Side by Side Diff: src/heap.h

Issue 2101002: Cardmarking writebarrier. (Closed)
Patch Set: fixed review comments Created 10 years, 7 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/globals.h ('k') | src/heap.cc » ('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 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
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
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
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
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 1235
1198 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) 1236 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1199 // Record the copy of an object in the NewSpace's statistics. 1237 // Record the copy of an object in the NewSpace's statistics.
1200 static void RecordCopiedObject(HeapObject* obj); 1238 static void RecordCopiedObject(HeapObject* obj);
1201 1239
1202 // Record statistics before and after garbage collection. 1240 // Record statistics before and after garbage collection.
1203 static void ReportStatisticsBeforeGC(); 1241 static void ReportStatisticsBeforeGC();
1204 static void ReportStatisticsAfterGC(); 1242 static void ReportStatisticsAfterGC();
1205 #endif 1243 #endif
1206 1244
1207 // Rebuild remembered set in an old space.
1208 static void RebuildRSets(PagedSpace* space);
1209
1210 // Rebuild remembered set in the large object space.
1211 static void RebuildRSets(LargeObjectSpace* space);
1212
1213 // Slow part of scavenge object. 1245 // Slow part of scavenge object.
1214 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); 1246 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);
1215 1247
1216 // Initializes a function with a shared part and prototype. 1248 // Initializes a function with a shared part and prototype.
1217 // Returns the function. 1249 // Returns the function.
1218 // Note: this code was factored out of AllocateFunction such that 1250 // Note: this code was factored out of AllocateFunction such that
1219 // other parts of the VM could use it. Specifically, a function that creates 1251 // other parts of the VM could use it. Specifically, a function that creates
1220 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. 1252 // instances of type JS_FUNCTION_TYPE benefit from the use of this function.
1221 // Please note this does not perform a garbage collection. 1253 // Please note this does not perform a garbage collection.
1222 static inline Object* InitializeFunction(JSFunction* function, 1254 static inline Object* InitializeFunction(JSFunction* function,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 } 1321 }
1290 1322
1291 ~LinearAllocationScope() { 1323 ~LinearAllocationScope() {
1292 Heap::linear_allocation_scope_depth_--; 1324 Heap::linear_allocation_scope_depth_--;
1293 ASSERT(Heap::linear_allocation_scope_depth_ >= 0); 1325 ASSERT(Heap::linear_allocation_scope_depth_ >= 0);
1294 } 1326 }
1295 }; 1327 };
1296 1328
1297 1329
1298 #ifdef DEBUG 1330 #ifdef DEBUG
1299 // Visitor class to verify interior pointers that do not have remembered set 1331 // Visitor class to verify interior pointers in spaces that do not contain
1300 // bits. All heap object pointers have to point into the heap to a location 1332 // or care about intergenerational references. All heap object pointers have to
1301 // that has a map pointer at its first word. Caveat: Heap::Contains is an 1333 // point into the heap to a location that has a map pointer at its first word.
1302 // approximation because it can return true for objects in a heap space but 1334 // Caveat: Heap::Contains is an approximation because it can return true for
1303 // above the allocation pointer. 1335 // objects in a heap space but above the allocation pointer.
1304 class VerifyPointersVisitor: public ObjectVisitor { 1336 class VerifyPointersVisitor: public ObjectVisitor {
1305 public: 1337 public:
1306 void VisitPointers(Object** start, Object** end) { 1338 void VisitPointers(Object** start, Object** end) {
1307 for (Object** current = start; current < end; current++) { 1339 for (Object** current = start; current < end; current++) {
1308 if ((*current)->IsHeapObject()) { 1340 if ((*current)->IsHeapObject()) {
1309 HeapObject* object = HeapObject::cast(*current); 1341 HeapObject* object = HeapObject::cast(*current);
1310 ASSERT(Heap::Contains(object)); 1342 ASSERT(Heap::Contains(object));
1311 ASSERT(object->map()->IsMap()); 1343 ASSERT(object->map()->IsMap());
1312 } 1344 }
1313 } 1345 }
1314 } 1346 }
1315 }; 1347 };
1316 1348
1317 1349
1318 // Visitor class to verify interior pointers that have remembered set bits. 1350 // Visitor class to verify interior pointers in spaces that use region marks
1319 // As VerifyPointersVisitor but also checks that remembered set bits are 1351 // to keep track of intergenerational references.
1320 // always set for pointers into new space. 1352 // As VerifyPointersVisitor but also checks that dirty marks are set
1321 class VerifyPointersAndRSetVisitor: public ObjectVisitor { 1353 // for regions covering intergenerational references.
1354 class VerifyPointersAndDirtyRegionsVisitor: public ObjectVisitor {
1322 public: 1355 public:
1323 void VisitPointers(Object** start, Object** end) { 1356 void VisitPointers(Object** start, Object** end) {
1324 for (Object** current = start; current < end; current++) { 1357 for (Object** current = start; current < end; current++) {
1325 if ((*current)->IsHeapObject()) { 1358 if ((*current)->IsHeapObject()) {
1326 HeapObject* object = HeapObject::cast(*current); 1359 HeapObject* object = HeapObject::cast(*current);
1327 ASSERT(Heap::Contains(object)); 1360 ASSERT(Heap::Contains(object));
1328 ASSERT(object->map()->IsMap()); 1361 ASSERT(object->map()->IsMap());
1329 if (Heap::InNewSpace(object)) { 1362 if (Heap::InNewSpace(object)) {
1330 ASSERT(Page::IsRSetSet(reinterpret_cast<Address>(current), 0)); 1363 ASSERT(Heap::InToSpace(object));
1364 Address addr = reinterpret_cast<Address>(current);
1365 ASSERT(Page::FromAddress(addr)->IsRegionDirty(addr));
1331 } 1366 }
1332 } 1367 }
1333 } 1368 }
1334 } 1369 }
1335 }; 1370 };
1336 #endif 1371 #endif
1337 1372
1338 1373
1339 // Space iterator for iterating over all spaces of the heap. 1374 // Space iterator for iterating over all spaces of the heap.
1340 // Returns each space in turn, and null when it is done. 1375 // Returns each space in turn, and null when it is done.
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 1870
1836 // To speed up scavenge collections new space string are kept 1871 // To speed up scavenge collections new space string are kept
1837 // separate from old space strings. 1872 // separate from old space strings.
1838 static List<Object*> new_space_strings_; 1873 static List<Object*> new_space_strings_;
1839 static List<Object*> old_space_strings_; 1874 static List<Object*> old_space_strings_;
1840 }; 1875 };
1841 1876
1842 } } // namespace v8::internal 1877 } } // namespace v8::internal
1843 1878
1844 #endif // V8_HEAP_H_ 1879 #endif // V8_HEAP_H_
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698