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

Unified Diff: src/isolate.cc

Issue 2676513008: [wasm] Managed<T> ensures T's lifetime does not leak past Isolate's (Closed)
Patch Set: moved cctest Created 3 years, 10 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
« src/isolate.h ('K') | « src/isolate.h ('k') | src/managed.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 38a26be1e29a70450d6d08460fbe0e7473b25244..7cd688a5ca436b8f1cf5730f24e16f565207d627 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -2030,6 +2030,46 @@ Isolate::ThreadDataTable::~ThreadDataTable() {
// DCHECK_NULL(list_);
}
+void Isolate::ReleaseManagedLifelines() {
+ for (Isolate::ManagedLifeline* current = managed_lifelines_root_.next_;
+ current != nullptr;) {
bradnelson 2017/02/16 23:59:20 The for loop vs while obscures this slightly, mayb
+ Isolate::ManagedLifeline* next = current->next_;
+ current->Dispose();
+ delete current;
+ current = next;
+ }
+}
+
+Isolate::ManagedLifeline* Isolate::RegisterForReleaseAtTeardown(
+ void* value, Isolate::ManagedLifeline::Deleter deleter) {
+ DCHECK_NOT_NULL(value);
+ DCHECK_NOT_NULL(deleter);
+
+ Isolate::ManagedLifeline* ret = new Isolate::ManagedLifeline();
+ ret->value_ = value;
+ ret->deleter_ = deleter;
+ // Insert at head. We keep the head alive for the lifetime of the Isolate
+ // because otherwise we can't reset the head, should we delete it before
+ // the isolate expires
+ Isolate::ManagedLifeline* next = managed_lifelines_root_.next_;
+ managed_lifelines_root_.next_ = ret;
+ ret->prev_ = &managed_lifelines_root_;
+ ret->next_ = next;
+ if (next != nullptr) next->prev_ = ret;
+ return ret;
+}
+
+void Isolate::UnregisterFromReleaseAtTeardown(
+ Isolate::ManagedLifeline** lifeline_ptr) {
+ DCHECK_NOT_NULL(lifeline_ptr);
+ Isolate::ManagedLifeline* lifeline = *lifeline_ptr;
+ DCHECK_NOT_NULL(lifeline->prev_);
+
+ lifeline->prev_->next_ = lifeline->next_;
+ if (lifeline->next_ != nullptr) lifeline->next_->prev_ = lifeline->prev_;
+ delete lifeline;
+ *lifeline_ptr = nullptr;
+}
Isolate::PerIsolateThreadData::~PerIsolateThreadData() {
#if defined(USE_SIMULATOR)
@@ -2399,6 +2439,7 @@ void Isolate::Deinit() {
root_index_map_ = NULL;
ClearSerializerData();
+ ReleaseManagedLifelines();
}
« src/isolate.h ('K') | « src/isolate.h ('k') | src/managed.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698