Chromium Code Reviews| 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; |
| } |