| 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/code_generator.h" | 5 #include "vm/code_generator.h" |
| 6 | 6 |
| 7 #include "vm/assembler_macros.h" | 7 #include "vm/assembler_macros.h" |
| 8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
| 9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 void FunctionsCache::AddCompiledFunction(const Function& function, | 1656 void FunctionsCache::AddCompiledFunction(const Function& function, |
| 1657 int num_arguments, | 1657 int num_arguments, |
| 1658 int num_named_arguments) { | 1658 int num_named_arguments) { |
| 1659 // TODO(srdjan): Evaluate if populating the function cache is needed. | 1659 // TODO(srdjan): Evaluate if populating the function cache is needed. |
| 1660 // It is turned off currently because we do not populate code objects | 1660 // It is turned off currently because we do not populate code objects |
| 1661 // in snapshot and hence end up in an inconsistent state as function | 1661 // in snapshot and hence end up in an inconsistent state as function |
| 1662 // cache is populated but there are no code objects. | 1662 // cache is populated but there are no code objects. |
| 1663 #if 0 | 1663 #if 0 |
| 1664 ASSERT(function.HasCode()); | 1664 ASSERT(function.HasCode()); |
| 1665 Array& cache = Array::Handle(class_.functions_cache()); | 1665 Array& cache = Array::Handle(class_.functions_cache()); |
| 1666 if (cache.IsNull()) { |
| 1667 class_.InitFunctionsCache(); |
| 1668 cache = class_.functions_cache(); |
| 1669 } |
| 1666 // Search for first free slot. Last entry is always NULL object. | 1670 // Search for first free slot. Last entry is always NULL object. |
| 1667 for (intptr_t i = 0; i < (cache.Length() - kNumEntries); i += kNumEntries) { | 1671 for (intptr_t i = 0; i < (cache.Length() - kNumEntries); i += kNumEntries) { |
| 1668 if (Object::Handle(cache.At(i)).IsNull()) { | 1672 if (Object::Handle(cache.At(i)).IsNull()) { |
| 1669 EnterFunctionAt(i, | 1673 EnterFunctionAt(i, |
| 1670 cache, | 1674 cache, |
| 1671 function, | 1675 function, |
| 1672 num_arguments, | 1676 num_arguments, |
| 1673 num_named_arguments); | 1677 num_named_arguments); |
| 1674 return; | 1678 return; |
| 1675 } | 1679 } |
| 1676 } | 1680 } |
| 1677 intptr_t ix = cache.Length() - kNumEntries; | 1681 intptr_t ix = cache.Length() - kNumEntries; |
| 1678 // Grow by 8 entries. | 1682 // Grow by 8 entries. |
| 1679 cache = Array::Grow(cache, cache.Length() + (8 * kNumEntries)); | 1683 cache = Array::Grow(cache, cache.Length() + (8 * kNumEntries)); |
| 1680 class_.set_functions_cache(cache); | 1684 class_.set_functions_cache(cache); |
| 1681 EnterFunctionAt(ix, | 1685 EnterFunctionAt(ix, |
| 1682 cache, | 1686 cache, |
| 1683 function, | 1687 function, |
| 1684 num_arguments, | 1688 num_arguments, |
| 1685 num_named_arguments); | 1689 num_named_arguments); |
| 1686 #endif | 1690 #endif |
| 1687 } | 1691 } |
| 1688 | 1692 |
| 1689 | 1693 |
| 1690 // Only the number of named arguments is checked, but not the actual names. | 1694 // Only the number of named arguments is checked, but not the actual names. |
| 1691 RawCode* FunctionsCache::LookupCode(const String& function_name, | 1695 RawCode* FunctionsCache::LookupCode(const String& function_name, |
| 1692 int num_arguments, | 1696 int num_arguments, |
| 1693 int num_named_arguments) { | 1697 int num_named_arguments) { |
| 1694 const Array& cache = Array::Handle(class_.functions_cache()); | 1698 const Array& cache = Array::Handle(class_.functions_cache()); |
| 1699 if (cache.IsNull()) { |
| 1700 return Code::null(); // Functions cache has not been populated yet. |
| 1701 } |
| 1695 String& test_name = String::Handle(); | 1702 String& test_name = String::Handle(); |
| 1696 for (intptr_t i = 0; i < cache.Length(); i += kNumEntries) { | 1703 for (intptr_t i = 0; i < cache.Length(); i += kNumEntries) { |
| 1697 test_name ^= cache.At(i + FunctionsCache::kFunctionName); | 1704 test_name ^= cache.At(i + FunctionsCache::kFunctionName); |
| 1698 if (test_name.IsNull()) { | 1705 if (test_name.IsNull()) { |
| 1699 // Found NULL, no more entries to check, abort lookup. | 1706 // Found NULL, no more entries to check, abort lookup. |
| 1700 return Code::null(); | 1707 return Code::null(); |
| 1701 } | 1708 } |
| 1702 if (function_name.Equals(test_name)) { | 1709 if (function_name.Equals(test_name)) { |
| 1703 Smi& smi = Smi::Handle(); | 1710 Smi& smi = Smi::Handle(); |
| 1704 smi ^= cache.At(i + FunctionsCache::kArgCount); | 1711 smi ^= cache.At(i + FunctionsCache::kArgCount); |
| 1705 if (num_arguments == smi.Value()) { | 1712 if (num_arguments == smi.Value()) { |
| 1706 smi ^= cache.At(i + FunctionsCache::kNamedArgCount); | 1713 smi ^= cache.At(i + FunctionsCache::kNamedArgCount); |
| 1707 if (num_named_arguments == smi.Value()) { | 1714 if (num_named_arguments == smi.Value()) { |
| 1708 Function& result = Function::Handle(); | 1715 Function& result = Function::Handle(); |
| 1709 result ^= cache.At(i + FunctionsCache::kFunction); | 1716 result ^= cache.At(i + FunctionsCache::kFunction); |
| 1710 ASSERT(!result.IsNull()); | 1717 ASSERT(!result.IsNull()); |
| 1711 ASSERT(result.HasCode()); | 1718 ASSERT(result.HasCode()); |
| 1712 return result.CurrentCode(); | 1719 return result.CurrentCode(); |
| 1713 } | 1720 } |
| 1714 } | 1721 } |
| 1715 } | 1722 } |
| 1716 } | 1723 } |
| 1717 // The cache is null terminated, therefore the loop above should never | 1724 // The cache is null terminated, therefore the loop above should never |
| 1718 // terminate by itself. | 1725 // terminate by itself. |
| 1719 UNREACHABLE(); | 1726 UNREACHABLE(); |
| 1720 return Code::null(); | 1727 return Code::null(); |
| 1721 } | 1728 } |
| 1722 | 1729 |
| 1723 } // namespace dart | 1730 } // namespace dart |
| OLD | NEW |