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 | 10 |
10 #include "src/allocation.h" | 11 #include "src/allocation.h" |
11 #include "src/assert-scope.h" | 12 #include "src/assert-scope.h" |
12 #include "src/counters.h" | 13 #include "src/counters.h" |
13 #include "src/globals.h" | 14 #include "src/globals.h" |
14 #include "src/heap/gc-idle-time-handler.h" | 15 #include "src/heap/gc-idle-time-handler.h" |
15 #include "src/heap/gc-tracer.h" | 16 #include "src/heap/gc-tracer.h" |
16 #include "src/heap/incremental-marking.h" | 17 #include "src/heap/incremental-marking.h" |
17 #include "src/heap/mark-compact.h" | 18 #include "src/heap/mark-compact.h" |
18 #include "src/heap/objects-visiting.h" | 19 #include "src/heap/objects-visiting.h" |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 | 868 |
868 // The hidden_string is special because it is the empty string, but does | 869 // The hidden_string is special because it is the empty string, but does |
869 // not match the empty string. | 870 // not match the empty string. |
870 String* hidden_string() { return hidden_string_; } | 871 String* hidden_string() { return hidden_string_; } |
871 | 872 |
872 void set_native_contexts_list(Object* object) { | 873 void set_native_contexts_list(Object* object) { |
873 native_contexts_list_ = object; | 874 native_contexts_list_ = object; |
874 } | 875 } |
875 Object* native_contexts_list() const { return native_contexts_list_; } | 876 Object* native_contexts_list() const { return native_contexts_list_; } |
876 | 877 |
877 void set_array_buffers_list(Object* object) { array_buffers_list_ = object; } | |
878 Object* array_buffers_list() const { return array_buffers_list_; } | |
879 | |
880 void set_last_array_buffer_in_list(Object* object) { | |
881 last_array_buffer_in_list_ = object; | |
882 } | |
883 Object* last_array_buffer_in_list() const { | |
884 return last_array_buffer_in_list_; | |
885 } | |
886 | |
887 void set_allocation_sites_list(Object* object) { | 878 void set_allocation_sites_list(Object* object) { |
888 allocation_sites_list_ = object; | 879 allocation_sites_list_ = object; |
889 } | 880 } |
890 Object* allocation_sites_list() { return allocation_sites_list_; } | 881 Object* allocation_sites_list() { return allocation_sites_list_; } |
891 | 882 |
892 // Used in CreateAllocationSiteStub and the (de)serializer. | 883 // Used in CreateAllocationSiteStub and the (de)serializer. |
893 Object** allocation_sites_list_address() { return &allocation_sites_list_; } | 884 Object** allocation_sites_list_address() { return &allocation_sites_list_; } |
894 | 885 |
895 void set_encountered_weak_collections(Object* weak_collection) { | 886 void set_encountered_weak_collections(Object* weak_collection) { |
896 encountered_weak_collections_ = weak_collection; | 887 encountered_weak_collections_ = weak_collection; |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1483 // trigger the event. In order to track ALL allocations one must turn off | 1474 // trigger the event. In order to track ALL allocations one must turn off |
1484 // FLAG_inline_new and FLAG_use_allocation_folding. | 1475 // FLAG_inline_new and FLAG_use_allocation_folding. |
1485 inline void OnAllocationEvent(HeapObject* object, int size_in_bytes); | 1476 inline void OnAllocationEvent(HeapObject* object, int size_in_bytes); |
1486 | 1477 |
1487 // This event is triggered after object is moved to a new place. | 1478 // This event is triggered after object is moved to a new place. |
1488 inline void OnMoveEvent(HeapObject* target, HeapObject* source, | 1479 inline void OnMoveEvent(HeapObject* target, HeapObject* source, |
1489 int size_in_bytes); | 1480 int size_in_bytes); |
1490 | 1481 |
1491 bool deserialization_complete() const { return deserialization_complete_; } | 1482 bool deserialization_complete() const { return deserialization_complete_; } |
1492 | 1483 |
1484 void RegisterLiveArrayBuffer(void* data, size_t length); | |
1485 void UnregisterArrayBuffer(void* data); | |
1486 void AddDiscoveredArrayBuffer(void* data); | |
1487 | |
1493 protected: | 1488 protected: |
1494 // Methods made available to tests. | 1489 // Methods made available to tests. |
1495 | 1490 |
1496 // Allocates a JS Map in the heap. | 1491 // Allocates a JS Map in the heap. |
1497 MUST_USE_RESULT AllocationResult | 1492 MUST_USE_RESULT AllocationResult |
1498 AllocateMap(InstanceType instance_type, int instance_size, | 1493 AllocateMap(InstanceType instance_type, int instance_size, |
1499 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND); | 1494 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND); |
1500 | 1495 |
1501 // Allocates and initializes a new JavaScript object based on a | 1496 // Allocates and initializes a new JavaScript object based on a |
1502 // constructor. | 1497 // constructor. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1535 MUST_USE_RESULT AllocationResult | 1530 MUST_USE_RESULT AllocationResult |
1536 AllocateFixedArray(int length, PretenureFlag pretenure = NOT_TENURED); | 1531 AllocateFixedArray(int length, PretenureFlag pretenure = NOT_TENURED); |
1537 | 1532 |
1538 static const int kInitialStringTableSize = 2048; | 1533 static const int kInitialStringTableSize = 2048; |
1539 static const int kInitialEvalCacheSize = 64; | 1534 static const int kInitialEvalCacheSize = 64; |
1540 static const int kInitialNumberStringCacheSize = 256; | 1535 static const int kInitialNumberStringCacheSize = 256; |
1541 | 1536 |
1542 private: | 1537 private: |
1543 Heap(); | 1538 Heap(); |
1544 | 1539 |
1540 void ReapDeadArrayBuffers(); | |
Hannes Payer (out of office)
2015/04/29 11:48:21
Can we call it FreeDeadArrayBuffers?
| |
1541 | |
1545 // The amount of external memory registered through the API kept alive | 1542 // The amount of external memory registered through the API kept alive |
1546 // by global handles | 1543 // by global handles |
1547 int64_t amount_of_external_allocated_memory_; | 1544 int64_t amount_of_external_allocated_memory_; |
1548 | 1545 |
1549 // Caches the amount of external memory registered at the last global gc. | 1546 // Caches the amount of external memory registered at the last global gc. |
1550 int64_t amount_of_external_allocated_memory_at_last_global_gc_; | 1547 int64_t amount_of_external_allocated_memory_at_last_global_gc_; |
1551 | 1548 |
1552 // This can be calculated directly from a pointer to the heap; however, it is | 1549 // This can be calculated directly from a pointer to the heap; however, it is |
1553 // more expedient to get at the isolate directly from within Heap methods. | 1550 // more expedient to get at the isolate directly from within Heap methods. |
1554 Isolate* isolate_; | 1551 Isolate* isolate_; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1653 // last GC. | 1650 // last GC. |
1654 bool old_gen_exhausted_; | 1651 bool old_gen_exhausted_; |
1655 | 1652 |
1656 // Indicates that inline bump-pointer allocation has been globally disabled | 1653 // Indicates that inline bump-pointer allocation has been globally disabled |
1657 // for all spaces. This is used to disable allocations in generated code. | 1654 // for all spaces. This is used to disable allocations in generated code. |
1658 bool inline_allocation_disabled_; | 1655 bool inline_allocation_disabled_; |
1659 | 1656 |
1660 // Weak list heads, threaded through the objects. | 1657 // Weak list heads, threaded through the objects. |
1661 // List heads are initialized lazily and contain the undefined_value at start. | 1658 // List heads are initialized lazily and contain the undefined_value at start. |
1662 Object* native_contexts_list_; | 1659 Object* native_contexts_list_; |
1663 Object* array_buffers_list_; | |
1664 Object* last_array_buffer_in_list_; | |
1665 Object* allocation_sites_list_; | 1660 Object* allocation_sites_list_; |
1666 | 1661 |
1667 // List of encountered weak collections (JSWeakMap and JSWeakSet) during | 1662 // List of encountered weak collections (JSWeakMap and JSWeakSet) during |
1668 // marking. It is initialized during marking, destroyed after marking and | 1663 // marking. It is initialized during marking, destroyed after marking and |
1669 // contains Smi(0) while marking is not active. | 1664 // contains Smi(0) while marking is not active. |
1670 Object* encountered_weak_collections_; | 1665 Object* encountered_weak_collections_; |
1671 | 1666 |
1672 Object* encountered_weak_cells_; | 1667 Object* encountered_weak_cells_; |
1673 | 1668 |
1674 StoreBufferRebuilder store_buffer_rebuilder_; | 1669 StoreBufferRebuilder store_buffer_rebuilder_; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1988 StoreBufferEvent event); | 1983 StoreBufferEvent event); |
1989 | 1984 |
1990 // Performs a major collection in the whole heap. | 1985 // Performs a major collection in the whole heap. |
1991 void MarkCompact(); | 1986 void MarkCompact(); |
1992 | 1987 |
1993 // Code to be run before and after mark-compact. | 1988 // Code to be run before and after mark-compact. |
1994 void MarkCompactPrologue(); | 1989 void MarkCompactPrologue(); |
1995 void MarkCompactEpilogue(); | 1990 void MarkCompactEpilogue(); |
1996 | 1991 |
1997 void ProcessNativeContexts(WeakObjectRetainer* retainer); | 1992 void ProcessNativeContexts(WeakObjectRetainer* retainer); |
1998 void ProcessArrayBuffers(WeakObjectRetainer* retainer, bool stop_after_young); | |
1999 void ProcessAllocationSites(WeakObjectRetainer* retainer); | 1993 void ProcessAllocationSites(WeakObjectRetainer* retainer); |
2000 | 1994 |
2001 // Deopts all code that contains allocation instruction which are tenured or | 1995 // Deopts all code that contains allocation instruction which are tenured or |
2002 // not tenured. Moreover it clears the pretenuring allocation site statistics. | 1996 // not tenured. Moreover it clears the pretenuring allocation site statistics. |
2003 void ResetAllAllocationSitesDependentCode(PretenureFlag flag); | 1997 void ResetAllAllocationSitesDependentCode(PretenureFlag flag); |
2004 | 1998 |
2005 // Evaluates local pretenuring for the old space and calls | 1999 // Evaluates local pretenuring for the old space and calls |
2006 // ResetAllTenuredAllocationSitesDependentCode if too many objects died in | 2000 // ResetAllTenuredAllocationSitesDependentCode if too many objects died in |
2007 // the old space. | 2001 // the old space. |
2008 void EvaluateOldSpaceLocalPretenuring(uint64_t size_of_objects_before_gc); | 2002 void EvaluateOldSpaceLocalPretenuring(uint64_t size_of_objects_before_gc); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2149 MemoryChunk* chunks_queued_for_free_; | 2143 MemoryChunk* chunks_queued_for_free_; |
2150 | 2144 |
2151 base::Mutex relocation_mutex_; | 2145 base::Mutex relocation_mutex_; |
2152 | 2146 |
2153 int gc_callbacks_depth_; | 2147 int gc_callbacks_depth_; |
2154 | 2148 |
2155 bool deserialization_complete_; | 2149 bool deserialization_complete_; |
2156 | 2150 |
2157 bool concurrent_sweeping_enabled_; | 2151 bool concurrent_sweeping_enabled_; |
2158 | 2152 |
2153 std::map<void*, size_t> live_array_buffers_; | |
2154 std::map<void*, size_t> not_yet_discovered_array_buffers_; | |
2155 | |
2159 friend class AlwaysAllocateScope; | 2156 friend class AlwaysAllocateScope; |
2160 friend class Deserializer; | 2157 friend class Deserializer; |
2161 friend class Factory; | 2158 friend class Factory; |
2162 friend class GCCallbacksScope; | 2159 friend class GCCallbacksScope; |
2163 friend class GCTracer; | 2160 friend class GCTracer; |
2164 friend class HeapIterator; | 2161 friend class HeapIterator; |
2165 friend class Isolate; | 2162 friend class Isolate; |
2166 friend class MarkCompactCollector; | 2163 friend class MarkCompactCollector; |
2167 friend class MarkCompactMarkingVisitor; | 2164 friend class MarkCompactMarkingVisitor; |
2168 friend class MapCompact; | 2165 friend class MapCompact; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2610 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2607 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
2611 | 2608 |
2612 private: | 2609 private: |
2613 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2610 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2614 }; | 2611 }; |
2615 #endif // DEBUG | 2612 #endif // DEBUG |
2616 } | 2613 } |
2617 } // namespace v8::internal | 2614 } // namespace v8::internal |
2618 | 2615 |
2619 #endif // V8_HEAP_HEAP_H_ | 2616 #endif // V8_HEAP_HEAP_H_ |
OLD | NEW |