Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 #ifndef V8_HEAP_H_ | 28 #ifndef V8_HEAP_H_ |
| 29 #define V8_HEAP_H_ | 29 #define V8_HEAP_H_ |
| 30 | 30 |
| 31 #include <math.h> | 31 #include <math.h> |
| 32 | 32 |
| 33 #include "globals.h" | 33 #include "globals.h" |
| 34 #include "list.h" | 34 #include "list.h" |
| 35 #include "spaces.h" | 35 #include "spaces.h" |
| 36 #include "splay-tree-inl.h" | 36 #include "splay-tree-inl.h" |
| 37 #include "v8-counters.h" | 37 #include "v8-counters.h" |
| 38 #include "v8globals.h" | |
| 38 | 39 |
| 39 namespace v8 { | 40 namespace v8 { |
| 40 namespace internal { | 41 namespace internal { |
| 41 | 42 |
| 42 | 43 |
| 43 // Defines all the roots in Heap. | 44 // Defines all the roots in Heap. |
| 44 #define STRONG_ROOT_LIST(V) \ | 45 #define STRONG_ROOT_LIST(V) \ |
| 45 V(Map, byte_array_map, ByteArrayMap) \ | 46 V(Map, byte_array_map, ByteArrayMap) \ |
| 46 V(Map, free_space_map, FreeSpaceMap) \ | 47 V(Map, free_space_map, FreeSpaceMap) \ |
| 47 V(Map, one_pointer_filler_map, OnePointerFillerMap) \ | 48 V(Map, one_pointer_filler_map, OnePointerFillerMap) \ |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 class WeakObjectRetainer; | 229 class WeakObjectRetainer; |
| 229 | 230 |
| 230 | 231 |
| 231 typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); | 232 typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); |
| 232 | 233 |
| 233 typedef void (*PointerRegionCallback)(Address start, | 234 typedef void (*PointerRegionCallback)(Address start, |
| 234 Address end, | 235 Address end, |
| 235 ObjectSlotCallback copy_object_func); | 236 ObjectSlotCallback copy_object_func); |
| 236 | 237 |
| 237 | 238 |
| 239 class StoreBufferRebuilder : public AllStatic { | |
| 240 public: | |
| 241 void Callback(MemoryChunk* page, StoreBufferEvent event); | |
| 242 | |
| 243 private: | |
| 244 // The fullness of the store buffer when we started to scan the current page. | |
|
Vyacheslav Egorov (Chromium)
2011/03/28 15:13:19
I can't grok the comment.
Erik Corry
2011/03/28 15:56:07
Rewritten.
| |
| 245 Object*** start_of_current_page_; | |
| 246 // The current page we are scanning in the store buffer iterator. | |
| 247 MemoryChunk* current_page_; | |
| 248 }; | |
| 249 | |
| 250 | |
| 251 | |
| 238 // The all static Heap captures the interface to the global object heap. | 252 // The all static Heap captures the interface to the global object heap. |
| 239 // All JavaScript contexts by this process share the same object heap. | 253 // All JavaScript contexts by this process share the same object heap. |
| 240 | 254 |
| 241 class Heap : public AllStatic { | 255 class Heap : public AllStatic { |
| 242 public: | 256 public: |
| 243 // Configure heap size before setup. Return false if the heap has been | 257 // Configure heap size before setup. Return false if the heap has been |
| 244 // setup already. | 258 // setup already. |
| 245 static bool ConfigureHeap(intptr_t max_semispace_size, | 259 static bool ConfigureHeap(intptr_t max_semispace_size, |
| 246 intptr_t max_old_gen_size, | 260 intptr_t max_old_gen_size, |
| 247 intptr_t max_executable_size); | 261 intptr_t max_executable_size); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 } | 858 } |
| 845 static Object* global_contexts_list() { return global_contexts_list_; } | 859 static Object* global_contexts_list() { return global_contexts_list_; } |
| 846 | 860 |
| 847 // Iterates over all roots in the heap. | 861 // Iterates over all roots in the heap. |
| 848 static void IterateRoots(ObjectVisitor* v, VisitMode mode); | 862 static void IterateRoots(ObjectVisitor* v, VisitMode mode); |
| 849 // Iterates over all strong roots in the heap. | 863 // Iterates over all strong roots in the heap. |
| 850 static void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); | 864 static void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); |
| 851 // Iterates over all the other roots in the heap. | 865 // Iterates over all the other roots in the heap. |
| 852 static void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); | 866 static void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); |
| 853 | 867 |
| 854 enum ExpectedPageWatermarkState { | |
| 855 WATERMARK_SHOULD_BE_VALID, | |
| 856 WATERMARK_CAN_BE_INVALID | |
| 857 }; | |
| 858 | |
| 859 // For each region of pointers on a page in use from an old space call | 868 // For each region of pointers on a page in use from an old space call |
| 860 // visit_pointer_region callback. | 869 // visit_pointer_region callback. |
| 861 // If either visit_pointer_region or callback can cause an allocation | 870 // If either visit_pointer_region or callback can cause an allocation |
| 862 // in old space and changes in allocation watermark then | 871 // in old space and changes in allocation watermark then |
| 863 // can_preallocate_during_iteration should be set to true. | 872 // can_preallocate_during_iteration should be set to true. |
| 864 // All pages will be marked as having invalid watermark upon | 873 // All pages will be marked as having invalid watermark upon |
| 865 // iteration completion. | 874 // iteration completion. |
| 866 static void IteratePointers( | 875 static void IteratePointers( |
| 867 PagedSpace* space, | 876 PagedSpace* space, |
| 868 PointerRegionCallback visit_pointer_region, | 877 PointerRegionCallback visit_pointer_region, |
| 878 ObjectSlotCallback callback); | |
| 879 static void IteratePointersOnPage( | |
| 880 PagedSpace* space, | |
| 881 PointerRegionCallback visit_pointer_region, | |
| 869 ObjectSlotCallback callback, | 882 ObjectSlotCallback callback, |
| 870 ExpectedPageWatermarkState expected_page_watermark_state); | 883 Page* page); |
| 871 | 884 |
| 872 // Iterate pointers to from semispace of new space found in memory interval | 885 // Iterate pointers to from semispace of new space found in memory interval |
| 873 // from start to end. | 886 // from start to end. |
| 874 static void IterateAndMarkPointersToFromSpace(Address start, | 887 static void IterateAndMarkPointersToFromSpace(Address start, |
| 875 Address end, | 888 Address end, |
| 876 ObjectSlotCallback callback); | 889 ObjectSlotCallback callback); |
| 877 | 890 |
| 878 // Iterate pointers to new space found in memory interval from start to end. | 891 // Iterate pointers to new space found in memory interval from start to end. |
| 879 static void IteratePointersToNewSpace(Address start, | 892 static void IteratePointersToNewSpace(Address start, |
| 880 Address end, | 893 Address end, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 return &global_contexts_list_; | 961 return &global_contexts_list_; |
| 949 } | 962 } |
| 950 | 963 |
| 951 #ifdef DEBUG | 964 #ifdef DEBUG |
| 952 static void Print(); | 965 static void Print(); |
| 953 static void PrintHandles(); | 966 static void PrintHandles(); |
| 954 | 967 |
| 955 // Verify the heap is in its normal state before or after a GC. | 968 // Verify the heap is in its normal state before or after a GC. |
| 956 static void Verify(); | 969 static void Verify(); |
| 957 | 970 |
| 958 static void OldPointerSpaceCheckStoreBuffer( | 971 static void OldPointerSpaceCheckStoreBuffer(); |
| 959 ExpectedPageWatermarkState watermark_state); | 972 static void MapSpaceCheckStoreBuffer(); |
| 960 static void MapSpaceCheckStoreBuffer( | |
| 961 ExpectedPageWatermarkState watermark_state); | |
| 962 static void LargeObjectSpaceCheckStoreBuffer(); | 973 static void LargeObjectSpaceCheckStoreBuffer(); |
| 963 | 974 |
| 964 // Report heap statistics. | 975 // Report heap statistics. |
| 965 static void ReportHeapStatistics(const char* title); | 976 static void ReportHeapStatistics(const char* title); |
| 966 static void ReportCodeStatistics(const char* title); | 977 static void ReportCodeStatistics(const char* title); |
| 967 | 978 |
| 968 // Fill in bogus values in from space | 979 // Fill in bogus values in from space |
| 969 static void ZapFromSpace(); | 980 static void ZapFromSpace(); |
| 970 #endif | 981 #endif |
| 971 | 982 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1058 int length, | 1069 int length, |
| 1059 PretenureFlag pretenure); | 1070 PretenureFlag pretenure); |
| 1060 | 1071 |
| 1061 // True if we have reached the allocation limit in the old generation that | 1072 // True if we have reached the allocation limit in the old generation that |
| 1062 // should force the next GC (caused normally) to be a full one. | 1073 // should force the next GC (caused normally) to be a full one. |
| 1063 static bool OldGenerationPromotionLimitReached() { | 1074 static bool OldGenerationPromotionLimitReached() { |
| 1064 return (PromotedSpaceSize() + PromotedExternalMemorySize()) | 1075 return (PromotedSpaceSize() + PromotedExternalMemorySize()) |
| 1065 > old_gen_promotion_limit_; | 1076 > old_gen_promotion_limit_; |
| 1066 } | 1077 } |
| 1067 | 1078 |
| 1068 static intptr_t OldGenerationSpaceAvailable() { | 1079 static inline intptr_t OldGenerationSpaceAvailable() { |
| 1069 return old_gen_allocation_limit_ - | 1080 return old_gen_allocation_limit_ - |
| 1070 (PromotedSpaceSize() + PromotedExternalMemorySize()); | 1081 (PromotedSpaceSize() + PromotedExternalMemorySize()); |
| 1071 } | 1082 } |
| 1072 | 1083 |
| 1073 // True if we have reached the allocation limit in the old generation that | 1084 // True if we have reached the allocation limit in the old generation that |
| 1074 // should artificially cause a GC right now. | 1085 // should artificially cause a GC right now. |
| 1075 static bool OldGenerationAllocationLimitReached() { | 1086 static inline bool OldGenerationAllocationLimitReached(); |
| 1076 return OldGenerationSpaceAvailable() < 0; | |
| 1077 } | |
| 1078 | 1087 |
| 1079 // Can be called when the embedding application is idle. | 1088 // Can be called when the embedding application is idle. |
| 1080 static bool IdleNotification(); | 1089 static bool IdleNotification(); |
| 1081 | 1090 |
| 1082 // Declare all the root indices. | 1091 // Declare all the root indices. |
| 1083 enum RootListIndex { | 1092 enum RootListIndex { |
| 1084 #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, | 1093 #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, |
| 1085 STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION) | 1094 STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION) |
| 1086 #undef ROOT_INDEX_DECLARATION | 1095 #undef ROOT_INDEX_DECLARATION |
| 1087 | 1096 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 static int amount_of_external_allocated_memory_at_last_global_gc_; | 1273 static int amount_of_external_allocated_memory_at_last_global_gc_; |
| 1265 | 1274 |
| 1266 // Indicates that an allocation has failed in the old generation since the | 1275 // Indicates that an allocation has failed in the old generation since the |
| 1267 // last GC. | 1276 // last GC. |
| 1268 static int old_gen_exhausted_; | 1277 static int old_gen_exhausted_; |
| 1269 | 1278 |
| 1270 static Object* roots_[kRootListLength]; | 1279 static Object* roots_[kRootListLength]; |
| 1271 | 1280 |
| 1272 static Object* global_contexts_list_; | 1281 static Object* global_contexts_list_; |
| 1273 | 1282 |
| 1283 static StoreBufferRebuilder store_buffer_rebuilder_; | |
| 1284 | |
| 1274 struct StringTypeTable { | 1285 struct StringTypeTable { |
| 1275 InstanceType type; | 1286 InstanceType type; |
| 1276 int size; | 1287 int size; |
| 1277 RootListIndex index; | 1288 RootListIndex index; |
| 1278 }; | 1289 }; |
| 1279 | 1290 |
| 1280 struct ConstantSymbolTable { | 1291 struct ConstantSymbolTable { |
| 1281 const char* contents; | 1292 const char* contents; |
| 1282 RootListIndex index; | 1293 RootListIndex index; |
| 1283 }; | 1294 }; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1375 MUST_USE_RESULT static MaybeObject* AllocateEmptyFixedArray(); | 1386 MUST_USE_RESULT static MaybeObject* AllocateEmptyFixedArray(); |
| 1376 | 1387 |
| 1377 // Performs a minor collection in new generation. | 1388 // Performs a minor collection in new generation. |
| 1378 static void Scavenge(); | 1389 static void Scavenge(); |
| 1379 | 1390 |
| 1380 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( | 1391 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( |
| 1381 Object** pointer); | 1392 Object** pointer); |
| 1382 | 1393 |
| 1383 static Address DoScavenge(ObjectVisitor* scavenge_visitor, | 1394 static Address DoScavenge(ObjectVisitor* scavenge_visitor, |
| 1384 Address new_space_front); | 1395 Address new_space_front); |
| 1396 static void ScavengeStoreBufferCallback(MemoryChunk* page, | |
| 1397 StoreBufferEvent event); | |
| 1385 | 1398 |
| 1386 // Performs a major collection in the whole heap. | 1399 // Performs a major collection in the whole heap. |
| 1387 static void MarkCompact(GCTracer* tracer); | 1400 static void MarkCompact(GCTracer* tracer); |
| 1388 | 1401 |
| 1389 // Code to be run before and after mark-compact. | 1402 // Code to be run before and after mark-compact. |
| 1390 static void MarkCompactPrologue(bool is_compacting); | 1403 static void MarkCompactPrologue(bool is_compacting); |
| 1391 | 1404 |
| 1392 // Completely clear the Instanceof cache (to stop it keeping objects alive | 1405 // Completely clear the Instanceof cache (to stop it keeping objects alive |
| 1393 // around a GC). | 1406 // around a GC). |
| 1394 static void CompletelyClearInstanceofCache() { | 1407 static void CompletelyClearInstanceofCache() { |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2250 | 2263 |
| 2251 AssertNoAllocation no_alloc; // i.e. no gc allowed. | 2264 AssertNoAllocation no_alloc; // i.e. no gc allowed. |
| 2252 | 2265 |
| 2253 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2266 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2254 }; | 2267 }; |
| 2255 #endif // DEBUG || LIVE_OBJECT_LIST | 2268 #endif // DEBUG || LIVE_OBJECT_LIST |
| 2256 | 2269 |
| 2257 } } // namespace v8::internal | 2270 } } // namespace v8::internal |
| 2258 | 2271 |
| 2259 #endif // V8_HEAP_H_ | 2272 #endif // V8_HEAP_H_ |
| OLD | NEW |