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

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, 6 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
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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]))->
460 raw_addr();
460 } 461 }
461 462
462 intptr_t num_values() const { return num_values_; } 463 intptr_t num_values() const { return num_values_; }
463 RawObject** get_value(intptr_t i) { 464 RawObject** get_value(intptr_t i) {
464 ASSERT(i >= 0); 465 ASSERT(i >= 0);
465 ASSERT(i < num_values_); 466 ASSERT(i < num_values_);
466 return (reinterpret_cast<PersistentHandle*>(values_[i]))->raw_addr(); 467 return (reinterpret_cast<FinalizablePersistentHandle*>(values_[i]))->
468 raw_addr();
467 } 469 }
468 470
469 static WeakReferenceSet* Pop(WeakReferenceSet** queue) { 471 static WeakReferenceSet* Pop(WeakReferenceSet** queue) {
470 ASSERT(queue != NULL); 472 ASSERT(queue != NULL);
471 WeakReferenceSet* head = *queue; 473 WeakReferenceSet* head = *queue;
472 if (head != NULL) { 474 if (head != NULL) {
473 *queue = head->next(); 475 *queue = head->next();
474 head->next_ = NULL; 476 head->next_ = NULL;
475 } 477 }
476 return head; 478 return head;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 ApiLocalScope* scope = top_scope_; 612 ApiLocalScope* scope = top_scope_;
611 while (scope != NULL) { 613 while (scope != NULL) {
612 if (scope->local_handles()->IsValidHandle(object)) { 614 if (scope->local_handles()->IsValidHandle(object)) {
613 return true; 615 return true;
614 } 616 }
615 scope = scope->previous(); 617 scope = scope->previous();
616 } 618 }
617 return false; 619 return false;
618 } 620 }
619 621
620 bool IsValidPersistentHandle(Dart_Handle object) const { 622 bool IsValidPersistentHandle(Dart_PersistentHandle object) const {
621 return persistent_handles_.IsValidHandle(object); 623 return persistent_handles_.IsValidHandle(object);
622 } 624 }
623 625
624 bool IsValidWeakPersistentHandle(Dart_Handle object) const { 626 bool IsValidWeakPersistentHandle(Dart_WeakPersistentHandle object) const {
625 return weak_persistent_handles_.IsValidHandle(object); 627 return weak_persistent_handles_.IsValidHandle(object);
626 } 628 }
627 629
628 bool IsValidPrologueWeakPersistentHandle(Dart_Handle object) const { 630 bool IsValidPrologueWeakPersistentHandle(
631 Dart_WeakPersistentHandle object) const {
629 return prologue_weak_persistent_handles_.IsValidHandle(object); 632 return prologue_weak_persistent_handles_.IsValidHandle(object);
630 } 633 }
631 634
632 bool IsProtectedHandle(PersistentHandle* object) const { 635 bool IsProtectedHandle(PersistentHandle* object) const {
633 if (object == NULL) return false; 636 if (object == NULL) return false;
634 return object == null_ || object == true_ || object == false_; 637 return object == null_ || object == true_ || object == false_;
635 } 638 }
636 639
637 int CountLocalHandles() const { 640 int CountLocalHandles() const {
638 int total = 0; 641 int total = 0;
639 ApiLocalScope* scope = top_scope_; 642 ApiLocalScope* scope = top_scope_;
640 while (scope != NULL) { 643 while (scope != NULL) {
641 total += scope->local_handles()->CountHandles(); 644 total += scope->local_handles()->CountHandles();
642 scope = scope->previous(); 645 scope = scope->previous();
643 } 646 }
644 return total; 647 return total;
645 } 648 }
646 int CountPersistentHandles() const { 649 int CountPersistentHandles() const {
647 return persistent_handles_.CountHandles(); 650 return persistent_handles_.CountHandles();
648 } 651 }
649 int ZoneSizeInBytes() const { 652 int ZoneSizeInBytes() const {
650 int total = 0; 653 int total = 0;
651 ApiLocalScope* scope = top_scope_; 654 ApiLocalScope* scope = top_scope_;
652 while (scope != NULL) { 655 while (scope != NULL) {
653 total += scope->zone()->SizeInBytes(); 656 total += scope->zone()->SizeInBytes();
654 scope = scope->previous(); 657 scope = scope->previous();
655 } 658 }
656 return total; 659 return total;
657 } 660 }
658 PersistentHandle* Null() {
659 if (null_ == NULL) {
660 null_ = persistent_handles().AllocateHandle();
661 null_->set_raw(Object::null());
662 }
663 return null_;
664 }
665 PersistentHandle* True() {
666 if (true_ == NULL) {
667 true_ = persistent_handles().AllocateHandle();
668 true_->set_raw(Bool::True());
669 }
670 return true_;
671 }
672 PersistentHandle* False() {
673 if (false_ == NULL) {
674 false_ = persistent_handles().AllocateHandle();
675 false_->set_raw(Bool::False());
676 }
677 return false_;
678 }
679 661
680 void SetupAcquiredError() { 662 void SetupAcquiredError() {
681 ASSERT(acquired_error_ == NULL); 663 ASSERT(acquired_error_ == NULL);
682 acquired_error_ = persistent_handles().AllocateHandle(); 664 acquired_error_ = persistent_handles().AllocateHandle();
683 acquired_error_->set_raw( 665 acquired_error_->set_raw(
684 String::New("Internal Dart data pointers have been acquired, " 666 String::New("Internal Dart data pointers have been acquired, "
685 "please release them using Dart_TypedDataReleaseData.")); 667 "please release them using Dart_TypedDataReleaseData."));
686 } 668 }
687 669
688 PersistentHandle* AcquiredError() const { 670 PersistentHandle* AcquiredError() const {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 ApiNativeScope::Current()->zone()) {} 731 ApiNativeScope::Current()->zone()) {}
750 ApiGrowableArray() 732 ApiGrowableArray()
751 : BaseGrowableArray<T, ValueObject>( 733 : BaseGrowableArray<T, ValueObject>(
752 ApiNativeScope::Current()->zone()) {} 734 ApiNativeScope::Current()->zone()) {}
753 }; 735 };
754 736
755 737
756 } // namespace dart 738 } // namespace dart
757 739
758 #endif // VM_DART_API_STATE_H_ 740 #endif // VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698