163 {
165
167 const bool value_collected_this_gc =
168 GCVisitorType::ForwardOrSetNullIfCollected(
169 current_entry, ¤t_entry->untag()->value_);
170 if (!value_collected_this_gc && before_gc_space ==
Heap::kNew) {
173 const intptr_t
external_size = current_entry->untag()->external_size_;
175 " bytes from new to old space",
177 visitor->isolate_group()->heap()->PromotedExternal(
external_size);
178 }
179 }
180 GCVisitorType::ForwardOrSetNullIfCollected(current_entry,
181 ¤t_entry->untag()->detach_);
182 GCVisitorType::ForwardOrSetNullIfCollected(
183 current_entry, ¤t_entry->untag()->finalizer_);
184
185 ObjectPtr token_object = current_entry->untag()->token();
186
187 const bool is_detached = token_object == current_entry;
188
189 if (!value_collected_this_gc) return;
190 if (is_detached) return;
191
192 FinalizerBasePtr finalizer = current_entry->untag()->finalizer();
193
194 if (finalizer.IsRawNull()) {
196 current_entry->untag());
197
198
199 return;
200 }
201
203 current_entry->untag(), finalizer->untag());
204
205 FinalizerPtr finalizer_dart = static_cast<FinalizerPtr>(finalizer);
206
207
208
209
210
211
212
213
214
215
216
219
220 if (finalizer.IsNativeFinalizer()) {
221 NativeFinalizerPtr native_finalizer =
222 static_cast<NativeFinalizerPtr>(finalizer);
223
224
226 visitor);
227
228
229
230 }
231
232 FinalizerEntryPtr previous_head =
233 finalizer_dart->untag()->exchange_entries_collected(current_entry);
234 current_entry->untag()->set_next(previous_head);
235 const bool first_entry = previous_head.IsRawNull();
236
237
238
239
240
241 if (!first_entry && previous_head->IsNewObject() &&
242 current_entry->IsOldObject()) {
243 TRACE_FINALIZER(
"Entry %p (old) next is %p (new)", current_entry->untag(),
244 previous_head->untag());
245
246 }
247
248
249 if (first_entry) {
250 Isolate* isolate = finalizer->untag()->isolate_;
251 if (isolate == nullptr) {
252 TRACE_FINALIZER(
"Not scheduling finalizer %p callback on isolate null",
253 finalizer->untag());
254 } else {
256 finalizer->untag(), isolate);
257
258 PersistentHandle* handle =
259 isolate->group()->api_state()->AllocatePersistentHandle();
260 handle->set_ptr(finalizer);
262 message_handler->PostMessage(
264 false);
265 }
266 }
267}
static std::unique_ptr< Message > New(Args &&... args)
static Thread * Current()
#define TRACE_FINALIZER(format,...)
Heap::Space SpaceForExternal(FinalizerEntryPtr raw_entry)
void RunNativeFinalizerCallback(NativeFinalizerPtr raw_finalizer, FinalizerEntryPtr raw_entry, Heap::Space before_gc_space, GCVisitorType *visitor)
std::function< void(const T &message, const MessageReply< T > &reply)> MessageHandler