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

Side by Side Diff: runtime/vm/dart_api_state.h

Issue 15772005: - Add different types for persistent and weak persistent handles (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 Dart_WeakPersistentHandleFinalizer callback() const { return callback_; } 180 Dart_WeakPersistentHandleFinalizer callback() const { return callback_; }
181 void set_callback(Dart_WeakPersistentHandleFinalizer callback) { 181 void set_callback(Dart_WeakPersistentHandleFinalizer callback) {
182 callback_ = callback; 182 callback_ = callback;
183 } 183 }
184 184
185 static void Finalize(FinalizablePersistentHandle* handle) { 185 static void Finalize(FinalizablePersistentHandle* handle) {
186 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); 186 Dart_WeakPersistentHandleFinalizer callback = handle->callback();
187 if (callback != NULL) { 187 if (callback != NULL) {
188 void* peer = handle->peer(); 188 void* peer = handle->peer();
189 handle->Clear(); 189 handle->Clear();
190 (*callback)(reinterpret_cast<Dart_Handle>(handle), peer); 190 (*callback)(reinterpret_cast<Dart_WeakPersistentHandle>(handle), peer);
191 } else { 191 } else {
192 handle->Clear(); 192 handle->Clear();
193 } 193 }
194 } 194 }
195 195
196 private: 196 private:
197 friend class FinalizablePersistentHandles; 197 friend class FinalizablePersistentHandles;
198 198
199 FinalizablePersistentHandle() : raw_(NULL), peer_(NULL), callback_(NULL) { } 199 FinalizablePersistentHandle() : raw_(NULL), peer_(NULL), callback_(NULL) { }
200 ~FinalizablePersistentHandle() { } 200 ~FinalizablePersistentHandle() { }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 handle->set_raw(NULL); 344 handle->set_raw(NULL);
345 return handle; 345 return handle;
346 } 346 }
347 347
348 void FreeHandle(PersistentHandle* handle) { 348 void FreeHandle(PersistentHandle* handle) {
349 handle->FreeHandle(free_list()); 349 handle->FreeHandle(free_list());
350 set_free_list(handle); 350 set_free_list(handle);
351 } 351 }
352 352
353 // Validate if passed in handle is a Persistent Handle. 353 // Validate if passed in handle is a Persistent Handle.
354 bool IsValidHandle(Dart_Handle object) const { 354 bool IsValidHandle(Dart_PersistentHandle object) const {
355 return IsValidScopedHandle(reinterpret_cast<uword>(object)); 355 return IsValidScopedHandle(reinterpret_cast<uword>(object));
356 } 356 }
357 357
358 // Returns a count of active handles (used for testing purposes). 358 // Returns a count of active handles (used for testing purposes).
359 int CountHandles() const { 359 int CountHandles() const {
360 return CountScopedHandles(); 360 return CountScopedHandles();
361 } 361 }
362 362
363 private: 363 private:
364 PersistentHandle* free_list_; 364 PersistentHandle* free_list_;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 handle->set_callback(NULL); 418 handle->set_callback(NULL);
419 return handle; 419 return handle;
420 } 420 }
421 421
422 void FreeHandle(FinalizablePersistentHandle* handle) { 422 void FreeHandle(FinalizablePersistentHandle* handle) {
423 handle->FreeHandle(free_list()); 423 handle->FreeHandle(free_list());
424 set_free_list(handle); 424 set_free_list(handle);
425 } 425 }
426 426
427 // Validate if passed in handle is a Persistent Handle. 427 // Validate if passed in handle is a Persistent Handle.
428 bool IsValidHandle(Dart_Handle object) const { 428 bool IsValidHandle(Dart_WeakPersistentHandle object) const {
429 return IsValidScopedHandle(reinterpret_cast<uword>(object)); 429 return IsValidScopedHandle(reinterpret_cast<uword>(object));
430 } 430 }
431 431
432 // Returns a count of active handles (used for testing purposes). 432 // Returns a count of active handles (used for testing purposes).
433 int CountHandles() const { 433 int CountHandles() const {
434 return CountScopedHandles(); 434 return CountScopedHandles();
435 } 435 }
436 436
437 private: 437 private:
438 FinalizablePersistentHandle* free_list_; 438 FinalizablePersistentHandle* free_list_;
(...skipping 10 matching lines...) Expand all
449 values_(values), num_values_(values_length) { 449 values_(values), num_values_(values_length) {
450 } 450 }
451 ~WeakReferenceSet() {} 451 ~WeakReferenceSet() {}
452 452
453 WeakReferenceSet* next() const { return next_; } 453 WeakReferenceSet* next() const { return next_; }
454 454
455 intptr_t num_keys() const { return num_keys_; } 455 intptr_t num_keys() const { return num_keys_; }
456 RawObject** get_key(intptr_t i) { 456 RawObject** get_key(intptr_t i) {
457 ASSERT(i >= 0); 457 ASSERT(i >= 0);
458 ASSERT(i < num_keys_); 458 ASSERT(i < num_keys_);
459 return (reinterpret_cast<PersistentHandle*>(keys_[i]))->raw_addr(); 459 return (reinterpret_cast<FinalizablePersistentHandle*>(keys_[i]))->raw_addr( );
460 } 460 }
461 461
462 intptr_t num_values() const { return num_values_; } 462 intptr_t num_values() const { return num_values_; }
463 RawObject** get_value(intptr_t i) { 463 RawObject** get_value(intptr_t i) {
464 ASSERT(i >= 0); 464 ASSERT(i >= 0);
465 ASSERT(i < num_values_); 465 ASSERT(i < num_values_);
466 return (reinterpret_cast<PersistentHandle*>(values_[i]))->raw_addr(); 466 return (reinterpret_cast<FinalizablePersistentHandle*>(values_[i]))->raw_add r();
467 } 467 }
468 468
469 static WeakReferenceSet* Pop(WeakReferenceSet** queue) { 469 static WeakReferenceSet* Pop(WeakReferenceSet** queue) {
470 ASSERT(queue != NULL); 470 ASSERT(queue != NULL);
471 WeakReferenceSet* head = *queue; 471 WeakReferenceSet* head = *queue;
472 if (head != NULL) { 472 if (head != NULL) {
473 *queue = head->next(); 473 *queue = head->next();
474 head->next_ = NULL; 474 head->next_ = NULL;
475 } 475 }
476 return head; 476 return head;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 ApiLocalScope* scope = top_scope_; 610 ApiLocalScope* scope = top_scope_;
611 while (scope != NULL) { 611 while (scope != NULL) {
612 if (scope->local_handles()->IsValidHandle(object)) { 612 if (scope->local_handles()->IsValidHandle(object)) {
613 return true; 613 return true;
614 } 614 }
615 scope = scope->previous(); 615 scope = scope->previous();
616 } 616 }
617 return false; 617 return false;
618 } 618 }
619 619
620 bool IsValidPersistentHandle(Dart_Handle object) const { 620 bool IsValidPersistentHandle(Dart_PersistentHandle object) const {
621 return persistent_handles_.IsValidHandle(object); 621 return persistent_handles_.IsValidHandle(object);
622 } 622 }
623 623
624 bool IsValidWeakPersistentHandle(Dart_Handle object) const { 624 bool IsValidWeakPersistentHandle(Dart_WeakPersistentHandle object) const {
625 return weak_persistent_handles_.IsValidHandle(object); 625 return weak_persistent_handles_.IsValidHandle(object);
626 } 626 }
627 627
628 bool IsValidPrologueWeakPersistentHandle(Dart_Handle object) const { 628 bool IsValidPrologueWeakPersistentHandle(Dart_WeakPersistentHandle object) con st {
629 return prologue_weak_persistent_handles_.IsValidHandle(object); 629 return prologue_weak_persistent_handles_.IsValidHandle(object);
630 } 630 }
631 631
632 bool IsProtectedHandle(PersistentHandle* object) const { 632 bool IsProtectedHandle(PersistentHandle* object) const {
633 if (object == NULL) return false; 633 if (object == NULL) return false;
634 return object == null_ || object == true_ || object == false_; 634 return object == null_ || object == true_ || object == false_;
635 } 635 }
636 636
637 int CountLocalHandles() const { 637 int CountLocalHandles() const {
638 int total = 0; 638 int total = 0;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 ApiNativeScope::Current()->zone()) {} 749 ApiNativeScope::Current()->zone()) {}
750 ApiGrowableArray() 750 ApiGrowableArray()
751 : BaseGrowableArray<T, ValueObject>( 751 : BaseGrowableArray<T, ValueObject>(
752 ApiNativeScope::Current()->zone()) {} 752 ApiNativeScope::Current()->zone()) {}
753 }; 753 };
754 754
755 755
756 } // namespace dart 756 } // namespace dart
757 757
758 #endif // VM_DART_API_STATE_H_ 758 #endif // VM_DART_API_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698