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

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') | runtime/vm/thread.h » ('J')
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 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 ApiState* state = I->api_state(); 996 ApiState* state = I->api_state();
996 ASSERT(state != NULL); 997 ASSERT(state != NULL);
997 ASSERT(state->IsValidPersistentHandle(obj1)); 998 ASSERT(state->IsValidPersistentHandle(obj1));
998 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2)); 999 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2));
999 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); 1000 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1);
1000 obj1_ref->set_raw(obj2_ref); 1001 obj1_ref->set_raw(obj2_ref);
1001 } 1002 }
1002 1003
1003 1004
1004 static Dart_WeakPersistentHandle AllocateFinalizableHandle( 1005 static Dart_WeakPersistentHandle AllocateFinalizableHandle(
1005 Isolate* isolate, 1006 Thread* thread,
1006 Dart_Handle object, 1007 Dart_Handle object,
1007 bool is_prologue, 1008 bool is_prologue,
1008 void* peer, 1009 void* peer,
1009 intptr_t external_allocation_size, 1010 intptr_t external_allocation_size,
1010 Dart_WeakPersistentHandleFinalizer callback) { 1011 Dart_WeakPersistentHandleFinalizer callback) {
1011 REUSABLE_OBJECT_HANDLESCOPE(isolate); 1012 REUSABLE_OBJECT_HANDLESCOPE(thread);
1012 Object& ref = isolate->ObjectHandle(); 1013 Object& ref = thread->ObjectHandle();
1013 ref = Api::UnwrapHandle(object); 1014 ref = Api::UnwrapHandle(object);
1014 FinalizablePersistentHandle* finalizable_ref = 1015 FinalizablePersistentHandle* finalizable_ref =
1015 FinalizablePersistentHandle::New(isolate, 1016 FinalizablePersistentHandle::New(thread->isolate(),
1016 is_prologue, 1017 is_prologue,
1017 ref, 1018 ref,
1018 peer, 1019 peer,
1019 callback, 1020 callback,
1020 external_allocation_size); 1021 external_allocation_size);
1021 return finalizable_ref->apiHandle(); 1022 return finalizable_ref->apiHandle();
1022 } 1023 }
1023 1024
1024 1025
1025 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( 1026 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(
1026 Dart_Handle object, 1027 Dart_Handle object,
1027 void* peer, 1028 void* peer,
1028 intptr_t external_allocation_size, 1029 intptr_t external_allocation_size,
1029 Dart_WeakPersistentHandleFinalizer callback) { 1030 Dart_WeakPersistentHandleFinalizer callback) {
1030 Isolate* isolate = Isolate::Current(); 1031 Thread* thread = Thread::Current();
1031 CHECK_ISOLATE(isolate); 1032 CHECK_ISOLATE(thread->isolate());
1032 if (callback == NULL) { 1033 if (callback == NULL) {
1033 return NULL; 1034 return NULL;
1034 } 1035 }
1035 return AllocateFinalizableHandle(isolate, 1036 return AllocateFinalizableHandle(thread,
1036 object, 1037 object,
1037 false, 1038 false,
1038 peer, 1039 peer,
1039 external_allocation_size, 1040 external_allocation_size,
1040 callback); 1041 callback);
1041 } 1042 }
1042 1043
1043 1044
1044 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( 1045 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle(
1045 Dart_Handle object, 1046 Dart_Handle object,
1046 void* peer, 1047 void* peer,
1047 intptr_t external_allocation_size, 1048 intptr_t external_allocation_size,
1048 Dart_WeakPersistentHandleFinalizer callback) { 1049 Dart_WeakPersistentHandleFinalizer callback) {
1049 Isolate* isolate = Isolate::Current(); 1050 Thread* thread = Thread::Current();
1050 CHECK_ISOLATE(isolate); 1051 CHECK_ISOLATE(thread->isolate());
1051 if (callback == NULL) { 1052 if (callback == NULL) {
1052 return NULL; 1053 return NULL;
1053 } 1054 }
1054 return AllocateFinalizableHandle(isolate, 1055 return AllocateFinalizableHandle(thread,
1055 object, 1056 object,
1056 true, 1057 true,
1057 peer, 1058 peer,
1058 external_allocation_size, 1059 external_allocation_size,
1059 callback); 1060 callback);
1060 } 1061 }
1061 1062
1062 1063
1063 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { 1064 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) {
1064 Isolate* isolate = Isolate::Current(); 1065 Isolate* isolate = Isolate::Current();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 } 1199 }
1199 } 1200 }
1200 isolate->set_gc_prologue_callback(prologue_callback); 1201 isolate->set_gc_prologue_callback(prologue_callback);
1201 isolate->set_gc_epilogue_callback(epilogue_callback); 1202 isolate->set_gc_epilogue_callback(epilogue_callback);
1202 return Api::Success(); 1203 return Api::Success();
1203 } 1204 }
1204 1205
1205 1206
1206 class PrologueWeakVisitor : public HandleVisitor { 1207 class PrologueWeakVisitor : public HandleVisitor {
1207 public: 1208 public:
1208 PrologueWeakVisitor(Isolate* isolate, 1209 PrologueWeakVisitor(Thread* thread,
1209 Dart_GcPrologueWeakHandleCallback callback) 1210 Dart_GcPrologueWeakHandleCallback callback)
1210 : HandleVisitor(isolate), 1211 : HandleVisitor(thread),
1211 callback_(callback) { 1212 callback_(callback) {
1212 } 1213 }
1213 1214
1215
1214 void VisitHandle(uword addr) { 1216 void VisitHandle(uword addr) {
1215 NoSafepointScope no_safepoint; 1217 NoSafepointScope no_safepoint;
1216 FinalizablePersistentHandle* handle = 1218 FinalizablePersistentHandle* handle =
1217 reinterpret_cast<FinalizablePersistentHandle*>(addr); 1219 reinterpret_cast<FinalizablePersistentHandle*>(addr);
1218 RawObject* raw_obj = handle->raw(); 1220 RawObject* raw_obj = handle->raw();
1219 if (raw_obj->IsHeapObject()) { 1221 if (raw_obj->IsHeapObject()) {
1220 ASSERT(handle->IsPrologueWeakPersistent()); 1222 ASSERT(handle->IsPrologueWeakPersistent());
1221 ReusableInstanceHandleScope reused_instance_handle(isolate()); 1223 ReusableInstanceHandleScope reused_instance_handle(thread());
1222 Instance& instance = reused_instance_handle.Handle(); 1224 Instance& instance = reused_instance_handle.Handle();
1223 instance ^= reinterpret_cast<RawInstance*>(handle->raw()); 1225 instance ^= reinterpret_cast<RawInstance*>(handle->raw());
1224 intptr_t num_native_fields = instance.NumNativeFields(); 1226 intptr_t num_native_fields = instance.NumNativeFields();
1225 intptr_t* native_fields = instance.NativeFieldsDataAddr(); 1227 intptr_t* native_fields = instance.NativeFieldsDataAddr();
1226 if (native_fields != NULL) { 1228 if (native_fields != NULL) {
1227 callback_(isolate()->init_callback_data(), 1229 callback_(thread()->isolate()->init_callback_data(),
1228 reinterpret_cast<Dart_WeakPersistentHandle>(addr), 1230 reinterpret_cast<Dart_WeakPersistentHandle>(addr),
1229 num_native_fields, 1231 num_native_fields,
1230 native_fields); 1232 native_fields);
1231 } 1233 }
1232 } 1234 }
1233 } 1235 }
1234 1236
1235 private: 1237 private:
1236 Dart_GcPrologueWeakHandleCallback callback_; 1238 Dart_GcPrologueWeakHandleCallback callback_;
1237 1239
1238 DISALLOW_COPY_AND_ASSIGN(PrologueWeakVisitor); 1240 DISALLOW_COPY_AND_ASSIGN(PrologueWeakVisitor);
1239 }; 1241 };
1240 1242
1241 1243
1242 DART_EXPORT Dart_Handle Dart_VisitPrologueWeakHandles( 1244 DART_EXPORT Dart_Handle Dart_VisitPrologueWeakHandles(
1243 Dart_GcPrologueWeakHandleCallback callback) { 1245 Dart_GcPrologueWeakHandleCallback callback) {
1244 Isolate* isolate = Isolate::Current(); 1246 Thread* thread = Thread::Current();
1245 CHECK_ISOLATE(isolate); 1247 CHECK_ISOLATE(thread->isolate());
1246 PrologueWeakVisitor visitor(isolate, callback); 1248 PrologueWeakVisitor visitor(thread, callback);
1247 isolate->VisitPrologueWeakPersistentHandles(&visitor); 1249 thread->isolate()->VisitPrologueWeakPersistentHandles(&visitor);
1248 return Api::Success(); 1250 return Api::Success();
1249 } 1251 }
1250 1252
1251 1253
1252 // --- Initialization and Globals --- 1254 // --- Initialization and Globals ---
1253 1255
1254 DART_EXPORT const char* Dart_VersionString() { 1256 DART_EXPORT const char* Dart_VersionString() {
1255 return Version::String(); 1257 return Version::String();
1256 } 1258 }
1257 1259
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 Error& malformed_type_error = Error::Handle(Z); 1896 Error& malformed_type_error = Error::Handle(Z);
1895 *value = instance.IsInstanceOf(type_obj, 1897 *value = instance.IsInstanceOf(type_obj,
1896 Object::null_type_arguments(), 1898 Object::null_type_arguments(),
1897 &malformed_type_error); 1899 &malformed_type_error);
1898 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. 1900 ASSERT(malformed_type_error.IsNull()); // Type was created from a class.
1899 return Api::Success(); 1901 return Api::Success();
1900 } 1902 }
1901 1903
1902 1904
1903 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { 1905 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) {
1904 Isolate* isolate = Isolate::Current(); 1906 Thread* thread = Thread::Current();
1905 CHECK_ISOLATE(isolate); 1907 CHECK_ISOLATE(thread->isolate());
1906 REUSABLE_OBJECT_HANDLESCOPE(isolate); 1908 REUSABLE_OBJECT_HANDLESCOPE(thread);
1907 Object& ref = isolate->ObjectHandle(); 1909 Object& ref = thread->ObjectHandle();
1908 ref = Api::UnwrapHandle(object); 1910 ref = Api::UnwrapHandle(object);
1909 return ref.IsInstance(); 1911 return ref.IsInstance();
1910 } 1912 }
1911 1913
1912 1914
1913 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { 1915 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) {
1914 TRACE_API_CALL(CURRENT_FUNC); 1916 TRACE_API_CALL(CURRENT_FUNC);
1915 return RawObject::IsNumberClassId(Api::ClassId(object)); 1917 return RawObject::IsNumberClassId(Api::ClassId(object));
1916 } 1918 }
1917 1919
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 1999
1998 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { 2000 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) {
1999 TRACE_API_CALL(CURRENT_FUNC); 2001 TRACE_API_CALL(CURRENT_FUNC);
2000 return Api::ClassId(handle) == kTypeParameterCid; 2002 return Api::ClassId(handle) == kTypeParameterCid;
2001 } 2003 }
2002 2004
2003 2005
2004 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 2006 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
2005 // We can't use a fast class index check here because there are many 2007 // We can't use a fast class index check here because there are many
2006 // different signature classes for closures. 2008 // different signature classes for closures.
2007 Isolate* isolate = Isolate::Current(); 2009 Thread* thread = Thread::Current();
2008 CHECK_ISOLATE(isolate); 2010 CHECK_ISOLATE(thread->isolate());
2009 ReusableObjectHandleScope reused_obj_handle(isolate); 2011 ReusableObjectHandleScope reused_obj_handle(thread);
2010 const Instance& closure_obj = 2012 const Instance& closure_obj =
2011 Api::UnwrapInstanceHandle(reused_obj_handle, object); 2013 Api::UnwrapInstanceHandle(reused_obj_handle, object);
2012 return (!closure_obj.IsNull() && closure_obj.IsClosure()); 2014 return (!closure_obj.IsNull() && closure_obj.IsClosure());
2013 } 2015 }
2014 2016
2015 2017
2016 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) { 2018 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) {
2017 TRACE_API_CALL(CURRENT_FUNC); 2019 TRACE_API_CALL(CURRENT_FUNC);
2018 intptr_t cid = Api::ClassId(handle); 2020 intptr_t cid = Api::ClassId(handle);
2019 return RawObject::IsTypedDataClassId(cid) || 2021 return RawObject::IsTypedDataClassId(cid) ||
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 } 2289 }
2288 *value = obj.value(); 2290 *value = obj.value();
2289 return Api::Success(); 2291 return Api::Success();
2290 } 2292 }
2291 2293
2292 2294
2293 // --- Strings --- 2295 // --- Strings ---
2294 2296
2295 2297
2296 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { 2298 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
2297 Isolate* isolate = Isolate::Current(); 2299 Thread* thread = Thread::Current();
2298 CHECK_ISOLATE(isolate); 2300 CHECK_ISOLATE(thread->isolate());
2299 ReusableObjectHandleScope reused_obj_handle(isolate); 2301 ReusableObjectHandleScope reused_obj_handle(thread);
2300 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); 2302 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str);
2301 if (str_obj.IsNull()) { 2303 if (str_obj.IsNull()) {
2302 RETURN_TYPE_ERROR(isolate, str, String); 2304 RETURN_TYPE_ERROR(thread->isolate(), str, String);
2303 } 2305 }
2304 *len = str_obj.Length(); 2306 *len = str_obj.Length();
2305 return Api::Success(); 2307 return Api::Success();
2306 } 2308 }
2307 2309
2308 2310
2309 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { 2311 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) {
2310 DARTSCOPE(Thread::Current()); 2312 DARTSCOPE(Thread::Current());
2311 if (str == NULL) { 2313 if (str == NULL) {
2312 RETURN_NULL_ERROR(str); 2314 RETURN_NULL_ERROR(str);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 for (intptr_t i = 0; i < copy_len; i++) { 2486 for (intptr_t i = 0; i < copy_len; i++) {
2485 utf16_array[i] = str_obj.CharAt(i); 2487 utf16_array[i] = str_obj.CharAt(i);
2486 } 2488 }
2487 *length = copy_len; 2489 *length = copy_len;
2488 return Api::Success(); 2490 return Api::Success();
2489 } 2491 }
2490 2492
2491 2493
2492 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, 2494 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str,
2493 intptr_t* size) { 2495 intptr_t* size) {
2494 Isolate* isolate = Isolate::Current(); 2496 Thread* thread = Thread::Current();
2495 CHECK_ISOLATE(isolate); 2497 CHECK_ISOLATE(thread->isolate());
2496 ReusableObjectHandleScope reused_obj_handle(isolate); 2498 ReusableObjectHandleScope reused_obj_handle(thread);
2497 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); 2499 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str);
2498 if (str_obj.IsNull()) { 2500 if (str_obj.IsNull()) {
2499 RETURN_TYPE_ERROR(isolate, str, String); 2501 RETURN_TYPE_ERROR(thread->isolate(), str, String);
2500 } 2502 }
2501 if (size == NULL) { 2503 if (size == NULL) {
2502 RETURN_NULL_ERROR(size); 2504 RETURN_NULL_ERROR(size);
2503 } 2505 }
2504 *size = (str_obj.Length() * str_obj.CharSize()); 2506 *size = (str_obj.Length() * str_obj.CharSize());
2505 return Api::Success(); 2507 return Api::Success();
2506 } 2508 }
2507 2509
2508 2510
2509 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, 2511 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2555 return str; 2557 return str;
2556 } 2558 }
2557 return Api::NewHandle(I, str_obj.MakeExternal(array, length, peer, cback)); 2559 return Api::NewHandle(I, str_obj.MakeExternal(array, length, peer, cback));
2558 } 2560 }
2559 2561
2560 2562
2561 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, 2563 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object,
2562 intptr_t* char_size, 2564 intptr_t* char_size,
2563 intptr_t* str_len, 2565 intptr_t* str_len,
2564 void** peer) { 2566 void** peer) {
2565 Isolate* isolate = Isolate::Current(); 2567 Thread* thread = Thread::Current();
2566 CHECK_ISOLATE(isolate); 2568 CHECK_ISOLATE(thread->isolate());
2567 ReusableObjectHandleScope reused_obj_handle(isolate); 2569 ReusableObjectHandleScope reused_obj_handle(thread);
2568 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); 2570 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object);
2569 if (str.IsNull()) { 2571 if (str.IsNull()) {
2570 RETURN_TYPE_ERROR(isolate, object, String); 2572 RETURN_TYPE_ERROR(thread->isolate(), object, String);
2571 } 2573 }
2572 if (str.IsExternal()) { 2574 if (str.IsExternal()) {
2573 *peer = str.GetPeer(); 2575 *peer = str.GetPeer();
2574 ASSERT(*peer != NULL); 2576 ASSERT(*peer != NULL);
2575 } else { 2577 } else {
2576 NoSafepointScope no_safepoint_scope; 2578 NoSafepointScope no_safepoint_scope;
2577 *peer = isolate->heap()->GetPeer(str.raw()); 2579 *peer = thread->isolate()->heap()->GetPeer(str.raw());
2578 } 2580 }
2579 *char_size = str.CharSize(); 2581 *char_size = str.CharSize();
2580 *str_len = str.Length(); 2582 *str_len = str.Length();
2581 return Api::Success(); 2583 return Api::Success();
2582 } 2584 }
2583 2585
2584 2586
2585 // --- Lists --- 2587 // --- Lists ---
2586 2588
2587 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { 2589 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) {
(...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
4582 if (cls.IsNull()) { 4584 if (cls.IsNull()) {
4583 return Api::NewError( 4585 return Api::NewError(
4584 "Unable to create native wrapper class : already exists"); 4586 "Unable to create native wrapper class : already exists");
4585 } 4587 }
4586 return Api::NewHandle(I, cls.RareType()); 4588 return Api::NewHandle(I, cls.RareType());
4587 } 4589 }
4588 4590
4589 4591
4590 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, 4592 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj,
4591 int* count) { 4593 int* count) {
4592 Isolate* isolate = Isolate::Current(); 4594 Thread* thread = Thread::Current();
4593 CHECK_ISOLATE(isolate); 4595 CHECK_ISOLATE(thread->isolate());
4594 ReusableObjectHandleScope reused_obj_handle(isolate); 4596 ReusableObjectHandleScope reused_obj_handle(thread);
4595 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); 4597 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj);
4596 if (instance.IsNull()) { 4598 if (instance.IsNull()) {
4597 RETURN_TYPE_ERROR(isolate, obj, Instance); 4599 RETURN_TYPE_ERROR(thread->isolate(), obj, Instance);
4598 } 4600 }
4599 *count = instance.NumNativeFields(); 4601 *count = instance.NumNativeFields();
4600 return Api::Success(); 4602 return Api::Success();
4601 } 4603 }
4602 4604
4603 4605
4604 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, 4606 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj,
4605 int index, 4607 int index,
4606 intptr_t* value) { 4608 intptr_t* value) {
4607 Isolate* isolate = Isolate::Current(); 4609 Thread* thread = Thread::Current();
4608 CHECK_ISOLATE(isolate); 4610 CHECK_ISOLATE(thread->isolate());
4609 ReusableObjectHandleScope reused_obj_handle(isolate); 4611 ReusableObjectHandleScope reused_obj_handle(thread);
4610 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); 4612 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj);
4611 if (instance.IsNull()) { 4613 if (instance.IsNull()) {
4612 RETURN_TYPE_ERROR(isolate, obj, Instance); 4614 RETURN_TYPE_ERROR(thread->isolate(), obj, Instance);
4613 } 4615 }
4614 if (!instance.IsValidNativeIndex(index)) { 4616 if (!instance.IsValidNativeIndex(index)) {
4615 return Api::NewError( 4617 return Api::NewError(
4616 "%s: invalid index %d passed in to access native instance field", 4618 "%s: invalid index %d passed in to access native instance field",
4617 CURRENT_FUNC, index); 4619 CURRENT_FUNC, index);
4618 } 4620 }
4619 *value = instance.GetNativeField(index); 4621 *value = instance.GetNativeField(index);
4620 return Api::Success(); 4622 return Api::Success();
4621 } 4623 }
4622 4624
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
5527 return Api::Success(); 5529 return Api::Success();
5528 } 5530 }
5529 5531
5530 5532
5531 // --- Peer support --- 5533 // --- Peer support ---
5532 5534
5533 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { 5535 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) {
5534 if (peer == NULL) { 5536 if (peer == NULL) {
5535 RETURN_NULL_ERROR(peer); 5537 RETURN_NULL_ERROR(peer);
5536 } 5538 }
5537 Isolate* isolate = Isolate::Current(); 5539 Thread* thread = Thread::Current();
5538 CHECK_ISOLATE(isolate); 5540 CHECK_ISOLATE(thread->isolate());
5539 REUSABLE_OBJECT_HANDLESCOPE(isolate); 5541 REUSABLE_OBJECT_HANDLESCOPE(thread);
5540 Object& obj = isolate->ObjectHandle(); 5542 Object& obj = thread->ObjectHandle();
5541 obj = Api::UnwrapHandle(object); 5543 obj = Api::UnwrapHandle(object);
5542 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { 5544 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) {
5543 const char* msg = 5545 const char* msg =
5544 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; 5546 "%s: argument 'object' cannot be a subtype of Null, num, or bool";
5545 return Api::NewError(msg, CURRENT_FUNC); 5547 return Api::NewError(msg, CURRENT_FUNC);
5546 } 5548 }
5547 { 5549 {
5548 NoSafepointScope no_safepoint; 5550 NoSafepointScope no_safepoint;
5549 RawObject* raw_obj = obj.raw(); 5551 RawObject* raw_obj = obj.raw();
5550 *peer = isolate->heap()->GetPeer(raw_obj); 5552 *peer = thread->isolate()->heap()->GetPeer(raw_obj);
5551 } 5553 }
5552 return Api::Success(); 5554 return Api::Success();
5553 } 5555 }
5554 5556
5555 5557
5556 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { 5558 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) {
5557 Isolate* isolate = Isolate::Current(); 5559 Thread* thread = Thread::Current();
5558 CHECK_ISOLATE(isolate); 5560 CHECK_ISOLATE(thread->isolate());
5559 REUSABLE_OBJECT_HANDLESCOPE(isolate); 5561 REUSABLE_OBJECT_HANDLESCOPE(thread);
5560 Object& obj = isolate->ObjectHandle(); 5562 Object& obj = thread->ObjectHandle();
5561 obj = Api::UnwrapHandle(object); 5563 obj = Api::UnwrapHandle(object);
5562 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { 5564 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) {
5563 const char* msg = 5565 const char* msg =
5564 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; 5566 "%s: argument 'object' cannot be a subtype of Null, num, or bool";
5565 return Api::NewError(msg, CURRENT_FUNC); 5567 return Api::NewError(msg, CURRENT_FUNC);
5566 } 5568 }
5567 { 5569 {
5568 NoSafepointScope no_safepoint; 5570 NoSafepointScope no_safepoint;
5569 RawObject* raw_obj = obj.raw(); 5571 RawObject* raw_obj = obj.raw();
5570 isolate->heap()->SetPeer(raw_obj, peer); 5572 thread->isolate()->heap()->SetPeer(raw_obj, peer);
5571 } 5573 }
5572 return Api::Success(); 5574 return Api::Success();
5573 } 5575 }
5574 5576
5575 5577
5576 // --- Service support --- 5578 // --- Service support ---
5577 5579
5578 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { 5580 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) {
5579 Isolate* iso = reinterpret_cast<Isolate*>(isolate); 5581 Isolate* iso = reinterpret_cast<Isolate*>(isolate);
5580 return ServiceIsolate::IsServiceIsolate(iso); 5582 return ServiceIsolate::IsServiceIsolate(iso);
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
6061 ApiReallocate); 6063 ApiReallocate);
6062 writer.WriteFullSnapshot(); 6064 writer.WriteFullSnapshot();
6063 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6065 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6064 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6066 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6065 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); 6067 *instructions_snapshot_size = writer.InstructionsSnapshotSize();
6066 6068
6067 return Api::Success(); 6069 return Api::Success();
6068 } 6070 }
6069 6071
6070 } // namespace dart 6072 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/gc_marker.cc » ('j') | runtime/vm/thread.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698