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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_DART_API_STATE_H_ 5 #ifndef VM_DART_API_STATE_H_
6 #define VM_DART_API_STATE_H_ 6 #define VM_DART_API_STATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "platform/thread.h" 10 #include "platform/thread.h"
11 #include "platform/utils.h"
11 #include "vm/dart_api_impl.h" 12 #include "vm/dart_api_impl.h"
12 #include "vm/flags.h" 13 #include "vm/flags.h"
13 #include "vm/growable_array.h" 14 #include "vm/growable_array.h"
14 #include "vm/handles.h" 15 #include "vm/handles.h"
15 #include "vm/object.h" 16 #include "vm/object.h"
16 #include "vm/os.h" 17 #include "vm/os.h"
17 #include "vm/raw_object.h" 18 #include "vm/raw_object.h"
18 #include "vm/visitor.h" 19 #include "vm/visitor.h"
19 20
20 #include "vm/handles_impl.h" 21 #include "vm/handles_impl.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 static intptr_t raw_offset() { 192 static intptr_t raw_offset() {
192 return OFFSET_OF(FinalizablePersistentHandle, raw_); 193 return OFFSET_OF(FinalizablePersistentHandle, raw_);
193 } 194 }
194 void* peer() const { return peer_; } 195 void* peer() const { return peer_; }
195 void set_peer(void* peer) { peer_ = peer; } 196 void set_peer(void* peer) { peer_ = peer; }
196 Dart_WeakPersistentHandleFinalizer callback() const { return callback_; } 197 Dart_WeakPersistentHandleFinalizer callback() const { return callback_; }
197 void set_callback(Dart_WeakPersistentHandleFinalizer callback) { 198 void set_callback(Dart_WeakPersistentHandleFinalizer callback) {
198 callback_ = callback; 199 callback_ = callback;
199 } 200 }
200 201
202 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.
203 ASSERT(size >= 0);
204 external_size_ = Utils::RoundUp(size, kObjectAlignment);
205 // TODO(koda): On repeated/large external allocations for existing objects,
206 // without any intervening normal allocation, GC will not trigger.
207 heap->AllocateExternal(external_size_, raw());
208 }
209
210 // Called when the referent becomes unreachable.
211 void UpdateUnreachable(Heap* heap) {
212 heap->FreeExternal(external_size_, raw());
213 Finalize(this);
214 }
215
216 // Called when the referent has moved, potentially between generations.
217 void UpdateRelocated(RawObject* raw_before, Heap* heap) {
218 heap->FreeExternal(external_size_, raw_before);
219 heap->AllocateExternal(external_size_, raw());
220 }
221
201 static void Finalize(FinalizablePersistentHandle* handle) { 222 static void Finalize(FinalizablePersistentHandle* handle) {
202 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); 223 Dart_WeakPersistentHandleFinalizer callback = handle->callback();
203 if (callback != NULL) { 224 if (callback != NULL) {
204 void* peer = handle->peer(); 225 void* peer = handle->peer();
205 handle->Clear(); 226 handle->Clear();
206 (*callback)(reinterpret_cast<Dart_WeakPersistentHandle>(handle), peer); 227 (*callback)(reinterpret_cast<Dart_WeakPersistentHandle>(handle), peer);
207 } else { 228 } else {
208 handle->Clear(); 229 handle->Clear();
209 } 230 }
210 } 231 }
211 232
212 private: 233 private:
213 friend class FinalizablePersistentHandles; 234 friend class FinalizablePersistentHandles;
214 235
215 FinalizablePersistentHandle() : raw_(NULL), peer_(NULL), callback_(NULL) { } 236 FinalizablePersistentHandle()
237 : raw_(NULL),
238 peer_(NULL),
239 external_size_(0),
240 callback_(NULL) { }
216 ~FinalizablePersistentHandle() { } 241 ~FinalizablePersistentHandle() { }
217 242
218 // Overload the raw_ field as a next pointer when adding freed 243 // Overload the raw_ field as a next pointer when adding freed
219 // handles to the free list. 244 // handles to the free list.
220 FinalizablePersistentHandle* Next() { 245 FinalizablePersistentHandle* Next() {
221 return reinterpret_cast<FinalizablePersistentHandle*>(raw_); 246 return reinterpret_cast<FinalizablePersistentHandle*>(raw_);
222 } 247 }
223 void SetNext(FinalizablePersistentHandle* free_list) { 248 void SetNext(FinalizablePersistentHandle* free_list) {
224 raw_ = reinterpret_cast<RawObject*>(free_list); 249 raw_ = reinterpret_cast<RawObject*>(free_list);
225 ASSERT(!raw_->IsHeapObject()); 250 ASSERT(!raw_->IsHeapObject());
226 } 251 }
227 void FreeHandle(FinalizablePersistentHandle* free_list) { 252 void FreeHandle(FinalizablePersistentHandle* free_list) {
228 Clear(); 253 Clear();
229 SetNext(free_list); 254 SetNext(free_list);
230 } 255 }
231 256
232 void Clear() { 257 void Clear() {
233 raw_ = Object::null(); 258 raw_ = Object::null();
234 peer_ = NULL; 259 peer_ = NULL;
260 external_size_ = 0;
235 callback_ = NULL; 261 callback_ = NULL;
236 } 262 }
237 263
238 RawObject* raw_; 264 RawObject* raw_;
239 void* peer_; 265 void* peer_;
266 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
240 Dart_WeakPersistentHandleFinalizer callback_; 267 Dart_WeakPersistentHandleFinalizer callback_;
241 DISALLOW_ALLOCATION(); // Allocated through AllocateHandle methods. 268 DISALLOW_ALLOCATION(); // Allocated through AllocateHandle methods.
242 DISALLOW_COPY_AND_ASSIGN(FinalizablePersistentHandle); 269 DISALLOW_COPY_AND_ASSIGN(FinalizablePersistentHandle);
243 }; 270 };
244 271
245 272
246 // Local handles repository structure. 273 // Local handles repository structure.
247 static const int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize; 274 static const int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize;
248 static const int kLocalHandlesPerChunk = 64; 275 static const int kLocalHandlesPerChunk = 64;
249 static const int kOffsetOfRawPtrInLocalHandle = 0; 276 static const int kOffsetOfRawPtrInLocalHandle = 0;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // by calling FreeHandle. 458 // by calling FreeHandle.
432 FinalizablePersistentHandle* AllocateHandle() { 459 FinalizablePersistentHandle* AllocateHandle() {
433 FinalizablePersistentHandle* handle; 460 FinalizablePersistentHandle* handle;
434 if (free_list_ != NULL) { 461 if (free_list_ != NULL) {
435 handle = free_list_; 462 handle = free_list_;
436 free_list_ = handle->Next(); 463 free_list_ = handle->Next();
437 } else { 464 } else {
438 handle = reinterpret_cast<FinalizablePersistentHandle*>( 465 handle = reinterpret_cast<FinalizablePersistentHandle*>(
439 AllocateScopedHandle()); 466 AllocateScopedHandle());
440 } 467 }
441 handle->set_callback(NULL); 468 handle->Clear();
442 return handle; 469 return handle;
443 } 470 }
444 471
445 void FreeHandle(FinalizablePersistentHandle* handle) { 472 void FreeHandle(FinalizablePersistentHandle* handle) {
446 handle->FreeHandle(free_list()); 473 handle->FreeHandle(free_list());
447 set_free_list(handle); 474 set_free_list(handle);
448 } 475 }
449 476
450 // Validate if passed in handle is a Persistent Handle. 477 // Validate if passed in handle is a Persistent Handle.
451 bool IsValidHandle(Dart_WeakPersistentHandle object) const { 478 bool IsValidHandle(Dart_WeakPersistentHandle object) const {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 ApiNativeScope::Current()->zone()) {} 809 ApiNativeScope::Current()->zone()) {}
783 ApiGrowableArray() 810 ApiGrowableArray()
784 : BaseGrowableArray<T, ValueObject>( 811 : BaseGrowableArray<T, ValueObject>(
785 ApiNativeScope::Current()->zone()) {} 812 ApiNativeScope::Current()->zone()) {}
786 }; 813 };
787 814
788 815
789 } // namespace dart 816 } // namespace dart
790 817
791 #endif // VM_DART_API_STATE_H_ 818 #endif // VM_DART_API_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698