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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 /* The first 32 roots above this line should be boring from a GC point of */ \ | 89 /* The first 32 roots above this line should be boring from a GC point of */ \ |
90 /* view. This means they are never in new space and never on a page that */ \ | 90 /* view. This means they are never in new space and never on a page that */ \ |
91 /* is being compacted. */ \ | 91 /* is being compacted. */ \ |
92 V(FixedArray, number_string_cache, NumberStringCache) \ | 92 V(FixedArray, number_string_cache, NumberStringCache) \ |
93 V(Object, instanceof_cache_function, InstanceofCacheFunction) \ | 93 V(Object, instanceof_cache_function, InstanceofCacheFunction) \ |
94 V(Object, instanceof_cache_map, InstanceofCacheMap) \ | 94 V(Object, instanceof_cache_map, InstanceofCacheMap) \ |
95 V(Object, instanceof_cache_answer, InstanceofCacheAnswer) \ | 95 V(Object, instanceof_cache_answer, InstanceofCacheAnswer) \ |
96 V(FixedArray, single_character_string_cache, SingleCharacterStringCache) \ | 96 V(FixedArray, single_character_string_cache, SingleCharacterStringCache) \ |
97 V(FixedArray, string_split_cache, StringSplitCache) \ | 97 V(FixedArray, string_split_cache, StringSplitCache) \ |
98 V(Object, termination_exception, TerminationException) \ | 98 V(Object, termination_exception, TerminationException) \ |
99 V(Smi, string_hash_seed, StringHashSeed) \ | 99 V(Smi, hash_seed, HashSeed) \ |
100 V(Map, string_map, StringMap) \ | 100 V(Map, string_map, StringMap) \ |
101 V(Map, symbol_map, SymbolMap) \ | 101 V(Map, symbol_map, SymbolMap) \ |
102 V(Map, cons_string_map, ConsStringMap) \ | 102 V(Map, cons_string_map, ConsStringMap) \ |
103 V(Map, cons_ascii_string_map, ConsAsciiStringMap) \ | 103 V(Map, cons_ascii_string_map, ConsAsciiStringMap) \ |
104 V(Map, sliced_string_map, SlicedStringMap) \ | 104 V(Map, sliced_string_map, SlicedStringMap) \ |
105 V(Map, sliced_ascii_string_map, SlicedAsciiStringMap) \ | 105 V(Map, sliced_ascii_string_map, SlicedAsciiStringMap) \ |
106 V(Map, cons_symbol_map, ConsSymbolMap) \ | 106 V(Map, cons_symbol_map, ConsSymbolMap) \ |
107 V(Map, cons_ascii_symbol_map, ConsAsciiSymbolMap) \ | 107 V(Map, cons_ascii_symbol_map, ConsAsciiSymbolMap) \ |
108 V(Map, external_symbol_map, ExternalSymbolMap) \ | 108 V(Map, external_symbol_map, ExternalSymbolMap) \ |
109 V(Map, external_symbol_with_ascii_data_map, ExternalSymbolWithAsciiDataMap) \ | 109 V(Map, external_symbol_with_ascii_data_map, ExternalSymbolWithAsciiDataMap) \ |
(...skipping 29 matching lines...) Expand all Loading... |
139 V(Map, block_context_map, BlockContextMap) \ | 139 V(Map, block_context_map, BlockContextMap) \ |
140 V(Map, oddball_map, OddballMap) \ | 140 V(Map, oddball_map, OddballMap) \ |
141 V(Map, message_object_map, JSMessageObjectMap) \ | 141 V(Map, message_object_map, JSMessageObjectMap) \ |
142 V(Map, foreign_map, ForeignMap) \ | 142 V(Map, foreign_map, ForeignMap) \ |
143 V(HeapNumber, nan_value, NanValue) \ | 143 V(HeapNumber, nan_value, NanValue) \ |
144 V(HeapNumber, infinity_value, InfinityValue) \ | 144 V(HeapNumber, infinity_value, InfinityValue) \ |
145 V(HeapNumber, minus_zero_value, MinusZeroValue) \ | 145 V(HeapNumber, minus_zero_value, MinusZeroValue) \ |
146 V(Map, neander_map, NeanderMap) \ | 146 V(Map, neander_map, NeanderMap) \ |
147 V(JSObject, message_listeners, MessageListeners) \ | 147 V(JSObject, message_listeners, MessageListeners) \ |
148 V(Foreign, prototype_accessors, PrototypeAccessors) \ | 148 V(Foreign, prototype_accessors, PrototypeAccessors) \ |
149 V(NumberDictionary, code_stubs, CodeStubs) \ | 149 V(UnseededNumberDictionary, code_stubs, CodeStubs) \ |
150 V(NumberDictionary, non_monomorphic_cache, NonMonomorphicCache) \ | 150 V(UnseededNumberDictionary, non_monomorphic_cache, NonMonomorphicCache) \ |
151 V(PolymorphicCodeCache, polymorphic_code_cache, PolymorphicCodeCache) \ | 151 V(PolymorphicCodeCache, polymorphic_code_cache, PolymorphicCodeCache) \ |
152 V(Code, js_entry_code, JsEntryCode) \ | 152 V(Code, js_entry_code, JsEntryCode) \ |
153 V(Code, js_construct_entry_code, JsConstructEntryCode) \ | 153 V(Code, js_construct_entry_code, JsConstructEntryCode) \ |
154 V(FixedArray, natives_source_cache, NativesSourceCache) \ | 154 V(FixedArray, natives_source_cache, NativesSourceCache) \ |
155 V(Object, last_script_id, LastScriptId) \ | 155 V(Object, last_script_id, LastScriptId) \ |
156 V(Script, empty_script, EmptyScript) \ | 156 V(Script, empty_script, EmptyScript) \ |
157 V(Smi, real_stack_limit, RealStackLimit) \ | 157 V(Smi, real_stack_limit, RealStackLimit) \ |
158 V(StringDictionary, intrinsic_function_names, IntrinsicFunctionNames) \ | 158 V(StringDictionary, intrinsic_function_names, IntrinsicFunctionNames) \ |
159 | 159 |
160 #define ROOT_LIST(V) \ | 160 #define ROOT_LIST(V) \ |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 427 |
428 Heap* heap_; | 428 Heap* heap_; |
429 | 429 |
430 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); | 430 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); |
431 }; | 431 }; |
432 | 432 |
433 | 433 |
434 class Heap { | 434 class Heap { |
435 public: | 435 public: |
436 // Configure heap size before setup. Return false if the heap has been | 436 // Configure heap size before setup. Return false if the heap has been |
437 // setup already. | 437 // set up already. |
438 bool ConfigureHeap(int max_semispace_size, | 438 bool ConfigureHeap(int max_semispace_size, |
439 intptr_t max_old_gen_size, | 439 intptr_t max_old_gen_size, |
440 intptr_t max_executable_size); | 440 intptr_t max_executable_size); |
441 bool ConfigureHeapDefault(); | 441 bool ConfigureHeapDefault(); |
442 | 442 |
443 // Initializes the global object heap. If create_heap_objects is true, | 443 // Initializes the global object heap. If create_heap_objects is true, |
444 // also creates the basic non-mutable objects. | 444 // also creates the basic non-mutable objects. |
445 // Returns whether it succeeded. | 445 // Returns whether it succeeded. |
446 bool Setup(bool create_heap_objects); | 446 bool SetUp(bool create_heap_objects); |
447 | 447 |
448 // Destroys all memory allocated by the heap. | 448 // Destroys all memory allocated by the heap. |
449 void TearDown(); | 449 void TearDown(); |
450 | 450 |
451 // Set the stack limit in the roots_ array. Some architectures generate | 451 // Set the stack limit in the roots_ array. Some architectures generate |
452 // code that looks here, because it is faster than loading from the static | 452 // code that looks here, because it is faster than loading from the static |
453 // jslimit_/real_jslimit_ variable in the StackGuard. | 453 // jslimit_/real_jslimit_ variable in the StackGuard. |
454 void SetStackLimits(); | 454 void SetStackLimits(); |
455 | 455 |
456 // Returns whether Setup has been called. | 456 // Returns whether SetUp has been called. |
457 bool HasBeenSetup(); | 457 bool HasBeenSetUp(); |
458 | 458 |
459 // Returns the maximum amount of memory reserved for the heap. For | 459 // Returns the maximum amount of memory reserved for the heap. For |
460 // the young generation, we reserve 4 times the amount needed for a | 460 // the young generation, we reserve 4 times the amount needed for a |
461 // semi space. The young generation consists of two semi spaces and | 461 // semi space. The young generation consists of two semi spaces and |
462 // we reserve twice the amount needed for those in order to ensure | 462 // we reserve twice the amount needed for those in order to ensure |
463 // that new space can be aligned to its size. | 463 // that new space can be aligned to its size. |
464 intptr_t MaxReserved() { | 464 intptr_t MaxReserved() { |
465 return 4 * reserved_semispace_size_ + max_old_generation_size_; | 465 return 4 * reserved_semispace_size_ + max_old_generation_size_; |
466 } | 466 } |
467 int MaxSemiSpaceSize() { return max_semispace_size_; } | 467 int MaxSemiSpaceSize() { return max_semispace_size_; } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 | 608 |
609 // Allocates an empty code cache. | 609 // Allocates an empty code cache. |
610 MUST_USE_RESULT MaybeObject* AllocateCodeCache(); | 610 MUST_USE_RESULT MaybeObject* AllocateCodeCache(); |
611 | 611 |
612 // Allocates a serialized scope info. | 612 // Allocates a serialized scope info. |
613 MUST_USE_RESULT MaybeObject* AllocateScopeInfo(int length); | 613 MUST_USE_RESULT MaybeObject* AllocateScopeInfo(int length); |
614 | 614 |
615 // Allocates an empty PolymorphicCodeCache. | 615 // Allocates an empty PolymorphicCodeCache. |
616 MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache(); | 616 MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache(); |
617 | 617 |
| 618 // Allocates a pre-tenured empty AccessorPair. |
| 619 MUST_USE_RESULT MaybeObject* AllocateAccessorPair(); |
| 620 |
618 // Clear the Instanceof cache (used when a prototype changes). | 621 // Clear the Instanceof cache (used when a prototype changes). |
619 inline void ClearInstanceofCache(); | 622 inline void ClearInstanceofCache(); |
620 | 623 |
621 // Allocates and fully initializes a String. There are two String | 624 // Allocates and fully initializes a String. There are two String |
622 // encodings: ASCII and two byte. One should choose between the three string | 625 // encodings: ASCII and two byte. One should choose between the three string |
623 // allocation functions based on the encoding of the string buffer used to | 626 // allocation functions based on the encoding of the string buffer used to |
624 // initialized the string. | 627 // initialized the string. |
625 // - ...FromAscii initializes the string from a buffer that is ASCII | 628 // - ...FromAscii initializes the string from a buffer that is ASCII |
626 // encoded (it does not check that the buffer is ASCII encoded) and the | 629 // encoded (it does not check that the buffer is ASCII encoded) and the |
627 // result will be ASCII encoded. | 630 // result will be ASCII encoded. |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 // Checks whether an address/object in a space. | 1132 // Checks whether an address/object in a space. |
1130 // Currently used by tests, serialization and heap verification only. | 1133 // Currently used by tests, serialization and heap verification only. |
1131 bool InSpace(Address addr, AllocationSpace space); | 1134 bool InSpace(Address addr, AllocationSpace space); |
1132 bool InSpace(HeapObject* value, AllocationSpace space); | 1135 bool InSpace(HeapObject* value, AllocationSpace space); |
1133 | 1136 |
1134 // Finds out which space an object should get promoted to based on its type. | 1137 // Finds out which space an object should get promoted to based on its type. |
1135 inline OldSpace* TargetSpace(HeapObject* object); | 1138 inline OldSpace* TargetSpace(HeapObject* object); |
1136 inline AllocationSpace TargetSpaceId(InstanceType type); | 1139 inline AllocationSpace TargetSpaceId(InstanceType type); |
1137 | 1140 |
1138 // Sets the stub_cache_ (only used when expanding the dictionary). | 1141 // Sets the stub_cache_ (only used when expanding the dictionary). |
1139 void public_set_code_stubs(NumberDictionary* value) { | 1142 void public_set_code_stubs(UnseededNumberDictionary* value) { |
1140 roots_[kCodeStubsRootIndex] = value; | 1143 roots_[kCodeStubsRootIndex] = value; |
1141 } | 1144 } |
1142 | 1145 |
1143 // Support for computing object sizes for old objects during GCs. Returns | 1146 // Support for computing object sizes for old objects during GCs. Returns |
1144 // a function that is guaranteed to be safe for computing object sizes in | 1147 // a function that is guaranteed to be safe for computing object sizes in |
1145 // the current GC phase. | 1148 // the current GC phase. |
1146 HeapObjectCallback GcSafeSizeOfOldObjectFunction() { | 1149 HeapObjectCallback GcSafeSizeOfOldObjectFunction() { |
1147 return gc_safe_size_of_old_object_; | 1150 return gc_safe_size_of_old_object_; |
1148 } | 1151 } |
1149 | 1152 |
1150 // Sets the non_monomorphic_cache_ (only used when expanding the dictionary). | 1153 // Sets the non_monomorphic_cache_ (only used when expanding the dictionary). |
1151 void public_set_non_monomorphic_cache(NumberDictionary* value) { | 1154 void public_set_non_monomorphic_cache(UnseededNumberDictionary* value) { |
1152 roots_[kNonMonomorphicCacheRootIndex] = value; | 1155 roots_[kNonMonomorphicCacheRootIndex] = value; |
1153 } | 1156 } |
1154 | 1157 |
1155 void public_set_empty_script(Script* script) { | 1158 void public_set_empty_script(Script* script) { |
1156 roots_[kEmptyScriptRootIndex] = script; | 1159 roots_[kEmptyScriptRootIndex] = script; |
1157 } | 1160 } |
1158 | 1161 |
1159 void public_set_store_buffer_top(Address* top) { | 1162 void public_set_store_buffer_top(Address* top) { |
1160 roots_[kStoreBufferTopRootIndex] = reinterpret_cast<Smi*>(top); | 1163 roots_[kStoreBufferTopRootIndex] = reinterpret_cast<Smi*>(top); |
1161 } | 1164 } |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 | 1405 |
1403 | 1406 |
1404 void UpdateNewSpaceReferencesInExternalStringTable( | 1407 void UpdateNewSpaceReferencesInExternalStringTable( |
1405 ExternalStringTableUpdaterCallback updater_func); | 1408 ExternalStringTableUpdaterCallback updater_func); |
1406 | 1409 |
1407 void UpdateReferencesInExternalStringTable( | 1410 void UpdateReferencesInExternalStringTable( |
1408 ExternalStringTableUpdaterCallback updater_func); | 1411 ExternalStringTableUpdaterCallback updater_func); |
1409 | 1412 |
1410 void ProcessWeakReferences(WeakObjectRetainer* retainer); | 1413 void ProcessWeakReferences(WeakObjectRetainer* retainer); |
1411 | 1414 |
| 1415 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); |
| 1416 |
1412 // Helper function that governs the promotion policy from new space to | 1417 // Helper function that governs the promotion policy from new space to |
1413 // old. If the object's old address lies below the new space's age | 1418 // old. If the object's old address lies below the new space's age |
1414 // mark or if we've already filled the bottom 1/16th of the to space, | 1419 // mark or if we've already filled the bottom 1/16th of the to space, |
1415 // we try to promote this object. | 1420 // we try to promote this object. |
1416 inline bool ShouldBePromoted(Address old_address, int object_size); | 1421 inline bool ShouldBePromoted(Address old_address, int object_size); |
1417 | 1422 |
1418 int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } | 1423 int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } |
1419 | 1424 |
1420 void ClearJSFunctionResultCaches(); | 1425 void ClearJSFunctionResultCaches(); |
1421 | 1426 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 // around a GC). | 1504 // around a GC). |
1500 inline void CompletelyClearInstanceofCache(); | 1505 inline void CompletelyClearInstanceofCache(); |
1501 | 1506 |
1502 // The roots that have an index less than this are always in old space. | 1507 // The roots that have an index less than this are always in old space. |
1503 static const int kOldSpaceRoots = 0x20; | 1508 static const int kOldSpaceRoots = 0x20; |
1504 | 1509 |
1505 bool idle_notification_will_schedule_next_gc() { | 1510 bool idle_notification_will_schedule_next_gc() { |
1506 return idle_notification_will_schedule_next_gc_; | 1511 return idle_notification_will_schedule_next_gc_; |
1507 } | 1512 } |
1508 | 1513 |
1509 uint32_t StringHashSeed() { | 1514 uint32_t HashSeed() { |
1510 uint32_t seed = static_cast<uint32_t>(string_hash_seed()->value()); | 1515 uint32_t seed = static_cast<uint32_t>(hash_seed()->value()); |
1511 ASSERT(FLAG_randomize_string_hashes || seed == 0); | 1516 ASSERT(FLAG_randomize_hashes || seed == 0); |
1512 return seed; | 1517 return seed; |
1513 } | 1518 } |
1514 | 1519 |
1515 private: | 1520 private: |
1516 Heap(); | 1521 Heap(); |
1517 | 1522 |
1518 // This can be calculated directly from a pointer to the heap; however, it is | 1523 // This can be calculated directly from a pointer to the heap; however, it is |
1519 // more expedient to get at the isolate directly from within Heap methods. | 1524 // more expedient to get at the isolate directly from within Heap methods. |
1520 Isolate* isolate_; | 1525 Isolate* isolate_; |
1521 | 1526 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 unsigned int gc_count_at_last_idle_gc_; | 1909 unsigned int gc_count_at_last_idle_gc_; |
1905 int scavenges_since_last_idle_round_; | 1910 int scavenges_since_last_idle_round_; |
1906 | 1911 |
1907 static const int kMaxMarkSweepsInIdleRound = 7; | 1912 static const int kMaxMarkSweepsInIdleRound = 7; |
1908 static const int kIdleScavengeThreshold = 5; | 1913 static const int kIdleScavengeThreshold = 5; |
1909 | 1914 |
1910 // Shared state read by the scavenge collector and set by ScavengeObject. | 1915 // Shared state read by the scavenge collector and set by ScavengeObject. |
1911 PromotionQueue promotion_queue_; | 1916 PromotionQueue promotion_queue_; |
1912 | 1917 |
1913 // Flag is set when the heap has been configured. The heap can be repeatedly | 1918 // Flag is set when the heap has been configured. The heap can be repeatedly |
1914 // configured through the API until it is setup. | 1919 // configured through the API until it is set up. |
1915 bool configured_; | 1920 bool configured_; |
1916 | 1921 |
1917 ExternalStringTable external_string_table_; | 1922 ExternalStringTable external_string_table_; |
1918 | 1923 |
1919 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; | 1924 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; |
1920 | 1925 |
1921 MemoryChunk* chunks_queued_for_free_; | 1926 MemoryChunk* chunks_queued_for_free_; |
1922 | 1927 |
1923 friend class Factory; | 1928 friend class Factory; |
1924 friend class GCTracer; | 1929 friend class GCTracer; |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2610 | 2615 |
2611 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2616 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2612 }; | 2617 }; |
2613 #endif // DEBUG || LIVE_OBJECT_LIST | 2618 #endif // DEBUG || LIVE_OBJECT_LIST |
2614 | 2619 |
2615 } } // namespace v8::internal | 2620 } } // namespace v8::internal |
2616 | 2621 |
2617 #undef HEAP | 2622 #undef HEAP |
2618 | 2623 |
2619 #endif // V8_HEAP_H_ | 2624 #endif // V8_HEAP_H_ |
OLD | NEW |