📄 heap.h.svn-base
字号:
void VisitPointers(Object** start, Object** end) { for (Object** current = start; current < end; current++) { if ((*current)->IsHeapObject()) { HeapObject* object = HeapObject::cast(*current); ASSERT(Heap::Contains(object)); ASSERT(object->map()->IsMap()); } } }};// Visitor class to verify interior pointers that have remembered set bits.// As VerifyPointersVisitor but also checks that remembered set bits are// always set for pointers into new space.class VerifyPointersAndRSetVisitor: public ObjectVisitor { public: void VisitPointers(Object** start, Object** end) { for (Object** current = start; current < end; current++) { if ((*current)->IsHeapObject()) { HeapObject* object = HeapObject::cast(*current); ASSERT(Heap::Contains(object)); ASSERT(object->map()->IsMap()); if (Heap::InNewSpace(object)) { ASSERT(Page::IsRSetSet(reinterpret_cast<Address>(current), 0)); } } } }};#endif// Space iterator for iterating over all spaces of the heap.// Returns each space in turn, and null when it is done.class AllSpaces BASE_EMBEDDED { public: Space* next(); AllSpaces() { counter_ = FIRST_SPACE; } private: int counter_;};// Space iterator for iterating over all old spaces of the heap: Old pointer// space, old data space and code space.// Returns each space in turn, and null when it is done.class OldSpaces BASE_EMBEDDED { public: OldSpace* next(); OldSpaces() { counter_ = OLD_POINTER_SPACE; } private: int counter_;};// Space iterator for iterating over all the paged spaces of the heap:// Map space, old pointer space, old data space and code space.// Returns each space in turn, and null when it is done.class PagedSpaces BASE_EMBEDDED { public: PagedSpace* next(); PagedSpaces() { counter_ = OLD_POINTER_SPACE; } private: int counter_;};// Space iterator for iterating over all spaces of the heap.// For each space an object iterator is provided. The deallocation of the// returned object iterators is handled by the space iterator.class SpaceIterator : public Malloced { public: SpaceIterator(); virtual ~SpaceIterator(); bool has_next(); ObjectIterator* next(); private: ObjectIterator* CreateIterator(); int current_space_; // from enum AllocationSpace. ObjectIterator* iterator_; // object iterator for the current space.};// A HeapIterator provides iteration over the whole heap It aggregates a the// specific iterators for the different spaces as these can only iterate over// one space only.class HeapIterator BASE_EMBEDDED { public: explicit HeapIterator(); virtual ~HeapIterator(); bool has_next(); HeapObject* next(); void reset(); private: // Perform the initialization. void Init(); // Perform all necessary shutdown (destruction) work. void Shutdown(); // Space iterator for iterating all the spaces. SpaceIterator* space_iterator_; // Object iterator for the space currently being iterated. ObjectIterator* object_iterator_;};// ----------------------------------------------------------------------------// Marking stack for tracing live objects.class MarkingStack { public: void Initialize(Address low, Address high) { top_ = low_ = reinterpret_cast<HeapObject**>(low); high_ = reinterpret_cast<HeapObject**>(high); overflowed_ = false; } bool is_full() { return top_ >= high_; } bool is_empty() { return top_ <= low_; } bool overflowed() { return overflowed_; } void clear_overflowed() { overflowed_ = false; } // Push the (marked) object on the marking stack if there is room, // otherwise mark the object as overflowed and wait for a rescan of the // heap. void Push(HeapObject* object) { CHECK(object->IsHeapObject()); if (is_full()) { object->SetOverflow(); overflowed_ = true; } else { *(top_++) = object; } } HeapObject* Pop() { ASSERT(!is_empty()); HeapObject* object = *(--top_); CHECK(object->IsHeapObject()); return object; } private: HeapObject** low_; HeapObject** top_; HeapObject** high_; bool overflowed_;};// A helper class to document/test C++ scopes where we do not// expect a GC. Usage://// /* Allocation not allowed: we cannot handle a GC in this scope. */// { AssertNoAllocation nogc;// ...// }#ifdef DEBUGclass DisallowAllocationFailure { public: DisallowAllocationFailure() { old_state_ = Heap::disallow_allocation_failure_; Heap::disallow_allocation_failure_ = true; } ~DisallowAllocationFailure() { Heap::disallow_allocation_failure_ = old_state_; } private: bool old_state_;};class AssertNoAllocation { public: AssertNoAllocation() { old_state_ = Heap::allow_allocation(false); } ~AssertNoAllocation() { Heap::allow_allocation(old_state_); } private: bool old_state_;};#else // ndef DEBUGclass AssertNoAllocation { public: AssertNoAllocation() { } ~AssertNoAllocation() { }};#endif#ifdef ENABLE_LOGGING_AND_PROFILING// The HeapProfiler writes data to the log files, which can be postprocessed// to generate .hp files for use by the GHC/Valgrind tool hp2ps.class HeapProfiler { public: // Write a single heap sample to the log file. static void WriteSample(); private: // Update the array info with stats from obj. static void CollectStats(HeapObject* obj, HistogramInfo* info);};#endif// GCTracer collects and prints ONE line after each garbage collector// invocation IFF --trace_gc is used.class GCTracer BASE_EMBEDDED { public: GCTracer(); ~GCTracer(); // Sets the collector. void set_collector(GarbageCollector collector) { collector_ = collector; } // Sets the GC count. void set_gc_count(int count) { gc_count_ = count; } // Sets the full GC count. void set_full_gc_count(int count) { full_gc_count_ = count; } // Sets the flag that this is a compacting full GC. void set_is_compacting() { is_compacting_ = true; } // Increment and decrement the count of marked objects. void increment_marked_count() { ++marked_count_; } void decrement_marked_count() { --marked_count_; } int marked_count() { return marked_count_; } private: // Returns a string matching the collector. const char* CollectorString(); // Returns size of object in heap (in MB). double SizeOfHeapObjects() { return (static_cast<double>(Heap::SizeOfObjects())) / MB; } double start_time_; // Timestamp set in the constructor. double start_size_; // Size of objects in heap set in constructor. GarbageCollector collector_; // Type of collector. // A count (including this one, eg, the first collection is 1) of the // number of garbage collections. int gc_count_; // A count (including this one) of the number of full garbage collections. int full_gc_count_; // True if the current GC is a compacting full collection, false // otherwise. bool is_compacting_; // True if the *previous* full GC cwas a compacting collection (will be // false if there has not been a previous full GC). bool previous_has_compacted_; // On a full GC, a count of the number of marked objects. Incremented // when an object is marked and decremented when an object's mark bit is // cleared. Will be zero on a scavenge collection. int marked_count_; // The count from the end of the previous full GC. Will be zero if there // was no previous full GC. int previous_marked_count_;};} } // namespace v8::internal#endif // V8_HEAP_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -