OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 | 1570 |
1571 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size | 1571 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size |
1572 // is set to avoid expanding the dictionary during bootstrapping. | 1572 // is set to avoid expanding the dictionary during bootstrapping. |
1573 obj = NumberDictionary::Allocate(64); | 1573 obj = NumberDictionary::Allocate(64); |
1574 if (obj->IsFailure()) return false; | 1574 if (obj->IsFailure()) return false; |
1575 set_non_monomorphic_cache(NumberDictionary::cast(obj)); | 1575 set_non_monomorphic_cache(NumberDictionary::cast(obj)); |
1576 | 1576 |
1577 CreateFixedStubs(); | 1577 CreateFixedStubs(); |
1578 | 1578 |
1579 // Allocate the number->string conversion cache | 1579 // Allocate the number->string conversion cache |
1580 ASSERT(IsPowerOf2(kNumberStringCacheSize)); | |
1581 obj = AllocateFixedArray(kNumberStringCacheSize * 2); | 1580 obj = AllocateFixedArray(kNumberStringCacheSize * 2); |
1582 if (obj->IsFailure()) return false; | 1581 if (obj->IsFailure()) return false; |
1583 set_number_string_cache(FixedArray::cast(obj)); | 1582 set_number_string_cache(FixedArray::cast(obj)); |
1584 | 1583 |
1585 // Allocate cache for single character strings. | 1584 // Allocate cache for single character strings. |
1586 obj = AllocateFixedArray(String::kMaxAsciiCharCode+1); | 1585 obj = AllocateFixedArray(String::kMaxAsciiCharCode+1); |
1587 if (obj->IsFailure()) return false; | 1586 if (obj->IsFailure()) return false; |
1588 set_single_character_string_cache(FixedArray::cast(obj)); | 1587 set_single_character_string_cache(FixedArray::cast(obj)); |
1589 | 1588 |
1590 // Allocate cache for external strings pointing to native source code. | 1589 // Allocate cache for external strings pointing to native source code. |
(...skipping 13 matching lines...) Expand all Loading... |
1604 // Initialize descriptor cache. | 1603 // Initialize descriptor cache. |
1605 DescriptorLookupCache::Clear(); | 1604 DescriptorLookupCache::Clear(); |
1606 | 1605 |
1607 // Initialize compilation cache. | 1606 // Initialize compilation cache. |
1608 CompilationCache::Clear(); | 1607 CompilationCache::Clear(); |
1609 | 1608 |
1610 return true; | 1609 return true; |
1611 } | 1610 } |
1612 | 1611 |
1613 | 1612 |
1614 static inline int NumberStringTruncateHash(int value) { | 1613 static inline int double_get_hash(double d) { |
1615 return (((value >> 16) ^ value)) & (Heap::kNumberStringCacheSize - 1); | 1614 DoubleRepresentation rep(d); |
| 1615 return ((static_cast<int>(rep.bits) ^ static_cast<int>(rep.bits >> 32)) & |
| 1616 (Heap::kNumberStringCacheSize - 1)); |
1616 } | 1617 } |
1617 | 1618 |
1618 | 1619 |
1619 static inline int DoubleGetHash(double d) { | 1620 static inline int smi_get_hash(Smi* smi) { |
1620 DoubleRepresentation rep(d); | 1621 return (smi->value() & (Heap::kNumberStringCacheSize - 1)); |
1621 int value = (static_cast<int>(rep.bits) ^ static_cast<int>(rep.bits >> 32)); | |
1622 return NumberStringTruncateHash(value); | |
1623 } | 1622 } |
1624 | 1623 |
1625 | 1624 |
1626 static inline int SmiGetHash(Smi* smi) { | |
1627 return NumberStringTruncateHash(smi->value()); | |
1628 } | |
1629 | |
1630 | 1625 |
1631 Object* Heap::GetNumberStringCache(Object* number) { | 1626 Object* Heap::GetNumberStringCache(Object* number) { |
1632 int hash; | 1627 int hash; |
1633 if (number->IsSmi()) { | 1628 if (number->IsSmi()) { |
1634 hash = SmiGetHash(Smi::cast(number)); | 1629 hash = smi_get_hash(Smi::cast(number)); |
1635 } else { | 1630 } else { |
1636 hash = DoubleGetHash(number->Number()); | 1631 hash = double_get_hash(number->Number()); |
1637 } | 1632 } |
1638 Object* key = number_string_cache()->get(hash * 2); | 1633 Object* key = number_string_cache()->get(hash * 2); |
1639 if (key == number) { | 1634 if (key == number) { |
1640 return String::cast(number_string_cache()->get(hash * 2 + 1)); | 1635 return String::cast(number_string_cache()->get(hash * 2 + 1)); |
1641 } else if (key->IsHeapNumber() && | 1636 } else if (key->IsHeapNumber() && |
1642 number->IsHeapNumber() && | 1637 number->IsHeapNumber() && |
1643 key->Number() == number->Number()) { | 1638 key->Number() == number->Number()) { |
1644 return String::cast(number_string_cache()->get(hash * 2 + 1)); | 1639 return String::cast(number_string_cache()->get(hash * 2 + 1)); |
1645 } | 1640 } |
1646 return undefined_value(); | 1641 return undefined_value(); |
1647 } | 1642 } |
1648 | 1643 |
1649 | 1644 |
1650 void Heap::SetNumberStringCache(Object* number, String* string) { | 1645 void Heap::SetNumberStringCache(Object* number, String* string) { |
1651 int hash; | 1646 int hash; |
1652 if (number->IsSmi()) { | 1647 if (number->IsSmi()) { |
1653 hash = SmiGetHash(Smi::cast(number)); | 1648 hash = smi_get_hash(Smi::cast(number)); |
1654 number_string_cache()->set(hash * 2, number, SKIP_WRITE_BARRIER); | 1649 number_string_cache()->set(hash * 2, number, SKIP_WRITE_BARRIER); |
1655 } else { | 1650 } else { |
1656 hash = DoubleGetHash(number->Number()); | 1651 hash = double_get_hash(number->Number()); |
1657 number_string_cache()->set(hash * 2, number); | 1652 number_string_cache()->set(hash * 2, number); |
1658 } | 1653 } |
1659 number_string_cache()->set(hash * 2 + 1, string); | 1654 number_string_cache()->set(hash * 2 + 1, string); |
1660 } | 1655 } |
1661 | 1656 |
1662 | 1657 |
1663 Object* Heap::SmiOrNumberFromDouble(double value, | 1658 Object* Heap::SmiOrNumberFromDouble(double value, |
1664 bool new_object, | 1659 bool new_object, |
1665 PretenureFlag pretenure) { | 1660 PretenureFlag pretenure) { |
1666 // We need to distinguish the minus zero value and this cannot be | 1661 // We need to distinguish the minus zero value and this cannot be |
(...skipping 2427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4094 void ExternalStringTable::TearDown() { | 4089 void ExternalStringTable::TearDown() { |
4095 new_space_strings_.Free(); | 4090 new_space_strings_.Free(); |
4096 old_space_strings_.Free(); | 4091 old_space_strings_.Free(); |
4097 } | 4092 } |
4098 | 4093 |
4099 | 4094 |
4100 List<Object*> ExternalStringTable::new_space_strings_; | 4095 List<Object*> ExternalStringTable::new_space_strings_; |
4101 List<Object*> ExternalStringTable::old_space_strings_; | 4096 List<Object*> ExternalStringTable::old_space_strings_; |
4102 | 4097 |
4103 } } // namespace v8::internal | 4098 } } // namespace v8::internal |
OLD | NEW |