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

Unified Diff: runtime/vm/dart_api_state.h

Issue 187113003: Track external allocated memory for weak persistent handles. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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
Index: runtime/vm/dart_api_state.h
===================================================================
--- runtime/vm/dart_api_state.h (revision 33235)
+++ runtime/vm/dart_api_state.h (working copy)
@@ -8,6 +8,7 @@
#include "include/dart_api.h"
#include "platform/thread.h"
+#include "platform/utils.h"
#include "vm/dart_api_impl.h"
#include "vm/flags.h"
#include "vm/growable_array.h"
@@ -198,6 +199,26 @@
callback_ = callback;
}
+ void InitializeExternalAllocationSize(intptr_t size, Heap* heap) {
Ivan Posva 2014/03/05 21:21:23 Somehow this name does not feel right. As it is ca
koda 2014/03/05 21:52:08 Done.
+ ASSERT(size >= 0);
+ external_allocation_size_ = Utils::RoundUp(size, kObjectAlignment);
+ // TODO(koda): On repeated/large external allocations for existing objects,
+ // without any intervening normal allocation, GC will not trigger.
+ heap->AllocateExternal(external_allocation_size_, raw());
+ }
+
+ // Called when the referent becomes unreachable.
+ void UpdateUnreachable(Heap* heap) {
+ heap->FreeExternal(external_allocation_size_, raw());
+ Finalize(this);
+ }
+
+ // Called when the referent has moved, potentially between generations.
+ void UpdateRelocated(RawObject* raw_before, Heap* heap) {
+ heap->FreeExternal(external_allocation_size_, raw_before);
+ heap->AllocateExternal(external_allocation_size_, raw());
+ }
+
static void Finalize(FinalizablePersistentHandle* handle) {
Dart_WeakPersistentHandleFinalizer callback = handle->callback();
if (callback != NULL) {
@@ -212,7 +233,11 @@
private:
friend class FinalizablePersistentHandles;
- FinalizablePersistentHandle() : raw_(NULL), peer_(NULL), callback_(NULL) { }
+ FinalizablePersistentHandle()
+ : raw_(NULL),
+ peer_(NULL),
+ external_allocation_size_(0),
Ivan Posva 2014/03/05 21:21:23 How about just external_size?
koda 2014/03/05 21:52:08 Done.
+ callback_(NULL) { }
~FinalizablePersistentHandle() { }
// Overload the raw_ field as a next pointer when adding freed
@@ -232,11 +257,13 @@
void Clear() {
raw_ = Object::null();
peer_ = NULL;
+ external_allocation_size_ = 0;
callback_ = NULL;
}
RawObject* raw_;
void* peer_;
+ intptr_t external_allocation_size_;
Dart_WeakPersistentHandleFinalizer callback_;
DISALLOW_ALLOCATION(); // Allocated through AllocateHandle methods.
DISALLOW_COPY_AND_ASSIGN(FinalizablePersistentHandle);
@@ -438,7 +465,7 @@
handle = reinterpret_cast<FinalizablePersistentHandle*>(
AllocateScopedHandle());
}
- handle->set_callback(NULL);
+ handle->Clear();
return handle;
}
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/gc_marker.cc » ('j') | runtime/vm/heap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698