| OLD | NEW |
| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 }; | 520 }; |
| 521 | 521 |
| 522 | 522 |
| 523 // Implementation of the API State used in dart api for maintaining | 523 // Implementation of the API State used in dart api for maintaining |
| 524 // local scopes, persistent handles etc. These are setup on a per isolate | 524 // local scopes, persistent handles etc. These are setup on a per isolate |
| 525 // basis and destroyed when the isolate is shutdown. | 525 // basis and destroyed when the isolate is shutdown. |
| 526 class ApiState { | 526 class ApiState { |
| 527 public: | 527 public: |
| 528 ApiState() : top_scope_(NULL), delayed_weak_reference_sets_(NULL), | 528 ApiState() : top_scope_(NULL), delayed_weak_reference_sets_(NULL), |
| 529 null_(NULL), true_(NULL), false_(NULL), | 529 null_(NULL), true_(NULL), false_(NULL), |
| 530 callback_error_(NULL) {} | 530 acquired_error_(NULL) {} |
| 531 ~ApiState() { | 531 ~ApiState() { |
| 532 while (top_scope_ != NULL) { | 532 while (top_scope_ != NULL) { |
| 533 ApiLocalScope* scope = top_scope_; | 533 ApiLocalScope* scope = top_scope_; |
| 534 top_scope_ = top_scope_->previous(); | 534 top_scope_ = top_scope_->previous(); |
| 535 delete scope; | 535 delete scope; |
| 536 } | 536 } |
| 537 if (null_ != NULL) { | 537 if (null_ != NULL) { |
| 538 persistent_handles().FreeHandle(null_); | 538 persistent_handles().FreeHandle(null_); |
| 539 null_ = NULL; | 539 null_ = NULL; |
| 540 } | 540 } |
| 541 if (true_ != NULL) { | 541 if (true_ != NULL) { |
| 542 persistent_handles().FreeHandle(true_); | 542 persistent_handles().FreeHandle(true_); |
| 543 true_ = NULL; | 543 true_ = NULL; |
| 544 } | 544 } |
| 545 if (false_ != NULL) { | 545 if (false_ != NULL) { |
| 546 persistent_handles().FreeHandle(false_); | 546 persistent_handles().FreeHandle(false_); |
| 547 false_ = NULL; | 547 false_ = NULL; |
| 548 } | 548 } |
| 549 if (acquired_error_ != NULL) { |
| 550 persistent_handles().FreeHandle(acquired_error_); |
| 551 acquired_error_ = NULL; |
| 552 } |
| 549 } | 553 } |
| 550 | 554 |
| 551 // Accessors. | 555 // Accessors. |
| 552 ApiLocalScope* top_scope() const { return top_scope_; } | 556 ApiLocalScope* top_scope() const { return top_scope_; } |
| 553 void set_top_scope(ApiLocalScope* value) { top_scope_ = value; } | 557 void set_top_scope(ApiLocalScope* value) { top_scope_ = value; } |
| 554 | 558 |
| 555 PersistentHandles& persistent_handles() { return persistent_handles_; } | 559 PersistentHandles& persistent_handles() { return persistent_handles_; } |
| 556 | 560 |
| 557 FinalizablePersistentHandles& weak_persistent_handles() { | 561 FinalizablePersistentHandles& weak_persistent_handles() { |
| 558 return weak_persistent_handles_; | 562 return weak_persistent_handles_; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 int total = 0; | 648 int total = 0; |
| 645 ApiLocalScope* scope = top_scope_; | 649 ApiLocalScope* scope = top_scope_; |
| 646 while (scope != NULL) { | 650 while (scope != NULL) { |
| 647 total += scope->zone()->SizeInBytes(); | 651 total += scope->zone()->SizeInBytes(); |
| 648 scope = scope->previous(); | 652 scope = scope->previous(); |
| 649 } | 653 } |
| 650 return total; | 654 return total; |
| 651 } | 655 } |
| 652 PersistentHandle* Null() { | 656 PersistentHandle* Null() { |
| 653 if (null_ == NULL) { | 657 if (null_ == NULL) { |
| 654 DARTSCOPE(Isolate::Current()); | |
| 655 | |
| 656 Object& null_object = Object::Handle(); | |
| 657 null_ = persistent_handles().AllocateHandle(); | 658 null_ = persistent_handles().AllocateHandle(); |
| 658 null_->set_raw(null_object); | 659 null_->set_raw(Object::null()); |
| 659 } | 660 } |
| 660 return null_; | 661 return null_; |
| 661 } | 662 } |
| 662 PersistentHandle* True() { | 663 PersistentHandle* True() { |
| 663 if (true_ == NULL) { | 664 if (true_ == NULL) { |
| 664 DARTSCOPE(Isolate::Current()); | |
| 665 | |
| 666 true_ = persistent_handles().AllocateHandle(); | 665 true_ = persistent_handles().AllocateHandle(); |
| 667 true_->set_raw(Bool::True()); | 666 true_->set_raw(Bool::True()); |
| 668 } | 667 } |
| 669 return true_; | 668 return true_; |
| 670 } | 669 } |
| 671 PersistentHandle* False() { | 670 PersistentHandle* False() { |
| 672 if (false_ == NULL) { | 671 if (false_ == NULL) { |
| 673 DARTSCOPE(Isolate::Current()); | |
| 674 | |
| 675 false_ = persistent_handles().AllocateHandle(); | 672 false_ = persistent_handles().AllocateHandle(); |
| 676 false_->set_raw(Bool::False()); | 673 false_->set_raw(Bool::False()); |
| 677 } | 674 } |
| 678 return false_; | 675 return false_; |
| 679 } | 676 } |
| 680 | 677 |
| 681 void SetupCallbackError() { | 678 void SetupAcquiredError() { |
| 682 ASSERT(callback_error_ == NULL); | 679 ASSERT(acquired_error_ == NULL); |
| 683 callback_error_ = persistent_handles().AllocateHandle(); | 680 acquired_error_ = persistent_handles().AllocateHandle(); |
| 684 callback_error_->set_raw( | 681 acquired_error_->set_raw( |
| 685 String::New("Internal Dart data pointers have been acquired, " | 682 String::New("Internal Dart data pointers have been acquired, " |
| 686 "please release them using Dart_ByteArrayReleaseData.")); | 683 "please release them using Dart_TypedDataReleaseData.")); |
| 687 } | 684 } |
| 688 | 685 |
| 689 PersistentHandle* CallbackError() const { | 686 PersistentHandle* AcquiredError() const { |
| 690 ASSERT(callback_error_ != NULL); | 687 ASSERT(acquired_error_ != NULL); |
| 691 return callback_error_; | 688 return acquired_error_; |
| 692 } | 689 } |
| 693 | 690 |
| 694 void DelayWeakReferenceSet(WeakReferenceSet* reference_set) { | 691 void DelayWeakReferenceSet(WeakReferenceSet* reference_set) { |
| 695 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_); | 692 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_); |
| 696 } | 693 } |
| 697 | 694 |
| 698 private: | 695 private: |
| 699 PersistentHandles persistent_handles_; | 696 PersistentHandles persistent_handles_; |
| 700 FinalizablePersistentHandles weak_persistent_handles_; | 697 FinalizablePersistentHandles weak_persistent_handles_; |
| 701 FinalizablePersistentHandles prologue_weak_persistent_handles_; | 698 FinalizablePersistentHandles prologue_weak_persistent_handles_; |
| 702 ApiLocalScope* top_scope_; | 699 ApiLocalScope* top_scope_; |
| 703 WeakReferenceSet* delayed_weak_reference_sets_; | 700 WeakReferenceSet* delayed_weak_reference_sets_; |
| 704 | 701 |
| 705 // Persistent handles to important objects. | 702 // Persistent handles to important objects. |
| 706 PersistentHandle* null_; | 703 PersistentHandle* null_; |
| 707 PersistentHandle* true_; | 704 PersistentHandle* true_; |
| 708 PersistentHandle* false_; | 705 PersistentHandle* false_; |
| 709 PersistentHandle* callback_error_; | 706 PersistentHandle* acquired_error_; |
| 710 | 707 |
| 711 DISALLOW_COPY_AND_ASSIGN(ApiState); | 708 DISALLOW_COPY_AND_ASSIGN(ApiState); |
| 712 }; | 709 }; |
| 713 | 710 |
| 714 | 711 |
| 715 class ApiNativeScope { | 712 class ApiNativeScope { |
| 716 public: | 713 public: |
| 717 ApiNativeScope() { | 714 ApiNativeScope() { |
| 718 // Currently no support for nesting native scopes. | 715 // Currently no support for nesting native scopes. |
| 719 ASSERT(Current() == NULL); | 716 ASSERT(Current() == NULL); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 ApiNativeScope::Current()->zone()) {} | 748 ApiNativeScope::Current()->zone()) {} |
| 752 ApiGrowableArray() | 749 ApiGrowableArray() |
| 753 : BaseGrowableArray<T, ValueObject>( | 750 : BaseGrowableArray<T, ValueObject>( |
| 754 ApiNativeScope::Current()->zone()) {} | 751 ApiNativeScope::Current()->zone()) {} |
| 755 }; | 752 }; |
| 756 | 753 |
| 757 | 754 |
| 758 } // namespace dart | 755 } // namespace dart |
| 759 | 756 |
| 760 #endif // VM_DART_API_STATE_H_ | 757 #endif // VM_DART_API_STATE_H_ |
| OLD | NEW |