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

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

Issue 1436243005: Collect closure functions in isolate (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
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
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 4780 matching lines...) Expand 10 before | Expand all | Expand 10 after
7209 } 7128 }
7210 7129
7211 7130
7212 static void AddFunctionServiceId(const JSONObject& jsobj, 7131 static void AddFunctionServiceId(const JSONObject& jsobj,
7213 const Function& f, 7132 const Function& f,
7214 const Class& cls) { 7133 const Class& cls) {
7215 // Special kinds of functions use indices in their respective lists. 7134 // Special kinds of functions use indices in their respective lists.
7216 intptr_t id = -1; 7135 intptr_t id = -1;
7217 const char* selector = NULL; 7136 const char* selector = NULL;
7218 if (f.IsNonImplicitClosureFunction()) { 7137 if (f.IsNonImplicitClosureFunction()) {
7219 id = cls.FindClosureIndex(f); 7138 id = Isolate::Current()->FindClosureIndex(f);
7220 selector = "closures"; 7139 selector = "closures";
7221 } else if (f.IsImplicitClosureFunction()) { 7140 } else if (f.IsImplicitClosureFunction()) {
7222 id = cls.FindImplicitClosureFunctionIndex(f); 7141 id = cls.FindImplicitClosureFunctionIndex(f);
7223 selector = "implicit_closures"; 7142 selector = "implicit_closures";
7224 } else if (f.IsNoSuchMethodDispatcher() || f.IsInvokeFieldDispatcher()) { 7143 } else if (f.IsNoSuchMethodDispatcher() || f.IsInvokeFieldDispatcher()) {
7225 id = cls.FindInvocationDispatcherFunctionIndex(f); 7144 id = cls.FindInvocationDispatcherFunctionIndex(f);
7226 selector = "dispatchers"; 7145 selector = "dispatchers";
7227 } 7146 }
7228 if (id != -1) { 7147 if (id != -1) {
7229 ASSERT(selector != NULL); 7148 ASSERT(selector != NULL);
(...skipping 14651 matching lines...) Expand 10 before | Expand all | Expand 10 after
21881 return tag_label.ToCString(); 21800 return tag_label.ToCString();
21882 } 21801 }
21883 21802
21884 21803
21885 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21804 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21886 Instance::PrintJSONImpl(stream, ref); 21805 Instance::PrintJSONImpl(stream, ref);
21887 } 21806 }
21888 21807
21889 21808
21890 } // namespace dart 21809 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698