Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: runtime/vm/dart_api_state.cc

Issue 2012973002: Background finalization. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_state.h ('k') | runtime/vm/gc_marker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_state.cc
diff --git a/runtime/vm/dart_api_state.cc b/runtime/vm/dart_api_state.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d959fb7089de8d6d308e44d0fbcff7599dd7782b
--- /dev/null
+++ b/runtime/vm/dart_api_state.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/dart_api_state.h"
+
+#include "platform/assert.h"
+#include "platform/utils.h"
+#include "vm/heap.h"
+#include "vm/isolate.h"
+#include "vm/lockers.h"
+#include "vm/thread.h"
+#include "vm/timeline.h"
+
+namespace dart {
+
+BackgroundFinalizer::BackgroundFinalizer(Isolate* isolate,
+ FinalizationQueue* queue) :
+ isolate_(isolate),
+ queue_(queue) {
+ MonitorLocker ml(isolate->heap()->finalization_tasks_lock());
+ isolate->heap()->set_finalization_tasks(
+ isolate->heap()->finalization_tasks() + 1);
+ ml.Notify();
+}
+
+
+void BackgroundFinalizer::Run() {
+ bool result = Thread::EnterIsolateAsHelper(isolate_,
+ Thread::kFinalizerTask,
+ true /* bypass_safepoint */);
+ ASSERT(result);
+
+ {
+ TIMELINE_FUNCTION_GC_DURATION(Thread::Current(),
+ "BackgroundFinalization");
+
+ for (intptr_t i = 0; i < queue_->length(); i++) {
+ FinalizablePersistentHandle* handle = (*queue_)[i];
+ FinalizablePersistentHandle::Finalize(isolate_, handle);
+ }
+ delete queue_;
+ }
+
+ // Exit isolate cleanly *before* notifying it, to avoid shutdown race.
+ Thread::ExitIsolateAsHelper();
+
+ {
+ Heap* heap = isolate_->heap();
+ MonitorLocker ml(heap->finalization_tasks_lock());
+ heap->set_finalization_tasks(heap->finalization_tasks() - 1);
+ ml.Notify();
+ }
+}
+
+} // namespace dart
« no previous file with comments | « runtime/vm/dart_api_state.h ('k') | runtime/vm/gc_marker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698