Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
dart::Heap Class Reference

#include <heap.h>

Public Types

enum  Space { kNew , kOld , kCode }
 
enum  WeakSelector {
  kPeers = 0 , kIdentityHashes , kCanonicalHashes , kObjectIds ,
  kLoadingUnits , kHeapSamplingData , kNumWeakSelectors
}
 

Public Member Functions

 ~Heap ()
 
Scavengernew_space ()
 
PageSpaceold_space ()
 
uword Allocate (Thread *thread, intptr_t size, Space space)
 
bool AllocatedExternal (intptr_t size, Space space)
 
void FreedExternal (intptr_t size, Space space)
 
void PromotedExternal (intptr_t size)
 
void CheckExternalGC (Thread *thread)
 
bool Contains (uword addr) const
 
bool NewContains (uword addr) const
 
bool OldContains (uword addr) const
 
bool CodeContains (uword addr) const
 
bool DataContains (uword addr) const
 
void NotifyIdle (int64_t deadline)
 
void NotifyDestroyed ()
 
Dart_PerformanceMode mode () const
 
Dart_PerformanceMode SetMode (Dart_PerformanceMode mode)
 
void CollectGarbage (Thread *thread, GCType type, GCReason reason)
 
void CollectAllGarbage (GCReason reason=GCReason::kFull, bool compact=false)
 
void CheckCatchUp (Thread *thread)
 
void CheckConcurrentMarking (Thread *thread, GCReason reason, intptr_t size)
 
void CheckFinalizeMarking (Thread *thread)
 
void StartConcurrentMarking (Thread *thread, GCReason reason)
 
void WaitForMarkerTasks (Thread *thread)
 
void WaitForSweeperTasks (Thread *thread)
 
void WaitForSweeperTasksAtSafepoint (Thread *thread)
 
void WriteProtect (bool read_only)
 
void WriteProtectCode (bool read_only)
 
bool Verify (const char *msg, MarkExpectation mark_expectation=kForbidMarked)
 
void PrintSizes () const
 
intptr_t UsedInWords (Space space) const
 
intptr_t CapacityInWords (Space space) const
 
intptr_t ExternalInWords (Space space) const
 
intptr_t TotalUsedInWords () const
 
intptr_t TotalCapacityInWords () const
 
intptr_t TotalExternalInWords () const
 
int64_t GCTimeInMicros (Space space) const
 
intptr_t Collections (Space space) const
 
ObjectSetCreateAllocatedObjectSet (Zone *zone, MarkExpectation mark_expectation)
 
void SetPeer (ObjectPtr raw_obj, void *peer)
 
void * GetPeer (ObjectPtr raw_obj) const
 
int64_t PeerCount () const
 
intptr_t SetHashIfNotSet (ObjectPtr raw_obj, intptr_t hash)
 
intptr_t GetHash (ObjectPtr raw_obj) const
 
void SetCanonicalHash (ObjectPtr raw_obj, intptr_t hash)
 
intptr_t GetCanonicalHash (ObjectPtr raw_obj) const
 
void ResetCanonicalHashTable ()
 
void SetObjectId (ObjectPtr raw_obj, intptr_t object_id)
 
intptr_t GetObjectId (ObjectPtr raw_obj) const
 
void ResetObjectIdTable ()
 
void SetLoadingUnit (ObjectPtr raw_obj, intptr_t unit_id)
 
intptr_t GetLoadingUnit (ObjectPtr raw_obj) const
 
void SetHeapSamplingData (ObjectPtr obj, void *data)
 
intptr_t GetWeakEntry (ObjectPtr raw_obj, WeakSelector sel) const
 
void SetWeakEntry (ObjectPtr raw_obj, WeakSelector sel, intptr_t val)
 
intptr_t SetWeakEntryIfNonExistent (ObjectPtr raw_obj, WeakSelector sel, intptr_t val)
 
WeakTableGetWeakTable (Space space, WeakSelector selector) const
 
void SetWeakTable (Space space, WeakSelector selector, WeakTable *value)
 
void ForwardWeakEntries (ObjectPtr before_object, ObjectPtr after_object)
 
void ForwardWeakTables (ObjectPointerVisitor *visitor)
 
void ReportSurvivingAllocations (Dart_HeapSamplingReportCallback callback, void *context)
 
void UpdateGlobalMaxUsed ()
 
void PrintToJSONObject (Space space, JSONObject *object) const
 
void PrintMemoryUsageJSON (JSONStream *stream) const
 
void PrintMemoryUsageJSON (JSONObject *jsobj) const
 
void PrintHeapMapToJSONStream (IsolateGroup *isolate_group, JSONStream *stream)
 
intptr_t ReachabilityBarrier ()
 
IsolateGroupisolate_group () const
 
bool is_vm_isolate () const
 
void SetupImagePage (void *pointer, uword size, bool is_executable)
 
Space SpaceForExternal (intptr_t size) const
 
void CollectOnNthAllocation (intptr_t num_allocations)
 

Static Public Member Functions

static void Init (IsolateGroup *isolate_group, bool is_vm_isolate, intptr_t max_new_gen_words, intptr_t max_old_gen_words)
 
static const char * GCTypeToString (GCType type)
 
static const char * GCReasonToString (GCReason reason)
 

Static Public Attributes

static constexpr uint8_t kZapByte = 0xf3
 

Friends

class Become
 
class GCCompactor
 
class Precompiler
 
class ServiceEvent
 
class Scavenger
 
class PageSpace
 
class ProgramReloadContext
 
class ClassFinalizer
 
class HeapIterationScope
 
class GCMarker
 
class ProgramVisitor
 
class Serializer
 
class HeapTestHelper
 
class GCTestHelper
 
class GCIncrementalCompactor
 

Detailed Description

Definition at line 35 of file heap.h.

Member Enumeration Documentation

◆ Space

Enumerator
kNew 
kOld 
kCode 

Definition at line 37 of file heap.h.

37 {
38 kNew,
39 kOld,
40 kCode,
41 };
@ kCode
Definition: heap.h:40
@ kNew
Definition: heap.h:38
@ kOld
Definition: heap.h:39

◆ WeakSelector

Enumerator
kPeers 
kIdentityHashes 
kCanonicalHashes 
kObjectIds 
kLoadingUnits 
kHeapSamplingData 
kNumWeakSelectors 

Definition at line 43 of file heap.h.

43 {
44 kPeers = 0,
45#if !defined(HASH_IN_OBJECT_HEADER)
47#endif
51#if !defined(PRODUCT) || defined(FORCE_INCLUDE_SAMPLING_HEAP_PROFILER)
53#endif
55 };
@ kIdentityHashes
Definition: heap.h:46
@ kCanonicalHashes
Definition: heap.h:48
@ kHeapSamplingData
Definition: heap.h:52
@ kObjectIds
Definition: heap.h:49
@ kNumWeakSelectors
Definition: heap.h:54
@ kLoadingUnits
Definition: heap.h:50
@ kPeers
Definition: heap.h:44

Constructor & Destructor Documentation

◆ ~Heap()

dart::Heap::~Heap ( )

Definition at line 63 of file heap.cc.

63 {
64#if !defined(PRODUCT) || defined(FORCE_INCLUDE_SAMPLING_HEAP_PROFILER)
67 if (cleanup != nullptr) {
68 new_weak_tables_[kHeapSamplingData]->CleanupValues(cleanup);
69 old_weak_tables_[kHeapSamplingData]->CleanupValues(cleanup);
70 }
71#endif
72
73 for (int sel = 0; sel < kNumWeakSelectors; sel++) {
74 delete new_weak_tables_[sel];
75 delete old_weak_tables_[sel];
76 }
77}
static Dart_HeapSamplingDeleteCallback delete_callback()
Definition: sampler.h:54
void CleanupValues(Dart_HeapSamplingDeleteCallback cleanup)
Definition: weak_table.cc:156
void(* Dart_HeapSamplingDeleteCallback)(void *data)
Definition: dart_api.h:1288

Member Function Documentation

◆ Allocate()

uword dart::Heap::Allocate ( Thread thread,
intptr_t  size,
Space  space 
)
inline

Definition at line 65 of file heap.h.

65 {
66 ASSERT(!read_only_);
67 switch (space) {
68 case kNew:
69 // Do not attempt to allocate very large objects in new space.
71 return AllocateOld(thread, size, /*executable*/ false);
72 }
73 return AllocateNew(thread, size);
74 case kOld:
75 return AllocateOld(thread, size, /*executable*/ false);
76 case kCode:
77 return AllocateOld(thread, size, /*executable*/ true);
78 default:
80 }
81 return 0;
82 }
#define UNREACHABLE()
Definition: assert.h:248
#define ASSERT(E)
bool IsAllocatableInNewSpace(intptr_t size)
Definition: spaces.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ AllocatedExternal()

bool dart::Heap::AllocatedExternal ( intptr_t  size,
Space  space 
)

Definition at line 180 of file heap.cc.

180 {
181 if (space == kNew) {
182 if (!new_space_.AllocatedExternal(size)) {
183 return false;
184 }
185 } else {
186 ASSERT(space == kOld);
187 if (!old_space_.AllocatedExternal(size)) {
188 return false;
189 }
190 }
191
192 Thread* thread = Thread::Current();
193 if ((thread->no_callback_scope_depth() == 0) && !thread->force_growth()) {
194 CheckExternalGC(thread);
195 } else {
196 // Check delayed until Dart_TypedDataRelease/~ForceGrowthScope.
197 }
198 return true;
199}
void CheckExternalGC(Thread *thread)
Definition: heap.cc:215
bool AllocatedExternal(intptr_t size)
Definition: pages.h:278
bool AllocatedExternal(intptr_t size)
Definition: scavenger.h:202
static Thread * Current()
Definition: thread.h:362

◆ CapacityInWords()

intptr_t dart::Heap::CapacityInWords ( Space  space) const

Definition at line 806 of file heap.cc.

806 {
807 return space == kNew ? new_space_.CapacityInWords()
808 : old_space_.CapacityInWords();
809}
intptr_t CapacityInWords() const
Definition: pages.h:195
intptr_t CapacityInWords() const
Definition: scavenger.h:164

◆ CheckCatchUp()

void dart::Heap::CheckCatchUp ( Thread thread)

Definition at line 585 of file heap.cc.

585 {
586 ASSERT(!thread->force_growth());
587 if (old_space()->ReachedHardThreshold()) {
589 } else {
591 }
592}
void CheckConcurrentMarking(Thread *thread, GCReason reason, intptr_t size)
Definition: heap.cc:594
PageSpace * old_space()
Definition: heap.h:63
void CollectGarbage(Thread *thread, GCType type, GCReason reason)
Definition: heap.cc:558

◆ CheckConcurrentMarking()

void dart::Heap::CheckConcurrentMarking ( Thread thread,
GCReason  reason,
intptr_t  size 
)

Definition at line 594 of file heap.cc.

596 {
597 ASSERT(!thread->force_growth());
598
599 PageSpace::Phase phase;
600 {
601 MonitorLocker ml(old_space_.tasks_lock());
602 phase = old_space_.phase();
603 }
604
605 switch (phase) {
607 if (mode_ != Dart_PerformanceMode_Latency) {
609 }
610 return;
613 return; // Busy.
615 CollectOldSpaceGarbage(thread, GCType::kMarkSweep, GCReason::kFinalize);
616 return;
617 case PageSpace::kDone:
618 if (old_space_.ReachedSoftThreshold()) {
619 StartConcurrentMarking(thread, reason);
620 }
621 return;
622 default:
623 UNREACHABLE();
624 }
625}
void StartConcurrentMarking(Thread *thread, GCReason reason)
Definition: heap.cc:641
bool ReachedSoftThreshold() const
Definition: pages.h:179
void IncrementalMarkWithSizeBudget(intptr_t size)
Definition: pages.cc:905
@ kAwaitingFinalization
Definition: pages.h:133
@ kSweepingRegular
Definition: pages.h:135
@ kSweepingLarge
Definition: pages.h:134
Monitor * tasks_lock() const
Definition: pages.h:314
Phase phase() const
Definition: pages.h:341
@ Dart_PerformanceMode_Latency
Definition: dart_api.h:1380

◆ CheckExternalGC()

void dart::Heap::CheckExternalGC ( Thread thread)

Definition at line 215 of file heap.cc.

215 {
216 ASSERT(thread->no_safepoint_scope_depth() == 0);
217 ASSERT(thread->no_callback_scope_depth() == 0);
218 ASSERT(!thread->force_growth());
219
220 if (mode_ == Dart_PerformanceMode_Latency) {
221 return;
222 }
223
224 if (new_space_.ExternalInWords() >= (4 * new_space_.CapacityInWords())) {
225 // Attempt to free some external allocation by a scavenge. (If the total
226 // remains above the limit, next external alloc will trigger another.)
228 // Promotion may have pushed old space over its limit. Fall through for old
229 // space GC check.
230 }
231
232 if (old_space_.ReachedHardThreshold()) {
234 } else {
236 }
237}
bool ReachedHardThreshold() const
Definition: pages.h:176
intptr_t ExternalInWords() const
Definition: scavenger.h:168

◆ CheckFinalizeMarking()

void dart::Heap::CheckFinalizeMarking ( Thread thread)

Definition at line 627 of file heap.cc.

627 {
628 ASSERT(!thread->force_growth());
629
630 PageSpace::Phase phase;
631 {
632 MonitorLocker ml(old_space_.tasks_lock());
633 phase = old_space_.phase();
634 }
635
637 CollectOldSpaceGarbage(thread, GCType::kMarkSweep, GCReason::kFinalize);
638 }
639}

◆ CodeContains()

bool dart::Heap::CodeContains ( uword  addr) const

Definition at line 251 of file heap.cc.

251 {
252 return old_space_.CodeContains(addr);
253}
bool CodeContains(uword addr) const
Definition: pages.cc:625

◆ CollectAllGarbage()

void dart::Heap::CollectAllGarbage ( GCReason  reason = GCReason::kFull,
bool  compact = false 
)

Definition at line 573 of file heap.cc.

573 {
574 Thread* thread = Thread::Current();
575 if (thread->is_marking()) {
576 // If incremental marking is happening, we need to finish the GC cycle
577 // and perform a follow-up GC to purge any "floating garbage" that may be
578 // retained by the incremental barrier.
579 CollectOldSpaceGarbage(thread, GCType::kMarkSweep, reason);
580 }
581 CollectOldSpaceGarbage(
582 thread, compact ? GCType::kMarkCompact : GCType::kMarkSweep, reason);
583}

◆ CollectGarbage()

void dart::Heap::CollectGarbage ( Thread thread,
GCType  type,
GCReason  reason 
)

Definition at line 558 of file heap.cc.

558 {
559 switch (type) {
562 CollectNewSpaceGarbage(thread, type, reason);
563 break;
566 CollectOldSpaceGarbage(thread, type, reason);
567 break;
568 default:
569 UNREACHABLE();
570 }
571}
GLenum type

◆ Collections()

intptr_t dart::Heap::Collections ( Space  space) const

Definition at line 835 of file heap.cc.

835 {
836 if (space == kNew) {
837 return new_space_.collections();
838 }
839 return old_space_.collections();
840}
intptr_t collections() const
Definition: pages.h:263
intptr_t collections() const
Definition: scavenger.h:193

◆ CollectOnNthAllocation()

void dart::Heap::CollectOnNthAllocation ( intptr_t  num_allocations)

Definition at line 720 of file heap.cc.

720 {
721 // Prevent generated code from using the TLAB fast path on next allocation.
723 gc_on_nth_allocation_ = num_allocations;
724}
void AbandonRemainingTLABForDebugging(Thread *thread)
Definition: scavenger.cc:1850

◆ Contains()

bool dart::Heap::Contains ( uword  addr) const

Definition at line 239 of file heap.cc.

239 {
240 return new_space_.Contains(addr) || old_space_.Contains(addr);
241}
bool Contains(uword addr) const
Definition: pages.cc:607
bool Contains(uword addr) const
Definition: scavenger.h:136

◆ CreateAllocatedObjectSet()

ObjectSet * dart::Heap::CreateAllocatedObjectSet ( Zone zone,
MarkExpectation  mark_expectation 
)

Definition at line 743 of file heap.cc.

744 {
745 ObjectSet* allocated_set = new (zone) ObjectSet(zone);
746
747 this->AddRegionsToObjectSet(allocated_set);
748 Isolate* vm_isolate = Dart::vm_isolate();
749 vm_isolate->group()->heap()->AddRegionsToObjectSet(allocated_set);
750
751 {
752 VerifyObjectVisitor object_visitor(isolate_group(), allocated_set,
753 mark_expectation);
754 this->VisitObjectsNoImagePages(&object_visitor);
755 }
756 {
757 VerifyObjectVisitor object_visitor(isolate_group(), allocated_set,
759 this->VisitObjectsImagePages(&object_visitor);
760 }
761 {
762 // VM isolate heap is premarked.
763 VerifyObjectVisitor vm_object_visitor(isolate_group(), allocated_set,
765 vm_isolate->group()->heap()->VisitObjects(&vm_object_visitor);
766 }
767
768 return allocated_set;
769}
static Isolate * vm_isolate()
Definition: dart.h:68
IsolateGroup * isolate_group() const
Definition: heap.h:273
@ kRequireMarked
Definition: verifier.h:21

◆ DataContains()

bool dart::Heap::DataContains ( uword  addr) const

Definition at line 255 of file heap.cc.

255 {
256 return old_space_.DataContains(addr);
257}
bool DataContains(uword addr) const
Definition: pages.cc:634

◆ ExternalInWords()

intptr_t dart::Heap::ExternalInWords ( Space  space) const

Definition at line 811 of file heap.cc.

811 {
812 return space == kNew ? new_space_.ExternalInWords()
813 : old_space_.ExternalInWords();
814}
intptr_t ExternalInWords() const
Definition: pages.h:212

◆ ForwardWeakEntries()

void dart::Heap::ForwardWeakEntries ( ObjectPtr  before_object,
ObjectPtr  after_object 
)

Definition at line 930 of file heap.cc.

930 {
931 const auto before_space =
932 before_object->IsImmediateOrOldObject() ? Heap::kOld : Heap::kNew;
933 const auto after_space =
934 after_object->IsImmediateOrOldObject() ? Heap::kOld : Heap::kNew;
935
936 for (int sel = 0; sel < Heap::kNumWeakSelectors; sel++) {
937 const auto selector = static_cast<Heap::WeakSelector>(sel);
938 auto before_table = GetWeakTable(before_space, selector);
939 intptr_t entry = before_table->RemoveValueExclusive(before_object);
940 if (entry != 0) {
941 auto after_table = GetWeakTable(after_space, selector);
942 after_table->SetValueExclusive(after_object, entry);
943 }
944 }
945
947 [&](Isolate* isolate) {
948 auto before_table = before_object->IsImmediateOrOldObject()
949 ? isolate->forward_table_old()
950 : isolate->forward_table_new();
951 if (before_table != nullptr) {
952 intptr_t entry = before_table->RemoveValueExclusive(before_object);
953 if (entry != 0) {
954 auto after_table = after_object->IsImmediateOrOldObject()
955 ? isolate->forward_table_old()
956 : isolate->forward_table_new();
957 ASSERT(after_table != nullptr);
958 after_table->SetValueExclusive(after_object, entry);
959 }
960 }
961 },
962 /*at_safepoint=*/true);
963}
WeakSelector
Definition: heap.h:43
WeakTable * GetWeakTable(Space space, WeakSelector selector) const
Definition: heap.h:225
void ForEachIsolate(std::function< void(Isolate *isolate)> function, bool at_safepoint=false)
Definition: isolate.cc:2841
if(end==-1)

◆ ForwardWeakTables()

void dart::Heap::ForwardWeakTables ( ObjectPointerVisitor visitor)

Definition at line 965 of file heap.cc.

965 {
966 // NOTE: This method is only used by the compactor, so there is no need to
967 // process the `Heap::kNew` tables.
968 for (int sel = 0; sel < Heap::kNumWeakSelectors; sel++) {
969 WeakSelector selector = static_cast<Heap::WeakSelector>(sel);
970 GetWeakTable(Heap::kOld, selector)->Forward(visitor);
971 }
972
973 // Isolates might have forwarding tables (used for during snapshotting in
974 // isolate communication).
976 [&](Isolate* isolate) {
977 auto table_old = isolate->forward_table_old();
978 if (table_old != nullptr) table_old->Forward(visitor);
979 },
980 /*at_safepoint=*/true);
981}
void Forward(ObjectPointerVisitor *visitor)
Definition: weak_table.cc:131

◆ FreedExternal()

void dart::Heap::FreedExternal ( intptr_t  size,
Space  space 
)

Definition at line 201 of file heap.cc.

201 {
202 if (space == kNew) {
203 new_space_.FreedExternal(size);
204 } else {
205 ASSERT(space == kOld);
206 old_space_.FreedExternal(size);
207 }
208}
void FreedExternal(intptr_t size)
Definition: pages.h:293
void FreedExternal(intptr_t size)
Definition: scavenger.h:218

◆ GCReasonToString()

const char * dart::Heap::GCReasonToString ( GCReason  reason)
static

Definition at line 860 of file heap.cc.

860 {
861 switch (gc_reason) {
863 return "new space";
865 return "store buffer";
867 return "promotion";
869 return "old space";
871 return "finalize";
872 case GCReason::kFull:
873 return "full";
875 return "external";
876 case GCReason::kIdle:
877 return "idle";
879 return "destroyed";
881 return "debugging";
883 return "catch-up";
884 default:
885 UNREACHABLE();
886 return "";
887 }
888}

◆ GCTimeInMicros()

int64_t dart::Heap::GCTimeInMicros ( Space  space) const

Definition at line 828 of file heap.cc.

828 {
829 if (space == kNew) {
830 return new_space_.gc_time_micros();
831 }
832 return old_space_.gc_time_micros();
833}
int64_t gc_time_micros() const
Definition: pages.h:259
int64_t gc_time_micros() const
Definition: scavenger.h:189

◆ GCTypeToString()

const char * dart::Heap::GCTypeToString ( GCType  type)
static

Definition at line 842 of file heap.cc.

842 {
843 switch (type) {
845 return "Scavenge";
847 return "Evacuate";
849 return "StartCMark";
851 return "MarkSweep";
853 return "MarkCompact";
854 default:
855 UNREACHABLE();
856 return "";
857 }
858}

◆ GetCanonicalHash()

intptr_t dart::Heap::GetCanonicalHash ( ObjectPtr  raw_obj) const
inline

Definition at line 186 of file heap.h.

186 {
187 return GetWeakEntry(raw_obj, kCanonicalHashes);
188 }
intptr_t GetWeakEntry(ObjectPtr raw_obj, WeakSelector sel) const
Definition: heap.cc:904

◆ GetHash()

intptr_t dart::Heap::GetHash ( ObjectPtr  raw_obj) const
inline

Definition at line 178 of file heap.h.

178 {
179 return GetWeakEntry(raw_obj, kIdentityHashes);
180 }

◆ GetLoadingUnit()

intptr_t dart::Heap::GetLoadingUnit ( ObjectPtr  raw_obj) const
inline

Definition at line 207 of file heap.h.

207 {
208 ASSERT(Thread::Current()->IsDartMutatorThread());
209 return GetWeakEntry(raw_obj, kLoadingUnits);
210 }

◆ GetObjectId()

intptr_t dart::Heap::GetObjectId ( ObjectPtr  raw_obj) const
inline

Definition at line 197 of file heap.h.

197 {
198 ASSERT(Thread::Current()->IsDartMutatorThread());
199 return GetWeakEntry(raw_obj, kObjectIds);
200 }

◆ GetPeer()

void * dart::Heap::GetPeer ( ObjectPtr  raw_obj) const
inline

Definition at line 167 of file heap.h.

167 {
168 return reinterpret_cast<void*>(GetWeakEntry(raw_obj, kPeers));
169 }

◆ GetWeakEntry()

intptr_t dart::Heap::GetWeakEntry ( ObjectPtr  raw_obj,
WeakSelector  sel 
) const

Definition at line 904 of file heap.cc.

904 {
905 if (raw_obj->IsImmediateOrOldObject()) {
906 return old_weak_tables_[sel]->GetValue(raw_obj);
907 } else {
908 return new_weak_tables_[sel]->GetValue(raw_obj);
909 }
910}
intptr_t GetValue(ObjectPtr key)
Definition: weak_table.h:55

◆ GetWeakTable()

WeakTable * dart::Heap::GetWeakTable ( Space  space,
WeakSelector  selector 
) const
inline

Definition at line 225 of file heap.h.

225 {
226 if (space == kNew) {
227 return new_weak_tables_[selector];
228 }
229 ASSERT(space == kOld);
230 return old_weak_tables_[selector];
231 }

◆ Init()

void dart::Heap::Init ( IsolateGroup isolate_group,
bool  is_vm_isolate,
intptr_t  max_new_gen_words,
intptr_t  max_old_gen_words 
)
static

Definition at line 704 of file heap.cc.

707 {
708 ASSERT(isolate_group->heap() == nullptr);
709 std::unique_ptr<Heap> heap(new Heap(isolate_group, is_vm_isolate,
710 max_new_gen_words, max_old_gen_words));
711 isolate_group->set_heap(std::move(heap));
712}
bool is_vm_isolate() const
Definition: heap.h:274
Heap * heap() const
Definition: isolate.h:296

◆ is_vm_isolate()

bool dart::Heap::is_vm_isolate ( ) const
inline

Definition at line 274 of file heap.h.

274{ return is_vm_isolate_; }

◆ isolate_group()

IsolateGroup * dart::Heap::isolate_group ( ) const
inline

Definition at line 273 of file heap.h.

273{ return isolate_group_; }

◆ mode()

Dart_PerformanceMode dart::Heap::mode ( ) const
inline

Definition at line 103 of file heap.h.

103{ return mode_; }

◆ new_space()

Scavenger * dart::Heap::new_space ( )
inline

Definition at line 62 of file heap.h.

62{ return &new_space_; }

◆ NewContains()

bool dart::Heap::NewContains ( uword  addr) const

Definition at line 243 of file heap.cc.

243 {
244 return new_space_.Contains(addr);
245}

◆ NotifyDestroyed()

void dart::Heap::NotifyDestroyed ( )

Definition at line 436 of file heap.cc.

436 {
438 CollectAllGarbage(GCReason::kDestroyed, /*compact=*/true);
440}
void CollectAllGarbage(GCReason reason=GCReason::kFull, bool compact=false)
Definition: heap.cc:573
static void ClearCache()
Definition: page.cc:36
#define TIMELINE_FUNCTION_GC_DURATION(thread, name)
Definition: timeline.h:41

◆ NotifyIdle()

void dart::Heap::NotifyIdle ( int64_t  deadline)

Definition at line 375 of file heap.cc.

375 {
376 Thread* thread = Thread::Current();
377 TIMELINE_FUNCTION_GC_DURATION(thread, "NotifyIdle");
378 {
379 GcSafepointOperationScope safepoint_operation(thread);
380
381 // Check if we want to collect new-space first, because if we want to
382 // collect both new-space and old-space, the new-space collection should run
383 // first to shrink the root set (make old-space GC faster) and avoid
384 // intergenerational garbage (make old-space GC free more memory).
385 if (new_space_.ShouldPerformIdleScavenge(deadline)) {
386 CollectNewSpaceGarbage(thread, GCType::kScavenge, GCReason::kIdle);
387 }
388
389 // Check if we want to collect old-space, in decreasing order of cost.
390 // Because we use a deadline instead of a timeout, we automatically take any
391 // time used up by a scavenge into account when deciding if we can complete
392 // a mark-sweep on time.
393 if (old_space_.ShouldPerformIdleMarkCompact(deadline)) {
394 // We prefer mark-compact over other old space GCs if we have enough time,
395 // since it removes old space fragmentation and frees up most memory.
396 // Blocks for O(heap), roughly twice as costly as mark-sweep.
397 CollectOldSpaceGarbage(thread, GCType::kMarkCompact, GCReason::kIdle);
398 } else if (old_space_.ReachedHardThreshold()) {
399 // Even though the following GC may exceed our idle deadline, we need to
400 // ensure than that promotions during idle scavenges do not lead to
401 // unbounded growth of old space. If a program is allocating only in new
402 // space and all scavenges happen during idle time, then NotifyIdle will
403 // be the only place that checks the old space allocation limit.
404 // Compare the tail end of Heap::CollectNewSpaceGarbage.
405 // Blocks for O(heap).
406 CollectOldSpaceGarbage(thread, GCType::kMarkSweep, GCReason::kIdle);
407 } else if (old_space_.ShouldStartIdleMarkSweep(deadline) ||
408 old_space_.ReachedSoftThreshold()) {
409 // If we have both work to do and enough time, start or finish GC.
410 // If we have crossed the soft threshold, ignore time; the next old-space
411 // allocation will trigger this work anyway, so we try to pay at least
412 // some of that cost with idle time.
413 // Blocks for O(roots).
414 PageSpace::Phase phase;
415 {
416 MonitorLocker ml(old_space_.tasks_lock());
417 phase = old_space_.phase();
418 }
420 CollectOldSpaceGarbage(thread, GCType::kMarkSweep, GCReason::kFinalize);
421 } else if (phase == PageSpace::kDone) {
423 }
424 }
425 }
426
427 if (FLAG_mark_when_idle) {
428 old_space_.IncrementalMarkWithTimeBudget(deadline);
429 }
430
431 if (OS::GetCurrentMonotonicMicros() < deadline) {
433 }
434}
static int64_t GetCurrentMonotonicMicros()
bool ShouldStartIdleMarkSweep(int64_t deadline)
Definition: pages.cc:833
bool ShouldPerformIdleMarkCompact(int64_t deadline)
Definition: pages.cc:860
void IncrementalMarkWithTimeBudget(int64_t deadline)
Definition: pages.cc:911
bool ShouldPerformIdleScavenge(int64_t deadline)
Definition: scavenger.cc:1170

◆ old_space()

PageSpace * dart::Heap::old_space ( )
inline

Definition at line 63 of file heap.h.

63{ return &old_space_; }

◆ OldContains()

bool dart::Heap::OldContains ( uword  addr) const

Definition at line 247 of file heap.cc.

247 {
248 return old_space_.Contains(addr);
249}

◆ PeerCount()

int64_t dart::Heap::PeerCount ( ) const

Definition at line 890 of file heap.cc.

890 {
891 return new_weak_tables_[kPeers]->count() + old_weak_tables_[kPeers]->count();
892}
intptr_t count() const
Definition: weak_table.h:51

◆ PrintHeapMapToJSONStream()

void dart::Heap::PrintHeapMapToJSONStream ( IsolateGroup isolate_group,
JSONStream stream 
)
inline

Definition at line 265 of file heap.h.

266 {
268 }
void PrintHeapMapToJSONStream(IsolateGroup *isolate_group, JSONStream *stream) const
Definition: pages.cc:772

◆ PrintMemoryUsageJSON() [1/2]

void dart::Heap::PrintMemoryUsageJSON ( JSONObject jsobj) const

Definition at line 997 of file heap.cc.

997 {
998 jsobj->AddProperty("type", "MemoryUsage");
999 jsobj->AddProperty64("heapUsage", TotalUsedInWords() * kWordSize);
1000 jsobj->AddProperty64("heapCapacity", TotalCapacityInWords() * kWordSize);
1001 jsobj->AddProperty64("externalUsage", TotalExternalInWords() * kWordSize);
1002}
intptr_t TotalExternalInWords() const
Definition: heap.cc:824
intptr_t TotalCapacityInWords() const
Definition: heap.cc:820
intptr_t TotalUsedInWords() const
Definition: heap.cc:816
constexpr intptr_t kWordSize
Definition: globals.h:509

◆ PrintMemoryUsageJSON() [2/2]

void dart::Heap::PrintMemoryUsageJSON ( JSONStream stream) const

Definition at line 992 of file heap.cc.

992 {
993 JSONObject obj(stream);
995}
void PrintMemoryUsageJSON(JSONStream *stream) const
Definition: heap.cc:992

◆ PrintSizes()

void dart::Heap::PrintSizes ( ) const

Definition at line 793 of file heap.cc.

793 {
795 "New space (%" Pd "k of %" Pd
796 "k) "
797 "Old space (%" Pd "k of %" Pd "k)\n",
800}
intptr_t UsedInWords(Space space) const
Definition: heap.cc:802
intptr_t CapacityInWords(Space space) const
Definition: heap.cc:806
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
constexpr intptr_t KBInWords
Definition: globals.h:535
#define Pd
Definition: globals.h:408

◆ PrintToJSONObject()

void dart::Heap::PrintToJSONObject ( Space  space,
JSONObject object 
) const

Definition at line 984 of file heap.cc.

984 {
985 if (space == kNew) {
986 new_space_.PrintToJSONObject(object);
987 } else {
988 old_space_.PrintToJSONObject(object);
989 }
990}
void PrintToJSONObject(JSONObject *object) const
Definition: pages.cc:735
void PrintToJSONObject(JSONObject *object) const
Definition: scavenger.cc:2132

◆ PromotedExternal()

void dart::Heap::PromotedExternal ( intptr_t  size)

Definition at line 210 of file heap.cc.

210 {
211 new_space_.FreedExternal(size);
212 old_space_.AllocatedExternal(size);
213}

◆ ReachabilityBarrier()

intptr_t dart::Heap::ReachabilityBarrier ( )
inline

Definition at line 271 of file heap.h.

271{ return old_space_.collections(); }

◆ ReportSurvivingAllocations()

void dart::Heap::ReportSurvivingAllocations ( Dart_HeapSamplingReportCallback  callback,
void *  context 
)
inline

Definition at line 245 of file heap.h.

246 {
248 context);
250 context);
251 }
void ReportSurvivingAllocations(Dart_HeapSamplingReportCallback callback, void *context)
Definition: weak_table.cc:144
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ ResetCanonicalHashTable()

void dart::Heap::ResetCanonicalHashTable ( )

Definition at line 894 of file heap.cc.

894 {
895 new_weak_tables_[kCanonicalHashes]->Reset();
896 old_weak_tables_[kCanonicalHashes]->Reset();
897}

◆ ResetObjectIdTable()

void dart::Heap::ResetObjectIdTable ( )

Definition at line 899 of file heap.cc.

899 {
900 new_weak_tables_[kObjectIds]->Reset();
901 old_weak_tables_[kObjectIds]->Reset();
902}

◆ SetCanonicalHash()

void dart::Heap::SetCanonicalHash ( ObjectPtr  raw_obj,
intptr_t  hash 
)
inline

Definition at line 183 of file heap.h.

183 {
185 }
static uint32_t hash(const SkShaderBase::GradientInfo &v)
void SetWeakEntry(ObjectPtr raw_obj, WeakSelector sel, intptr_t val)
Definition: heap.cc:912

◆ SetHashIfNotSet()

intptr_t dart::Heap::SetHashIfNotSet ( ObjectPtr  raw_obj,
intptr_t  hash 
)
inline

Definition at line 175 of file heap.h.

175 {
177 }
intptr_t SetWeakEntryIfNonExistent(ObjectPtr raw_obj, WeakSelector sel, intptr_t val)
Definition: heap.cc:920

◆ SetHeapSamplingData()

void dart::Heap::SetHeapSamplingData ( ObjectPtr  obj,
void *  data 
)
inline

Definition at line 213 of file heap.h.

213 {
214 SetWeakEntry(obj, kHeapSamplingData, reinterpret_cast<intptr_t>(data));
215 }
static int8_t data[kExtLength]

◆ SetLoadingUnit()

void dart::Heap::SetLoadingUnit ( ObjectPtr  raw_obj,
intptr_t  unit_id 
)
inline

Definition at line 203 of file heap.h.

203 {
204 ASSERT(Thread::Current()->IsDartMutatorThread());
205 SetWeakEntry(raw_obj, kLoadingUnits, unit_id);
206 }

◆ SetMode()

Dart_PerformanceMode dart::Heap::SetMode ( Dart_PerformanceMode  mode)

Definition at line 442 of file heap.cc.

442 {
443 Dart_PerformanceMode old_mode = mode_.exchange(new_mode);
444 if ((old_mode == Dart_PerformanceMode_Latency) &&
445 (new_mode == Dart_PerformanceMode_Default)) {
447 }
448 return old_mode;
449}
void CheckCatchUp(Thread *thread)
Definition: heap.cc:585
T exchange(T arg, std::memory_order order=std::memory_order_relaxed)
Definition: atomic.h:48
Dart_PerformanceMode
Definition: dart_api.h:1369
@ Dart_PerformanceMode_Default
Definition: dart_api.h:1373

◆ SetObjectId()

void dart::Heap::SetObjectId ( ObjectPtr  raw_obj,
intptr_t  object_id 
)
inline

Definition at line 193 of file heap.h.

193 {
194 ASSERT(Thread::Current()->IsDartMutatorThread());
195 SetWeakEntry(raw_obj, kObjectIds, object_id);
196 }

◆ SetPeer()

void dart::Heap::SetPeer ( ObjectPtr  raw_obj,
void *  peer 
)
inline

Definition at line 164 of file heap.h.

164 {
165 SetWeakEntry(raw_obj, kPeers, reinterpret_cast<intptr_t>(peer));
166 }

◆ SetupImagePage()

void dart::Heap::SetupImagePage ( void *  pointer,
uword  size,
bool  is_executable 
)
inline

Definition at line 276 of file heap.h.

276 {
277 old_space_.SetupImagePage(pointer, size, is_executable);
278 }
void SetupImagePage(void *pointer, uword size, bool is_executable)
Definition: pages.cc:1509

◆ SetWeakEntry()

void dart::Heap::SetWeakEntry ( ObjectPtr  raw_obj,
WeakSelector  sel,
intptr_t  val 
)

Definition at line 912 of file heap.cc.

912 {
913 if (raw_obj->IsImmediateOrOldObject()) {
914 old_weak_tables_[sel]->SetValue(raw_obj, val);
915 } else {
916 new_weak_tables_[sel]->SetValue(raw_obj, val);
917 }
918}
void SetValue(ObjectPtr key, intptr_t val)
Definition: weak_table.h:60

◆ SetWeakEntryIfNonExistent()

intptr_t dart::Heap::SetWeakEntryIfNonExistent ( ObjectPtr  raw_obj,
WeakSelector  sel,
intptr_t  val 
)

Definition at line 920 of file heap.cc.

922 {
923 if (raw_obj->IsImmediateOrOldObject()) {
924 return old_weak_tables_[sel]->SetValueIfNonExistent(raw_obj, val);
925 } else {
926 return new_weak_tables_[sel]->SetValueIfNonExistent(raw_obj, val);
927 }
928}
intptr_t SetValueIfNonExistent(ObjectPtr key, intptr_t val)
Definition: weak_table.h:65

◆ SetWeakTable()

void dart::Heap::SetWeakTable ( Space  space,
WeakSelector  selector,
WeakTable value 
)
inline

Definition at line 232 of file heap.h.

232 {
233 if (space == kNew) {
234 new_weak_tables_[selector] = value;
235 } else {
236 ASSERT(space == kOld);
237 old_weak_tables_[selector] = value;
238 }
239 }
uint8_t value

◆ SpaceForExternal()

Heap::Space dart::Heap::SpaceForExternal ( intptr_t  size) const

Definition at line 1141 of file heap.cc.

1141 {
1142 // If 'size' would be a significant fraction of new space, then use old.
1143 const int kExtNewRatio = 16;
1144 if (size > (new_space_.ThresholdInWords() * kWordSize) / kExtNewRatio) {
1145 return Heap::kOld;
1146 } else {
1147 return Heap::kNew;
1148 }
1149}
intptr_t ThresholdInWords() const
Definition: scavenger.h:176

◆ StartConcurrentMarking()

void dart::Heap::StartConcurrentMarking ( Thread thread,
GCReason  reason 
)

Definition at line 641 of file heap.cc.

641 {
642 GcSafepointOperationScope safepoint_operation(thread);
643 RecordBeforeGC(GCType::kStartConcurrentMark, reason);
644 VMTagScope tagScope(thread, reason == GCReason::kIdle
645 ? VMTag::kGCIdleTagId
646 : VMTag::kGCOldSpaceTagId);
647 TIMELINE_FUNCTION_GC_DURATION(thread, "StartConcurrentMarking");
648 old_space_.CollectGarbage(thread, /*compact=*/false, /*finalize=*/false);
649 RecordAfterGC(GCType::kStartConcurrentMark);
650 PrintStats();
651#if defined(SUPPORT_TIMELINE)
652 PrintStatsToTimeline(&tbes, reason);
653#endif
654}
void CollectGarbage(Thread *thread, bool compact, bool finalize)
Definition: pages.cc:974

◆ TotalCapacityInWords()

intptr_t dart::Heap::TotalCapacityInWords ( ) const

Definition at line 820 of file heap.cc.

820 {
822}

◆ TotalExternalInWords()

intptr_t dart::Heap::TotalExternalInWords ( ) const

Definition at line 824 of file heap.cc.

824 {
826}
intptr_t ExternalInWords(Space space) const
Definition: heap.cc:811

◆ TotalUsedInWords()

intptr_t dart::Heap::TotalUsedInWords ( ) const

Definition at line 816 of file heap.cc.

816 {
817 return UsedInWords(kNew) + UsedInWords(kOld);
818}

◆ UpdateGlobalMaxUsed()

void dart::Heap::UpdateGlobalMaxUsed ( )

Definition at line 689 of file heap.cc.

689 {
690 ASSERT(isolate_group_ != nullptr);
691 // We are accessing the used in words count for both new and old space
692 // without synchronizing. The value of this metric is approximate.
693 isolate_group_->GetHeapGlobalUsedMaxMetric()->SetValue(
696}

◆ UsedInWords()

intptr_t dart::Heap::UsedInWords ( Space  space) const

Definition at line 802 of file heap.cc.

802 {
803 return space == kNew ? new_space_.UsedInWords() : old_space_.UsedInWords();
804}
intptr_t UsedInWords() const
Definition: pages.h:194
intptr_t UsedInWords() const
Definition: scavenger.h:160

◆ Verify()

bool dart::Heap::Verify ( const char *  msg,
MarkExpectation  mark_expectation = kForbidMarked 
)

Definition at line 771 of file heap.cc.

771 {
772 if (FLAG_disable_heap_verification) {
773 return true;
774 }
775 HeapIterationScope heap_iteration_scope(Thread::Current());
776 return VerifyGC(msg, mark_expectation);
777}
friend class HeapIterationScope
Definition: heap.h:384

◆ WaitForMarkerTasks()

void dart::Heap::WaitForMarkerTasks ( Thread thread)

Definition at line 656 of file heap.cc.

656 {
657 MonitorLocker ml(old_space_.tasks_lock());
658 while ((old_space_.phase() == PageSpace::kMarking) ||
659 (old_space_.phase() == PageSpace::kAwaitingFinalization)) {
660 while (old_space_.phase() == PageSpace::kMarking) {
661 ml.WaitWithSafepointCheck(thread);
662 }
663 if (old_space_.phase() == PageSpace::kAwaitingFinalization) {
664 ml.Exit();
665 CollectOldSpaceGarbage(thread, GCType::kMarkSweep, GCReason::kFinalize);
666 ml.Enter();
667 }
668 }
669}

◆ WaitForSweeperTasks()

void dart::Heap::WaitForSweeperTasks ( Thread thread)

Definition at line 671 of file heap.cc.

671 {
672 ASSERT(!thread->OwnsGCSafepoint());
673 MonitorLocker ml(old_space_.tasks_lock());
674 while ((old_space_.phase() == PageSpace::kSweepingLarge) ||
675 (old_space_.phase() == PageSpace::kSweepingRegular)) {
676 ml.WaitWithSafepointCheck(thread);
677 }
678}

◆ WaitForSweeperTasksAtSafepoint()

void dart::Heap::WaitForSweeperTasksAtSafepoint ( Thread thread)

Definition at line 680 of file heap.cc.

680 {
681 ASSERT(thread->OwnsGCSafepoint());
682 MonitorLocker ml(old_space_.tasks_lock());
683 while ((old_space_.phase() == PageSpace::kSweepingLarge) ||
684 (old_space_.phase() == PageSpace::kSweepingRegular)) {
685 ml.Wait();
686 }
687}

◆ WriteProtect()

void dart::Heap::WriteProtect ( bool  read_only)

Definition at line 698 of file heap.cc.

698 {
699 read_only_ = read_only;
700 new_space_.WriteProtect(read_only);
701 old_space_.WriteProtect(read_only);
702}
void WriteProtect(bool read_only)
Definition: pages.cc:722
void WriteProtect(bool read_only)
Definition: scavenger.cc:2126

◆ WriteProtectCode()

void dart::Heap::WriteProtectCode ( bool  read_only)
inline

Definition at line 127 of file heap.h.

127 {
128 old_space_.WriteProtectCode(read_only);
129 }
void WriteProtectCode(bool read_only)
Definition: pages.cc:812

Friends And Related Function Documentation

◆ Become

friend class Become
friend

Definition at line 376 of file heap.h.

◆ ClassFinalizer

friend class ClassFinalizer
friend

Definition at line 383 of file heap.h.

◆ GCCompactor

friend class GCCompactor
friend

Definition at line 377 of file heap.h.

◆ GCIncrementalCompactor

friend class GCIncrementalCompactor
friend

Definition at line 390 of file heap.h.

◆ GCMarker

friend class GCMarker
friend

Definition at line 385 of file heap.h.

◆ GCTestHelper

friend class GCTestHelper
friend

Definition at line 389 of file heap.h.

◆ HeapIterationScope

friend class HeapIterationScope
friend

Definition at line 384 of file heap.h.

◆ HeapTestHelper

friend class HeapTestHelper
friend

Definition at line 388 of file heap.h.

◆ PageSpace

friend class PageSpace
friend

Definition at line 381 of file heap.h.

◆ Precompiler

friend class Precompiler
friend

Definition at line 378 of file heap.h.

◆ ProgramReloadContext

friend class ProgramReloadContext
friend

Definition at line 382 of file heap.h.

◆ ProgramVisitor

friend class ProgramVisitor
friend

Definition at line 386 of file heap.h.

◆ Scavenger

friend class Scavenger
friend

Definition at line 380 of file heap.h.

◆ Serializer

friend class Serializer
friend

Definition at line 387 of file heap.h.

◆ ServiceEvent

friend class ServiceEvent
friend

Definition at line 379 of file heap.h.

Member Data Documentation

◆ kZapByte

constexpr uint8_t dart::Heap::kZapByte = 0xf3
staticconstexpr

Definition at line 58 of file heap.h.


The documentation for this class was generated from the following files: