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

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, 9 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 SetExternalAllocationSize(intptr_t size, Heap* heap) {
Ivan Posva 2014/03/06 21:59:33 SetExternalSize() to match the field.
koda 2014/03/06 22:55:07 Done.
+ ASSERT(size >= 0);
+ external_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_size_, raw());
+ }
+
+ // Called when the referent becomes unreachable.
+ void UpdateUnreachable(Heap* heap) {
+ heap->FreeExternal(external_size_, raw());
+ Finalize(this);
+ }
+
+ // Called when the referent has moved, potentially between generations.
+ void UpdateRelocated(RawObject* raw_before, Heap* heap) {
+ heap->FreeExternal(external_size_, raw_before);
+ heap->AllocateExternal(external_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_size_(0),
+ 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_size_ = 0;
callback_ = NULL;
}
RawObject* raw_;
void* peer_;
+ intptr_t external_size_;
siva 2014/03/06 17:17:39 Not for this CL but just a thought: Now that we ha
koda 2014/03/06 22:55:07 Sounds like a good idea. It would simplify the cod
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;
}

Powered by Google App Engine
This is Rietveld 408576698