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 2193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 entry ^= arr.At(i); | 2204 entry ^= arr.At(i); |
2205 if (function.raw() != entry.raw()) { | 2205 if (function.raw() != entry.raw()) { |
2206 AddFunction(entry); | 2206 AddFunction(entry); |
2207 } | 2207 } |
2208 } | 2208 } |
2209 } | 2209 } |
2210 | 2210 |
2211 | 2211 |
2212 intptr_t Class::FindFunctionIndex(const Function& needle) const { | 2212 intptr_t Class::FindFunctionIndex(const Function& needle) const { |
2213 Thread* thread = Thread::Current(); | 2213 Thread* thread = Thread::Current(); |
2214 Isolate* isolate = thread->isolate(); | |
2215 if (EnsureIsFinalized(thread) != Error::null()) { | 2214 if (EnsureIsFinalized(thread) != Error::null()) { |
2216 return -1; | 2215 return -1; |
2217 } | 2216 } |
2218 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2217 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2219 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 2218 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
2220 Array& funcs = isolate->ArrayHandle(); | 2219 Array& funcs = thread->ArrayHandle(); |
2221 Function& function = isolate->FunctionHandle(); | 2220 Function& function = thread->FunctionHandle(); |
2222 funcs ^= functions(); | 2221 funcs ^= functions(); |
2223 ASSERT(!funcs.IsNull()); | 2222 ASSERT(!funcs.IsNull()); |
2224 const intptr_t len = funcs.Length(); | 2223 const intptr_t len = funcs.Length(); |
2225 for (intptr_t i = 0; i < len; i++) { | 2224 for (intptr_t i = 0; i < len; i++) { |
2226 function ^= funcs.At(i); | 2225 function ^= funcs.At(i); |
2227 if (function.raw() == needle.raw()) { | 2226 if (function.raw() == needle.raw()) { |
2228 return i; | 2227 return i; |
2229 } | 2228 } |
2230 } | 2229 } |
2231 // No function found. | 2230 // No function found. |
(...skipping 26 matching lines...) Expand all Loading... |
2258 } | 2257 } |
2259 const Function& closure_func = | 2258 const Function& closure_func = |
2260 Function::Handle(func.ImplicitClosureFunction()); | 2259 Function::Handle(func.ImplicitClosureFunction()); |
2261 ASSERT(!closure_func.IsNull()); | 2260 ASSERT(!closure_func.IsNull()); |
2262 return closure_func.raw(); | 2261 return closure_func.raw(); |
2263 } | 2262 } |
2264 | 2263 |
2265 | 2264 |
2266 intptr_t Class::FindImplicitClosureFunctionIndex(const Function& needle) const { | 2265 intptr_t Class::FindImplicitClosureFunctionIndex(const Function& needle) const { |
2267 Thread* thread = Thread::Current(); | 2266 Thread* thread = Thread::Current(); |
2268 Isolate* isolate = thread->isolate(); | |
2269 if (EnsureIsFinalized(thread) != Error::null()) { | 2267 if (EnsureIsFinalized(thread) != Error::null()) { |
2270 return -1; | 2268 return -1; |
2271 } | 2269 } |
2272 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2270 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2273 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 2271 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
2274 Array& funcs = isolate->ArrayHandle(); | 2272 Array& funcs = thread->ArrayHandle(); |
2275 Function& function = isolate->FunctionHandle(); | 2273 Function& function = thread->FunctionHandle(); |
2276 funcs ^= functions(); | 2274 funcs ^= functions(); |
2277 ASSERT(!funcs.IsNull()); | 2275 ASSERT(!funcs.IsNull()); |
2278 Function& implicit_closure = Function::Handle(isolate); | 2276 Function& implicit_closure = Function::Handle(thread->zone()); |
2279 const intptr_t len = funcs.Length(); | 2277 const intptr_t len = funcs.Length(); |
2280 for (intptr_t i = 0; i < len; i++) { | 2278 for (intptr_t i = 0; i < len; i++) { |
2281 function ^= funcs.At(i); | 2279 function ^= funcs.At(i); |
2282 implicit_closure ^= function.implicit_closure_function(); | 2280 implicit_closure ^= function.implicit_closure_function(); |
2283 if (implicit_closure.IsNull()) { | 2281 if (implicit_closure.IsNull()) { |
2284 // Skip non-implicit closure functions. | 2282 // Skip non-implicit closure functions. |
2285 continue; | 2283 continue; |
2286 } | 2284 } |
2287 if (needle.raw() == implicit_closure.raw()) { | 2285 if (needle.raw() == implicit_closure.raw()) { |
2288 return i; | 2286 return i; |
2289 } | 2287 } |
2290 } | 2288 } |
2291 // No function found. | 2289 // No function found. |
2292 return -1; | 2290 return -1; |
2293 } | 2291 } |
2294 | 2292 |
2295 | 2293 |
2296 | 2294 |
2297 intptr_t Class::FindInvocationDispatcherFunctionIndex( | 2295 intptr_t Class::FindInvocationDispatcherFunctionIndex( |
2298 const Function& needle) const { | 2296 const Function& needle) const { |
2299 Thread* thread = Thread::Current(); | 2297 Thread* thread = Thread::Current(); |
2300 Isolate* isolate = thread->isolate(); | |
2301 if (EnsureIsFinalized(thread) != Error::null()) { | 2298 if (EnsureIsFinalized(thread) != Error::null()) { |
2302 return -1; | 2299 return -1; |
2303 } | 2300 } |
2304 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2301 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2305 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 2302 REUSABLE_OBJECT_HANDLESCOPE(thread); |
2306 Array& funcs = isolate->ArrayHandle(); | 2303 Array& funcs = thread->ArrayHandle(); |
2307 Object& object = isolate->ObjectHandle(); | 2304 Object& object = thread->ObjectHandle(); |
2308 funcs ^= invocation_dispatcher_cache(); | 2305 funcs ^= invocation_dispatcher_cache(); |
2309 ASSERT(!funcs.IsNull()); | 2306 ASSERT(!funcs.IsNull()); |
2310 const intptr_t len = funcs.Length(); | 2307 const intptr_t len = funcs.Length(); |
2311 for (intptr_t i = 0; i < len; i++) { | 2308 for (intptr_t i = 0; i < len; i++) { |
2312 object = funcs.At(i); | 2309 object = funcs.At(i); |
2313 // The invocation_dispatcher_cache is a table with some entries that | 2310 // The invocation_dispatcher_cache is a table with some entries that |
2314 // are functions. | 2311 // are functions. |
2315 if (object.IsFunction()) { | 2312 if (object.IsFunction()) { |
2316 if (Function::Cast(object).raw() == needle.raw()) { | 2313 if (Function::Cast(object).raw() == needle.raw()) { |
2317 return i; | 2314 return i; |
2318 } | 2315 } |
2319 } | 2316 } |
2320 } | 2317 } |
2321 // No function found. | 2318 // No function found. |
2322 return -1; | 2319 return -1; |
2323 } | 2320 } |
2324 | 2321 |
2325 | 2322 |
2326 | 2323 |
2327 RawFunction* Class::InvocationDispatcherFunctionFromIndex(intptr_t idx) const { | 2324 RawFunction* Class::InvocationDispatcherFunctionFromIndex(intptr_t idx) const { |
2328 Isolate* isolate = Isolate::Current(); | 2325 Thread* thread = Thread::Current(); |
2329 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 2326 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2330 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 2327 REUSABLE_OBJECT_HANDLESCOPE(thread); |
2331 Array& dispatcher_cache = isolate->ArrayHandle(); | 2328 Array& dispatcher_cache = thread->ArrayHandle(); |
2332 Object& object = isolate->ObjectHandle(); | 2329 Object& object = thread->ObjectHandle(); |
2333 dispatcher_cache ^= invocation_dispatcher_cache(); | 2330 dispatcher_cache ^= invocation_dispatcher_cache(); |
2334 object = dispatcher_cache.At(idx); | 2331 object = dispatcher_cache.At(idx); |
2335 if (!object.IsFunction()) { | 2332 if (!object.IsFunction()) { |
2336 return Function::null(); | 2333 return Function::null(); |
2337 } | 2334 } |
2338 return Function::Cast(object).raw(); | 2335 return Function::Cast(object).raw(); |
2339 } | 2336 } |
2340 | 2337 |
2341 | 2338 |
2342 void Class::AddClosureFunction(const Function& function) const { | 2339 void Class::AddClosureFunction(const Function& function) const { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 if (best_fit_index >= 0) { | 2374 if (best_fit_index >= 0) { |
2378 closure ^= closures.At(best_fit_index); | 2375 closure ^= closures.At(best_fit_index); |
2379 } | 2376 } |
2380 return closure.raw(); | 2377 return closure.raw(); |
2381 } | 2378 } |
2382 | 2379 |
2383 intptr_t Class::FindClosureIndex(const Function& needle) const { | 2380 intptr_t Class::FindClosureIndex(const Function& needle) const { |
2384 if (closures() == GrowableObjectArray::null()) { | 2381 if (closures() == GrowableObjectArray::null()) { |
2385 return -1; | 2382 return -1; |
2386 } | 2383 } |
2387 Isolate* isolate = Isolate::Current(); | 2384 Thread* thread = Thread::Current(); |
2388 const GrowableObjectArray& closures_array = | 2385 const GrowableObjectArray& closures_array = |
2389 GrowableObjectArray::Handle(isolate, closures()); | 2386 GrowableObjectArray::Handle(thread->zone(), closures()); |
2390 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 2387 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
2391 Function& closure = isolate->FunctionHandle(); | 2388 Function& closure = thread->FunctionHandle(); |
2392 intptr_t num_closures = closures_array.Length(); | 2389 intptr_t num_closures = closures_array.Length(); |
2393 for (intptr_t i = 0; i < num_closures; i++) { | 2390 for (intptr_t i = 0; i < num_closures; i++) { |
2394 closure ^= closures_array.At(i); | 2391 closure ^= closures_array.At(i); |
2395 ASSERT(!closure.IsNull()); | 2392 ASSERT(!closure.IsNull()); |
2396 if (closure.raw() == needle.raw()) { | 2393 if (closure.raw() == needle.raw()) { |
2397 return i; | 2394 return i; |
2398 } | 2395 } |
2399 } | 2396 } |
2400 return -1; | 2397 return -1; |
2401 } | 2398 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2435 } | 2432 } |
2436 | 2433 |
2437 | 2434 |
2438 intptr_t Class::NumTypeParameters(Thread* thread) const { | 2435 intptr_t Class::NumTypeParameters(Thread* thread) const { |
2439 if (IsMixinApplication() && !is_mixin_type_applied()) { | 2436 if (IsMixinApplication() && !is_mixin_type_applied()) { |
2440 ClassFinalizer::ApplyMixinType(*this); | 2437 ClassFinalizer::ApplyMixinType(*this); |
2441 } | 2438 } |
2442 if (type_parameters() == TypeArguments::null()) { | 2439 if (type_parameters() == TypeArguments::null()) { |
2443 return 0; | 2440 return 0; |
2444 } | 2441 } |
2445 Isolate* isolate = thread->isolate(); | 2442 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
2446 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(isolate); | 2443 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
2447 TypeArguments& type_params = isolate->TypeArgumentsHandle(); | |
2448 type_params = type_parameters(); | 2444 type_params = type_parameters(); |
2449 return type_params.Length(); | 2445 return type_params.Length(); |
2450 } | 2446 } |
2451 | 2447 |
2452 | 2448 |
2453 intptr_t Class::NumOwnTypeArguments() const { | 2449 intptr_t Class::NumOwnTypeArguments() const { |
2454 // Return cached value if already calculated. | 2450 // Return cached value if already calculated. |
2455 if (num_own_type_arguments() != kUnknownNumTypeArguments) { | 2451 if (num_own_type_arguments() != kUnknownNumTypeArguments) { |
2456 return num_own_type_arguments(); | 2452 return num_own_type_arguments(); |
2457 } | 2453 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2581 (value.IsType() && !value.IsDynamicType()) || | 2577 (value.IsType() && !value.IsDynamicType()) || |
2582 value.IsMixinAppType()); | 2578 value.IsMixinAppType()); |
2583 StorePointer(&raw_ptr()->super_type_, value.raw()); | 2579 StorePointer(&raw_ptr()->super_type_, value.raw()); |
2584 } | 2580 } |
2585 | 2581 |
2586 | 2582 |
2587 // Return a TypeParameter if the type_name is a type parameter of this class. | 2583 // Return a TypeParameter if the type_name is a type parameter of this class. |
2588 // Return null otherwise. | 2584 // Return null otherwise. |
2589 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { | 2585 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { |
2590 ASSERT(!type_name.IsNull()); | 2586 ASSERT(!type_name.IsNull()); |
2591 Isolate* isolate = Isolate::Current(); | 2587 Thread* thread = Thread::Current(); |
2592 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(isolate); | 2588 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
2593 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(isolate); | 2589 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); |
2594 REUSABLE_STRING_HANDLESCOPE(isolate); | 2590 REUSABLE_STRING_HANDLESCOPE(thread); |
2595 TypeArguments& type_params = isolate->TypeArgumentsHandle(); | 2591 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
2596 TypeParameter& type_param = isolate->TypeParameterHandle(); | 2592 TypeParameter& type_param = thread->TypeParameterHandle(); |
2597 String& type_param_name = isolate->StringHandle(); | 2593 String& type_param_name = thread->StringHandle(); |
2598 | 2594 |
2599 type_params ^= type_parameters(); | 2595 type_params ^= type_parameters(); |
2600 if (!type_params.IsNull()) { | 2596 if (!type_params.IsNull()) { |
2601 const intptr_t num_type_params = type_params.Length(); | 2597 const intptr_t num_type_params = type_params.Length(); |
2602 for (intptr_t i = 0; i < num_type_params; i++) { | 2598 for (intptr_t i = 0; i < num_type_params; i++) { |
2603 type_param ^= type_params.TypeAt(i); | 2599 type_param ^= type_params.TypeAt(i); |
2604 type_param_name = type_param.name(); | 2600 type_param_name = type_param.name(); |
2605 if (type_param_name.Equals(type_name)) { | 2601 if (type_param_name.Equals(type_name)) { |
2606 return type_param.raw(); | 2602 return type_param.raw(); |
2607 } | 2603 } |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3086 Array::Grow(arr, num_old_fields + num_new_fields, Heap::kOld)); | 3082 Array::Grow(arr, num_old_fields + num_new_fields, Heap::kOld)); |
3087 for (intptr_t i = 0; i < num_new_fields; i++) { | 3083 for (intptr_t i = 0; i < num_new_fields; i++) { |
3088 new_arr.SetAt(i + num_old_fields, *new_fields.At(i)); | 3084 new_arr.SetAt(i + num_old_fields, *new_fields.At(i)); |
3089 } | 3085 } |
3090 SetFields(new_arr); | 3086 SetFields(new_arr); |
3091 } | 3087 } |
3092 | 3088 |
3093 | 3089 |
3094 intptr_t Class::FindFieldIndex(const Field& needle) const { | 3090 intptr_t Class::FindFieldIndex(const Field& needle) const { |
3095 Thread* thread = Thread::Current(); | 3091 Thread* thread = Thread::Current(); |
3096 Isolate* isolate = thread->isolate(); | |
3097 if (EnsureIsFinalized(thread) != Error::null()) { | 3092 if (EnsureIsFinalized(thread) != Error::null()) { |
3098 return -1; | 3093 return -1; |
3099 } | 3094 } |
3100 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 3095 REUSABLE_ARRAY_HANDLESCOPE(thread); |
3101 REUSABLE_FIELD_HANDLESCOPE(isolate); | 3096 REUSABLE_FIELD_HANDLESCOPE(thread); |
3102 REUSABLE_STRING_HANDLESCOPE(isolate); | 3097 REUSABLE_STRING_HANDLESCOPE(thread); |
3103 Array& fields_array = isolate->ArrayHandle(); | 3098 Array& fields_array = thread->ArrayHandle(); |
3104 Field& field = isolate->FieldHandle(); | 3099 Field& field = thread->FieldHandle(); |
3105 String& field_name = isolate->StringHandle(); | 3100 String& field_name = thread->StringHandle(); |
3106 fields_array ^= fields(); | 3101 fields_array ^= fields(); |
3107 ASSERT(!fields_array.IsNull()); | 3102 ASSERT(!fields_array.IsNull()); |
3108 String& needle_name = String::Handle(isolate); | 3103 String& needle_name = String::Handle(thread->zone()); |
3109 needle_name ^= needle.name(); | 3104 needle_name ^= needle.name(); |
3110 const intptr_t len = fields_array.Length(); | 3105 const intptr_t len = fields_array.Length(); |
3111 for (intptr_t i = 0; i < len; i++) { | 3106 for (intptr_t i = 0; i < len; i++) { |
3112 field ^= fields_array.At(i); | 3107 field ^= fields_array.At(i); |
3113 field_name ^= field.name(); | 3108 field_name ^= field.name(); |
3114 if (field_name.Equals(needle_name)) { | 3109 if (field_name.Equals(needle_name)) { |
3115 return i; | 3110 return i; |
3116 } | 3111 } |
3117 } | 3112 } |
3118 // No field found. | 3113 // No field found. |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3701 types ^= canonical_types(); | 3696 types ^= canonical_types(); |
3702 ASSERT(!types.IsNull() && (types.Length() > 1)); | 3697 ASSERT(!types.IsNull() && (types.Length() > 1)); |
3703 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); | 3698 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); |
3704 types.SetAt(0, type); | 3699 types.SetAt(0, type); |
3705 } | 3700 } |
3706 } | 3701 } |
3707 | 3702 |
3708 | 3703 |
3709 intptr_t Class::FindCanonicalTypeIndex(const Type& needle) const { | 3704 intptr_t Class::FindCanonicalTypeIndex(const Type& needle) const { |
3710 Thread* thread = Thread::Current(); | 3705 Thread* thread = Thread::Current(); |
3711 Isolate* isolate = thread->isolate(); | |
3712 if (EnsureIsFinalized(thread) != Error::null()) { | 3706 if (EnsureIsFinalized(thread) != Error::null()) { |
3713 return -1; | 3707 return -1; |
3714 } | 3708 } |
3715 if (needle.raw() == CanonicalType()) { | 3709 if (needle.raw() == CanonicalType()) { |
3716 // For a generic type or signature type, there exists another index with the | 3710 // For a generic type or signature type, there exists another index with the |
3717 // same type. It will never be returned by this function. | 3711 // same type. It will never be returned by this function. |
3718 return 0; | 3712 return 0; |
3719 } | 3713 } |
3720 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 3714 REUSABLE_OBJECT_HANDLESCOPE(thread); |
3721 Object& types = isolate->ObjectHandle(); | 3715 Object& types = thread->ObjectHandle(); |
3722 types = canonical_types(); | 3716 types = canonical_types(); |
3723 if (types.IsNull()) { | 3717 if (types.IsNull()) { |
3724 return -1; | 3718 return -1; |
3725 } | 3719 } |
3726 const intptr_t len = Array::Cast(types).Length(); | 3720 const intptr_t len = Array::Cast(types).Length(); |
3727 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(isolate); | 3721 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread); |
3728 AbstractType& type = isolate->AbstractTypeHandle(); | 3722 AbstractType& type = thread->AbstractTypeHandle(); |
3729 for (intptr_t i = 0; i < len; i++) { | 3723 for (intptr_t i = 0; i < len; i++) { |
3730 type ^= Array::Cast(types).At(i); | 3724 type ^= Array::Cast(types).At(i); |
3731 if (needle.raw() == type.raw()) { | 3725 if (needle.raw() == type.raw()) { |
3732 return i; | 3726 return i; |
3733 } | 3727 } |
3734 } | 3728 } |
3735 // No type found. | 3729 // No type found. |
3736 return -1; | 3730 return -1; |
3737 } | 3731 } |
3738 | 3732 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4099 } | 4093 } |
4100 } else if (kind == kAny) { | 4094 } else if (kind == kAny) { |
4101 return func.raw(); | 4095 return func.raw(); |
4102 } | 4096 } |
4103 return Function::null(); | 4097 return Function::null(); |
4104 } | 4098 } |
4105 | 4099 |
4106 | 4100 |
4107 RawFunction* Class::LookupFunction(const String& name, MemberKind kind) const { | 4101 RawFunction* Class::LookupFunction(const String& name, MemberKind kind) const { |
4108 Thread* thread = Thread::Current(); | 4102 Thread* thread = Thread::Current(); |
4109 Isolate* isolate = thread->isolate(); | |
4110 if (EnsureIsFinalized(thread) != Error::null()) { | 4103 if (EnsureIsFinalized(thread) != Error::null()) { |
4111 return Function::null(); | 4104 return Function::null(); |
4112 } | 4105 } |
4113 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4106 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4114 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 4107 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
4115 Array& funcs = isolate->ArrayHandle(); | 4108 Array& funcs = thread->ArrayHandle(); |
4116 funcs ^= functions(); | 4109 funcs ^= functions(); |
4117 ASSERT(!funcs.IsNull()); | 4110 ASSERT(!funcs.IsNull()); |
4118 const intptr_t len = funcs.Length(); | 4111 const intptr_t len = funcs.Length(); |
4119 Function& function = isolate->FunctionHandle(); | 4112 Function& function = thread->FunctionHandle(); |
4120 if (len >= kFunctionLookupHashTreshold) { | 4113 if (len >= kFunctionLookupHashTreshold) { |
4121 ClassFunctionsSet set(raw_ptr()->functions_hash_table_); | 4114 ClassFunctionsSet set(raw_ptr()->functions_hash_table_); |
4122 REUSABLE_STRING_HANDLESCOPE(isolate); | 4115 REUSABLE_STRING_HANDLESCOPE(thread); |
4123 function ^= set.GetOrNull(FunctionName(name, &(isolate->StringHandle()))); | 4116 function ^= set.GetOrNull(FunctionName(name, &(thread->StringHandle()))); |
4124 // No mutations. | 4117 // No mutations. |
4125 ASSERT(set.Release().raw() == raw_ptr()->functions_hash_table_); | 4118 ASSERT(set.Release().raw() == raw_ptr()->functions_hash_table_); |
4126 return function.IsNull() ? Function::null() | 4119 return function.IsNull() ? Function::null() |
4127 : CheckFunctionType(function, kind); | 4120 : CheckFunctionType(function, kind); |
4128 } | 4121 } |
4129 if (name.IsSymbol()) { | 4122 if (name.IsSymbol()) { |
4130 // Quick Symbol compare. | 4123 // Quick Symbol compare. |
4131 NoSafepointScope no_safepoint; | 4124 NoSafepointScope no_safepoint; |
4132 for (intptr_t i = 0; i < len; i++) { | 4125 for (intptr_t i = 0; i < len; i++) { |
4133 function ^= funcs.At(i); | 4126 function ^= funcs.At(i); |
4134 if (function.name() == name.raw()) { | 4127 if (function.name() == name.raw()) { |
4135 return CheckFunctionType(function, kind); | 4128 return CheckFunctionType(function, kind); |
4136 } | 4129 } |
4137 } | 4130 } |
4138 } else { | 4131 } else { |
4139 REUSABLE_STRING_HANDLESCOPE(isolate); | 4132 REUSABLE_STRING_HANDLESCOPE(thread); |
4140 String& function_name = isolate->StringHandle(); | 4133 String& function_name = thread->StringHandle(); |
4141 for (intptr_t i = 0; i < len; i++) { | 4134 for (intptr_t i = 0; i < len; i++) { |
4142 function ^= funcs.At(i); | 4135 function ^= funcs.At(i); |
4143 function_name ^= function.name(); | 4136 function_name ^= function.name(); |
4144 if (function_name.Equals(name)) { | 4137 if (function_name.Equals(name)) { |
4145 return CheckFunctionType(function, kind); | 4138 return CheckFunctionType(function, kind); |
4146 } | 4139 } |
4147 } | 4140 } |
4148 } | 4141 } |
4149 // No function found. | 4142 // No function found. |
4150 return Function::null(); | 4143 return Function::null(); |
4151 } | 4144 } |
4152 | 4145 |
4153 | 4146 |
4154 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, | 4147 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, |
4155 MemberKind kind) const { | 4148 MemberKind kind) const { |
4156 Thread* thread = Thread::Current(); | 4149 Thread* thread = Thread::Current(); |
4157 Isolate* isolate = thread->isolate(); | |
4158 if (EnsureIsFinalized(thread) != Error::null()) { | 4150 if (EnsureIsFinalized(thread) != Error::null()) { |
4159 return Function::null(); | 4151 return Function::null(); |
4160 } | 4152 } |
4161 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4153 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4162 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 4154 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
4163 REUSABLE_STRING_HANDLESCOPE(isolate); | 4155 REUSABLE_STRING_HANDLESCOPE(thread); |
4164 Array& funcs = isolate->ArrayHandle(); | 4156 Array& funcs = thread->ArrayHandle(); |
4165 funcs ^= functions(); | 4157 funcs ^= functions(); |
4166 ASSERT(!funcs.IsNull()); | 4158 ASSERT(!funcs.IsNull()); |
4167 const intptr_t len = funcs.Length(); | 4159 const intptr_t len = funcs.Length(); |
4168 Function& function = isolate->FunctionHandle(); | 4160 Function& function = thread->FunctionHandle(); |
4169 String& function_name = isolate->StringHandle(); | 4161 String& function_name = thread->StringHandle(); |
4170 for (intptr_t i = 0; i < len; i++) { | 4162 for (intptr_t i = 0; i < len; i++) { |
4171 function ^= funcs.At(i); | 4163 function ^= funcs.At(i); |
4172 function_name ^= function.name(); | 4164 function_name ^= function.name(); |
4173 if (String::EqualsIgnoringPrivateKey(function_name, name)) { | 4165 if (String::EqualsIgnoringPrivateKey(function_name, name)) { |
4174 return CheckFunctionType(function, kind); | 4166 return CheckFunctionType(function, kind); |
4175 } | 4167 } |
4176 } | 4168 } |
4177 // No function found. | 4169 // No function found. |
4178 return Function::null(); | 4170 return Function::null(); |
4179 } | 4171 } |
4180 | 4172 |
4181 | 4173 |
4182 RawFunction* Class::LookupGetterFunction(const String& name) const { | 4174 RawFunction* Class::LookupGetterFunction(const String& name) const { |
4183 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); | 4175 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); |
4184 } | 4176 } |
4185 | 4177 |
4186 | 4178 |
4187 RawFunction* Class::LookupSetterFunction(const String& name) const { | 4179 RawFunction* Class::LookupSetterFunction(const String& name) const { |
4188 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); | 4180 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); |
4189 } | 4181 } |
4190 | 4182 |
4191 | 4183 |
4192 RawFunction* Class::LookupAccessorFunction(const char* prefix, | 4184 RawFunction* Class::LookupAccessorFunction(const char* prefix, |
4193 intptr_t prefix_length, | 4185 intptr_t prefix_length, |
4194 const String& name) const { | 4186 const String& name) const { |
4195 Thread* thread = Thread::Current(); | 4187 Thread* thread = Thread::Current(); |
4196 Isolate* isolate = thread->isolate(); | |
4197 if (EnsureIsFinalized(thread) != Error::null()) { | 4188 if (EnsureIsFinalized(thread) != Error::null()) { |
4198 return Function::null(); | 4189 return Function::null(); |
4199 } | 4190 } |
4200 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4191 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4201 REUSABLE_FUNCTION_HANDLESCOPE(isolate); | 4192 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
4202 REUSABLE_STRING_HANDLESCOPE(isolate); | 4193 REUSABLE_STRING_HANDLESCOPE(thread); |
4203 Array& funcs = isolate->ArrayHandle(); | 4194 Array& funcs = thread->ArrayHandle(); |
4204 funcs ^= functions(); | 4195 funcs ^= functions(); |
4205 intptr_t len = funcs.Length(); | 4196 intptr_t len = funcs.Length(); |
4206 Function& function = isolate->FunctionHandle(); | 4197 Function& function = thread->FunctionHandle(); |
4207 String& function_name = isolate->StringHandle(); | 4198 String& function_name = thread->StringHandle(); |
4208 for (intptr_t i = 0; i < len; i++) { | 4199 for (intptr_t i = 0; i < len; i++) { |
4209 function ^= funcs.At(i); | 4200 function ^= funcs.At(i); |
4210 function_name ^= function.name(); | 4201 function_name ^= function.name(); |
4211 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { | 4202 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { |
4212 return function.raw(); | 4203 return function.raw(); |
4213 } | 4204 } |
4214 } | 4205 } |
4215 | 4206 |
4216 // No function found. | 4207 // No function found. |
4217 return Function::null(); | 4208 return Function::null(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4255 } | 4246 } |
4256 | 4247 |
4257 | 4248 |
4258 RawField* Class::LookupField(const String& name) const { | 4249 RawField* Class::LookupField(const String& name) const { |
4259 return LookupField(name, kAny); | 4250 return LookupField(name, kAny); |
4260 } | 4251 } |
4261 | 4252 |
4262 | 4253 |
4263 RawField* Class::LookupField(const String& name, MemberKind kind) const { | 4254 RawField* Class::LookupField(const String& name, MemberKind kind) const { |
4264 Thread* thread = Thread::Current(); | 4255 Thread* thread = Thread::Current(); |
4265 Isolate* isolate = thread->isolate(); | |
4266 if (EnsureIsFinalized(thread) != Error::null()) { | 4256 if (EnsureIsFinalized(thread) != Error::null()) { |
4267 return Field::null(); | 4257 return Field::null(); |
4268 } | 4258 } |
4269 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 4259 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4270 REUSABLE_FIELD_HANDLESCOPE(isolate); | 4260 REUSABLE_FIELD_HANDLESCOPE(thread); |
4271 REUSABLE_STRING_HANDLESCOPE(isolate); | 4261 REUSABLE_STRING_HANDLESCOPE(thread); |
4272 Array& flds = isolate->ArrayHandle(); | 4262 Array& flds = thread->ArrayHandle(); |
4273 flds ^= fields(); | 4263 flds ^= fields(); |
4274 ASSERT(!flds.IsNull()); | 4264 ASSERT(!flds.IsNull()); |
4275 intptr_t len = flds.Length(); | 4265 intptr_t len = flds.Length(); |
4276 Field& field = isolate->FieldHandle(); | 4266 Field& field = thread->FieldHandle(); |
4277 String& field_name = isolate->StringHandle(); | 4267 String& field_name = thread->StringHandle(); |
4278 for (intptr_t i = 0; i < len; i++) { | 4268 for (intptr_t i = 0; i < len; i++) { |
4279 field ^= flds.At(i); | 4269 field ^= flds.At(i); |
4280 field_name ^= field.name(); | 4270 field_name ^= field.name(); |
4281 if (String::EqualsIgnoringPrivateKey(field_name, name)) { | 4271 if (String::EqualsIgnoringPrivateKey(field_name, name)) { |
4282 if (kind == kInstance) { | 4272 if (kind == kInstance) { |
4283 if (!field.is_static()) { | 4273 if (!field.is_static()) { |
4284 return field.raw(); | 4274 return field.raw(); |
4285 } | 4275 } |
4286 } else if (kind == kStatic) { | 4276 } else if (kind == kStatic) { |
4287 if (field.is_static()) { | 4277 if (field.is_static()) { |
(...skipping 5207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9495 } | 9485 } |
9496 } | 9486 } |
9497 StorePointer(&raw_ptr()->exports_, exports.raw()); | 9487 StorePointer(&raw_ptr()->exports_, exports.raw()); |
9498 return obj.raw(); | 9488 return obj.raw(); |
9499 } | 9489 } |
9500 return Object::null(); | 9490 return Object::null(); |
9501 } | 9491 } |
9502 | 9492 |
9503 | 9493 |
9504 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { | 9494 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { |
9505 Isolate* isolate = Isolate::Current(); | 9495 Thread* thread = Thread::Current(); |
9506 REUSABLE_ARRAY_HANDLESCOPE(isolate); | 9496 REUSABLE_ARRAY_HANDLESCOPE(thread); |
9507 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 9497 REUSABLE_OBJECT_HANDLESCOPE(thread); |
9508 REUSABLE_STRING_HANDLESCOPE(isolate); | 9498 REUSABLE_STRING_HANDLESCOPE(thread); |
9509 Array& dict = isolate->ArrayHandle(); | 9499 Array& dict = thread->ArrayHandle(); |
9510 dict ^= dictionary(); | 9500 dict ^= dictionary(); |
9511 intptr_t dict_size = dict.Length() - 1; | 9501 intptr_t dict_size = dict.Length() - 1; |
9512 *index = name.Hash() % dict_size; | 9502 *index = name.Hash() % dict_size; |
9513 Object& entry = isolate->ObjectHandle(); | 9503 Object& entry = thread->ObjectHandle(); |
9514 String& entry_name = isolate->StringHandle(); | 9504 String& entry_name = thread->StringHandle(); |
9515 entry = dict.At(*index); | 9505 entry = dict.At(*index); |
9516 // Search the entry in the hash set. | 9506 // Search the entry in the hash set. |
9517 while (!entry.IsNull()) { | 9507 while (!entry.IsNull()) { |
9518 entry_name = entry.DictionaryName(); | 9508 entry_name = entry.DictionaryName(); |
9519 ASSERT(!entry_name.IsNull()); | 9509 ASSERT(!entry_name.IsNull()); |
9520 if (entry_name.Equals(name)) { | 9510 if (entry_name.Equals(name)) { |
9521 return entry.raw(); | 9511 return entry.raw(); |
9522 } | 9512 } |
9523 *index = (*index + 1) % dict_size; | 9513 *index = (*index + 1) % dict_size; |
9524 entry = dict.At(*index); | 9514 entry = dict.At(*index); |
(...skipping 5163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14688 return Instance::null(); | 14678 return Instance::null(); |
14689 } | 14679 } |
14690 intptr_t instance_size = cls.instance_size(); | 14680 intptr_t instance_size = cls.instance_size(); |
14691 ASSERT(instance_size > 0); | 14681 ASSERT(instance_size > 0); |
14692 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); | 14682 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); |
14693 return reinterpret_cast<RawInstance*>(raw); | 14683 return reinterpret_cast<RawInstance*>(raw); |
14694 } | 14684 } |
14695 | 14685 |
14696 | 14686 |
14697 bool Instance::IsValidFieldOffset(intptr_t offset) const { | 14687 bool Instance::IsValidFieldOffset(intptr_t offset) const { |
14698 Isolate* isolate = Isolate::Current(); | 14688 Thread* thread = Thread::Current(); |
14699 REUSABLE_CLASS_HANDLESCOPE(isolate); | 14689 REUSABLE_CLASS_HANDLESCOPE(thread); |
14700 Class& cls = isolate->ClassHandle(); | 14690 Class& cls = thread->ClassHandle(); |
14701 cls = clazz(); | 14691 cls = clazz(); |
14702 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); | 14692 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); |
14703 } | 14693 } |
14704 | 14694 |
14705 | 14695 |
14706 intptr_t Instance::ElementSizeFor(intptr_t cid) { | 14696 intptr_t Instance::ElementSizeFor(intptr_t cid) { |
14707 if (RawObject::IsExternalTypedDataClassId(cid)) { | 14697 if (RawObject::IsExternalTypedDataClassId(cid)) { |
14708 return ExternalTypedData::ElementSizeInBytes(cid); | 14698 return ExternalTypedData::ElementSizeInBytes(cid); |
14709 } else if (RawObject::IsTypedDataClassId(cid)) { | 14699 } else if (RawObject::IsTypedDataClassId(cid)) { |
14710 return TypedData::ElementSizeInBytes(cid); | 14700 return TypedData::ElementSizeInBytes(cid); |
(...skipping 5575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20286 } else { | 20276 } else { |
20287 return Instance::Cast(a).OperatorEquals(Instance::Cast(b)); | 20277 return Instance::Cast(a).OperatorEquals(Instance::Cast(b)); |
20288 } | 20278 } |
20289 } | 20279 } |
20290 static uword Hash(const Object& obj) { | 20280 static uword Hash(const Object& obj) { |
20291 if (obj.IsNull()) { | 20281 if (obj.IsNull()) { |
20292 return 0; | 20282 return 0; |
20293 } | 20283 } |
20294 // TODO(koda): Ensure VM classes only produce Smi hash codes, and remove | 20284 // TODO(koda): Ensure VM classes only produce Smi hash codes, and remove |
20295 // non-Smi cases once Dart-side implementation is complete. | 20285 // non-Smi cases once Dart-side implementation is complete. |
20296 Isolate* isolate = Isolate::Current(); | 20286 Thread* thread = Thread::Current(); |
20297 REUSABLE_INSTANCE_HANDLESCOPE(isolate); | 20287 REUSABLE_INSTANCE_HANDLESCOPE(thread); |
20298 Instance& hash_code = isolate->InstanceHandle(); | 20288 Instance& hash_code = thread->InstanceHandle(); |
20299 hash_code ^= Instance::Cast(obj).HashCode(); | 20289 hash_code ^= Instance::Cast(obj).HashCode(); |
20300 if (hash_code.IsSmi()) { | 20290 if (hash_code.IsSmi()) { |
20301 // May waste some bits on 64-bit, to ensure consistency with non-Smi case. | 20291 // May waste some bits on 64-bit, to ensure consistency with non-Smi case. |
20302 return static_cast<uword>(Smi::Cast(hash_code).AsTruncatedUint32Value()); | 20292 return static_cast<uword>(Smi::Cast(hash_code).AsTruncatedUint32Value()); |
20303 } else if (hash_code.IsInteger()) { | 20293 } else if (hash_code.IsInteger()) { |
20304 return static_cast<uword>( | 20294 return static_cast<uword>( |
20305 Integer::Cast(hash_code).AsTruncatedUint32Value()); | 20295 Integer::Cast(hash_code).AsTruncatedUint32Value()); |
20306 } else { | 20296 } else { |
20307 return 0; | 20297 return 0; |
20308 } | 20298 } |
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21509 return tag_label.ToCString(); | 21499 return tag_label.ToCString(); |
21510 } | 21500 } |
21511 | 21501 |
21512 | 21502 |
21513 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21503 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
21514 Instance::PrintJSONImpl(stream, ref); | 21504 Instance::PrintJSONImpl(stream, ref); |
21515 } | 21505 } |
21516 | 21506 |
21517 | 21507 |
21518 } // namespace dart | 21508 } // namespace dart |
OLD | NEW |