| OLD | NEW |
| 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 Loading... |
| 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 RawFunction* Isolate::LookupClosureFunction(const Script& script, |
| 1530 intptr_t token_pos) const { |
| 1531 const GrowableObjectArray& closures = |
| 1532 GrowableObjectArray::Handle(object_store()->closure_functions()); |
| 1533 ASSERT(!closures.IsNull()); |
| 1534 Function& closure = Function::Handle(); |
| 1535 intptr_t num_closures = closures.Length(); |
| 1536 intptr_t best_fit_token_pos = -1; |
| 1537 intptr_t best_fit_index = -1; |
| 1538 for (intptr_t i = 0; i < num_closures; i++) { |
| 1539 closure ^= closures.At(i); |
| 1540 ASSERT(!closure.IsNull()); |
| 1541 if ((closure.token_pos() <= token_pos) && |
| 1542 (token_pos <= closure.end_token_pos()) && |
| 1543 (best_fit_token_pos < closure.token_pos()) && |
| 1544 (closure.script() == script.raw())) { |
| 1545 best_fit_index = i; |
| 1546 best_fit_token_pos = closure.token_pos(); |
| 1547 } |
| 1548 } |
| 1549 closure = Function::null(); |
| 1550 if (best_fit_index >= 0) { |
| 1551 closure ^= closures.At(best_fit_index); |
| 1552 } |
| 1553 return closure.raw(); |
| 1554 } |
| 1555 |
| 1556 |
| 1557 intptr_t Isolate::FindClosureIndex(const Function& needle) const { |
| 1558 const GrowableObjectArray& closures_array = |
| 1559 GrowableObjectArray::Handle(object_store()->closure_functions()); |
| 1560 intptr_t num_closures = closures_array.Length(); |
| 1561 for (intptr_t i = 0; i < num_closures; i++) { |
| 1562 if (closures_array.At(i) == needle.raw()) { |
| 1563 return i; |
| 1564 } |
| 1565 } |
| 1566 return -1; |
| 1567 } |
| 1568 |
| 1569 |
| 1570 RawFunction* Isolate::ClosureFunctionFromIndex(intptr_t idx) const { |
| 1571 const GrowableObjectArray& closures_array = |
| 1572 GrowableObjectArray::Handle(object_store()->closure_functions()); |
| 1573 if ((idx < 0) || (idx >= closures_array.Length())) { |
| 1574 return Function::null(); |
| 1575 } |
| 1576 return Function::RawCast(closures_array.At(idx)); |
| 1577 } |
| 1578 |
| 1579 |
| 1520 static void AddFunctionsFromClass(const Class& cls, | 1580 static void AddFunctionsFromClass(const Class& cls, |
| 1521 GrowableArray<const Function*>* functions) { | 1581 GrowableArray<const Function*>* functions) { |
| 1522 const Array& class_functions = Array::Handle(cls.functions()); | 1582 const Array& class_functions = Array::Handle(cls.functions()); |
| 1523 // Class 'dynamic' is allocated/initialized in a special way, leaving | 1583 // Class 'dynamic' is allocated/initialized in a special way, leaving |
| 1524 // the functions field NULL instead of empty. | 1584 // the functions field NULL instead of empty. |
| 1525 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length(); | 1585 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length(); |
| 1526 for (int j = 0; j < func_len; j++) { | 1586 for (int j = 0; j < func_len; j++) { |
| 1527 Function& function = Function::Handle(); | 1587 Function& function = Function::Handle(); |
| 1528 function ^= class_functions.At(j); | 1588 function ^= class_functions.At(j); |
| 1529 if (function.usage_counter() > 0) { | 1589 if (function.usage_counter() > 0) { |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 } | 2590 } |
| 2531 | 2591 |
| 2532 | 2592 |
| 2533 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { | 2593 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { |
| 2534 return DeserializeObject(thread, | 2594 return DeserializeObject(thread, |
| 2535 serialized_message_, serialized_message_len_); | 2595 serialized_message_, serialized_message_len_); |
| 2536 } | 2596 } |
| 2537 | 2597 |
| 2538 | 2598 |
| 2539 } // namespace dart | 2599 } // namespace dart |
| OLD | NEW |