| 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 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 } | 1474 } |
| 1475 | 1475 |
| 1476 | 1476 |
| 1477 uword Isolate::GetAndClearStackOverflowFlags() { | 1477 uword Isolate::GetAndClearStackOverflowFlags() { |
| 1478 uword stack_overflow_flags = stack_overflow_flags_; | 1478 uword stack_overflow_flags = stack_overflow_flags_; |
| 1479 stack_overflow_flags_ = 0; | 1479 stack_overflow_flags_ = 0; |
| 1480 return stack_overflow_flags; | 1480 return stack_overflow_flags; |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 | 1483 |
| 1484 static int MostUsedFunctionFirst(const Function* const* a, | |
| 1485 const Function* const* b) { | |
| 1486 if ((*a)->usage_counter() > (*b)->usage_counter()) { | |
| 1487 return -1; | |
| 1488 } else if ((*a)->usage_counter() < (*b)->usage_counter()) { | |
| 1489 return 1; | |
| 1490 } else { | |
| 1491 return 0; | |
| 1492 } | |
| 1493 } | |
| 1494 | |
| 1495 | |
| 1496 void Isolate::AddClosureFunction(const Function& function) const { | 1484 void Isolate::AddClosureFunction(const Function& function) const { |
| 1497 GrowableObjectArray& closures = | 1485 GrowableObjectArray& closures = |
| 1498 GrowableObjectArray::Handle(object_store()->closure_functions()); | 1486 GrowableObjectArray::Handle(object_store()->closure_functions()); |
| 1499 ASSERT(!closures.IsNull()); | 1487 ASSERT(!closures.IsNull()); |
| 1500 ASSERT(function.IsNonImplicitClosureFunction()); | 1488 ASSERT(function.IsNonImplicitClosureFunction()); |
| 1501 closures.Add(function, Heap::kOld); | 1489 closures.Add(function, Heap::kOld); |
| 1502 } | 1490 } |
| 1503 | 1491 |
| 1504 | 1492 |
| 1505 // If the linear lookup turns out to be too expensive, the list | 1493 // If the linear lookup turns out to be too expensive, the list |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 RawFunction* Isolate::ClosureFunctionFromIndex(intptr_t idx) const { | 1530 RawFunction* Isolate::ClosureFunctionFromIndex(intptr_t idx) const { |
| 1543 const GrowableObjectArray& closures_array = | 1531 const GrowableObjectArray& closures_array = |
| 1544 GrowableObjectArray::Handle(object_store()->closure_functions()); | 1532 GrowableObjectArray::Handle(object_store()->closure_functions()); |
| 1545 if ((idx < 0) || (idx >= closures_array.Length())) { | 1533 if ((idx < 0) || (idx >= closures_array.Length())) { |
| 1546 return Function::null(); | 1534 return Function::null(); |
| 1547 } | 1535 } |
| 1548 return Function::RawCast(closures_array.At(idx)); | 1536 return Function::RawCast(closures_array.At(idx)); |
| 1549 } | 1537 } |
| 1550 | 1538 |
| 1551 | 1539 |
| 1552 static void AddFunctionsFromClass(const Class& cls, | |
| 1553 GrowableArray<const Function*>* functions) { | |
| 1554 const Array& class_functions = Array::Handle(cls.functions()); | |
| 1555 // Class 'dynamic' is allocated/initialized in a special way, leaving | |
| 1556 // the functions field NULL instead of empty. | |
| 1557 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length(); | |
| 1558 for (int j = 0; j < func_len; j++) { | |
| 1559 Function& function = Function::Handle(); | |
| 1560 function ^= class_functions.At(j); | |
| 1561 if (function.usage_counter() > 0) { | |
| 1562 functions->Add(&function); | |
| 1563 } | |
| 1564 } | |
| 1565 } | |
| 1566 | |
| 1567 | |
| 1568 void Isolate::PrintInvokedFunctions() { | |
| 1569 ASSERT(this == Isolate::Current()); | |
| 1570 const GrowableObjectArray& libraries = | |
| 1571 GrowableObjectArray::Handle(object_store()->libraries()); | |
| 1572 Library& library = Library::Handle(); | |
| 1573 GrowableArray<const Function*> invoked_functions; | |
| 1574 for (int i = 0; i < libraries.Length(); i++) { | |
| 1575 library ^= libraries.At(i); | |
| 1576 Class& cls = Class::Handle(); | |
| 1577 ClassDictionaryIterator iter(library, | |
| 1578 ClassDictionaryIterator::kIteratePrivate); | |
| 1579 while (iter.HasNext()) { | |
| 1580 cls = iter.GetNextClass(); | |
| 1581 AddFunctionsFromClass(cls, &invoked_functions); | |
| 1582 } | |
| 1583 } | |
| 1584 invoked_functions.Sort(MostUsedFunctionFirst); | |
| 1585 for (int i = 0; i < invoked_functions.length(); i++) { | |
| 1586 OS::Print("%10" Pd " x %s\n", | |
| 1587 invoked_functions[i]->usage_counter(), | |
| 1588 invoked_functions[i]->ToFullyQualifiedCString()); | |
| 1589 } | |
| 1590 } | |
| 1591 | |
| 1592 | |
| 1593 class FinalizeWeakPersistentHandlesVisitor : public HandleVisitor { | 1540 class FinalizeWeakPersistentHandlesVisitor : public HandleVisitor { |
| 1594 public: | 1541 public: |
| 1595 FinalizeWeakPersistentHandlesVisitor() : HandleVisitor(Thread::Current()) { | 1542 FinalizeWeakPersistentHandlesVisitor() : HandleVisitor(Thread::Current()) { |
| 1596 } | 1543 } |
| 1597 | 1544 |
| 1598 void VisitHandle(uword addr) { | 1545 void VisitHandle(uword addr) { |
| 1599 FinalizablePersistentHandle* handle = | 1546 FinalizablePersistentHandle* handle = |
| 1600 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 1547 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
| 1601 handle->UpdateUnreachable(thread()->isolate()); | 1548 handle->UpdateUnreachable(thread()->isolate()); |
| 1602 } | 1549 } |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2558 } | 2505 } |
| 2559 | 2506 |
| 2560 | 2507 |
| 2561 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { | 2508 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { |
| 2562 return DeserializeObject(thread, | 2509 return DeserializeObject(thread, |
| 2563 serialized_message_, serialized_message_len_); | 2510 serialized_message_, serialized_message_len_); |
| 2564 } | 2511 } |
| 2565 | 2512 |
| 2566 | 2513 |
| 2567 } // namespace dart | 2514 } // namespace dart |
| OLD | NEW |