| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // If 'size' would be a significant fraction of new space, then use old. | 86 // If 'size' would be a significant fraction of new space, then use old. |
| 87 static const int kExtNewRatio = 16; | 87 static const int kExtNewRatio = 16; |
| 88 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { | 88 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { |
| 89 return Heap::kOld; | 89 return Heap::kOld; |
| 90 } else { | 90 } else { |
| 91 return Heap::kNew; | 91 return Heap::kNew; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 WeakReferenceSetBuilder* ApiState::NewWeakReferenceSetBuilder() { |
| 97 return new WeakReferenceSetBuilder(this); |
| 98 } |
| 99 |
| 100 |
| 101 void ApiState::DelayWeakReferenceSet(WeakReferenceSet* reference_set) { |
| 102 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_); |
| 103 } |
| 104 |
| 105 |
| 96 Dart_Handle Api::InitNewHandle(Isolate* isolate, RawObject* raw) { | 106 Dart_Handle Api::InitNewHandle(Isolate* isolate, RawObject* raw) { |
| 97 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); | 107 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); |
| 98 ASSERT(local_handles != NULL); | 108 ASSERT(local_handles != NULL); |
| 99 LocalHandle* ref = local_handles->AllocateHandle(); | 109 LocalHandle* ref = local_handles->AllocateHandle(); |
| 100 ref->set_raw(raw); | 110 ref->set_raw(raw); |
| 101 return reinterpret_cast<Dart_Handle>(ref); | 111 return reinterpret_cast<Dart_Handle>(ref); |
| 102 } | 112 } |
| 103 | 113 |
| 104 | 114 |
| 105 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { | 115 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 | 745 |
| 736 | 746 |
| 737 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( | 747 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( |
| 738 Dart_WeakPersistentHandle object) { | 748 Dart_WeakPersistentHandle object) { |
| 739 FinalizablePersistentHandle* weak_ref = | 749 FinalizablePersistentHandle* weak_ref = |
| 740 FinalizablePersistentHandle::Cast(object); | 750 FinalizablePersistentHandle::Cast(object); |
| 741 return weak_ref->IsPrologueWeakPersistent(); | 751 return weak_ref->IsPrologueWeakPersistent(); |
| 742 } | 752 } |
| 743 | 753 |
| 744 | 754 |
| 745 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( | 755 DART_EXPORT Dart_WeakReferenceSetBuilder Dart_NewWeakReferenceSetBuilder() { |
| 746 Dart_WeakPersistentHandle* keys, | |
| 747 intptr_t num_keys, | |
| 748 Dart_WeakPersistentHandle* values, | |
| 749 intptr_t num_values) { | |
| 750 Isolate* isolate = Isolate::Current(); | 756 Isolate* isolate = Isolate::Current(); |
| 751 CHECK_ISOLATE(isolate); | 757 CHECK_ISOLATE(isolate); |
| 752 ApiState* state = isolate->api_state(); | 758 ApiState* state = isolate->api_state(); |
| 753 ASSERT(state != NULL); | 759 ASSERT(state != NULL); |
| 754 if (keys == NULL) { | 760 return reinterpret_cast<Dart_WeakReferenceSetBuilder>( |
| 755 RETURN_NULL_ERROR(keys); | 761 state->NewWeakReferenceSetBuilder()); |
| 762 } |
| 763 |
| 764 |
| 765 DART_EXPORT Dart_WeakReferenceSet Dart_NewWeakReferenceSet( |
| 766 Dart_WeakReferenceSetBuilder set_builder, |
| 767 Dart_WeakPersistentHandle key, |
| 768 Dart_WeakPersistentHandle value) { |
| 769 ASSERT(set_builder != NULL && key != NULL); |
| 770 WeakReferenceSetBuilder* builder = |
| 771 reinterpret_cast<WeakReferenceSetBuilder*>(set_builder); |
| 772 ApiState* state = builder->api_state(); |
| 773 ASSERT(state == Isolate::Current()->api_state()); |
| 774 WeakReferenceSet* reference_set = builder->NewWeakReferenceSet(); |
| 775 reference_set->AppendKey(key); |
| 776 if (value != NULL) { |
| 777 reference_set->AppendValue(value); |
| 756 } | 778 } |
| 757 if (num_keys <= 0) { | 779 state->DelayWeakReferenceSet(reference_set); |
| 758 return Api::NewError( | 780 return reinterpret_cast<Dart_WeakReferenceSet>(reference_set); |
| 759 "%s expects argument 'num_keys' to be greater than 0.", | 781 } |
| 760 CURRENT_FUNC); | |
| 761 } | |
| 762 if (values == NULL) { | |
| 763 RETURN_NULL_ERROR(values); | |
| 764 } | |
| 765 if (num_values <= 0) { | |
| 766 return Api::NewError( | |
| 767 "%s expects argument 'num_values' to be greater than 0.", | |
| 768 CURRENT_FUNC); | |
| 769 } | |
| 770 | 782 |
| 771 WeakReferenceSet* reference_set = new WeakReferenceSet(keys, num_keys, | 783 |
| 772 values, num_values); | 784 DART_EXPORT Dart_Handle Dart_AppendToWeakReferenceSet( |
| 773 state->DelayWeakReferenceSet(reference_set); | 785 Dart_WeakReferenceSet reference_set, |
| 786 Dart_WeakPersistentHandle key, |
| 787 Dart_WeakPersistentHandle value) { |
| 788 ASSERT(reference_set != NULL); |
| 789 WeakReferenceSet* set = reinterpret_cast<WeakReferenceSet*>(reference_set); |
| 790 set->Append(key, value); |
| 791 return Api::Success(); |
| 792 } |
| 793 |
| 794 |
| 795 DART_EXPORT Dart_Handle Dart_AppendKeyToWeakReferenceSet( |
| 796 Dart_WeakReferenceSet reference_set, |
| 797 Dart_WeakPersistentHandle key) { |
| 798 ASSERT(reference_set != NULL); |
| 799 WeakReferenceSet* set = reinterpret_cast<WeakReferenceSet*>(reference_set); |
| 800 set->AppendKey(key); |
| 801 return Api::Success(); |
| 802 } |
| 803 |
| 804 |
| 805 DART_EXPORT Dart_Handle Dart_AppendValueToWeakReferenceSet( |
| 806 Dart_WeakReferenceSet reference_set, |
| 807 Dart_WeakPersistentHandle value) { |
| 808 ASSERT(reference_set != NULL); |
| 809 WeakReferenceSet* set = reinterpret_cast<WeakReferenceSet*>(reference_set); |
| 810 set->AppendValue(value); |
| 774 return Api::Success(); | 811 return Api::Success(); |
| 775 } | 812 } |
| 776 | 813 |
| 777 | 814 |
| 778 // --- Garbage Collection Callbacks -- | 815 // --- Garbage Collection Callbacks -- |
| 779 | 816 |
| 780 DART_EXPORT Dart_Handle Dart_SetGcCallbacks( | 817 DART_EXPORT Dart_Handle Dart_SetGcCallbacks( |
| 781 Dart_GcPrologueCallback prologue_callback, | 818 Dart_GcPrologueCallback prologue_callback, |
| 782 Dart_GcEpilogueCallback epilogue_callback) { | 819 Dart_GcEpilogueCallback epilogue_callback) { |
| 783 Isolate* isolate = Isolate::Current(); | 820 Isolate* isolate = Isolate::Current(); |
| (...skipping 3928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4712 | 4749 |
| 4713 | 4750 |
| 4714 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4751 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4715 const char* name, | 4752 const char* name, |
| 4716 Dart_ServiceRequestCallback callback, | 4753 Dart_ServiceRequestCallback callback, |
| 4717 void* user_data) { | 4754 void* user_data) { |
| 4718 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4755 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4719 } | 4756 } |
| 4720 | 4757 |
| 4721 } // namespace dart | 4758 } // namespace dart |
| OLD | NEW |