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

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

Issue 1394673002: Move reusable handles from isolate to thread. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix release build Created 5 years, 2 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 | « no previous file | runtime/vm/gc_marker.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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 static bool GetNativeStringArgument(NativeArguments* arguments, 166 static bool GetNativeStringArgument(NativeArguments* arguments,
167 int arg_index, 167 int arg_index,
168 Dart_Handle* str, 168 Dart_Handle* str,
169 void** peer) { 169 void** peer) {
170 ASSERT(peer != NULL); 170 ASSERT(peer != NULL);
171 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { 171 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) {
172 *str = NULL; 172 *str = NULL;
173 return true; 173 return true;
174 } 174 }
175 Isolate* isolate = arguments->thread()->isolate(); 175 Thread* thread = arguments->thread();
176 Isolate* isolate = thread->isolate();
176 ASSERT(isolate == Isolate::Current()); 177 ASSERT(isolate == Isolate::Current());
177 *peer = NULL; 178 *peer = NULL;
178 REUSABLE_OBJECT_HANDLESCOPE(isolate); 179 REUSABLE_OBJECT_HANDLESCOPE(thread);
179 Object& obj = isolate->ObjectHandle(); 180 Object& obj = thread->ObjectHandle();
180 obj = arguments->NativeArgAt(arg_index); 181 obj = arguments->NativeArgAt(arg_index);
181 if (RawObject::IsStringClassId(obj.GetClassId())) { 182 if (RawObject::IsStringClassId(obj.GetClassId())) {
182 ASSERT(isolate->api_state() && 183 ASSERT(isolate->api_state() &&
183 isolate->api_state()->top_scope() != NULL); 184 isolate->api_state()->top_scope() != NULL);
184 *str = Api::NewHandle(isolate, obj.raw()); 185 *str = Api::NewHandle(isolate, obj.raw());
185 return true; 186 return true;
186 } 187 }
187 if (obj.IsNull()) { 188 if (obj.IsNull()) {
188 *str = Api::Null(); 189 *str = Api::Null();
189 return true; 190 return true;
190 } 191 }
191 return false; 192 return false;
192 } 193 }
193 194
194 195
195 static bool GetNativeIntegerArgument(NativeArguments* arguments, 196 static bool GetNativeIntegerArgument(NativeArguments* arguments,
196 int arg_index, 197 int arg_index,
197 int64_t* value) { 198 int64_t* value) {
198 ASSERT(value != NULL); 199 ASSERT(value != NULL);
199 if (Api::GetNativeIntegerArgument(arguments, arg_index, value)) { 200 if (Api::GetNativeIntegerArgument(arguments, arg_index, value)) {
200 return true; 201 return true;
201 } 202 }
202 Isolate* isolate = arguments->thread()->isolate(); 203 Thread* thread = arguments->thread();
203 ASSERT(isolate == Isolate::Current()); 204 ASSERT(thread == Thread::Current());
204 REUSABLE_OBJECT_HANDLESCOPE(isolate); 205 REUSABLE_OBJECT_HANDLESCOPE(thread);
205 Object& obj = isolate->ObjectHandle(); 206 Object& obj = thread->ObjectHandle();
206 obj = arguments->NativeArgAt(arg_index); 207 obj = arguments->NativeArgAt(arg_index);
207 intptr_t cid = obj.GetClassId(); 208 intptr_t cid = obj.GetClassId();
208 if (cid == kBigintCid) { 209 if (cid == kBigintCid) {
209 const Bigint& bigint = Bigint::Cast(obj); 210 const Bigint& bigint = Bigint::Cast(obj);
210 if (bigint.FitsIntoInt64()) { 211 if (bigint.FitsIntoInt64()) {
211 *value = bigint.AsInt64Value(); 212 *value = bigint.AsInt64Value();
212 return true; 213 return true;
213 } 214 }
214 } 215 }
215 return false; 216 return false;
216 } 217 }
217 218
218 219
219 static bool GetNativeUnsignedIntegerArgument(NativeArguments* arguments, 220 static bool GetNativeUnsignedIntegerArgument(NativeArguments* arguments,
220 int arg_index, 221 int arg_index,
221 uint64_t* value) { 222 uint64_t* value) {
222 ASSERT(value != NULL); 223 ASSERT(value != NULL);
223 int64_t arg_value = 0; 224 int64_t arg_value = 0;
224 if (Api::GetNativeIntegerArgument(arguments, arg_index, &arg_value)) { 225 if (Api::GetNativeIntegerArgument(arguments, arg_index, &arg_value)) {
225 *value = static_cast<uint64_t>(arg_value); 226 *value = static_cast<uint64_t>(arg_value);
226 return true; 227 return true;
227 } 228 }
228 Isolate* isolate = arguments->thread()->isolate(); 229 Thread* thread = arguments->thread();
229 ASSERT(isolate == Isolate::Current()); 230 ASSERT(thread == Thread::Current());
230 REUSABLE_OBJECT_HANDLESCOPE(isolate); 231 REUSABLE_OBJECT_HANDLESCOPE(thread);
231 Object& obj = isolate->ObjectHandle(); 232 Object& obj = thread->ObjectHandle();
232 obj = arguments->NativeArgAt(arg_index); 233 obj = arguments->NativeArgAt(arg_index);
233 intptr_t cid = obj.GetClassId(); 234 intptr_t cid = obj.GetClassId();
234 if (cid == kBigintCid) { 235 if (cid == kBigintCid) {
235 const Bigint& bigint = Bigint::Cast(obj); 236 const Bigint& bigint = Bigint::Cast(obj);
236 if (bigint.FitsIntoUint64()) { 237 if (bigint.FitsIntoUint64()) {
237 *value = bigint.AsUint64Value(); 238 *value = bigint.AsUint64Value();
238 return true; 239 return true;
239 } 240 }
240 } 241 }
241 return false; 242 return false;
242 } 243 }
243 244
244 245
245 static bool GetNativeDoubleArgument(NativeArguments* arguments, 246 static bool GetNativeDoubleArgument(NativeArguments* arguments,
246 int arg_index, 247 int arg_index,
247 double* value) { 248 double* value) {
248 ASSERT(value != NULL); 249 ASSERT(value != NULL);
249 if (Api::GetNativeDoubleArgument(arguments, arg_index, value)) { 250 if (Api::GetNativeDoubleArgument(arguments, arg_index, value)) {
250 return true; 251 return true;
251 } 252 }
252 Isolate* isolate = arguments->thread()->isolate(); 253 Thread* thread = arguments->thread();
253 ASSERT(isolate == Isolate::Current()); 254 ASSERT(thread == Thread::Current());
254 REUSABLE_OBJECT_HANDLESCOPE(isolate); 255 REUSABLE_OBJECT_HANDLESCOPE(thread);
255 Object& obj = isolate->ObjectHandle(); 256 Object& obj = thread->ObjectHandle();
256 obj = arguments->NativeArgAt(arg_index); 257 obj = arguments->NativeArgAt(arg_index);
257 intptr_t cid = obj.GetClassId(); 258 intptr_t cid = obj.GetClassId();
258 if (cid == kBigintCid) { 259 if (cid == kBigintCid) {
259 *value = Bigint::Cast(obj).AsDoubleValue(); 260 *value = Bigint::Cast(obj).AsDoubleValue();
260 return true; 261 return true;
261 } 262 }
262 return false; 263 return false;
263 } 264 }
264 265
265 266
266 static Dart_Handle GetNativeFieldsOfArgument(NativeArguments* arguments, 267 static Dart_Handle GetNativeFieldsOfArgument(NativeArguments* arguments,
267 int arg_index, 268 int arg_index,
268 int num_fields, 269 int num_fields,
269 intptr_t* field_values, 270 intptr_t* field_values,
270 const char* current_func) { 271 const char* current_func) {
271 ASSERT(field_values != NULL); 272 ASSERT(field_values != NULL);
272 if (Api::GetNativeFieldsOfArgument(arguments, 273 if (Api::GetNativeFieldsOfArgument(arguments,
273 arg_index, 274 arg_index,
274 num_fields, 275 num_fields,
275 field_values)) { 276 field_values)) {
276 return Api::Success(); 277 return Api::Success();
277 } 278 }
278 Isolate* isolate = arguments->thread()->isolate(); 279 Thread* thread = arguments->thread();
279 ASSERT(isolate == Isolate::Current()); 280 ASSERT(thread == Thread::Current());
280 REUSABLE_OBJECT_HANDLESCOPE(isolate); 281 REUSABLE_OBJECT_HANDLESCOPE(thread);
281 Object& obj = isolate->ObjectHandle(); 282 Object& obj = thread->ObjectHandle();
282 obj = arguments->NativeArgAt(arg_index); 283 obj = arguments->NativeArgAt(arg_index);
283 if (obj.IsNull()) { 284 if (obj.IsNull()) {
284 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); 285 memset(field_values, 0, (num_fields * sizeof(field_values[0])));
285 return Api::Success(); 286 return Api::Success();
286 } 287 }
287 // We did not succeed in extracting the native fields report the 288 // We did not succeed in extracting the native fields report the
288 // appropriate error. 289 // appropriate error.
289 if (!obj.IsInstance()) { 290 if (!obj.IsInstance()) {
290 return Api::NewError("%s expects argument at index '%d' to be of" 291 return Api::NewError("%s expects argument at index '%d' to be of"
291 " type Instance.", current_func, arg_index); 292 " type Instance.", current_func, arg_index);
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 ApiState* state = I->api_state(); 1003 ApiState* state = I->api_state();
1003 ASSERT(state != NULL); 1004 ASSERT(state != NULL);
1004 ASSERT(state->IsValidPersistentHandle(obj1)); 1005 ASSERT(state->IsValidPersistentHandle(obj1));
1005 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2)); 1006 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2));
1006 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); 1007 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1);
1007 obj1_ref->set_raw(obj2_ref); 1008 obj1_ref->set_raw(obj2_ref);
1008 } 1009 }
1009 1010
1010 1011
1011 static Dart_WeakPersistentHandle AllocateFinalizableHandle( 1012 static Dart_WeakPersistentHandle AllocateFinalizableHandle(
1012 Isolate* isolate, 1013 Thread* thread,
1013 Dart_Handle object, 1014 Dart_Handle object,
1014 bool is_prologue, 1015 bool is_prologue,
1015 void* peer, 1016 void* peer,
1016 intptr_t external_allocation_size, 1017 intptr_t external_allocation_size,
1017 Dart_WeakPersistentHandleFinalizer callback) { 1018 Dart_WeakPersistentHandleFinalizer callback) {
1018 REUSABLE_OBJECT_HANDLESCOPE(isolate); 1019 REUSABLE_OBJECT_HANDLESCOPE(thread);
1019 Object& ref = isolate->ObjectHandle(); 1020 Object& ref = thread->ObjectHandle();
1020 ref = Api::UnwrapHandle(object); 1021 ref = Api::UnwrapHandle(object);
1021 FinalizablePersistentHandle* finalizable_ref = 1022 FinalizablePersistentHandle* finalizable_ref =
1022 FinalizablePersistentHandle::New(isolate, 1023 FinalizablePersistentHandle::New(thread->isolate(),
1023 is_prologue, 1024 is_prologue,
1024 ref, 1025 ref,
1025 peer, 1026 peer,
1026 callback, 1027 callback,
1027 external_allocation_size); 1028 external_allocation_size);
1028 return finalizable_ref->apiHandle(); 1029 return finalizable_ref->apiHandle();
1029 } 1030 }
1030 1031
1031 1032
1032 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( 1033 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(
1033 Dart_Handle object, 1034 Dart_Handle object,
1034 void* peer, 1035 void* peer,
1035 intptr_t external_allocation_size, 1036 intptr_t external_allocation_size,
1036 Dart_WeakPersistentHandleFinalizer callback) { 1037 Dart_WeakPersistentHandleFinalizer callback) {
1037 Isolate* isolate = Isolate::Current(); 1038 Thread* thread = Thread::Current();
1038 CHECK_ISOLATE(isolate); 1039 CHECK_ISOLATE(thread->isolate());
1039 if (callback == NULL) { 1040 if (callback == NULL) {
1040 return NULL; 1041 return NULL;
1041 } 1042 }
1042 return AllocateFinalizableHandle(isolate, 1043 return AllocateFinalizableHandle(thread,
1043 object, 1044 object,
1044 false, 1045 false,
1045 peer, 1046 peer,
1046 external_allocation_size, 1047 external_allocation_size,
1047 callback); 1048 callback);
1048 } 1049 }
1049 1050
1050 1051
1051 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( 1052 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle(
1052 Dart_Handle object, 1053 Dart_Handle object,
1053 void* peer, 1054 void* peer,
1054 intptr_t external_allocation_size, 1055 intptr_t external_allocation_size,
1055 Dart_WeakPersistentHandleFinalizer callback) { 1056 Dart_WeakPersistentHandleFinalizer callback) {
1056 Isolate* isolate = Isolate::Current(); 1057 Thread* thread = Thread::Current();
1057 CHECK_ISOLATE(isolate); 1058 CHECK_ISOLATE(thread->isolate());
1058 if (callback == NULL) { 1059 if (callback == NULL) {
1059 return NULL; 1060 return NULL;
1060 } 1061 }
1061 return AllocateFinalizableHandle(isolate, 1062 return AllocateFinalizableHandle(thread,
1062 object, 1063 object,
1063 true, 1064 true,
1064 peer, 1065 peer,
1065 external_allocation_size, 1066 external_allocation_size,
1066 callback); 1067 callback);
1067 } 1068 }
1068 1069
1069 1070
1070 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { 1071 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) {
1071 Isolate* isolate = Isolate::Current(); 1072 Isolate* isolate = Isolate::Current();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1206 }
1206 } 1207 }
1207 isolate->set_gc_prologue_callback(prologue_callback); 1208 isolate->set_gc_prologue_callback(prologue_callback);
1208 isolate->set_gc_epilogue_callback(epilogue_callback); 1209 isolate->set_gc_epilogue_callback(epilogue_callback);
1209 return Api::Success(); 1210 return Api::Success();
1210 } 1211 }
1211 1212
1212 1213
1213 class PrologueWeakVisitor : public HandleVisitor { 1214 class PrologueWeakVisitor : public HandleVisitor {
1214 public: 1215 public:
1215 PrologueWeakVisitor(Isolate* isolate, 1216 PrologueWeakVisitor(Thread* thread,
1216 Dart_GcPrologueWeakHandleCallback callback) 1217 Dart_GcPrologueWeakHandleCallback callback)
1217 : HandleVisitor(isolate), 1218 : HandleVisitor(thread),
1218 callback_(callback) { 1219 callback_(callback) {
1219 } 1220 }
1220 1221
1222
1221 void VisitHandle(uword addr) { 1223 void VisitHandle(uword addr) {
1222 NoSafepointScope no_safepoint; 1224 NoSafepointScope no_safepoint;
1223 FinalizablePersistentHandle* handle = 1225 FinalizablePersistentHandle* handle =
1224 reinterpret_cast<FinalizablePersistentHandle*>(addr); 1226 reinterpret_cast<FinalizablePersistentHandle*>(addr);
1225 RawObject* raw_obj = handle->raw(); 1227 RawObject* raw_obj = handle->raw();
1226 if (raw_obj->IsHeapObject()) { 1228 if (raw_obj->IsHeapObject()) {
1227 ASSERT(handle->IsPrologueWeakPersistent()); 1229 ASSERT(handle->IsPrologueWeakPersistent());
1228 ReusableInstanceHandleScope reused_instance_handle(isolate()); 1230 ReusableInstanceHandleScope reused_instance_handle(thread());
1229 Instance& instance = reused_instance_handle.Handle(); 1231 Instance& instance = reused_instance_handle.Handle();
1230 instance ^= reinterpret_cast<RawInstance*>(handle->raw()); 1232 instance ^= reinterpret_cast<RawInstance*>(handle->raw());
1231 intptr_t num_native_fields = instance.NumNativeFields(); 1233 intptr_t num_native_fields = instance.NumNativeFields();
1232 intptr_t* native_fields = instance.NativeFieldsDataAddr(); 1234 intptr_t* native_fields = instance.NativeFieldsDataAddr();
1233 if (native_fields != NULL) { 1235 if (native_fields != NULL) {
1234 callback_(isolate()->init_callback_data(), 1236 callback_(thread()->isolate()->init_callback_data(),
1235 reinterpret_cast<Dart_WeakPersistentHandle>(addr), 1237 reinterpret_cast<Dart_WeakPersistentHandle>(addr),
1236 num_native_fields, 1238 num_native_fields,
1237 native_fields); 1239 native_fields);
1238 } 1240 }
1239 } 1241 }
1240 } 1242 }
1241 1243
1242 private: 1244 private:
1243 Dart_GcPrologueWeakHandleCallback callback_; 1245 Dart_GcPrologueWeakHandleCallback callback_;
1244 1246
1245 DISALLOW_COPY_AND_ASSIGN(PrologueWeakVisitor); 1247 DISALLOW_COPY_AND_ASSIGN(PrologueWeakVisitor);
1246 }; 1248 };
1247 1249
1248 1250
1249 DART_EXPORT Dart_Handle Dart_VisitPrologueWeakHandles( 1251 DART_EXPORT Dart_Handle Dart_VisitPrologueWeakHandles(
1250 Dart_GcPrologueWeakHandleCallback callback) { 1252 Dart_GcPrologueWeakHandleCallback callback) {
1251 Isolate* isolate = Isolate::Current(); 1253 Thread* thread = Thread::Current();
1252 CHECK_ISOLATE(isolate); 1254 CHECK_ISOLATE(thread->isolate());
1253 PrologueWeakVisitor visitor(isolate, callback); 1255 PrologueWeakVisitor visitor(thread, callback);
1254 isolate->VisitPrologueWeakPersistentHandles(&visitor); 1256 thread->isolate()->VisitPrologueWeakPersistentHandles(&visitor);
1255 return Api::Success(); 1257 return Api::Success();
1256 } 1258 }
1257 1259
1258 1260
1259 // --- Initialization and Globals --- 1261 // --- Initialization and Globals ---
1260 1262
1261 DART_EXPORT const char* Dart_VersionString() { 1263 DART_EXPORT const char* Dart_VersionString() {
1262 return Version::String(); 1264 return Version::String();
1263 } 1265 }
1264 1266
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 Error& malformed_type_error = Error::Handle(Z); 1905 Error& malformed_type_error = Error::Handle(Z);
1904 *value = instance.IsInstanceOf(type_obj, 1906 *value = instance.IsInstanceOf(type_obj,
1905 Object::null_type_arguments(), 1907 Object::null_type_arguments(),
1906 &malformed_type_error); 1908 &malformed_type_error);
1907 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. 1909 ASSERT(malformed_type_error.IsNull()); // Type was created from a class.
1908 return Api::Success(); 1910 return Api::Success();
1909 } 1911 }
1910 1912
1911 1913
1912 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { 1914 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) {
1913 Isolate* isolate = Isolate::Current(); 1915 Thread* thread = Thread::Current();
1914 CHECK_ISOLATE(isolate); 1916 CHECK_ISOLATE(thread->isolate());
1915 REUSABLE_OBJECT_HANDLESCOPE(isolate); 1917 REUSABLE_OBJECT_HANDLESCOPE(thread);
1916 Object& ref = isolate->ObjectHandle(); 1918 Object& ref = thread->ObjectHandle();
1917 ref = Api::UnwrapHandle(object); 1919 ref = Api::UnwrapHandle(object);
1918 return ref.IsInstance(); 1920 return ref.IsInstance();
1919 } 1921 }
1920 1922
1921 1923
1922 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { 1924 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) {
1923 TRACE_API_CALL(CURRENT_FUNC); 1925 TRACE_API_CALL(CURRENT_FUNC);
1924 return RawObject::IsNumberClassId(Api::ClassId(object)); 1926 return RawObject::IsNumberClassId(Api::ClassId(object));
1925 } 1927 }
1926 1928
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 2008
2007 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { 2009 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) {
2008 TRACE_API_CALL(CURRENT_FUNC); 2010 TRACE_API_CALL(CURRENT_FUNC);
2009 return Api::ClassId(handle) == kTypeParameterCid; 2011 return Api::ClassId(handle) == kTypeParameterCid;
2010 } 2012 }
2011 2013
2012 2014
2013 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 2015 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
2014 // We can't use a fast class index check here because there are many 2016 // We can't use a fast class index check here because there are many
2015 // different signature classes for closures. 2017 // different signature classes for closures.
2016 Isolate* isolate = Isolate::Current(); 2018 Thread* thread = Thread::Current();
2017 CHECK_ISOLATE(isolate); 2019 CHECK_ISOLATE(thread->isolate());
2018 ReusableObjectHandleScope reused_obj_handle(isolate); 2020 ReusableObjectHandleScope reused_obj_handle(thread);
2019 const Instance& closure_obj = 2021 const Instance& closure_obj =
2020 Api::UnwrapInstanceHandle(reused_obj_handle, object); 2022 Api::UnwrapInstanceHandle(reused_obj_handle, object);
2021 return (!closure_obj.IsNull() && closure_obj.IsClosure()); 2023 return (!closure_obj.IsNull() && closure_obj.IsClosure());
2022 } 2024 }
2023 2025
2024 2026
2025 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) { 2027 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) {
2026 TRACE_API_CALL(CURRENT_FUNC); 2028 TRACE_API_CALL(CURRENT_FUNC);
2027 intptr_t cid = Api::ClassId(handle); 2029 intptr_t cid = Api::ClassId(handle);
2028 return RawObject::IsTypedDataClassId(cid) || 2030 return RawObject::IsTypedDataClassId(cid) ||
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2296 } 2298 }
2297 *value = obj.value(); 2299 *value = obj.value();
2298 return Api::Success(); 2300 return Api::Success();
2299 } 2301 }
2300 2302
2301 2303
2302 // --- Strings --- 2304 // --- Strings ---
2303 2305
2304 2306
2305 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { 2307 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
2306 Isolate* isolate = Isolate::Current(); 2308 Thread* thread = Thread::Current();
2307 CHECK_ISOLATE(isolate); 2309 CHECK_ISOLATE(thread->isolate());
2308 ReusableObjectHandleScope reused_obj_handle(isolate); 2310 ReusableObjectHandleScope reused_obj_handle(thread);
2309 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); 2311 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str);
2310 if (str_obj.IsNull()) { 2312 if (str_obj.IsNull()) {
2311 RETURN_TYPE_ERROR(isolate, str, String); 2313 RETURN_TYPE_ERROR(thread->isolate(), str, String);
2312 } 2314 }
2313 *len = str_obj.Length(); 2315 *len = str_obj.Length();
2314 return Api::Success(); 2316 return Api::Success();
2315 } 2317 }
2316 2318
2317 2319
2318 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { 2320 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) {
2319 DARTSCOPE(Thread::Current()); 2321 DARTSCOPE(Thread::Current());
2320 if (str == NULL) { 2322 if (str == NULL) {
2321 RETURN_NULL_ERROR(str); 2323 RETURN_NULL_ERROR(str);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 for (intptr_t i = 0; i < copy_len; i++) { 2495 for (intptr_t i = 0; i < copy_len; i++) {
2494 utf16_array[i] = str_obj.CharAt(i); 2496 utf16_array[i] = str_obj.CharAt(i);
2495 } 2497 }
2496 *length = copy_len; 2498 *length = copy_len;
2497 return Api::Success(); 2499 return Api::Success();
2498 } 2500 }
2499 2501
2500 2502
2501 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, 2503 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str,
2502 intptr_t* size) { 2504 intptr_t* size) {
2503 Isolate* isolate = Isolate::Current(); 2505 Thread* thread = Thread::Current();
2504 CHECK_ISOLATE(isolate); 2506 CHECK_ISOLATE(thread->isolate());
2505 ReusableObjectHandleScope reused_obj_handle(isolate); 2507 ReusableObjectHandleScope reused_obj_handle(thread);
2506 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); 2508 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str);
2507 if (str_obj.IsNull()) { 2509 if (str_obj.IsNull()) {
2508 RETURN_TYPE_ERROR(isolate, str, String); 2510 RETURN_TYPE_ERROR(thread->isolate(), str, String);
2509 } 2511 }
2510 if (size == NULL) { 2512 if (size == NULL) {
2511 RETURN_NULL_ERROR(size); 2513 RETURN_NULL_ERROR(size);
2512 } 2514 }
2513 *size = (str_obj.Length() * str_obj.CharSize()); 2515 *size = (str_obj.Length() * str_obj.CharSize());
2514 return Api::Success(); 2516 return Api::Success();
2515 } 2517 }
2516 2518
2517 2519
2518 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, 2520 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 return str; 2566 return str;
2565 } 2567 }
2566 return Api::NewHandle(I, str_obj.MakeExternal(array, length, peer, cback)); 2568 return Api::NewHandle(I, str_obj.MakeExternal(array, length, peer, cback));
2567 } 2569 }
2568 2570
2569 2571
2570 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, 2572 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object,
2571 intptr_t* char_size, 2573 intptr_t* char_size,
2572 intptr_t* str_len, 2574 intptr_t* str_len,
2573 void** peer) { 2575 void** peer) {
2574 Isolate* isolate = Isolate::Current(); 2576 Thread* thread = Thread::Current();
2575 CHECK_ISOLATE(isolate); 2577 CHECK_ISOLATE(thread->isolate());
2576 ReusableObjectHandleScope reused_obj_handle(isolate); 2578 ReusableObjectHandleScope reused_obj_handle(thread);
2577 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); 2579 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object);
2578 if (str.IsNull()) { 2580 if (str.IsNull()) {
2579 RETURN_TYPE_ERROR(isolate, object, String); 2581 RETURN_TYPE_ERROR(thread->isolate(), object, String);
2580 } 2582 }
2581 if (str.IsExternal()) { 2583 if (str.IsExternal()) {
2582 *peer = str.GetPeer(); 2584 *peer = str.GetPeer();
2583 ASSERT(*peer != NULL); 2585 ASSERT(*peer != NULL);
2584 } else { 2586 } else {
2585 NoSafepointScope no_safepoint_scope; 2587 NoSafepointScope no_safepoint_scope;
2586 *peer = isolate->heap()->GetPeer(str.raw()); 2588 *peer = thread->isolate()->heap()->GetPeer(str.raw());
2587 } 2589 }
2588 *char_size = str.CharSize(); 2590 *char_size = str.CharSize();
2589 *str_len = str.Length(); 2591 *str_len = str.Length();
2590 return Api::Success(); 2592 return Api::Success();
2591 } 2593 }
2592 2594
2593 2595
2594 // --- Lists --- 2596 // --- Lists ---
2595 2597
2596 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { 2598 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) {
(...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
4591 if (cls.IsNull()) { 4593 if (cls.IsNull()) {
4592 return Api::NewError( 4594 return Api::NewError(
4593 "Unable to create native wrapper class : already exists"); 4595 "Unable to create native wrapper class : already exists");
4594 } 4596 }
4595 return Api::NewHandle(I, cls.RareType()); 4597 return Api::NewHandle(I, cls.RareType());
4596 } 4598 }
4597 4599
4598 4600
4599 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, 4601 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj,
4600 int* count) { 4602 int* count) {
4601 Isolate* isolate = Isolate::Current(); 4603 Thread* thread = Thread::Current();
4602 CHECK_ISOLATE(isolate); 4604 CHECK_ISOLATE(thread->isolate());
4603 ReusableObjectHandleScope reused_obj_handle(isolate); 4605 ReusableObjectHandleScope reused_obj_handle(thread);
4604 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); 4606 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj);
4605 if (instance.IsNull()) { 4607 if (instance.IsNull()) {
4606 RETURN_TYPE_ERROR(isolate, obj, Instance); 4608 RETURN_TYPE_ERROR(thread->isolate(), obj, Instance);
4607 } 4609 }
4608 *count = instance.NumNativeFields(); 4610 *count = instance.NumNativeFields();
4609 return Api::Success(); 4611 return Api::Success();
4610 } 4612 }
4611 4613
4612 4614
4613 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, 4615 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj,
4614 int index, 4616 int index,
4615 intptr_t* value) { 4617 intptr_t* value) {
4616 Isolate* isolate = Isolate::Current(); 4618 Thread* thread = Thread::Current();
4617 CHECK_ISOLATE(isolate); 4619 CHECK_ISOLATE(thread->isolate());
4618 ReusableObjectHandleScope reused_obj_handle(isolate); 4620 ReusableObjectHandleScope reused_obj_handle(thread);
4619 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); 4621 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj);
4620 if (instance.IsNull()) { 4622 if (instance.IsNull()) {
4621 RETURN_TYPE_ERROR(isolate, obj, Instance); 4623 RETURN_TYPE_ERROR(thread->isolate(), obj, Instance);
4622 } 4624 }
4623 if (!instance.IsValidNativeIndex(index)) { 4625 if (!instance.IsValidNativeIndex(index)) {
4624 return Api::NewError( 4626 return Api::NewError(
4625 "%s: invalid index %d passed in to access native instance field", 4627 "%s: invalid index %d passed in to access native instance field",
4626 CURRENT_FUNC, index); 4628 CURRENT_FUNC, index);
4627 } 4629 }
4628 *value = instance.GetNativeField(index); 4630 *value = instance.GetNativeField(index);
4629 return Api::Success(); 4631 return Api::Success();
4630 } 4632 }
4631 4633
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
5536 return Api::Success(); 5538 return Api::Success();
5537 } 5539 }
5538 5540
5539 5541
5540 // --- Peer support --- 5542 // --- Peer support ---
5541 5543
5542 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { 5544 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) {
5543 if (peer == NULL) { 5545 if (peer == NULL) {
5544 RETURN_NULL_ERROR(peer); 5546 RETURN_NULL_ERROR(peer);
5545 } 5547 }
5546 Isolate* isolate = Isolate::Current(); 5548 Thread* thread = Thread::Current();
5547 CHECK_ISOLATE(isolate); 5549 CHECK_ISOLATE(thread->isolate());
5548 REUSABLE_OBJECT_HANDLESCOPE(isolate); 5550 REUSABLE_OBJECT_HANDLESCOPE(thread);
5549 Object& obj = isolate->ObjectHandle(); 5551 Object& obj = thread->ObjectHandle();
5550 obj = Api::UnwrapHandle(object); 5552 obj = Api::UnwrapHandle(object);
5551 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { 5553 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) {
5552 const char* msg = 5554 const char* msg =
5553 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; 5555 "%s: argument 'object' cannot be a subtype of Null, num, or bool";
5554 return Api::NewError(msg, CURRENT_FUNC); 5556 return Api::NewError(msg, CURRENT_FUNC);
5555 } 5557 }
5556 { 5558 {
5557 NoSafepointScope no_safepoint; 5559 NoSafepointScope no_safepoint;
5558 RawObject* raw_obj = obj.raw(); 5560 RawObject* raw_obj = obj.raw();
5559 *peer = isolate->heap()->GetPeer(raw_obj); 5561 *peer = thread->isolate()->heap()->GetPeer(raw_obj);
5560 } 5562 }
5561 return Api::Success(); 5563 return Api::Success();
5562 } 5564 }
5563 5565
5564 5566
5565 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { 5567 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) {
5566 Isolate* isolate = Isolate::Current(); 5568 Thread* thread = Thread::Current();
5567 CHECK_ISOLATE(isolate); 5569 CHECK_ISOLATE(thread->isolate());
5568 REUSABLE_OBJECT_HANDLESCOPE(isolate); 5570 REUSABLE_OBJECT_HANDLESCOPE(thread);
5569 Object& obj = isolate->ObjectHandle(); 5571 Object& obj = thread->ObjectHandle();
5570 obj = Api::UnwrapHandle(object); 5572 obj = Api::UnwrapHandle(object);
5571 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { 5573 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) {
5572 const char* msg = 5574 const char* msg =
5573 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; 5575 "%s: argument 'object' cannot be a subtype of Null, num, or bool";
5574 return Api::NewError(msg, CURRENT_FUNC); 5576 return Api::NewError(msg, CURRENT_FUNC);
5575 } 5577 }
5576 { 5578 {
5577 NoSafepointScope no_safepoint; 5579 NoSafepointScope no_safepoint;
5578 RawObject* raw_obj = obj.raw(); 5580 RawObject* raw_obj = obj.raw();
5579 isolate->heap()->SetPeer(raw_obj, peer); 5581 thread->isolate()->heap()->SetPeer(raw_obj, peer);
5580 } 5582 }
5581 return Api::Success(); 5583 return Api::Success();
5582 } 5584 }
5583 5585
5584 5586
5585 // --- Service support --- 5587 // --- Service support ---
5586 5588
5587 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { 5589 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) {
5588 Isolate* iso = reinterpret_cast<Isolate*>(isolate); 5590 Isolate* iso = reinterpret_cast<Isolate*>(isolate);
5589 return ServiceIsolate::IsServiceIsolate(iso); 5591 return ServiceIsolate::IsServiceIsolate(iso);
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
6070 ApiReallocate); 6072 ApiReallocate);
6071 writer.WriteFullSnapshot(); 6073 writer.WriteFullSnapshot();
6072 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6074 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6073 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6075 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6074 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); 6076 *instructions_snapshot_size = writer.InstructionsSnapshotSize();
6075 6077
6076 return Api::Success(); 6078 return Api::Success();
6077 } 6079 }
6078 6080
6079 } // namespace dart 6081 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/gc_marker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698