OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_HEAP_H_ | 5 #ifndef V8_HEAP_HEAP_H_ |
6 #define V8_HEAP_HEAP_H_ | 6 #define V8_HEAP_HEAP_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 // Clients of this interface shouldn't depend on lots of heap internals. | 11 // Clients of this interface shouldn't depend on lots of heap internals. |
12 // Do not include anything from src/heap here! | 12 // Do not include anything from src/heap here! |
13 #include "include/v8.h" | 13 #include "include/v8.h" |
14 #include "src/allocation.h" | 14 #include "src/allocation.h" |
15 #include "src/assert-scope.h" | 15 #include "src/assert-scope.h" |
16 #include "src/base/atomic-utils.h" | 16 #include "src/base/atomic-utils.h" |
17 #include "src/globals.h" | 17 #include "src/globals.h" |
18 #include "src/heap-symbols.h" | 18 #include "src/heap-symbols.h" |
19 // TODO(mstarzinger): One more include to kill! | |
20 #include "src/heap/spaces.h" | |
21 #include "src/list.h" | 19 #include "src/list.h" |
| 20 #include "src/objects.h" |
22 | 21 |
23 namespace v8 { | 22 namespace v8 { |
24 namespace internal { | 23 namespace internal { |
25 | 24 |
26 using v8::MemoryPressureLevel; | 25 using v8::MemoryPressureLevel; |
27 | 26 |
28 // Defines all the roots in Heap. | 27 // Defines all the roots in Heap. |
29 #define STRONG_ROOT_LIST(V) \ | 28 #define STRONG_ROOT_LIST(V) \ |
30 /* Cluster the most popular ones in a few cache lines here at the top. */ \ | 29 /* Cluster the most popular ones in a few cache lines here at the top. */ \ |
31 /* The first 32 entries are most often used in the startup snapshot and */ \ | 30 /* The first 32 entries are most often used in the startup snapshot and */ \ |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 class GCIdleTimeAction; | 318 class GCIdleTimeAction; |
320 class GCIdleTimeHandler; | 319 class GCIdleTimeHandler; |
321 class GCIdleTimeHeapState; | 320 class GCIdleTimeHeapState; |
322 class GCTracer; | 321 class GCTracer; |
323 class HeapObjectsFilter; | 322 class HeapObjectsFilter; |
324 class HeapStats; | 323 class HeapStats; |
325 class HistogramTimer; | 324 class HistogramTimer; |
326 class Isolate; | 325 class Isolate; |
327 class MemoryAllocator; | 326 class MemoryAllocator; |
328 class MemoryReducer; | 327 class MemoryReducer; |
| 328 class ObjectIterator; |
329 class ObjectStats; | 329 class ObjectStats; |
| 330 class Page; |
330 class PagedSpace; | 331 class PagedSpace; |
331 class Scavenger; | 332 class Scavenger; |
332 class ScavengeJob; | 333 class ScavengeJob; |
333 class Space; | 334 class Space; |
334 class StoreBuffer; | 335 class StoreBuffer; |
335 class WeakObjectRetainer; | 336 class WeakObjectRetainer; |
336 | 337 |
337 typedef void (*ObjectSlotCallback)(HeapObject** from, HeapObject* to); | 338 typedef void (*ObjectSlotCallback)(HeapObject** from, HeapObject* to); |
338 | 339 |
339 enum PromotionMode { PROMOTE_MARKED, DEFAULT_PROMOTION }; | 340 enum PromotionMode { PROMOTE_MARKED, DEFAULT_PROMOTION }; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 struct Entry* front_; | 395 struct Entry* front_; |
395 struct Entry* rear_; | 396 struct Entry* rear_; |
396 struct Entry* limit_; | 397 struct Entry* limit_; |
397 | 398 |
398 List<Entry>* emergency_stack_; | 399 List<Entry>* emergency_stack_; |
399 Heap* heap_; | 400 Heap* heap_; |
400 | 401 |
401 DISALLOW_COPY_AND_ASSIGN(PromotionQueue); | 402 DISALLOW_COPY_AND_ASSIGN(PromotionQueue); |
402 }; | 403 }; |
403 | 404 |
| 405 class AllocationResult { |
| 406 public: |
| 407 // Implicit constructor from Object*. |
| 408 AllocationResult(Object* object) // NOLINT |
| 409 : object_(object) { |
| 410 // AllocationResults can't return Smis, which are used to represent |
| 411 // failure and the space to retry in. |
| 412 CHECK(!object->IsSmi()); |
| 413 } |
| 414 |
| 415 AllocationResult() : object_(Smi::FromInt(NEW_SPACE)) {} |
| 416 |
| 417 static inline AllocationResult Retry(AllocationSpace space = NEW_SPACE) { |
| 418 return AllocationResult(space); |
| 419 } |
| 420 |
| 421 inline bool IsRetry() { return object_->IsSmi(); } |
| 422 |
| 423 template <typename T> |
| 424 bool To(T** obj) { |
| 425 if (IsRetry()) return false; |
| 426 *obj = T::cast(object_); |
| 427 return true; |
| 428 } |
| 429 |
| 430 Object* ToObjectChecked() { |
| 431 CHECK(!IsRetry()); |
| 432 return object_; |
| 433 } |
| 434 |
| 435 inline AllocationSpace RetrySpace(); |
| 436 |
| 437 private: |
| 438 explicit AllocationResult(AllocationSpace space) |
| 439 : object_(Smi::FromInt(static_cast<int>(space))) {} |
| 440 |
| 441 Object* object_; |
| 442 }; |
| 443 |
| 444 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); |
| 445 |
404 class Heap { | 446 class Heap { |
405 public: | 447 public: |
406 // Declare all the root indices. This defines the root list order. | 448 // Declare all the root indices. This defines the root list order. |
407 enum RootListIndex { | 449 enum RootListIndex { |
408 #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, | 450 #define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, |
409 STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION) | 451 STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION) |
410 #undef ROOT_INDEX_DECLARATION | 452 #undef ROOT_INDEX_DECLARATION |
411 | 453 |
412 #define STRING_INDEX_DECLARATION(name, str) k##name##RootIndex, | 454 #define STRING_INDEX_DECLARATION(name, str) k##name##RootIndex, |
413 INTERNALIZED_STRING_LIST(STRING_INDEX_DECLARATION) | 455 INTERNALIZED_STRING_LIST(STRING_INDEX_DECLARATION) |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 external_memory_concurrently_freed_.Increment(freed); | 820 external_memory_concurrently_freed_.Increment(freed); |
779 } | 821 } |
780 | 822 |
781 void account_external_memory_concurrently_freed() { | 823 void account_external_memory_concurrently_freed() { |
782 external_memory_ -= external_memory_concurrently_freed_.Value(); | 824 external_memory_ -= external_memory_concurrently_freed_.Value(); |
783 external_memory_concurrently_freed_.SetValue(0); | 825 external_memory_concurrently_freed_.SetValue(0); |
784 } | 826 } |
785 | 827 |
786 void DeoptMarkedAllocationSites(); | 828 void DeoptMarkedAllocationSites(); |
787 | 829 |
788 bool DeoptMaybeTenuredAllocationSites() { | 830 inline bool DeoptMaybeTenuredAllocationSites(); |
789 return new_space_.IsAtMaximumCapacity() && maximum_size_scavenges_ == 0; | |
790 } | |
791 | 831 |
792 void AddWeakNewSpaceObjectToCodeDependency(Handle<HeapObject> obj, | 832 void AddWeakNewSpaceObjectToCodeDependency(Handle<HeapObject> obj, |
793 Handle<WeakCell> code); | 833 Handle<WeakCell> code); |
794 | 834 |
795 void AddWeakObjectToCodeDependency(Handle<HeapObject> obj, | 835 void AddWeakObjectToCodeDependency(Handle<HeapObject> obj, |
796 Handle<DependentCode> dep); | 836 Handle<DependentCode> dep); |
797 | 837 |
798 DependentCode* LookupWeakObjectToCodeDependency(Handle<HeapObject> obj); | 838 DependentCode* LookupWeakObjectToCodeDependency(Handle<HeapObject> obj); |
799 | 839 |
800 void CompactWeakFixedArrays(); | 840 void CompactWeakFixedArrays(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 // Destroys all memory allocated by the heap. | 894 // Destroys all memory allocated by the heap. |
855 void TearDown(); | 895 void TearDown(); |
856 | 896 |
857 // Returns whether SetUp has been called. | 897 // Returns whether SetUp has been called. |
858 bool HasBeenSetUp(); | 898 bool HasBeenSetUp(); |
859 | 899 |
860 // =========================================================================== | 900 // =========================================================================== |
861 // Getters for spaces. ======================================================= | 901 // Getters for spaces. ======================================================= |
862 // =========================================================================== | 902 // =========================================================================== |
863 | 903 |
864 Address NewSpaceTop() { return new_space_.top(); } | 904 inline Address NewSpaceTop(); |
865 | 905 |
866 NewSpace* new_space() { return &new_space_; } | 906 NewSpace* new_space() { return new_space_; } |
867 OldSpace* old_space() { return old_space_; } | 907 OldSpace* old_space() { return old_space_; } |
868 OldSpace* code_space() { return code_space_; } | 908 OldSpace* code_space() { return code_space_; } |
869 MapSpace* map_space() { return map_space_; } | 909 MapSpace* map_space() { return map_space_; } |
870 LargeObjectSpace* lo_space() { return lo_space_; } | 910 LargeObjectSpace* lo_space() { return lo_space_; } |
871 | 911 |
872 inline PagedSpace* paged_space(int idx); | 912 inline PagedSpace* paged_space(int idx); |
873 inline Space* space(int idx); | 913 inline Space* space(int idx); |
874 | 914 |
875 // Returns name of the space. | 915 // Returns name of the space. |
876 const char* GetSpaceName(int idx); | 916 const char* GetSpaceName(int idx); |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 // For keeping track of context disposals. | 2034 // For keeping track of context disposals. |
1995 int contexts_disposed_; | 2035 int contexts_disposed_; |
1996 | 2036 |
1997 // The length of the retained_maps array at the time of context disposal. | 2037 // The length of the retained_maps array at the time of context disposal. |
1998 // This separates maps in the retained_maps array that were created before | 2038 // This separates maps in the retained_maps array that were created before |
1999 // and after context disposal. | 2039 // and after context disposal. |
2000 int number_of_disposed_maps_; | 2040 int number_of_disposed_maps_; |
2001 | 2041 |
2002 int global_ic_age_; | 2042 int global_ic_age_; |
2003 | 2043 |
2004 NewSpace new_space_; | 2044 NewSpace* new_space_; |
2005 OldSpace* old_space_; | 2045 OldSpace* old_space_; |
2006 OldSpace* code_space_; | 2046 OldSpace* code_space_; |
2007 MapSpace* map_space_; | 2047 MapSpace* map_space_; |
2008 LargeObjectSpace* lo_space_; | 2048 LargeObjectSpace* lo_space_; |
2009 HeapState gc_state_; | 2049 HeapState gc_state_; |
2010 int gc_post_processing_depth_; | 2050 int gc_post_processing_depth_; |
2011 Address new_space_top_after_last_gc_; | 2051 Address new_space_top_after_last_gc_; |
2012 | 2052 |
2013 // Returns the amount of external memory registered since last global gc. | 2053 // Returns the amount of external memory registered since last global gc. |
2014 int64_t PromotedExternalMemorySize(); | 2054 int64_t PromotedExternalMemorySize(); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2519 friend class LargeObjectSpace; | 2559 friend class LargeObjectSpace; |
2520 friend class NewSpace; | 2560 friend class NewSpace; |
2521 friend class PagedSpace; | 2561 friend class PagedSpace; |
2522 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); | 2562 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); |
2523 }; | 2563 }; |
2524 | 2564 |
2525 } // namespace internal | 2565 } // namespace internal |
2526 } // namespace v8 | 2566 } // namespace v8 |
2527 | 2567 |
2528 #endif // V8_HEAP_HEAP_H_ | 2568 #endif // V8_HEAP_HEAP_H_ |
OLD | NEW |