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

Unified Diff: src/isolate.h

Issue 2676513008: [wasm] Managed<T> ensures T's lifetime does not leak past Isolate's (Closed)
Patch Set: renamed to ManagedObjectFinalizer, and using "finalizer"` 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
« no previous file with comments | « BUILD.gn ('k') | src/isolate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index ec52183cdf9c6ce009782ca847edafc218da96da..444d99feb8ce0205affb1214edd19bd39521021f 100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -533,6 +533,8 @@ class Isolate {
// for legacy API reasons.
void TearDown();
+ void ReleaseManagedObjects();
+
static void GlobalTearDown();
void ClearSerializerData();
@@ -1208,6 +1210,39 @@ class Isolate {
void set_allow_atomics_wait(bool set) { allow_atomics_wait_ = set; }
bool allow_atomics_wait() { return allow_atomics_wait_; }
+ // List of native heap values allocated by the runtime as part of its
+ // implementation that must be freed at isolate deinit.
+ class ManagedObjectFinalizer final {
+ public:
+ typedef void (*Deleter)(void*);
+ void Dispose() { deleter_(value_); }
+
+ private:
+ friend class Isolate;
+
+ ManagedObjectFinalizer() {
+ DCHECK_EQ(reinterpret_cast<void*>(this),
+ reinterpret_cast<void*>(&value_));
+ }
+
+ // value_ must be the first member
+ void* value_ = nullptr;
+ Deleter deleter_ = nullptr;
+ ManagedObjectFinalizer* prev_ = nullptr;
+ ManagedObjectFinalizer* next_ = nullptr;
+ };
+
+ // Register a native value for destruction at isolate teardown.
+ ManagedObjectFinalizer* RegisterForReleaseAtTeardown(
+ void* value, ManagedObjectFinalizer::Deleter deleter);
+
+ // Unregister a previously registered value from release at
+ // isolate teardown, deleting the ManagedObjectFinalizer.
+ // This transfers the responsibility of the previously managed value's
+ // deletion to the caller. Pass by pointer, because *finalizer_ptr gets
+ // reset to nullptr.
+ void UnregisterFromReleaseAtTeardown(ManagedObjectFinalizer** finalizer_ptr);
+
protected:
explicit Isolate(bool enable_serializer);
bool IsArrayOrObjectPrototype(Object* object);
@@ -1489,6 +1524,8 @@ class Isolate {
bool allow_atomics_wait_;
+ ManagedObjectFinalizer managed_object_finalizers_list_;
+
size_t total_regexp_code_generated_;
friend class ExecutionAccess;
« no previous file with comments | « BUILD.gn ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698