| 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 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 void FunctionsCache::AddCompiledFunction(const Function& function, | 1560 void FunctionsCache::AddCompiledFunction(const Function& function, |
| 1561 int num_arguments, | 1561 int num_arguments, |
| 1562 int num_named_arguments) { | 1562 int num_named_arguments) { |
| 1563 // TODO(srdjan): Evaluate if populating the function cache is needed. | 1563 // TODO(srdjan): Evaluate if populating the function cache is needed. |
| 1564 // It is turned off currently because we do not populate code objects | 1564 // It is turned off currently because we do not populate code objects |
| 1565 // in snapshot and hence end up in an inconsistent state as function | 1565 // in snapshot and hence end up in an inconsistent state as function |
| 1566 // cache is populated but there are no code objects. | 1566 // cache is populated but there are no code objects. |
| 1567 #if 0 | 1567 #if 0 |
| 1568 ASSERT(function.HasCode()); | 1568 ASSERT(function.HasCode()); |
| 1569 Array& cache = Array::Handle(class_.functions_cache()); | 1569 Array& cache = Array::Handle(class_.functions_cache()); |
| 1570 if (cache.IsNull()) { |
| 1571 class_.InitFunctionsCache(); |
| 1572 cache = class_.functions_cache(); |
| 1573 } |
| 1570 // Search for first free slot. Last entry is always NULL object. | 1574 // Search for first free slot. Last entry is always NULL object. |
| 1571 for (intptr_t i = 0; i < (cache.Length() - kNumEntries); i += kNumEntries) { | 1575 for (intptr_t i = 0; i < (cache.Length() - kNumEntries); i += kNumEntries) { |
| 1572 if (Object::Handle(cache.At(i)).IsNull()) { | 1576 if (Object::Handle(cache.At(i)).IsNull()) { |
| 1573 EnterFunctionAt(i, | 1577 EnterFunctionAt(i, |
| 1574 cache, | 1578 cache, |
| 1575 function, | 1579 function, |
| 1576 num_arguments, | 1580 num_arguments, |
| 1577 num_named_arguments); | 1581 num_named_arguments); |
| 1578 return; | 1582 return; |
| 1579 } | 1583 } |
| 1580 } | 1584 } |
| 1581 intptr_t ix = cache.Length() - kNumEntries; | 1585 intptr_t ix = cache.Length() - kNumEntries; |
| 1582 // Grow by 8 entries. | 1586 // Grow by 8 entries. |
| 1583 cache = Array::Grow(cache, cache.Length() + (8 * kNumEntries)); | 1587 cache = Array::Grow(cache, cache.Length() + (8 * kNumEntries)); |
| 1584 class_.set_functions_cache(cache); | 1588 class_.set_functions_cache(cache); |
| 1585 EnterFunctionAt(ix, | 1589 EnterFunctionAt(ix, |
| 1586 cache, | 1590 cache, |
| 1587 function, | 1591 function, |
| 1588 num_arguments, | 1592 num_arguments, |
| 1589 num_named_arguments); | 1593 num_named_arguments); |
| 1590 #endif | 1594 #endif |
| 1591 } | 1595 } |
| 1592 | 1596 |
| 1593 | 1597 |
| 1594 // Only the number of named arguments is checked, but not the actual names. | 1598 // Only the number of named arguments is checked, but not the actual names. |
| 1595 RawCode* FunctionsCache::LookupCode(const String& function_name, | 1599 RawCode* FunctionsCache::LookupCode(const String& function_name, |
| 1596 int num_arguments, | 1600 int num_arguments, |
| 1597 int num_named_arguments) { | 1601 int num_named_arguments) { |
| 1598 const Array& cache = Array::Handle(class_.functions_cache()); | 1602 const Array& cache = Array::Handle(class_.functions_cache()); |
| 1603 if (cache.IsNull()) { |
| 1604 return Code::null(); // Functions cache has not been populated yet. |
| 1605 } |
| 1599 String& test_name = String::Handle(); | 1606 String& test_name = String::Handle(); |
| 1600 for (intptr_t i = 0; i < cache.Length(); i += kNumEntries) { | 1607 for (intptr_t i = 0; i < cache.Length(); i += kNumEntries) { |
| 1601 test_name ^= cache.At(i + FunctionsCache::kFunctionName); | 1608 test_name ^= cache.At(i + FunctionsCache::kFunctionName); |
| 1602 if (test_name.IsNull()) { | 1609 if (test_name.IsNull()) { |
| 1603 // Found NULL, no more entries to check, abort lookup. | 1610 // Found NULL, no more entries to check, abort lookup. |
| 1604 return Code::null(); | 1611 return Code::null(); |
| 1605 } | 1612 } |
| 1606 if (function_name.Equals(test_name)) { | 1613 if (function_name.Equals(test_name)) { |
| 1607 Smi& smi = Smi::Handle(); | 1614 Smi& smi = Smi::Handle(); |
| 1608 smi ^= cache.At(i + FunctionsCache::kArgCount); | 1615 smi ^= cache.At(i + FunctionsCache::kArgCount); |
| 1609 if (num_arguments == smi.Value()) { | 1616 if (num_arguments == smi.Value()) { |
| 1610 smi ^= cache.At(i + FunctionsCache::kNamedArgCount); | 1617 smi ^= cache.At(i + FunctionsCache::kNamedArgCount); |
| 1611 if (num_named_arguments == smi.Value()) { | 1618 if (num_named_arguments == smi.Value()) { |
| 1612 Function& result = Function::Handle(); | 1619 Function& result = Function::Handle(); |
| 1613 result ^= cache.At(i + FunctionsCache::kFunction); | 1620 result ^= cache.At(i + FunctionsCache::kFunction); |
| 1614 ASSERT(!result.IsNull()); | 1621 ASSERT(!result.IsNull()); |
| 1615 ASSERT(result.HasCode()); | 1622 ASSERT(result.HasCode()); |
| 1616 return result.CurrentCode(); | 1623 return result.CurrentCode(); |
| 1617 } | 1624 } |
| 1618 } | 1625 } |
| 1619 } | 1626 } |
| 1620 } | 1627 } |
| 1621 // The cache is null terminated, therefore the loop above should never | 1628 // The cache is null terminated, therefore the loop above should never |
| 1622 // terminate by itself. | 1629 // terminate by itself. |
| 1623 UNREACHABLE(); | 1630 UNREACHABLE(); |
| 1624 return Code::null(); | 1631 return Code::null(); |
| 1625 } | 1632 } |
| 1626 | 1633 |
| 1627 } // namespace dart | 1634 } // namespace dart |
| OLD | NEW |