| 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 2302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2313 if (Function::Cast(object).raw() == needle.raw()) { | 2313 if (Function::Cast(object).raw() == needle.raw()) { |
| 2314 return i; | 2314 return i; |
| 2315 } | 2315 } |
| 2316 } | 2316 } |
| 2317 } | 2317 } |
| 2318 // No function found. | 2318 // No function found. |
| 2319 return -1; | 2319 return -1; |
| 2320 } | 2320 } |
| 2321 | 2321 |
| 2322 | 2322 |
| 2323 | |
| 2324 RawFunction* Class::InvocationDispatcherFunctionFromIndex(intptr_t idx) const { | 2323 RawFunction* Class::InvocationDispatcherFunctionFromIndex(intptr_t idx) const { |
| 2325 Thread* thread = Thread::Current(); | 2324 Thread* thread = Thread::Current(); |
| 2326 REUSABLE_ARRAY_HANDLESCOPE(thread); | 2325 REUSABLE_ARRAY_HANDLESCOPE(thread); |
| 2327 REUSABLE_OBJECT_HANDLESCOPE(thread); | 2326 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 2328 Array& dispatcher_cache = thread->ArrayHandle(); | 2327 Array& dispatcher_cache = thread->ArrayHandle(); |
| 2329 Object& object = thread->ObjectHandle(); | 2328 Object& object = thread->ObjectHandle(); |
| 2330 dispatcher_cache ^= invocation_dispatcher_cache(); | 2329 dispatcher_cache ^= invocation_dispatcher_cache(); |
| 2331 object = dispatcher_cache.At(idx); | 2330 object = dispatcher_cache.At(idx); |
| 2332 if (!object.IsFunction()) { | 2331 if (!object.IsFunction()) { |
| 2333 return Function::null(); | 2332 return Function::null(); |
| 2334 } | 2333 } |
| 2335 return Function::Cast(object).raw(); | 2334 return Function::Cast(object).raw(); |
| 2336 } | 2335 } |
| 2337 | 2336 |
| 2338 | 2337 |
| 2339 void Class::set_closures(const GrowableObjectArray& value) const { | |
| 2340 StorePointer(&raw_ptr()->closure_functions_, value.raw()); | |
| 2341 } | |
| 2342 | |
| 2343 | |
| 2344 void Class::AddClosureFunction(const Function& function) const { | |
| 2345 GrowableObjectArray& closures = | |
| 2346 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); | |
| 2347 if (closures.IsNull()) { | |
| 2348 closures = GrowableObjectArray::New(4, Heap::kOld); | |
| 2349 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); | |
| 2350 } | |
| 2351 ASSERT(function.IsNonImplicitClosureFunction()); | |
| 2352 ASSERT(function.Owner() == this->raw()); | |
| 2353 closures.Add(function, Heap::kOld); | |
| 2354 } | |
| 2355 | |
| 2356 | |
| 2357 // Lookup the innermost closure function that contains token at token_pos. | |
| 2358 RawFunction* Class::LookupClosureFunction(intptr_t token_pos) const { | |
| 2359 if (raw_ptr()->closure_functions_ == GrowableObjectArray::null()) { | |
| 2360 return Function::null(); | |
| 2361 } | |
| 2362 const GrowableObjectArray& closures = | |
| 2363 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); | |
| 2364 Function& closure = Function::Handle(); | |
| 2365 intptr_t num_closures = closures.Length(); | |
| 2366 intptr_t best_fit_token_pos = -1; | |
| 2367 intptr_t best_fit_index = -1; | |
| 2368 for (intptr_t i = 0; i < num_closures; i++) { | |
| 2369 closure ^= closures.At(i); | |
| 2370 ASSERT(!closure.IsNull()); | |
| 2371 if ((closure.token_pos() <= token_pos) && | |
| 2372 (token_pos <= closure.end_token_pos()) && | |
| 2373 (best_fit_token_pos < closure.token_pos())) { | |
| 2374 best_fit_index = i; | |
| 2375 best_fit_token_pos = closure.token_pos(); | |
| 2376 } | |
| 2377 } | |
| 2378 closure = Function::null(); | |
| 2379 if (best_fit_index >= 0) { | |
| 2380 closure ^= closures.At(best_fit_index); | |
| 2381 } | |
| 2382 return closure.raw(); | |
| 2383 } | |
| 2384 | |
| 2385 intptr_t Class::FindClosureIndex(const Function& needle) const { | |
| 2386 if (closures() == GrowableObjectArray::null()) { | |
| 2387 return -1; | |
| 2388 } | |
| 2389 Thread* thread = Thread::Current(); | |
| 2390 const GrowableObjectArray& closures_array = | |
| 2391 GrowableObjectArray::Handle(thread->zone(), closures()); | |
| 2392 REUSABLE_FUNCTION_HANDLESCOPE(thread); | |
| 2393 Function& closure = thread->FunctionHandle(); | |
| 2394 intptr_t num_closures = closures_array.Length(); | |
| 2395 for (intptr_t i = 0; i < num_closures; i++) { | |
| 2396 closure ^= closures_array.At(i); | |
| 2397 ASSERT(!closure.IsNull()); | |
| 2398 if (closure.raw() == needle.raw()) { | |
| 2399 return i; | |
| 2400 } | |
| 2401 } | |
| 2402 return -1; | |
| 2403 } | |
| 2404 | |
| 2405 | |
| 2406 RawFunction* Class::ClosureFunctionFromIndex(intptr_t idx) const { | |
| 2407 const GrowableObjectArray& closures_array = | |
| 2408 GrowableObjectArray::Handle(closures()); | |
| 2409 if ((idx < 0) || (idx >= closures_array.Length())) { | |
| 2410 return Function::null(); | |
| 2411 } | |
| 2412 Function& func = Function::Handle(); | |
| 2413 func ^= closures_array.At(idx); | |
| 2414 ASSERT(!func.IsNull()); | |
| 2415 return func.raw(); | |
| 2416 } | |
| 2417 | |
| 2418 | |
| 2419 void Class::set_signature_function(const Function& value) const { | 2338 void Class::set_signature_function(const Function& value) const { |
| 2420 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 2339 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
| 2421 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 2340 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
| 2422 } | 2341 } |
| 2423 | 2342 |
| 2424 | 2343 |
| 2425 void Class::set_state_bits(intptr_t bits) const { | 2344 void Class::set_state_bits(intptr_t bits) const { |
| 2426 StoreNonPointer(&raw_ptr()->state_bits_, static_cast<uint16_t>(bits)); | 2345 StoreNonPointer(&raw_ptr()->state_bits_, static_cast<uint16_t>(bits)); |
| 2427 } | 2346 } |
| 2428 | 2347 |
| (...skipping 4835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7264 } | 7183 } |
| 7265 | 7184 |
| 7266 | 7185 |
| 7267 static void AddFunctionServiceId(const JSONObject& jsobj, | 7186 static void AddFunctionServiceId(const JSONObject& jsobj, |
| 7268 const Function& f, | 7187 const Function& f, |
| 7269 const Class& cls) { | 7188 const Class& cls) { |
| 7270 // Special kinds of functions use indices in their respective lists. | 7189 // Special kinds of functions use indices in their respective lists. |
| 7271 intptr_t id = -1; | 7190 intptr_t id = -1; |
| 7272 const char* selector = NULL; | 7191 const char* selector = NULL; |
| 7273 if (f.IsNonImplicitClosureFunction()) { | 7192 if (f.IsNonImplicitClosureFunction()) { |
| 7274 id = cls.FindClosureIndex(f); | 7193 id = Isolate::Current()->FindClosureIndex(f); |
| 7275 selector = "closures"; | 7194 selector = "closures"; |
| 7276 } else if (f.IsImplicitClosureFunction()) { | 7195 } else if (f.IsImplicitClosureFunction()) { |
| 7277 id = cls.FindImplicitClosureFunctionIndex(f); | 7196 id = cls.FindImplicitClosureFunctionIndex(f); |
| 7278 selector = "implicit_closures"; | 7197 selector = "implicit_closures"; |
| 7279 } else if (f.IsNoSuchMethodDispatcher() || f.IsInvokeFieldDispatcher()) { | 7198 } else if (f.IsNoSuchMethodDispatcher() || f.IsInvokeFieldDispatcher()) { |
| 7280 id = cls.FindInvocationDispatcherFunctionIndex(f); | 7199 id = cls.FindInvocationDispatcherFunctionIndex(f); |
| 7281 selector = "dispatchers"; | 7200 selector = "dispatchers"; |
| 7282 } | 7201 } |
| 7283 if (id != -1) { | 7202 if (id != -1) { |
| 7284 ASSERT(selector != NULL); | 7203 ASSERT(selector != NULL); |
| (...skipping 14683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21968 return tag_label.ToCString(); | 21887 return tag_label.ToCString(); |
| 21969 } | 21888 } |
| 21970 | 21889 |
| 21971 | 21890 |
| 21972 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21891 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21973 Instance::PrintJSONImpl(stream, ref); | 21892 Instance::PrintJSONImpl(stream, ref); |
| 21974 } | 21893 } |
| 21975 | 21894 |
| 21976 | 21895 |
| 21977 } // namespace dart | 21896 } // namespace dart |
| OLD | NEW |