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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 1250463004: Migrate NoSafepointScope; add constrained concurrent allocation to unit test (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Assert current thread is mutator; add shared assertion macro. Created 5 years, 5 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
« no previous file with comments | « runtime/vm/base_isolate.h ('k') | runtime/vm/heap.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) 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/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after
3580 void* data_copy_; 3580 void* data_copy_;
3581 3581
3582 DISALLOW_COPY_AND_ASSIGN(AcquiredData); 3582 DISALLOW_COPY_AND_ASSIGN(AcquiredData);
3583 }; 3583 };
3584 3584
3585 3585
3586 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, 3586 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object,
3587 Dart_TypedData_Type* type, 3587 Dart_TypedData_Type* type,
3588 void** data, 3588 void** data,
3589 intptr_t* len) { 3589 intptr_t* len) {
3590 Isolate* isolate = Isolate::Current(); 3590 Thread* thread = Thread::Current();
3591 Isolate* isolate = thread->isolate();
3591 DARTSCOPE(isolate); 3592 DARTSCOPE(isolate);
3592 intptr_t class_id = Api::ClassId(object); 3593 intptr_t class_id = Api::ClassId(object);
3593 if (!RawObject::IsExternalTypedDataClassId(class_id) && 3594 if (!RawObject::IsExternalTypedDataClassId(class_id) &&
3594 !RawObject::IsTypedDataViewClassId(class_id) && 3595 !RawObject::IsTypedDataViewClassId(class_id) &&
3595 !RawObject::IsTypedDataClassId(class_id)) { 3596 !RawObject::IsTypedDataClassId(class_id)) {
3596 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); 3597 RETURN_TYPE_ERROR(isolate, object, 'TypedData');
3597 } 3598 }
3598 if (type == NULL) { 3599 if (type == NULL) {
3599 RETURN_NULL_ERROR(type); 3600 RETURN_NULL_ERROR(type);
3600 } 3601 }
(...skipping 17 matching lines...) Expand all
3618 length = obj.Length(); 3619 length = obj.Length();
3619 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); 3620 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id);
3620 data_tmp = obj.DataAddr(0); 3621 data_tmp = obj.DataAddr(0);
3621 external = true; 3622 external = true;
3622 } else if (RawObject::IsTypedDataClassId(class_id)) { 3623 } else if (RawObject::IsTypedDataClassId(class_id)) {
3623 // Regular typed data object, set up some GC and API callback guards. 3624 // Regular typed data object, set up some GC and API callback guards.
3624 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); 3625 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object);
3625 ASSERT(!obj.IsNull()); 3626 ASSERT(!obj.IsNull());
3626 length = obj.Length(); 3627 length = obj.Length();
3627 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); 3628 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id);
3628 isolate->IncrementNoSafepointScopeDepth(); 3629 thread->IncrementNoSafepointScopeDepth();
3629 START_NO_CALLBACK_SCOPE(isolate); 3630 START_NO_CALLBACK_SCOPE(isolate);
3630 data_tmp = obj.DataAddr(0); 3631 data_tmp = obj.DataAddr(0);
3631 } else { 3632 } else {
3632 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); 3633 ASSERT(RawObject::IsTypedDataViewClassId(class_id));
3633 const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object); 3634 const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object);
3634 ASSERT(!view_obj.IsNull()); 3635 ASSERT(!view_obj.IsNull());
3635 Smi& val = Smi::Handle(); 3636 Smi& val = Smi::Handle();
3636 val ^= TypedDataView::Length(view_obj); 3637 val ^= TypedDataView::Length(view_obj);
3637 length = val.Value(); 3638 length = val.Value();
3638 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); 3639 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id);
3639 val ^= TypedDataView::OffsetInBytes(view_obj); 3640 val ^= TypedDataView::OffsetInBytes(view_obj);
3640 intptr_t offset_in_bytes = val.Value(); 3641 intptr_t offset_in_bytes = val.Value();
3641 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); 3642 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj));
3642 isolate->IncrementNoSafepointScopeDepth(); 3643 thread->IncrementNoSafepointScopeDepth();
3643 START_NO_CALLBACK_SCOPE(isolate); 3644 START_NO_CALLBACK_SCOPE(isolate);
3644 if (TypedData::IsTypedData(obj)) { 3645 if (TypedData::IsTypedData(obj)) {
3645 const TypedData& data_obj = TypedData::Cast(obj); 3646 const TypedData& data_obj = TypedData::Cast(obj);
3646 data_tmp = data_obj.DataAddr(offset_in_bytes); 3647 data_tmp = data_obj.DataAddr(offset_in_bytes);
3647 } else { 3648 } else {
3648 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); 3649 ASSERT(ExternalTypedData::IsExternalTypedData(obj));
3649 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); 3650 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj);
3650 data_tmp = data_obj.DataAddr(offset_in_bytes); 3651 data_tmp = data_obj.DataAddr(offset_in_bytes);
3651 external = true; 3652 external = true;
3652 } 3653 }
(...skipping 17 matching lines...) Expand all
3670 table->SetValue(obj.raw(), reinterpret_cast<intptr_t>(ad)); 3671 table->SetValue(obj.raw(), reinterpret_cast<intptr_t>(ad));
3671 data_tmp = ad->GetData(); 3672 data_tmp = ad->GetData();
3672 } 3673 }
3673 *data = data_tmp; 3674 *data = data_tmp;
3674 *len = length; 3675 *len = length;
3675 return Api::Success(); 3676 return Api::Success();
3676 } 3677 }
3677 3678
3678 3679
3679 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { 3680 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) {
3680 Isolate* isolate = Isolate::Current(); 3681 Thread* thread = Thread::Current();
3682 Isolate* isolate = thread->isolate();
3681 DARTSCOPE(isolate); 3683 DARTSCOPE(isolate);
3682 intptr_t class_id = Api::ClassId(object); 3684 intptr_t class_id = Api::ClassId(object);
3683 if (!RawObject::IsExternalTypedDataClassId(class_id) && 3685 if (!RawObject::IsExternalTypedDataClassId(class_id) &&
3684 !RawObject::IsTypedDataViewClassId(class_id) && 3686 !RawObject::IsTypedDataViewClassId(class_id) &&
3685 !RawObject::IsTypedDataClassId(class_id)) { 3687 !RawObject::IsTypedDataClassId(class_id)) {
3686 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); 3688 RETURN_TYPE_ERROR(isolate, object, 'TypedData');
3687 } 3689 }
3688 if (!RawObject::IsExternalTypedDataClassId(class_id)) { 3690 if (!RawObject::IsExternalTypedDataClassId(class_id)) {
3689 isolate->DecrementNoSafepointScopeDepth(); 3691 thread->DecrementNoSafepointScopeDepth();
3690 END_NO_CALLBACK_SCOPE(isolate); 3692 END_NO_CALLBACK_SCOPE(isolate);
3691 } 3693 }
3692 if (FLAG_verify_acquired_data) { 3694 if (FLAG_verify_acquired_data) {
3693 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 3695 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
3694 WeakTable* table = isolate->api_state()->acquired_table(); 3696 WeakTable* table = isolate->api_state()->acquired_table();
3695 intptr_t current = table->GetValue(obj.raw()); 3697 intptr_t current = table->GetValue(obj.raw());
3696 if (current == 0) { 3698 if (current == 0) {
3697 return Api::NewError("Data was not acquired for this object."); 3699 return Api::NewError("Data was not acquired for this object.");
3698 } 3700 }
3699 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); 3701 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current);
(...skipping 2153 matching lines...) Expand 10 before | Expand all | Expand 10 after
5853 ASSERT(stream != NULL); 5855 ASSERT(stream != NULL);
5854 TimelineEvent* event = stream->StartEvent(); 5856 TimelineEvent* event = stream->StartEvent();
5855 if (event != NULL) { 5857 if (event != NULL) {
5856 event->AsyncEnd(label, async_id); 5858 event->AsyncEnd(label, async_id);
5857 event->Complete(); 5859 event->Complete();
5858 } 5860 }
5859 return Api::Success(); 5861 return Api::Success();
5860 } 5862 }
5861 5863
5862 } // namespace dart 5864 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/base_isolate.h ('k') | runtime/vm/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698