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 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2206 entry ^= arr.At(i); | 2206 entry ^= arr.At(i); |
2207 if (function.raw() != entry.raw()) { | 2207 if (function.raw() != entry.raw()) { |
2208 AddFunction(entry); | 2208 AddFunction(entry); |
2209 } | 2209 } |
2210 } | 2210 } |
2211 } | 2211 } |
2212 | 2212 |
2213 | 2213 |
2214 intptr_t Class::FindFunctionIndex(const Function& needle) const { | 2214 intptr_t Class::FindFunctionIndex(const Function& needle) const { |
2215 Thread* thread = Thread::Current(); | 2215 Thread* thread = Thread::Current(); |
2216 Isolate* isolate = thread->isolate(); | |
2217 if (EnsureIsFinalized(thread) != Error::null()) { | 2216 if (EnsureIsFinalized(thread) != Error::null()) { |
2218 return -1; | 2217 return -1; |
2219 } | 2218 } |
2220 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2219 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2221 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 2220 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
2222 Array& funcs = isolate->ArrayHandle(); | 2221 Array& funcs = thread->ArrayHandle(); |
2223 Function& function = isolate->FunctionHandle(); | 2222 Function& function = thread->FunctionHandle(); |
2224 funcs ^= functions(); | 2223 funcs ^= functions(); |
2225 ASSERT(!funcs.IsNull()); | 2224 ASSERT(!funcs.IsNull()); |
2226 const intptr_t len = funcs.Length(); | 2225 const intptr_t len = funcs.Length(); |
2227 for (intptr_t i = 0; i < len; i++) { | 2226 for (intptr_t i = 0; i < len; i++) { |
2228 function ^= funcs.At(i); | 2227 function ^= funcs.At(i); |
2229 if (function.raw() == needle.raw()) { | 2228 if (function.raw() == needle.raw()) { |
2230 return i; | 2229 return i; |
2231 } | 2230 } |
2232 } | 2231 } |
2233 // No function found. | 2232 // No function found. |
(...skipping 26 matching lines...) Expand all Loading... |
2260 } | 2259 } |
2261 const Function& closure_func = | 2260 const Function& closure_func = |
2262 Function::Handle(func.ImplicitClosureFunction()); | 2261 Function::Handle(func.ImplicitClosureFunction()); |
2263 ASSERT(!closure_func.IsNull()); | 2262 ASSERT(!closure_func.IsNull()); |
2264 return closure_func.raw(); | 2263 return closure_func.raw(); |
2265 } | 2264 } |
2266 | 2265 |
2267 | 2266 |
2268 intptr_t Class::FindImplicitClosureFunctionIndex(const Function& needle) const { | 2267 intptr_t Class::FindImplicitClosureFunctionIndex(const Function& needle) const { |
2269 Thread* thread = Thread::Current(); | 2268 Thread* thread = Thread::Current(); |
2270 Isolate* isolate = thread->isolate(); | |
2271 if (EnsureIsFinalized(thread) != Error::null()) { | 2269 if (EnsureIsFinalized(thread) != Error::null()) { |
2272 return -1; | 2270 return -1; |
2273 } | 2271 } |
2274 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2272 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2275 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 2273 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
2276 Array& funcs = isolate->ArrayHandle(); | 2274 Array& funcs = thread->ArrayHandle(); |
2277 Function& function = isolate->FunctionHandle(); | 2275 Function& function = thread->FunctionHandle(); |
2278 funcs ^= functions(); | 2276 funcs ^= functions(); |
2279 ASSERT(!funcs.IsNull()); | 2277 ASSERT(!funcs.IsNull()); |
2280 Function& implicit_closure = Function::Handle(isolate); | 2278 Function& implicit_closure = Function::Handle(thread->zone()); |
2281 const intptr_t len = funcs.Length(); | 2279 const intptr_t len = funcs.Length(); |
2282 for (intptr_t i = 0; i < len; i++) { | 2280 for (intptr_t i = 0; i < len; i++) { |
2283 function ^= funcs.At(i); | 2281 function ^= funcs.At(i); |
2284 implicit_closure ^= function.implicit_closure_function(); | 2282 implicit_closure ^= function.implicit_closure_function(); |
2285 if (implicit_closure.IsNull()) { | 2283 if (implicit_closure.IsNull()) { |
2286 // Skip non-implicit closure functions. | 2284 // Skip non-implicit closure functions. |
2287 continue; | 2285 continue; |
2288 } | 2286 } |
2289 if (needle.raw() == implicit_closure.raw()) { | 2287 if (needle.raw() == implicit_closure.raw()) { |
2290 return i; | 2288 return i; |
2291 } | 2289 } |
2292 } | 2290 } |
2293 // No function found. | 2291 // No function found. |
2294 return -1; | 2292 return -1; |
2295 } | 2293 } |
2296 | 2294 |
2297 | 2295 |
2298 | 2296 |
2299 intptr_t Class::FindInvocationDispatcherFunctionIndex( | 2297 intptr_t Class::FindInvocationDispatcherFunctionIndex( |
2300 const Function& needle) const { | 2298 const Function& needle) const { |
2301 Thread* thread = Thread::Current(); | 2299 Thread* thread = Thread::Current(); |
2302 Isolate* isolate = thread->isolate(); | |
2303 if (EnsureIsFinalized(thread) != Error::null()) { | 2300 if (EnsureIsFinalized(thread) != Error::null()) { |
2304 return -1; | 2301 return -1; |
2305 } | 2302 } |
2306 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2303 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2307 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 2304 REUSABLE_OBJECT_HANDLESCOPE(thread); |
2308 Array& funcs = isolate->ArrayHandle(); | 2305 Array& funcs = thread->ArrayHandle(); |
2309 Object& object = isolate->ObjectHandle(); | 2306 Object& object = thread->ObjectHandle(); |
2310 funcs ^= invocation_dispatcher_cache(); | 2307 funcs ^= invocation_dispatcher_cache(); |
2311 ASSERT(!funcs.IsNull()); | 2308 ASSERT(!funcs.IsNull()); |
2312 const intptr_t len = funcs.Length(); | 2309 const intptr_t len = funcs.Length(); |
2313 for (intptr_t i = 0; i < len; i++) { | 2310 for (intptr_t i = 0; i < len; i++) { |
2314 object = funcs.At(i); | 2311 object = funcs.At(i); |
2315 // The invocation_dispatcher_cache is a table with some entries that | 2312 // The invocation_dispatcher_cache is a table with some entries that |
2316 // are functions. | 2313 // are functions. |
2317 if (object.IsFunction()) { | 2314 if (object.IsFunction()) { |
2318 if (Function::Cast(object).raw() == needle.raw()) { | 2315 if (Function::Cast(object).raw() == needle.raw()) { |
2319 return i; | 2316 return i; |
2320 } | 2317 } |
2321 } | 2318 } |
2322 } | 2319 } |
2323 // No function found. | 2320 // No function found. |
2324 return -1; | 2321 return -1; |
2325 } | 2322 } |
2326 | 2323 |
2327 | 2324 |
2328 | 2325 |
2329 RawFunction* Class::InvocationDispatcherFunctionFromIndex(intptr_t idx) const { | 2326 RawFunction* Class::InvocationDispatcherFunctionFromIndex(intptr_t idx) const { |
2330 Isolate* isolate = Isolate::Current(); | 2327 Thread* thread = Thread::Current(); |
2331 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2328 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2332 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 2329 REUSABLE_OBJECT_HANDLESCOPE(thread); |
2333 Array& dispatcher_cache = isolate->ArrayHandle(); | 2330 Array& dispatcher_cache = thread->ArrayHandle(); |
2334 Object& object = isolate->ObjectHandle(); | 2331 Object& object = thread->ObjectHandle(); |
2335 dispatcher_cache ^= invocation_dispatcher_cache(); | 2332 dispatcher_cache ^= invocation_dispatcher_cache(); |
2336 object = dispatcher_cache.At(idx); | 2333 object = dispatcher_cache.At(idx); |
2337 if (!object.IsFunction()) { | 2334 if (!object.IsFunction()) { |
2338 return Function::null(); | 2335 return Function::null(); |
2339 } | 2336 } |
2340 return Function::Cast(object).raw(); | 2337 return Function::Cast(object).raw(); |
2341 } | 2338 } |
2342 | 2339 |
2343 | 2340 |
2344 void Class::AddClosureFunction(const Function& function) const { | 2341 void Class::AddClosureFunction(const Function& function) const { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 if (best_fit_index >= 0) { | 2376 if (best_fit_index >= 0) { |
2380 closure ^= closures.At(best_fit_index); | 2377 closure ^= closures.At(best_fit_index); |
2381 } | 2378 } |
2382 return closure.raw(); | 2379 return closure.raw(); |
2383 } | 2380 } |
2384 | 2381 |
2385 intptr_t Class::FindClosureIndex(const Function& needle) const { | 2382 intptr_t Class::FindClosureIndex(const Function& needle) const { |
2386 if (closures() == GrowableObjectArray::null()) { | 2383 if (closures() == GrowableObjectArray::null()) { |
2387 return -1; | 2384 return -1; |
2388 } | 2385 } |
2389 Isolate* isolate = Isolate::Current(); | 2386 Thread* thread = Thread::Current(); |
2390 const GrowableObjectArray& closures_array = | 2387 const GrowableObjectArray& closures_array = |
2391 GrowableObjectArray::Handle(isolate, closures()); | 2388 GrowableObjectArray::Handle(thread->zone(), closures()); |
2392 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 2389 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
2393 Function& closure = isolate->FunctionHandle(); | 2390 Function& closure = thread->FunctionHandle(); |
2394 intptr_t num_closures = closures_array.Length(); | 2391 intptr_t num_closures = closures_array.Length(); |
2395 for (intptr_t i = 0; i < num_closures; i++) { | 2392 for (intptr_t i = 0; i < num_closures; i++) { |
2396 closure ^= closures_array.At(i); | 2393 closure ^= closures_array.At(i); |
2397 ASSERT(!closure.IsNull()); | 2394 ASSERT(!closure.IsNull()); |
2398 if (closure.raw() == needle.raw()) { | 2395 if (closure.raw() == needle.raw()) { |
2399 return i; | 2396 return i; |
2400 } | 2397 } |
2401 } | 2398 } |
2402 return -1; | 2399 return -1; |
2403 } | 2400 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2437 } | 2434 } |
2438 | 2435 |
2439 | 2436 |
2440 intptr_t Class::NumTypeParameters(Thread* thread) const { | 2437 intptr_t Class::NumTypeParameters(Thread* thread) const { |
2441 if (IsMixinApplication() && !is_mixin_type_applied()) { | 2438 if (IsMixinApplication() && !is_mixin_type_applied()) { |
2442 ClassFinalizer::ApplyMixinType(*this); | 2439 ClassFinalizer::ApplyMixinType(*this); |
2443 } | 2440 } |
2444 if (type_parameters() == TypeArguments::null()) { | 2441 if (type_parameters() == TypeArguments::null()) { |
2445 return 0; | 2442 return 0; |
2446 } | 2443 } |
2447 Isolate* isolate = thread->isolate(); | 2444 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
2448 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(isolate); | 2445 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
2449 TypeArguments& type_params = isolate->TypeArgumentsHandle(); | |
2450 type_params = type_parameters(); | 2446 type_params = type_parameters(); |
2451 return type_params.Length(); | 2447 return type_params.Length(); |
2452 } | 2448 } |
2453 | 2449 |
2454 | 2450 |
2455 intptr_t Class::NumOwnTypeArguments() const { | 2451 intptr_t Class::NumOwnTypeArguments() const { |
2456 // Return cached value if already calculated. | 2452 // Return cached value if already calculated. |
2457 if (num_own_type_arguments() != kUnknownNumTypeArguments) { | 2453 if (num_own_type_arguments() != kUnknownNumTypeArguments) { |
2458 return num_own_type_arguments(); | 2454 return num_own_type_arguments(); |
2459 } | 2455 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2583 (value.IsType() && !value.IsDynamicType()) || | 2579 (value.IsType() && !value.IsDynamicType()) || |
2584 value.IsMixinAppType()); | 2580 value.IsMixinAppType()); |
2585 StorePointer(&raw_ptr()->super_type_, value.raw()); | 2581 StorePointer(&raw_ptr()->super_type_, value.raw()); |
2586 } | 2582 } |
2587 | 2583 |
2588 | 2584 |
2589 // Return a TypeParameter if the type_name is a type parameter of this class. | 2585 // Return a TypeParameter if the type_name is a type parameter of this class. |
2590 // Return null otherwise. | 2586 // Return null otherwise. |
2591 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { | 2587 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { |
2592 ASSERT(!type_name.IsNull()); | 2588 ASSERT(!type_name.IsNull()); |
2593 Isolate* isolate = Isolate::Current(); | 2589 Thread* thread = Thread::Current(); |
2594 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(isolate); | 2590 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
2595 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(isolate); | 2591 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); |
2596 REUSABLE_STRING_HANDLESCOPE(isolate); | 2592 REUSABLE_STRING_HANDLESCOPE(thread); |
2597 TypeArguments& type_params = isolate->TypeArgumentsHandle(); | 2593 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
2598 TypeParameter& type_param = isolate->TypeParameterHandle(); | 2594 TypeParameter& type_param = thread->TypeParameterHandle(); |
2599 String& type_param_name = isolate->StringHandle(); | 2595 String& type_param_name = thread->StringHandle(); |
2600 | 2596 |
2601 type_params ^= type_parameters(); | 2597 type_params ^= type_parameters(); |
2602 if (!type_params.IsNull()) { | 2598 if (!type_params.IsNull()) { |
2603 const intptr_t num_type_params = type_params.Length(); | 2599 const intptr_t num_type_params = type_params.Length(); |
2604 for (intptr_t i = 0; i < num_type_params; i++) { | 2600 for (intptr_t i = 0; i < num_type_params; i++) { |
2605 type_param ^= type_params.TypeAt(i); | 2601 type_param ^= type_params.TypeAt(i); |
2606 type_param_name = type_param.name(); | 2602 type_param_name = type_param.name(); |
2607 if (type_param_name.Equals(type_name)) { | 2603 if (type_param_name.Equals(type_name)) { |
2608 return type_param.raw(); | 2604 return type_param.raw(); |
2609 } | 2605 } |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3089 Array::Grow(arr, num_old_fields + num_new_fields, Heap::kOld)); | 3085 Array::Grow(arr, num_old_fields + num_new_fields, Heap::kOld)); |
3090 for (intptr_t i = 0; i < num_new_fields; i++) { | 3086 for (intptr_t i = 0; i < num_new_fields; i++) { |
3091 new_arr.SetAt(i + num_old_fields, *new_fields.At(i)); | 3087 new_arr.SetAt(i + num_old_fields, *new_fields.At(i)); |
3092 } | 3088 } |
3093 SetFields(new_arr); | 3089 SetFields(new_arr); |
3094 } | 3090 } |
3095 | 3091 |
3096 | 3092 |
3097 intptr_t Class::FindFieldIndex(const Field& needle) const { | 3093 intptr_t Class::FindFieldIndex(const Field& needle) const { |
3098 Thread* thread = Thread::Current(); | 3094 Thread* thread = Thread::Current(); |
3099 Isolate* isolate = thread->isolate(); | |
3100 if (EnsureIsFinalized(thread) != Error::null()) { | 3095 if (EnsureIsFinalized(thread) != Error::null()) { |
3101 return -1; | 3096 return -1; |
3102 } | 3097 } |
3103 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 3098 REUSABLE_ARRAY_HANDLESCOPE(thread); |
3104 REUSABLE_FIELD_HANDLESCOPE(isolate); | 3099 REUSABLE_FIELD_HANDLESCOPE(thread); |
3105 REUSABLE_STRING_HANDLESCOPE(isolate); | 3100 REUSABLE_STRING_HANDLESCOPE(thread); |
3106 Array& fields_array = isolate->ArrayHandle(); | 3101 Array& fields_array = thread->ArrayHandle(); |
3107 Field& field = isolate->FieldHandle(); | 3102 Field& field = thread->FieldHandle(); |
3108 String& field_name = isolate->StringHandle(); | 3103 String& field_name = thread->StringHandle(); |
3109 fields_array ^= fields(); | 3104 fields_array ^= fields(); |
3110 ASSERT(!fields_array.IsNull()); | 3105 ASSERT(!fields_array.IsNull()); |
3111 String& needle_name = String::Handle(isolate); | 3106 String& needle_name = String::Handle(thread->zone()); |
3112 needle_name ^= needle.name(); | 3107 needle_name ^= needle.name(); |
3113 const intptr_t len = fields_array.Length(); | 3108 const intptr_t len = fields_array.Length(); |
3114 for (intptr_t i = 0; i < len; i++) { | 3109 for (intptr_t i = 0; i < len; i++) { |
3115 field ^= fields_array.At(i); | 3110 field ^= fields_array.At(i); |
3116 field_name ^= field.name(); | 3111 field_name ^= field.name(); |
3117 if (field_name.Equals(needle_name)) { | 3112 if (field_name.Equals(needle_name)) { |
3118 return i; | 3113 return i; |
3119 } | 3114 } |
3120 } | 3115 } |
3121 // No field found. | 3116 // No field found. |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3704 types ^= canonical_types(); | 3699 types ^= canonical_types(); |
3705 ASSERT(!types.IsNull() && (types.Length() > 1)); | 3700 ASSERT(!types.IsNull() && (types.Length() > 1)); |
3706 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); | 3701 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); |
3707 types.SetAt(0, type); | 3702 types.SetAt(0, type); |
3708 } | 3703 } |
3709 } | 3704 } |
3710 | 3705 |
3711 | 3706 |
3712 intptr_t Class::FindCanonicalTypeIndex(const Type& needle) const { | 3707 intptr_t Class::FindCanonicalTypeIndex(const Type& needle) const { |
3713 Thread* thread = Thread::Current(); | 3708 Thread* thread = Thread::Current(); |
3714 Isolate* isolate = thread->isolate(); | |
3715 if (EnsureIsFinalized(thread) != Error::null()) { | 3709 if (EnsureIsFinalized(thread) != Error::null()) { |
3716 return -1; | 3710 return -1; |
3717 } | 3711 } |
3718 if (needle.raw() == CanonicalType()) { | 3712 if (needle.raw() == CanonicalType()) { |
3719 // For a generic type or signature type, there exists another index with the | 3713 // For a generic type or signature type, there exists another index with the |
3720 // same type. It will never be returned by this function. | 3714 // same type. It will never be returned by this function. |
3721 return 0; | 3715 return 0; |
3722 } | 3716 } |
3723 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 3717 REUSABLE_OBJECT_HANDLESCOPE(thread); |
3724 Object& types = isolate->ObjectHandle(); | 3718 Object& types = thread->ObjectHandle(); |
3725 types = canonical_types(); | 3719 types = canonical_types(); |
3726 if (types.IsNull()) { | 3720 if (types.IsNull()) { |
3727 return -1; | 3721 return -1; |
3728 } | 3722 } |
3729 const intptr_t len = Array::Cast(types).Length(); | 3723 const intptr_t len = Array::Cast(types).Length(); |
3730 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(isolate); | 3724 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread); |
3731 AbstractType& type = isolate->AbstractTypeHandle(); | 3725 AbstractType& type = thread->AbstractTypeHandle(); |
3732 for (intptr_t i = 0; i < len; i++) { | 3726 for (intptr_t i = 0; i < len; i++) { |
3733 type ^= Array::Cast(types).At(i); | 3727 type ^= Array::Cast(types).At(i); |
3734 if (needle.raw() == type.raw()) { | 3728 if (needle.raw() == type.raw()) { |
3735 return i; | 3729 return i; |
3736 } | 3730 } |
3737 } | 3731 } |
3738 // No type found. | 3732 // No type found. |
3739 return -1; | 3733 return -1; |
3740 } | 3734 } |
3741 | 3735 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4102 } | 4096 } |
4103 } else if (kind == kAny) { | 4097 } else if (kind == kAny) { |
4104 return func.raw(); | 4098 return func.raw(); |
4105 } | 4099 } |
4106 return Function::null(); | 4100 return Function::null(); |
4107 } | 4101 } |
4108 | 4102 |
4109 | 4103 |
4110 RawFunction* Class::LookupFunction(const String& name, MemberKind kind) const { | 4104 RawFunction* Class::LookupFunction(const String& name, MemberKind kind) const { |
4111 Thread* thread = Thread::Current(); | 4105 Thread* thread = Thread::Current(); |
4112 Isolate* isolate = thread->isolate(); | |
4113 if (EnsureIsFinalized(thread) != Error::null()) { | 4106 if (EnsureIsFinalized(thread) != Error::null()) { |
4114 return Function::null(); | 4107 return Function::null(); |
4115 } | 4108 } |
4116 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4109 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4117 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 4110 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
4118 Array& funcs = isolate->ArrayHandle(); | 4111 Array& funcs = thread->ArrayHandle(); |
4119 funcs ^= functions(); | 4112 funcs ^= functions(); |
4120 ASSERT(!funcs.IsNull()); | 4113 ASSERT(!funcs.IsNull()); |
4121 const intptr_t len = funcs.Length(); | 4114 const intptr_t len = funcs.Length(); |
4122 Function& function = isolate->FunctionHandle(); | 4115 Function& function = thread->FunctionHandle(); |
4123 if (len >= kFunctionLookupHashTreshold) { | 4116 if (len >= kFunctionLookupHashTreshold) { |
4124 ClassFunctionsSet set(raw_ptr()->functions_hash_table_); | 4117 ClassFunctionsSet set(raw_ptr()->functions_hash_table_); |
4125 REUSABLE_STRING_HANDLESCOPE(isolate); | 4118 REUSABLE_STRING_HANDLESCOPE(thread); |
4126 function ^= set.GetOrNull(FunctionName(name, &(isolate->StringHandle()))); | 4119 function ^= set.GetOrNull(FunctionName(name, &(thread->StringHandle()))); |
4127 // No mutations. | 4120 // No mutations. |
4128 ASSERT(set.Release().raw() == raw_ptr()->functions_hash_table_); | 4121 ASSERT(set.Release().raw() == raw_ptr()->functions_hash_table_); |
4129 return function.IsNull() ? Function::null() | 4122 return function.IsNull() ? Function::null() |
4130 : CheckFunctionType(function, kind); | 4123 : CheckFunctionType(function, kind); |
4131 } | 4124 } |
4132 if (name.IsSymbol()) { | 4125 if (name.IsSymbol()) { |
4133 // Quick Symbol compare. | 4126 // Quick Symbol compare. |
4134 NoSafepointScope no_safepoint; | 4127 NoSafepointScope no_safepoint; |
4135 for (intptr_t i = 0; i < len; i++) { | 4128 for (intptr_t i = 0; i < len; i++) { |
4136 function ^= funcs.At(i); | 4129 function ^= funcs.At(i); |
4137 if (function.name() == name.raw()) { | 4130 if (function.name() == name.raw()) { |
4138 return CheckFunctionType(function, kind); | 4131 return CheckFunctionType(function, kind); |
4139 } | 4132 } |
4140 } | 4133 } |
4141 } else { | 4134 } else { |
4142 REUSABLE_STRING_HANDLESCOPE(isolate); | 4135 REUSABLE_STRING_HANDLESCOPE(thread); |
4143 String& function_name = isolate->StringHandle(); | 4136 String& function_name = thread->StringHandle(); |
4144 for (intptr_t i = 0; i < len; i++) { | 4137 for (intptr_t i = 0; i < len; i++) { |
4145 function ^= funcs.At(i); | 4138 function ^= funcs.At(i); |
4146 function_name ^= function.name(); | 4139 function_name ^= function.name(); |
4147 if (function_name.Equals(name)) { | 4140 if (function_name.Equals(name)) { |
4148 return CheckFunctionType(function, kind); | 4141 return CheckFunctionType(function, kind); |
4149 } | 4142 } |
4150 } | 4143 } |
4151 } | 4144 } |
4152 // No function found. | 4145 // No function found. |
4153 return Function::null(); | 4146 return Function::null(); |
4154 } | 4147 } |
4155 | 4148 |
4156 | 4149 |
4157 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, | 4150 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, |
4158 MemberKind kind) const { | 4151 MemberKind kind) const { |
4159 Thread* thread = Thread::Current(); | 4152 Thread* thread = Thread::Current(); |
4160 Isolate* isolate = thread->isolate(); | |
4161 if (EnsureIsFinalized(thread) != Error::null()) { | 4153 if (EnsureIsFinalized(thread) != Error::null()) { |
4162 return Function::null(); | 4154 return Function::null(); |
4163 } | 4155 } |
4164 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4156 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4165 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 4157 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
4166 REUSABLE_STRING_HANDLESCOPE(isolate); | 4158 REUSABLE_STRING_HANDLESCOPE(thread); |
4167 Array& funcs = isolate->ArrayHandle(); | 4159 Array& funcs = thread->ArrayHandle(); |
4168 funcs ^= functions(); | 4160 funcs ^= functions(); |
4169 ASSERT(!funcs.IsNull()); | 4161 ASSERT(!funcs.IsNull()); |
4170 const intptr_t len = funcs.Length(); | 4162 const intptr_t len = funcs.Length(); |
4171 Function& function = isolate->FunctionHandle(); | 4163 Function& function = thread->FunctionHandle(); |
4172 String& function_name = isolate->StringHandle(); | 4164 String& function_name = thread->StringHandle(); |
4173 for (intptr_t i = 0; i < len; i++) { | 4165 for (intptr_t i = 0; i < len; i++) { |
4174 function ^= funcs.At(i); | 4166 function ^= funcs.At(i); |
4175 function_name ^= function.name(); | 4167 function_name ^= function.name(); |
4176 if (String::EqualsIgnoringPrivateKey(function_name, name)) { | 4168 if (String::EqualsIgnoringPrivateKey(function_name, name)) { |
4177 return CheckFunctionType(function, kind); | 4169 return CheckFunctionType(function, kind); |
4178 } | 4170 } |
4179 } | 4171 } |
4180 // No function found. | 4172 // No function found. |
4181 return Function::null(); | 4173 return Function::null(); |
4182 } | 4174 } |
4183 | 4175 |
4184 | 4176 |
4185 RawFunction* Class::LookupGetterFunction(const String& name) const { | 4177 RawFunction* Class::LookupGetterFunction(const String& name) const { |
4186 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); | 4178 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); |
4187 } | 4179 } |
4188 | 4180 |
4189 | 4181 |
4190 RawFunction* Class::LookupSetterFunction(const String& name) const { | 4182 RawFunction* Class::LookupSetterFunction(const String& name) const { |
4191 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); | 4183 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); |
4192 } | 4184 } |
4193 | 4185 |
4194 | 4186 |
4195 RawFunction* Class::LookupAccessorFunction(const char* prefix, | 4187 RawFunction* Class::LookupAccessorFunction(const char* prefix, |
4196 intptr_t prefix_length, | 4188 intptr_t prefix_length, |
4197 const String& name) const { | 4189 const String& name) const { |
4198 Thread* thread = Thread::Current(); | 4190 Thread* thread = Thread::Current(); |
4199 Isolate* isolate = thread->isolate(); | |
4200 if (EnsureIsFinalized(thread) != Error::null()) { | 4191 if (EnsureIsFinalized(thread) != Error::null()) { |
4201 return Function::null(); | 4192 return Function::null(); |
4202 } | 4193 } |
4203 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4194 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4204 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 4195 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
4205 REUSABLE_STRING_HANDLESCOPE(isolate); | 4196 REUSABLE_STRING_HANDLESCOPE(thread); |
4206 Array& funcs = isolate->ArrayHandle(); | 4197 Array& funcs = thread->ArrayHandle(); |
4207 funcs ^= functions(); | 4198 funcs ^= functions(); |
4208 intptr_t len = funcs.Length(); | 4199 intptr_t len = funcs.Length(); |
4209 Function& function = isolate->FunctionHandle(); | 4200 Function& function = thread->FunctionHandle(); |
4210 String& function_name = isolate->StringHandle(); | 4201 String& function_name = thread->StringHandle(); |
4211 for (intptr_t i = 0; i < len; i++) { | 4202 for (intptr_t i = 0; i < len; i++) { |
4212 function ^= funcs.At(i); | 4203 function ^= funcs.At(i); |
4213 function_name ^= function.name(); | 4204 function_name ^= function.name(); |
4214 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { | 4205 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { |
4215 return function.raw(); | 4206 return function.raw(); |
4216 } | 4207 } |
4217 } | 4208 } |
4218 | 4209 |
4219 // No function found. | 4210 // No function found. |
4220 return Function::null(); | 4211 return Function::null(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4258 } | 4249 } |
4259 | 4250 |
4260 | 4251 |
4261 RawField* Class::LookupField(const String& name) const { | 4252 RawField* Class::LookupField(const String& name) const { |
4262 return LookupField(name, kAny); | 4253 return LookupField(name, kAny); |
4263 } | 4254 } |
4264 | 4255 |
4265 | 4256 |
4266 RawField* Class::LookupField(const String& name, MemberKind kind) const { | 4257 RawField* Class::LookupField(const String& name, MemberKind kind) const { |
4267 Thread* thread = Thread::Current(); | 4258 Thread* thread = Thread::Current(); |
4268 Isolate* isolate = thread->isolate(); | |
4269 if (EnsureIsFinalized(thread) != Error::null()) { | 4259 if (EnsureIsFinalized(thread) != Error::null()) { |
4270 return Field::null(); | 4260 return Field::null(); |
4271 } | 4261 } |
4272 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4262 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4273 REUSABLE_FIELD_HANDLESCOPE(isolate); | 4263 REUSABLE_FIELD_HANDLESCOPE(thread); |
4274 REUSABLE_STRING_HANDLESCOPE(isolate); | 4264 REUSABLE_STRING_HANDLESCOPE(thread); |
4275 Array& flds = isolate->ArrayHandle(); | 4265 Array& flds = thread->ArrayHandle(); |
4276 flds ^= fields(); | 4266 flds ^= fields(); |
4277 ASSERT(!flds.IsNull()); | 4267 ASSERT(!flds.IsNull()); |
4278 intptr_t len = flds.Length(); | 4268 intptr_t len = flds.Length(); |
4279 Field& field = isolate->FieldHandle(); | 4269 Field& field = thread->FieldHandle(); |
4280 String& field_name = isolate->StringHandle(); | 4270 String& field_name = thread->StringHandle(); |
4281 for (intptr_t i = 0; i < len; i++) { | 4271 for (intptr_t i = 0; i < len; i++) { |
4282 field ^= flds.At(i); | 4272 field ^= flds.At(i); |
4283 field_name ^= field.name(); | 4273 field_name ^= field.name(); |
4284 if (String::EqualsIgnoringPrivateKey(field_name, name)) { | 4274 if (String::EqualsIgnoringPrivateKey(field_name, name)) { |
4285 if (kind == kInstance) { | 4275 if (kind == kInstance) { |
4286 if (!field.is_static()) { | 4276 if (!field.is_static()) { |
4287 return field.raw(); | 4277 return field.raw(); |
4288 } | 4278 } |
4289 } else if (kind == kStatic) { | 4279 } else if (kind == kStatic) { |
4290 if (field.is_static()) { | 4280 if (field.is_static()) { |
(...skipping 5207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9498 } | 9488 } |
9499 } | 9489 } |
9500 StorePointer(&raw_ptr()->exports_, exports.raw()); | 9490 StorePointer(&raw_ptr()->exports_, exports.raw()); |
9501 return obj.raw(); | 9491 return obj.raw(); |
9502 } | 9492 } |
9503 return Object::null(); | 9493 return Object::null(); |
9504 } | 9494 } |
9505 | 9495 |
9506 | 9496 |
9507 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { | 9497 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { |
9508 Isolate* isolate = Isolate::Current(); | 9498 Thread* thread = Thread::Current(); |
9509 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 9499 REUSABLE_ARRAY_HANDLESCOPE(thread); |
9510 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 9500 REUSABLE_OBJECT_HANDLESCOPE(thread); |
9511 REUSABLE_STRING_HANDLESCOPE(isolate); | 9501 REUSABLE_STRING_HANDLESCOPE(thread); |
9512 Array& dict = isolate->ArrayHandle(); | 9502 Array& dict = thread->ArrayHandle(); |
9513 dict ^= dictionary(); | 9503 dict ^= dictionary(); |
9514 intptr_t dict_size = dict.Length() - 1; | 9504 intptr_t dict_size = dict.Length() - 1; |
9515 *index = name.Hash() % dict_size; | 9505 *index = name.Hash() % dict_size; |
9516 Object& entry = isolate->ObjectHandle(); | 9506 Object& entry = thread->ObjectHandle(); |
9517 String& entry_name = isolate->StringHandle(); | 9507 String& entry_name = thread->StringHandle(); |
9518 entry = dict.At(*index); | 9508 entry = dict.At(*index); |
9519 // Search the entry in the hash set. | 9509 // Search the entry in the hash set. |
9520 while (!entry.IsNull()) { | 9510 while (!entry.IsNull()) { |
9521 entry_name = entry.DictionaryName(); | 9511 entry_name = entry.DictionaryName(); |
9522 ASSERT(!entry_name.IsNull()); | 9512 ASSERT(!entry_name.IsNull()); |
9523 if (entry_name.Equals(name)) { | 9513 if (entry_name.Equals(name)) { |
9524 return entry.raw(); | 9514 return entry.raw(); |
9525 } | 9515 } |
9526 *index = (*index + 1) % dict_size; | 9516 *index = (*index + 1) % dict_size; |
9527 entry = dict.At(*index); | 9517 entry = dict.At(*index); |
(...skipping 5185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14713 return Instance::null(); | 14703 return Instance::null(); |
14714 } | 14704 } |
14715 intptr_t instance_size = cls.instance_size(); | 14705 intptr_t instance_size = cls.instance_size(); |
14716 ASSERT(instance_size > 0); | 14706 ASSERT(instance_size > 0); |
14717 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); | 14707 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); |
14718 return reinterpret_cast<RawInstance*>(raw); | 14708 return reinterpret_cast<RawInstance*>(raw); |
14719 } | 14709 } |
14720 | 14710 |
14721 | 14711 |
14722 bool Instance::IsValidFieldOffset(intptr_t offset) const { | 14712 bool Instance::IsValidFieldOffset(intptr_t offset) const { |
14723 Isolate* isolate = Isolate::Current(); | 14713 Thread* thread = Thread::Current(); |
14724 REUSABLE_CLASS_HANDLESCOPE(isolate); | 14714 REUSABLE_CLASS_HANDLESCOPE(thread); |
14725 Class& cls = isolate->ClassHandle(); | 14715 Class& cls = thread->ClassHandle(); |
14726 cls = clazz(); | 14716 cls = clazz(); |
14727 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); | 14717 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); |
14728 } | 14718 } |
14729 | 14719 |
14730 | 14720 |
14731 intptr_t Instance::ElementSizeFor(intptr_t cid) { | 14721 intptr_t Instance::ElementSizeFor(intptr_t cid) { |
14732 if (RawObject::IsExternalTypedDataClassId(cid)) { | 14722 if (RawObject::IsExternalTypedDataClassId(cid)) { |
14733 return ExternalTypedData::ElementSizeInBytes(cid); | 14723 return ExternalTypedData::ElementSizeInBytes(cid); |
14734 } else if (RawObject::IsTypedDataClassId(cid)) { | 14724 } else if (RawObject::IsTypedDataClassId(cid)) { |
14735 return TypedData::ElementSizeInBytes(cid); | 14725 return TypedData::ElementSizeInBytes(cid); |
(...skipping 5575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20311 } else { | 20301 } else { |
20312 return Instance::Cast(a).OperatorEquals(Instance::Cast(b)); | 20302 return Instance::Cast(a).OperatorEquals(Instance::Cast(b)); |
20313 } | 20303 } |
20314 } | 20304 } |
20315 static uword Hash(const Object& obj) { | 20305 static uword Hash(const Object& obj) { |
20316 if (obj.IsNull()) { | 20306 if (obj.IsNull()) { |
20317 return 0; | 20307 return 0; |
20318 } | 20308 } |
20319 // TODO(koda): Ensure VM classes only produce Smi hash codes, and remove | 20309 // TODO(koda): Ensure VM classes only produce Smi hash codes, and remove |
20320 // non-Smi cases once Dart-side implementation is complete. | 20310 // non-Smi cases once Dart-side implementation is complete. |
20321 Isolate* isolate = Isolate::Current(); | 20311 Thread* thread = Thread::Current(); |
20322 REUSABLE_INSTANCE_HANDLESCOPE(isolate); | 20312 REUSABLE_INSTANCE_HANDLESCOPE(thread); |
20323 Instance& hash_code = isolate->InstanceHandle(); | 20313 Instance& hash_code = thread->InstanceHandle(); |
20324 hash_code ^= Instance::Cast(obj).HashCode(); | 20314 hash_code ^= Instance::Cast(obj).HashCode(); |
20325 if (hash_code.IsSmi()) { | 20315 if (hash_code.IsSmi()) { |
20326 // May waste some bits on 64-bit, to ensure consistency with non-Smi case. | 20316 // May waste some bits on 64-bit, to ensure consistency with non-Smi case. |
20327 return static_cast<uword>(Smi::Cast(hash_code).AsTruncatedUint32Value()); | 20317 return static_cast<uword>(Smi::Cast(hash_code).AsTruncatedUint32Value()); |
20328 } else if (hash_code.IsInteger()) { | 20318 } else if (hash_code.IsInteger()) { |
20329 return static_cast<uword>( | 20319 return static_cast<uword>( |
20330 Integer::Cast(hash_code).AsTruncatedUint32Value()); | 20320 Integer::Cast(hash_code).AsTruncatedUint32Value()); |
20331 } else { | 20321 } else { |
20332 return 0; | 20322 return 0; |
20333 } | 20323 } |
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21534 return tag_label.ToCString(); | 21524 return tag_label.ToCString(); |
21535 } | 21525 } |
21536 | 21526 |
21537 | 21527 |
21538 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21528 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
21539 Instance::PrintJSONImpl(stream, ref); | 21529 Instance::PrintJSONImpl(stream, ref); |
21540 } | 21530 } |
21541 | 21531 |
21542 | 21532 |
21543 } // namespace dart | 21533 } // namespace dart |
OLD | NEW |