| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 // Returns whether there is a chance that another major GC could | 861 // Returns whether there is a chance that another major GC could |
| 862 // collect more garbage. | 862 // collect more garbage. |
| 863 bool CollectGarbage(AllocationSpace space, GarbageCollector collector); | 863 bool CollectGarbage(AllocationSpace space, GarbageCollector collector); |
| 864 | 864 |
| 865 // Performs garbage collection operation. | 865 // Performs garbage collection operation. |
| 866 // Returns whether there is a chance that another major GC could | 866 // Returns whether there is a chance that another major GC could |
| 867 // collect more garbage. | 867 // collect more garbage. |
| 868 inline bool CollectGarbage(AllocationSpace space); | 868 inline bool CollectGarbage(AllocationSpace space); |
| 869 | 869 |
| 870 static const int kNoGCFlags = 0; | 870 static const int kNoGCFlags = 0; |
| 871 // TODO(gc) we are ignoring this flag |
| 871 static const int kForceCompactionMask = 1; | 872 static const int kForceCompactionMask = 1; |
| 872 static const int kMakeHeapIterableMask = 2; | 873 static const int kMakeHeapIterableMask = 2; |
| 873 | 874 |
| 874 // Performs a full garbage collection. If (flags & kForceCompactionMask) is | 875 // Performs a full garbage collection. If (flags & kForceCompactionMask) is |
| 875 // non-zero then force compaction. If (flags & kMakeHeapIterableMask) is non- | 876 // non-zero then force compaction. If (flags & kMakeHeapIterableMask) is non- |
| 876 // zero, then the slower precise sweeper is used, which leaves the heap in a | 877 // zero, then the slower precise sweeper is used, which leaves the heap in a |
| 877 // state where we can iterate over the heap visiting all objects. | 878 // state where we can iterate over the heap visiting all objects. |
| 878 void CollectAllGarbage(int flags); | 879 void CollectAllGarbage(int flags); |
| 879 | 880 |
| 880 // Ensure that we have swept all spaces in such a way that we can iterate | 881 // Ensure that we have swept all spaces in such a way that we can iterate |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 Map* MapForExternalArrayType(ExternalArrayType array_type); | 1208 Map* MapForExternalArrayType(ExternalArrayType array_type); |
| 1208 RootListIndex RootIndexForExternalArrayType( | 1209 RootListIndex RootIndexForExternalArrayType( |
| 1209 ExternalArrayType array_type); | 1210 ExternalArrayType array_type); |
| 1210 | 1211 |
| 1211 void RecordStats(HeapStats* stats, bool take_snapshot = false); | 1212 void RecordStats(HeapStats* stats, bool take_snapshot = false); |
| 1212 | 1213 |
| 1213 // Copy block of memory from src to dst. Size of block should be aligned | 1214 // Copy block of memory from src to dst. Size of block should be aligned |
| 1214 // by pointer size. | 1215 // by pointer size. |
| 1215 static inline void CopyBlock(Address dst, Address src, int byte_size); | 1216 static inline void CopyBlock(Address dst, Address src, int byte_size); |
| 1216 | 1217 |
| 1217 inline void CopyBlockToOldSpaceAndUpdateWriteBarrier(Address dst, | |
| 1218 Address src, | |
| 1219 int byte_size); | |
| 1220 | |
| 1221 // Optimized version of memmove for blocks with pointer size aligned sizes and | 1218 // Optimized version of memmove for blocks with pointer size aligned sizes and |
| 1222 // pointer size aligned addresses. | 1219 // pointer size aligned addresses. |
| 1223 static inline void MoveBlock(Address dst, Address src, int byte_size); | 1220 static inline void MoveBlock(Address dst, Address src, int byte_size); |
| 1224 | 1221 |
| 1225 // Check new space expansion criteria and expand semispaces if it was hit. | 1222 // Check new space expansion criteria and expand semispaces if it was hit. |
| 1226 void CheckNewSpaceExpansionCriteria(); | 1223 void CheckNewSpaceExpansionCriteria(); |
| 1227 | 1224 |
| 1228 inline void IncrementYoungSurvivorsCounter(int survived) { | 1225 inline void IncrementYoungSurvivorsCounter(int survived) { |
| 1229 young_survivors_after_last_gc_ = survived; | 1226 young_survivors_after_last_gc_ = survived; |
| 1230 survived_since_last_expansion_ += survived; | 1227 survived_since_last_expansion_ += survived; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1246 | 1243 |
| 1247 if (PromotedSpaceSize() >= adjusted_allocation_limit) return true; | 1244 if (PromotedSpaceSize() >= adjusted_allocation_limit) return true; |
| 1248 | 1245 |
| 1249 return false; | 1246 return false; |
| 1250 } | 1247 } |
| 1251 | 1248 |
| 1252 | 1249 |
| 1253 void UpdateNewSpaceReferencesInExternalStringTable( | 1250 void UpdateNewSpaceReferencesInExternalStringTable( |
| 1254 ExternalStringTableUpdaterCallback updater_func); | 1251 ExternalStringTableUpdaterCallback updater_func); |
| 1255 | 1252 |
| 1253 void UpdateReferencesInExternalStringTable( |
| 1254 ExternalStringTableUpdaterCallback updater_func); |
| 1255 |
| 1256 void ProcessWeakReferences(WeakObjectRetainer* retainer); | 1256 void ProcessWeakReferences(WeakObjectRetainer* retainer); |
| 1257 | 1257 |
| 1258 // Helper function that governs the promotion policy from new space to | 1258 // Helper function that governs the promotion policy from new space to |
| 1259 // old. If the object's old address lies below the new space's age | 1259 // old. If the object's old address lies below the new space's age |
| 1260 // mark or if we've already filled the bottom 1/16th of the to space, | 1260 // mark or if we've already filled the bottom 1/16th of the to space, |
| 1261 // we try to promote this object. | 1261 // we try to promote this object. |
| 1262 inline bool ShouldBePromoted(Address old_address, int object_size); | 1262 inline bool ShouldBePromoted(Address old_address, int object_size); |
| 1263 | 1263 |
| 1264 int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } | 1264 int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } |
| 1265 | 1265 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 OldSpace* old_data_space_; | 1361 OldSpace* old_data_space_; |
| 1362 OldSpace* code_space_; | 1362 OldSpace* code_space_; |
| 1363 MapSpace* map_space_; | 1363 MapSpace* map_space_; |
| 1364 CellSpace* cell_space_; | 1364 CellSpace* cell_space_; |
| 1365 LargeObjectSpace* lo_space_; | 1365 LargeObjectSpace* lo_space_; |
| 1366 HeapState gc_state_; | 1366 HeapState gc_state_; |
| 1367 | 1367 |
| 1368 // Returns the amount of external memory registered since last global gc. | 1368 // Returns the amount of external memory registered since last global gc. |
| 1369 int PromotedExternalMemorySize(); | 1369 int PromotedExternalMemorySize(); |
| 1370 | 1370 |
| 1371 int mc_count_; // how many mark-compact collections happened | |
| 1372 int ms_count_; // how many mark-sweep collections happened | 1371 int ms_count_; // how many mark-sweep collections happened |
| 1373 unsigned int gc_count_; // how many gc happened | 1372 unsigned int gc_count_; // how many gc happened |
| 1374 | 1373 |
| 1375 // Total length of the strings we failed to flatten since the last GC. | 1374 // Total length of the strings we failed to flatten since the last GC. |
| 1376 int unflattened_strings_length_; | 1375 int unflattened_strings_length_; |
| 1377 | 1376 |
| 1378 #define ROOT_ACCESSOR(type, name, camel_name) \ | 1377 #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 1379 inline void set_##name(type* value) { \ | 1378 inline void set_##name(type* value) { \ |
| 1380 roots_[k##camel_name##RootIndex] = value; \ | 1379 roots_[k##camel_name##RootIndex] = value; \ |
| 1381 } | 1380 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 | 1544 |
| 1546 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); | 1545 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); |
| 1547 static void ScavengeStoreBufferCallback(Heap* heap, | 1546 static void ScavengeStoreBufferCallback(Heap* heap, |
| 1548 MemoryChunk* page, | 1547 MemoryChunk* page, |
| 1549 StoreBufferEvent event); | 1548 StoreBufferEvent event); |
| 1550 | 1549 |
| 1551 // Performs a major collection in the whole heap. | 1550 // Performs a major collection in the whole heap. |
| 1552 void MarkCompact(GCTracer* tracer); | 1551 void MarkCompact(GCTracer* tracer); |
| 1553 | 1552 |
| 1554 // Code to be run before and after mark-compact. | 1553 // Code to be run before and after mark-compact. |
| 1555 void MarkCompactPrologue(bool is_compacting); | 1554 void MarkCompactPrologue(); |
| 1556 | 1555 |
| 1557 // Completely clear the Instanceof cache (to stop it keeping objects alive | 1556 // Completely clear the Instanceof cache (to stop it keeping objects alive |
| 1558 // around a GC). | 1557 // around a GC). |
| 1559 inline void CompletelyClearInstanceofCache(); | 1558 inline void CompletelyClearInstanceofCache(); |
| 1560 | 1559 |
| 1561 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | 1560 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) |
| 1562 // Record statistics before and after garbage collection. | 1561 // Record statistics before and after garbage collection. |
| 1563 void ReportStatisticsBeforeGC(); | 1562 void ReportStatisticsBeforeGC(); |
| 1564 void ReportStatisticsAfterGC(); | 1563 void ReportStatisticsAfterGC(); |
| 1565 #endif | 1564 #endif |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 | 2090 |
| 2092 // Sets the collector. | 2091 // Sets the collector. |
| 2093 void set_collector(GarbageCollector collector) { collector_ = collector; } | 2092 void set_collector(GarbageCollector collector) { collector_ = collector; } |
| 2094 | 2093 |
| 2095 // Sets the GC count. | 2094 // Sets the GC count. |
| 2096 void set_gc_count(unsigned int count) { gc_count_ = count; } | 2095 void set_gc_count(unsigned int count) { gc_count_ = count; } |
| 2097 | 2096 |
| 2098 // Sets the full GC count. | 2097 // Sets the full GC count. |
| 2099 void set_full_gc_count(int count) { full_gc_count_ = count; } | 2098 void set_full_gc_count(int count) { full_gc_count_ = count; } |
| 2100 | 2099 |
| 2101 // Sets the flag that this is a compacting full GC. | |
| 2102 void set_is_compacting() { is_compacting_ = true; } | |
| 2103 bool is_compacting() const { return is_compacting_; } | |
| 2104 | |
| 2105 // Increment and decrement the count of marked objects. | |
| 2106 void increment_marked_count() { ++marked_count_; } | |
| 2107 void decrement_marked_count() { --marked_count_; } | |
| 2108 | |
| 2109 int marked_count() { return marked_count_; } | |
| 2110 | |
| 2111 void increment_promoted_objects_size(int object_size) { | 2100 void increment_promoted_objects_size(int object_size) { |
| 2112 promoted_objects_size_ += object_size; | 2101 promoted_objects_size_ += object_size; |
| 2113 } | 2102 } |
| 2114 | 2103 |
| 2115 private: | 2104 private: |
| 2116 // Returns a string matching the collector. | 2105 // Returns a string matching the collector. |
| 2117 const char* CollectorString(); | 2106 const char* CollectorString(); |
| 2118 | 2107 |
| 2119 // Returns size of object in heap (in MB). | 2108 // Returns size of object in heap (in MB). |
| 2120 double SizeOfHeapObjects() { | 2109 double SizeOfHeapObjects() { |
| 2121 return (static_cast<double>(HEAP->SizeOfObjects())) / MB; | 2110 return (static_cast<double>(HEAP->SizeOfObjects())) / MB; |
| 2122 } | 2111 } |
| 2123 | 2112 |
| 2124 double start_time_; // Timestamp set in the constructor. | 2113 double start_time_; // Timestamp set in the constructor. |
| 2125 intptr_t start_size_; // Size of objects in heap set in constructor. | 2114 intptr_t start_size_; // Size of objects in heap set in constructor. |
| 2126 GarbageCollector collector_; // Type of collector. | 2115 GarbageCollector collector_; // Type of collector. |
| 2127 | 2116 |
| 2128 // A count (including this one, eg, the first collection is 1) of the | 2117 // A count (including this one, eg, the first collection is 1) of the |
| 2129 // number of garbage collections. | 2118 // number of garbage collections. |
| 2130 unsigned int gc_count_; | 2119 unsigned int gc_count_; |
| 2131 | 2120 |
| 2132 // A count (including this one) of the number of full garbage collections. | 2121 // A count (including this one) of the number of full garbage collections. |
| 2133 int full_gc_count_; | 2122 int full_gc_count_; |
| 2134 | 2123 |
| 2135 // True if the current GC is a compacting full collection, false | |
| 2136 // otherwise. | |
| 2137 bool is_compacting_; | |
| 2138 | |
| 2139 // On a full GC, a count of the number of marked objects. Incremented | |
| 2140 // when an object is marked and decremented when an object's mark bit is | |
| 2141 // cleared. Will be zero on a scavenge collection. | |
| 2142 int marked_count_; | |
| 2143 | |
| 2144 // Amounts of time spent in different scopes during GC. | 2124 // Amounts of time spent in different scopes during GC. |
| 2145 double scopes_[Scope::kNumberOfScopes]; | 2125 double scopes_[Scope::kNumberOfScopes]; |
| 2146 | 2126 |
| 2147 // Total amount of space either wasted or contained in one of free lists | 2127 // Total amount of space either wasted or contained in one of free lists |
| 2148 // before the current GC. | 2128 // before the current GC. |
| 2149 intptr_t in_free_list_or_wasted_before_gc_; | 2129 intptr_t in_free_list_or_wasted_before_gc_; |
| 2150 | 2130 |
| 2151 // Difference between space used in the heap at the beginning of the current | 2131 // Difference between space used in the heap at the beginning of the current |
| 2152 // collection and the end of the previous collection. | 2132 // collection and the end of the previous collection. |
| 2153 intptr_t allocated_since_last_gc_; | 2133 intptr_t allocated_since_last_gc_; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2347 | 2327 |
| 2348 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2328 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2349 }; | 2329 }; |
| 2350 #endif // DEBUG || LIVE_OBJECT_LIST | 2330 #endif // DEBUG || LIVE_OBJECT_LIST |
| 2351 | 2331 |
| 2352 } } // namespace v8::internal | 2332 } } // namespace v8::internal |
| 2353 | 2333 |
| 2354 #undef HEAP | 2334 #undef HEAP |
| 2355 | 2335 |
| 2356 #endif // V8_HEAP_H_ | 2336 #endif // V8_HEAP_H_ |
| OLD | NEW |