Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dart::WeakCodeReferences Class Referenceabstract

#include <weak_code.h>

Inheritance diagram for dart::WeakCodeReferences:
dart::ValueObject dart::CHACodeArray dart::FieldDependentArray

Public Member Functions

 WeakCodeReferences (const WeakArray &value)
 
virtual ~WeakCodeReferences ()
 
void Register (const Code &value)
 
virtual void UpdateArrayTo (const WeakArray &array)=0
 
virtual void ReportDeoptimization (const Code &code)=0
 
virtual void ReportSwitchingCode (const Code &code)=0
 
void DisableCode (bool are_mutators_stopped)
 
bool HasCodes () const
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Detailed Description

Definition at line 18 of file weak_code.h.

Constructor & Destructor Documentation

◆ WeakCodeReferences()

dart::WeakCodeReferences::WeakCodeReferences ( const WeakArray value)
inlineexplicit

Definition at line 20 of file weak_code.h.

20: array_(value) {}

◆ ~WeakCodeReferences()

virtual dart::WeakCodeReferences::~WeakCodeReferences ( )
inlinevirtual

Definition at line 21 of file weak_code.h.

21{}

Member Function Documentation

◆ DisableCode()

void dart::WeakCodeReferences::DisableCode ( bool  are_mutators_stopped)

Definition at line 40 of file weak_code.cc.

40 {
41#if defined(DART_PRECOMPILED_RUNTIME)
42 ASSERT(array_.IsNull());
43 return;
44#else
45 // Ensure mutators see empty code_objects only after code was deoptimized.
47 IsolateGroup::Current()->program_lock()->IsCurrentThreadWriter());
48
49 if (array_.IsNull()) {
50 return;
51 }
52
53 WeakCodeSet set(array_.ptr());
54
55 auto isolate_group = IsolateGroup::Current();
56 auto disable_code_fun = [&]() {
57 Code& code = Code::Handle();
58 isolate_group->ForEachIsolate(
59 [&](Isolate* isolate) {
60 auto mutator_thread = isolate->mutator_thread();
61 if (mutator_thread == nullptr) {
62 return;
63 }
64 DartFrameIterator iterator(
66 StackFrame* frame = iterator.NextFrame();
67 while (frame != nullptr) {
68 code = frame->LookupDartCode();
69
70 if (set.ContainsKey(code)) {
72 DeoptimizeAt(mutator_thread, code, frame);
73 }
74 frame = iterator.NextFrame();
75 }
76 },
77 /*at_safepoint=*/true);
78
79 // Switch functions that use dependent code to unoptimized code.
80 Object& owner = Object::Handle();
81 Function& function = Function::Handle();
82 WeakCodeSet::Iterator it(&set);
83 while (it.MoveNext()) {
84 code ^= set.GetKey(it.Current());
85 if (code.IsNull()) {
86 // Code was garbage collected already.
87 continue;
88 }
89 owner = code.owner();
90 if (owner.IsFunction()) {
91 function ^= owner.ptr();
92 } else if (owner.IsClass()) {
93 Class& cls = Class::Handle();
94 cls ^= owner.ptr();
95 cls.DisableAllocationStub();
96 continue;
97 } else if (owner.IsNull()) {
98 code.Print();
99 continue;
100 }
101
102 // Only optimized code can make dependencies (assumptions) about CHA /
103 // field guards and might need to be deoptimized if those assumptions no
104 // longer hold.
105 // See similar assertions when code gets registered in
106 // `Field::RegisterDependentCode` and `Class::RegisterCHACode`.
107 ASSERT(code.is_optimized());
108 ASSERT(function.unoptimized_code() != code.ptr());
109
110 // If function uses dependent code switch it to unoptimized.
111 if (function.CurrentCode() == code.ptr()) {
113 function.SwitchToUnoptimizedCode();
114 } else {
115 // Make non-OSR code non-entrant.
116 if (!code.IsDisabled()) {
118 code.DisableDartCode();
119 }
120 }
121 }
122
124 };
125
126 // Deoptimize stacks and disable code (with mutators stopped if they are not
127 // stopped yet).
128 if (are_mutators_stopped) {
129 disable_code_fun();
130 } else {
131 isolate_group->RunWithStoppedMutators(disable_code_fun);
132 }
133
134 set.Release();
135
136#endif // defined(DART_PRECOMPILED_RUNTIME)
137}
#define DEBUG_ASSERT(cond)
Definition assert.h:321
static IsolateGroup * Current()
Definition isolate.h:534
ObjectPtr ptr() const
Definition object.h:332
bool IsNull() const
Definition object.h:363
static Object & Handle()
Definition object.h:407
virtual void ReportDeoptimization(const Code &code)=0
virtual void UpdateArrayTo(const WeakArray &array)=0
virtual void ReportSwitchingCode(const Code &code)=0
#define ASSERT(E)
double frame
Definition examples.cpp:31
Dart_NativeFunction function
Definition fuchsia.cc:51
void DeoptimizeAt(Thread *mutator_thread, const Code &optimized_code, StackFrame *frame)
UnorderedHashSet< CodeTraits, WeakArrayStorageTraits > WeakCodeSet
Definition weak_code.cc:27
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition switches.h:76

◆ HasCodes()

bool dart::WeakCodeReferences::HasCodes ( ) const

Definition at line 29 of file weak_code.cc.

29 {
30 return !array_.IsNull() && (array_.Length() > 0);
31}
intptr_t Length() const
Definition object.h:6670

◆ Register()

void dart::WeakCodeReferences::Register ( const Code value)

Definition at line 33 of file weak_code.cc.

33 {
34 WeakCodeSet set(array_.IsNull() ? HashTables::New<WeakCodeSet>(4, Heap::kOld)
35 : array_.ptr());
36 set.Insert(value);
38}
@ kOld
Definition heap.h:39

◆ ReportDeoptimization()

virtual void dart::WeakCodeReferences::ReportDeoptimization ( const Code code)
pure virtual

◆ ReportSwitchingCode()

virtual void dart::WeakCodeReferences::ReportSwitchingCode ( const Code code)
pure virtual

◆ UpdateArrayTo()

virtual void dart::WeakCodeReferences::UpdateArrayTo ( const WeakArray array)
pure virtual

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