| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 V(NameDictionary, intrinsic_function_names, IntrinsicFunctionNames) \ | 181 V(NameDictionary, intrinsic_function_names, IntrinsicFunctionNames) \ |
| 182 V(Smi, arguments_adaptor_deopt_pc_offset, ArgumentsAdaptorDeoptPCOffset) \ | 182 V(Smi, arguments_adaptor_deopt_pc_offset, ArgumentsAdaptorDeoptPCOffset) \ |
| 183 V(Smi, construct_stub_deopt_pc_offset, ConstructStubDeoptPCOffset) \ | 183 V(Smi, construct_stub_deopt_pc_offset, ConstructStubDeoptPCOffset) \ |
| 184 V(Smi, getter_stub_deopt_pc_offset, GetterStubDeoptPCOffset) \ | 184 V(Smi, getter_stub_deopt_pc_offset, GetterStubDeoptPCOffset) \ |
| 185 V(Smi, setter_stub_deopt_pc_offset, SetterStubDeoptPCOffset) \ | 185 V(Smi, setter_stub_deopt_pc_offset, SetterStubDeoptPCOffset) \ |
| 186 V(JSObject, observation_state, ObservationState) \ | 186 V(JSObject, observation_state, ObservationState) \ |
| 187 V(Map, external_map, ExternalMap) \ | 187 V(Map, external_map, ExternalMap) \ |
| 188 V(Symbol, frozen_symbol, FrozenSymbol) \ | 188 V(Symbol, frozen_symbol, FrozenSymbol) \ |
| 189 V(SeededNumberDictionary, empty_slow_element_dictionary, \ | 189 V(SeededNumberDictionary, empty_slow_element_dictionary, \ |
| 190 EmptySlowElementDictionary) \ | 190 EmptySlowElementDictionary) \ |
| 191 V(Symbol, observed_symbol, ObservedSymbol) | 191 V(Symbol, observed_symbol, ObservedSymbol) \ |
| 192 V(HeapObject, i18n_template_one, I18nTemplateOne) \ |
| 193 V(HeapObject, i18n_template_two, I18nTemplateTwo) |
| 192 | 194 |
| 193 #define ROOT_LIST(V) \ | 195 #define ROOT_LIST(V) \ |
| 194 STRONG_ROOT_LIST(V) \ | 196 STRONG_ROOT_LIST(V) \ |
| 195 V(StringTable, string_table, StringTable) | 197 V(StringTable, string_table, StringTable) |
| 196 | 198 |
| 197 #define INTERNALIZED_STRING_LIST(V) \ | 199 #define INTERNALIZED_STRING_LIST(V) \ |
| 198 V(Array_string, "Array") \ | 200 V(Array_string, "Array") \ |
| 199 V(Object_string, "Object") \ | 201 V(Object_string, "Object") \ |
| 200 V(proto_string, "__proto__") \ | 202 V(proto_string, "__proto__") \ |
| 201 V(StringImpl_string, "StringImpl") \ | 203 V(StringImpl_string, "StringImpl") \ |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // separate from old space strings. | 470 // separate from old space strings. |
| 469 List<Object*> new_space_strings_; | 471 List<Object*> new_space_strings_; |
| 470 List<Object*> old_space_strings_; | 472 List<Object*> old_space_strings_; |
| 471 | 473 |
| 472 Heap* heap_; | 474 Heap* heap_; |
| 473 | 475 |
| 474 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); | 476 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); |
| 475 }; | 477 }; |
| 476 | 478 |
| 477 | 479 |
| 478 // The stack property of an error object is implemented as a getter that | |
| 479 // formats the attached raw stack trace into a string. This raw stack trace | |
| 480 // keeps code and function objects alive until the getter is called the first | |
| 481 // time. To release those objects, we call the getter after each GC for | |
| 482 // newly tenured error objects that are kept in a list. | |
| 483 class ErrorObjectList { | |
| 484 public: | |
| 485 inline void Add(JSObject* object); | |
| 486 | |
| 487 inline void Iterate(ObjectVisitor* v); | |
| 488 | |
| 489 void TearDown(); | |
| 490 | |
| 491 void RemoveUnmarked(Heap* heap); | |
| 492 | |
| 493 void DeferredFormatStackTrace(Isolate* isolate); | |
| 494 | |
| 495 void UpdateReferences(); | |
| 496 | |
| 497 void UpdateReferencesInNewSpace(Heap* heap); | |
| 498 | |
| 499 private: | |
| 500 static const int kBudgetPerGC = 16; | |
| 501 | |
| 502 ErrorObjectList() : nested_(false) { } | |
| 503 | |
| 504 friend class Heap; | |
| 505 | |
| 506 List<Object*> list_; | |
| 507 bool nested_; | |
| 508 | |
| 509 DISALLOW_COPY_AND_ASSIGN(ErrorObjectList); | |
| 510 }; | |
| 511 | |
| 512 | |
| 513 enum ArrayStorageAllocationMode { | 480 enum ArrayStorageAllocationMode { |
| 514 DONT_INITIALIZE_ARRAY_ELEMENTS, | 481 DONT_INITIALIZE_ARRAY_ELEMENTS, |
| 515 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE | 482 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
| 516 }; | 483 }; |
| 517 | 484 |
| 518 class Heap { | 485 class Heap { |
| 519 public: | 486 public: |
| 520 // Configure heap size before setup. Return false if the heap has been | 487 // Configure heap size before setup. Return false if the heap has been |
| 521 // set up already. | 488 // set up already. |
| 522 bool ConfigureHeap(int max_semispace_size, | 489 bool ConfigureHeap(int max_semispace_size, |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 void CollectAllAvailableGarbage(const char* gc_reason = NULL); | 1247 void CollectAllAvailableGarbage(const char* gc_reason = NULL); |
| 1281 | 1248 |
| 1282 // Check whether the heap is currently iterable. | 1249 // Check whether the heap is currently iterable. |
| 1283 bool IsHeapIterable(); | 1250 bool IsHeapIterable(); |
| 1284 | 1251 |
| 1285 // Ensure that we have swept all spaces in such a way that we can iterate | 1252 // Ensure that we have swept all spaces in such a way that we can iterate |
| 1286 // over all objects. May cause a GC. | 1253 // over all objects. May cause a GC. |
| 1287 void EnsureHeapIsIterable(); | 1254 void EnsureHeapIsIterable(); |
| 1288 | 1255 |
| 1289 // Notify the heap that a context has been disposed. | 1256 // Notify the heap that a context has been disposed. |
| 1290 int NotifyContextDisposed() { | 1257 int NotifyContextDisposed(); |
| 1291 flush_monomorphic_ics_ = true; | |
| 1292 return ++contexts_disposed_; | |
| 1293 } | |
| 1294 | 1258 |
| 1295 // Utility to invoke the scavenger. This is needed in test code to | 1259 // Utility to invoke the scavenger. This is needed in test code to |
| 1296 // ensure correct callback for weak global handles. | 1260 // ensure correct callback for weak global handles. |
| 1297 void PerformScavenge(); | 1261 void PerformScavenge(); |
| 1298 | 1262 |
| 1299 inline void increment_scan_on_scavenge_pages() { | 1263 inline void increment_scan_on_scavenge_pages() { |
| 1300 scan_on_scavenge_pages_++; | 1264 scan_on_scavenge_pages_++; |
| 1301 if (FLAG_gc_verbose) { | 1265 if (FLAG_gc_verbose) { |
| 1302 PrintF("Scan-on-scavenge pages: %d\n", scan_on_scavenge_pages_); | 1266 PrintF("Scan-on-scavenge pages: %d\n", scan_on_scavenge_pages_); |
| 1303 } | 1267 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1326 void RemoveGCEpilogueCallback(GCEpilogueCallback callback); | 1290 void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 1327 | 1291 |
| 1328 void SetGlobalGCPrologueCallback(GCCallback callback) { | 1292 void SetGlobalGCPrologueCallback(GCCallback callback) { |
| 1329 ASSERT((callback == NULL) ^ (global_gc_prologue_callback_ == NULL)); | 1293 ASSERT((callback == NULL) ^ (global_gc_prologue_callback_ == NULL)); |
| 1330 global_gc_prologue_callback_ = callback; | 1294 global_gc_prologue_callback_ = callback; |
| 1331 } | 1295 } |
| 1332 void SetGlobalGCEpilogueCallback(GCCallback callback) { | 1296 void SetGlobalGCEpilogueCallback(GCCallback callback) { |
| 1333 ASSERT((callback == NULL) ^ (global_gc_epilogue_callback_ == NULL)); | 1297 ASSERT((callback == NULL) ^ (global_gc_epilogue_callback_ == NULL)); |
| 1334 global_gc_epilogue_callback_ = callback; | 1298 global_gc_epilogue_callback_ = callback; |
| 1335 } | 1299 } |
| 1300 void SetI18nTemplateOne(ObjectTemplateInfo* tmpl) { |
| 1301 set_i18n_template_one(tmpl); |
| 1302 } |
| 1303 void SetI18nTemplateTwo(ObjectTemplateInfo* tmpl) { |
| 1304 set_i18n_template_two(tmpl); |
| 1305 } |
| 1336 | 1306 |
| 1337 // Heap root getters. We have versions with and without type::cast() here. | 1307 // Heap root getters. We have versions with and without type::cast() here. |
| 1338 // You can't use type::cast during GC because the assert fails. | 1308 // You can't use type::cast during GC because the assert fails. |
| 1339 // TODO(1490): Try removing the unchecked accessors, now that GC marking does | 1309 // TODO(1490): Try removing the unchecked accessors, now that GC marking does |
| 1340 // not corrupt the map. | 1310 // not corrupt the map. |
| 1341 #define ROOT_ACCESSOR(type, name, camel_name) \ | 1311 #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 1342 type* name() { \ | 1312 type* name() { \ |
| 1343 return type::cast(roots_[k##camel_name##RootIndex]); \ | 1313 return type::cast(roots_[k##camel_name##RootIndex]); \ |
| 1344 } \ | 1314 } \ |
| 1345 type* raw_unchecked_##name() { \ | 1315 type* raw_unchecked_##name() { \ |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 void ProcessWeakReferences(WeakObjectRetainer* retainer); | 1679 void ProcessWeakReferences(WeakObjectRetainer* retainer); |
| 1710 | 1680 |
| 1711 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); | 1681 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); |
| 1712 | 1682 |
| 1713 // Helper function that governs the promotion policy from new space to | 1683 // Helper function that governs the promotion policy from new space to |
| 1714 // old. If the object's old address lies below the new space's age | 1684 // old. If the object's old address lies below the new space's age |
| 1715 // mark or if we've already filled the bottom 1/16th of the to space, | 1685 // mark or if we've already filled the bottom 1/16th of the to space, |
| 1716 // we try to promote this object. | 1686 // we try to promote this object. |
| 1717 inline bool ShouldBePromoted(Address old_address, int object_size); | 1687 inline bool ShouldBePromoted(Address old_address, int object_size); |
| 1718 | 1688 |
| 1719 int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } | |
| 1720 | |
| 1721 void ClearJSFunctionResultCaches(); | 1689 void ClearJSFunctionResultCaches(); |
| 1722 | 1690 |
| 1723 void ClearNormalizedMapCaches(); | 1691 void ClearNormalizedMapCaches(); |
| 1724 | 1692 |
| 1725 GCTracer* tracer() { return tracer_; } | 1693 GCTracer* tracer() { return tracer_; } |
| 1726 | 1694 |
| 1727 // Returns the size of objects residing in non new spaces. | 1695 // Returns the size of objects residing in non new spaces. |
| 1728 intptr_t PromotedSpaceSizeOfObjects(); | 1696 intptr_t PromotedSpaceSizeOfObjects(); |
| 1729 | 1697 |
| 1730 double total_regexp_code_generated() { return total_regexp_code_generated_; } | 1698 double total_regexp_code_generated() { return total_regexp_code_generated_; } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1791 bool EnsureSweepersProgressed(int step_size) { | 1759 bool EnsureSweepersProgressed(int step_size) { |
| 1792 bool sweeping_complete = old_data_space()->EnsureSweeperProgress(step_size); | 1760 bool sweeping_complete = old_data_space()->EnsureSweeperProgress(step_size); |
| 1793 sweeping_complete &= old_pointer_space()->EnsureSweeperProgress(step_size); | 1761 sweeping_complete &= old_pointer_space()->EnsureSweeperProgress(step_size); |
| 1794 return sweeping_complete; | 1762 return sweeping_complete; |
| 1795 } | 1763 } |
| 1796 | 1764 |
| 1797 ExternalStringTable* external_string_table() { | 1765 ExternalStringTable* external_string_table() { |
| 1798 return &external_string_table_; | 1766 return &external_string_table_; |
| 1799 } | 1767 } |
| 1800 | 1768 |
| 1801 ErrorObjectList* error_object_list() { | |
| 1802 return &error_object_list_; | |
| 1803 } | |
| 1804 | |
| 1805 // Returns the current sweep generation. | 1769 // Returns the current sweep generation. |
| 1806 int sweep_generation() { | 1770 int sweep_generation() { |
| 1807 return sweep_generation_; | 1771 return sweep_generation_; |
| 1808 } | 1772 } |
| 1809 | 1773 |
| 1810 inline Isolate* isolate(); | 1774 inline Isolate* isolate(); |
| 1811 | 1775 |
| 1812 void CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags); | 1776 void CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags); |
| 1813 void CallGCEpilogueCallbacks(GCType gc_type); | 1777 void CallGCEpilogueCallbacks(GCType gc_type); |
| 1814 | 1778 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 | 1923 |
| 1960 // For keeping track of context disposals. | 1924 // For keeping track of context disposals. |
| 1961 int contexts_disposed_; | 1925 int contexts_disposed_; |
| 1962 | 1926 |
| 1963 int global_ic_age_; | 1927 int global_ic_age_; |
| 1964 | 1928 |
| 1965 bool flush_monomorphic_ics_; | 1929 bool flush_monomorphic_ics_; |
| 1966 | 1930 |
| 1967 int scan_on_scavenge_pages_; | 1931 int scan_on_scavenge_pages_; |
| 1968 | 1932 |
| 1969 #if V8_TARGET_ARCH_X64 | |
| 1970 static const int kMaxObjectSizeInNewSpace = 1024*KB; | |
| 1971 #else | |
| 1972 static const int kMaxObjectSizeInNewSpace = 512*KB; | |
| 1973 #endif | |
| 1974 | |
| 1975 NewSpace new_space_; | 1933 NewSpace new_space_; |
| 1976 OldSpace* old_pointer_space_; | 1934 OldSpace* old_pointer_space_; |
| 1977 OldSpace* old_data_space_; | 1935 OldSpace* old_data_space_; |
| 1978 OldSpace* code_space_; | 1936 OldSpace* code_space_; |
| 1979 MapSpace* map_space_; | 1937 MapSpace* map_space_; |
| 1980 CellSpace* cell_space_; | 1938 CellSpace* cell_space_; |
| 1981 PropertyCellSpace* property_cell_space_; | 1939 PropertyCellSpace* property_cell_space_; |
| 1982 LargeObjectSpace* lo_space_; | 1940 LargeObjectSpace* lo_space_; |
| 1983 HeapState gc_state_; | 1941 HeapState gc_state_; |
| 1984 int gc_post_processing_depth_; | 1942 int gc_post_processing_depth_; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2399 | 2357 |
| 2400 // Shared state read by the scavenge collector and set by ScavengeObject. | 2358 // Shared state read by the scavenge collector and set by ScavengeObject. |
| 2401 PromotionQueue promotion_queue_; | 2359 PromotionQueue promotion_queue_; |
| 2402 | 2360 |
| 2403 // Flag is set when the heap has been configured. The heap can be repeatedly | 2361 // Flag is set when the heap has been configured. The heap can be repeatedly |
| 2404 // configured through the API until it is set up. | 2362 // configured through the API until it is set up. |
| 2405 bool configured_; | 2363 bool configured_; |
| 2406 | 2364 |
| 2407 ExternalStringTable external_string_table_; | 2365 ExternalStringTable external_string_table_; |
| 2408 | 2366 |
| 2409 ErrorObjectList error_object_list_; | |
| 2410 | |
| 2411 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; | 2367 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; |
| 2412 | 2368 |
| 2413 MemoryChunk* chunks_queued_for_free_; | 2369 MemoryChunk* chunks_queued_for_free_; |
| 2414 | 2370 |
| 2415 Mutex* relocation_mutex_; | 2371 Mutex* relocation_mutex_; |
| 2416 #ifdef DEBUG | 2372 #ifdef DEBUG |
| 2417 bool relocation_mutex_locked_by_optimizer_thread_; | 2373 bool relocation_mutex_locked_by_optimizer_thread_; |
| 2418 #endif // DEBUG; | 2374 #endif // DEBUG; |
| 2419 | 2375 |
| 2420 friend class Factory; | 2376 friend class Factory; |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3091 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 3047 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
| 3092 | 3048 |
| 3093 private: | 3049 private: |
| 3094 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 3050 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 3095 }; | 3051 }; |
| 3096 #endif // DEBUG | 3052 #endif // DEBUG |
| 3097 | 3053 |
| 3098 } } // namespace v8::internal | 3054 } } // namespace v8::internal |
| 3099 | 3055 |
| 3100 #endif // V8_HEAP_H_ | 3056 #endif // V8_HEAP_H_ |
| OLD | NEW |