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

Side by Side Diff: runtime/vm/isolate.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
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »
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 "vm/isolate.h" 5 #include "vm/isolate.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 if ((*a)->usage_counter() > (*b)->usage_counter()) { 1510 if ((*a)->usage_counter() > (*b)->usage_counter()) {
1511 return -1; 1511 return -1;
1512 } else if ((*a)->usage_counter() < (*b)->usage_counter()) { 1512 } else if ((*a)->usage_counter() < (*b)->usage_counter()) {
1513 return 1; 1513 return 1;
1514 } else { 1514 } else {
1515 return 0; 1515 return 0;
1516 } 1516 }
1517 } 1517 }
1518 1518
1519 1519
1520 void Isolate::AddClosureFunction(const Function& function) const {
1521 GrowableObjectArray& closures =
1522 GrowableObjectArray::Handle(object_store()->closure_functions());
1523 ASSERT(!closures.IsNull());
1524 ASSERT(function.IsNonImplicitClosureFunction());
1525 closures.Add(function, Heap::kOld);
1526 }
1527
1528
1529 // If the linear lookup turns out to be too expensive, the list
1530 // of closures could be maintained in a hash map, with the key
1531 // being the token position of the closure. There are almost no
1532 // collisions with this simple hash value. However, iterating over
1533 // all closure functions becomes more difficult, especially when
1534 // the list/map changes while iterating over it.
1535 RawFunction* Isolate::LookupClosureFunction(const Function& parent,
1536 intptr_t token_pos) const {
1537 const GrowableObjectArray& closures =
1538 GrowableObjectArray::Handle(object_store()->closure_functions());
1539 ASSERT(!closures.IsNull());
1540 Function& closure = Function::Handle();
1541 intptr_t num_closures = closures.Length();
1542 for (intptr_t i = 0; i < num_closures; i++) {
1543 closure ^= closures.At(i);
1544 if ((closure.token_pos() == token_pos) &&
1545 (closure.parent_function() == parent.raw())) {
1546 return closure.raw();
1547 }
1548 }
1549 return Function::null();
1550 }
1551
1552
1553 intptr_t Isolate::FindClosureIndex(const Function& needle) const {
1554 const GrowableObjectArray& closures_array =
1555 GrowableObjectArray::Handle(object_store()->closure_functions());
1556 intptr_t num_closures = closures_array.Length();
1557 for (intptr_t i = 0; i < num_closures; i++) {
1558 if (closures_array.At(i) == needle.raw()) {
1559 return i;
1560 }
1561 }
1562 return -1;
1563 }
1564
1565
1566 RawFunction* Isolate::ClosureFunctionFromIndex(intptr_t idx) const {
1567 const GrowableObjectArray& closures_array =
1568 GrowableObjectArray::Handle(object_store()->closure_functions());
1569 if ((idx < 0) || (idx >= closures_array.Length())) {
1570 return Function::null();
1571 }
1572 return Function::RawCast(closures_array.At(idx));
1573 }
1574
1575
1520 static void AddFunctionsFromClass(const Class& cls, 1576 static void AddFunctionsFromClass(const Class& cls,
1521 GrowableArray<const Function*>* functions) { 1577 GrowableArray<const Function*>* functions) {
1522 const Array& class_functions = Array::Handle(cls.functions()); 1578 const Array& class_functions = Array::Handle(cls.functions());
1523 // Class 'dynamic' is allocated/initialized in a special way, leaving 1579 // Class 'dynamic' is allocated/initialized in a special way, leaving
1524 // the functions field NULL instead of empty. 1580 // the functions field NULL instead of empty.
1525 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length(); 1581 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length();
1526 for (int j = 0; j < func_len; j++) { 1582 for (int j = 0; j < func_len; j++) {
1527 Function& function = Function::Handle(); 1583 Function& function = Function::Handle();
1528 function ^= class_functions.At(j); 1584 function ^= class_functions.At(j);
1529 if (function.usage_counter() > 0) { 1585 if (function.usage_counter() > 0) {
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 } 2586 }
2531 2587
2532 2588
2533 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { 2589 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) {
2534 return DeserializeObject(thread, 2590 return DeserializeObject(thread,
2535 serialized_message_, serialized_message_len_); 2591 serialized_message_, serialized_message_len_);
2536 } 2592 }
2537 2593
2538 2594
2539 } // namespace dart 2595 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698