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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 // At any old GC clear the keyed lookup cache to enable collection of unused | 569 // At any old GC clear the keyed lookup cache to enable collection of unused |
570 // maps. | 570 // maps. |
571 KeyedLookupCache::Clear(); | 571 KeyedLookupCache::Clear(); |
572 ContextSlotCache::Clear(); | 572 ContextSlotCache::Clear(); |
573 DescriptorLookupCache::Clear(); | 573 DescriptorLookupCache::Clear(); |
574 | 574 |
575 CompilationCache::MarkCompactPrologue(); | 575 CompilationCache::MarkCompactPrologue(); |
576 | 576 |
577 Top::MarkCompactPrologue(is_compacting); | 577 Top::MarkCompactPrologue(is_compacting); |
578 ThreadManager::MarkCompactPrologue(is_compacting); | 578 ThreadManager::MarkCompactPrologue(is_compacting); |
579 | |
580 if (is_compacting) FlushNumberStringCache(); | |
579 } | 581 } |
580 | 582 |
581 | 583 |
582 void Heap::MarkCompactEpilogue(bool is_compacting) { | 584 void Heap::MarkCompactEpilogue(bool is_compacting) { |
583 Top::MarkCompactEpilogue(is_compacting); | 585 Top::MarkCompactEpilogue(is_compacting); |
584 ThreadManager::MarkCompactEpilogue(is_compacting); | 586 ThreadManager::MarkCompactEpilogue(is_compacting); |
585 } | 587 } |
586 | 588 |
587 | 589 |
588 Object* Heap::FindCodeObject(Address a) { | 590 Object* Heap::FindCodeObject(Address a) { |
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1566 set_code_stubs(NumberDictionary::cast(obj)); | 1568 set_code_stubs(NumberDictionary::cast(obj)); |
1567 | 1569 |
1568 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size | 1570 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size |
1569 // is set to avoid expanding the dictionary during bootstrapping. | 1571 // is set to avoid expanding the dictionary during bootstrapping. |
1570 obj = NumberDictionary::Allocate(64); | 1572 obj = NumberDictionary::Allocate(64); |
1571 if (obj->IsFailure()) return false; | 1573 if (obj->IsFailure()) return false; |
1572 set_non_monomorphic_cache(NumberDictionary::cast(obj)); | 1574 set_non_monomorphic_cache(NumberDictionary::cast(obj)); |
1573 | 1575 |
1574 CreateFixedStubs(); | 1576 CreateFixedStubs(); |
1575 | 1577 |
1576 // Allocate the number->string conversion cache | 1578 if (InitializeNumberStringCache()->IsFailure()) return false; |
1577 obj = AllocateFixedArray(kNumberStringCacheSize * 2); | |
1578 if (obj->IsFailure()) return false; | |
1579 set_number_string_cache(FixedArray::cast(obj)); | |
1580 | 1579 |
1581 // Allocate cache for single character strings. | 1580 // Allocate cache for single character strings. |
1582 obj = AllocateFixedArray(String::kMaxAsciiCharCode+1); | 1581 obj = AllocateFixedArray(String::kMaxAsciiCharCode+1); |
1583 if (obj->IsFailure()) return false; | 1582 if (obj->IsFailure()) return false; |
1584 set_single_character_string_cache(FixedArray::cast(obj)); | 1583 set_single_character_string_cache(FixedArray::cast(obj)); |
1585 | 1584 |
1586 // Allocate cache for external strings pointing to native source code. | 1585 // Allocate cache for external strings pointing to native source code. |
1587 obj = AllocateFixedArray(Natives::GetBuiltinsCount()); | 1586 obj = AllocateFixedArray(Natives::GetBuiltinsCount()); |
1588 if (obj->IsFailure()) return false; | 1587 if (obj->IsFailure()) return false; |
1589 set_natives_source_cache(FixedArray::cast(obj)); | 1588 set_natives_source_cache(FixedArray::cast(obj)); |
(...skipping 10 matching lines...) Expand all Loading... | |
1600 // Initialize descriptor cache. | 1599 // Initialize descriptor cache. |
1601 DescriptorLookupCache::Clear(); | 1600 DescriptorLookupCache::Clear(); |
1602 | 1601 |
1603 // Initialize compilation cache. | 1602 // Initialize compilation cache. |
1604 CompilationCache::Clear(); | 1603 CompilationCache::Clear(); |
1605 | 1604 |
1606 return true; | 1605 return true; |
1607 } | 1606 } |
1608 | 1607 |
1609 | 1608 |
1609 Object* Heap::InitializeNumberStringCache() { | |
1610 // Compute the size of the number string cache based on the max heap size. | |
1611 // max_semispace_size_ == 512 KB => number_string_cache_size = 16. | |
Mads Ager (chromium)
2010/01/06 11:16:00
32?
Also, the logic seems different from what the
| |
1612 // max_semispace_size_ == 8 MB => number_string_cache_size = 16KB. | |
1613 int number_string_cache_size = max_semispace_size_ / 512; | |
1614 number_string_cache_size = Max(32, Min(16*KB, number_string_cache_size)); | |
1615 Object* obj = AllocateFixedArray(number_string_cache_size * 2); | |
1616 if (!obj->IsFailure()) set_number_string_cache(FixedArray::cast(obj)); | |
1617 return obj; | |
1618 } | |
1619 | |
1620 | |
1621 void Heap::FlushNumberStringCache() { | |
1622 // Flush the number to string cache. | |
1623 int len = number_string_cache()->length(); | |
1624 for (int i = 0; i < len; i++) { | |
1625 number_string_cache()->set_undefined(i); | |
1626 } | |
1627 } | |
1628 | |
1629 | |
1610 static inline int double_get_hash(double d) { | 1630 static inline int double_get_hash(double d) { |
1611 DoubleRepresentation rep(d); | 1631 DoubleRepresentation rep(d); |
1612 return ((static_cast<int>(rep.bits) ^ static_cast<int>(rep.bits >> 32)) & | 1632 return static_cast<int>(rep.bits) ^ static_cast<int>(rep.bits >> 32); |
1613 (Heap::kNumberStringCacheSize - 1)); | |
1614 } | 1633 } |
1615 | 1634 |
1616 | 1635 |
1617 static inline int smi_get_hash(Smi* smi) { | 1636 static inline int smi_get_hash(Smi* smi) { |
1618 return (smi->value() & (Heap::kNumberStringCacheSize - 1)); | 1637 return smi->value(); |
1619 } | 1638 } |
1620 | 1639 |
1621 | 1640 |
1622 | |
1623 Object* Heap::GetNumberStringCache(Object* number) { | 1641 Object* Heap::GetNumberStringCache(Object* number) { |
1624 int hash; | 1642 int hash; |
1643 int mask = (number_string_cache()->length() >> 1) - 1; | |
1625 if (number->IsSmi()) { | 1644 if (number->IsSmi()) { |
1626 hash = smi_get_hash(Smi::cast(number)); | 1645 hash = smi_get_hash(Smi::cast(number)) & mask; |
1627 } else { | 1646 } else { |
1628 hash = double_get_hash(number->Number()); | 1647 hash = double_get_hash(number->Number()) & mask; |
1629 } | 1648 } |
1630 Object* key = number_string_cache()->get(hash * 2); | 1649 Object* key = number_string_cache()->get(hash * 2); |
1631 if (key == number) { | 1650 if (key == number) { |
1632 return String::cast(number_string_cache()->get(hash * 2 + 1)); | 1651 return String::cast(number_string_cache()->get(hash * 2 + 1)); |
1633 } else if (key->IsHeapNumber() && | 1652 } else if (key->IsHeapNumber() && |
1634 number->IsHeapNumber() && | 1653 number->IsHeapNumber() && |
1635 key->Number() == number->Number()) { | 1654 key->Number() == number->Number()) { |
1636 return String::cast(number_string_cache()->get(hash * 2 + 1)); | 1655 return String::cast(number_string_cache()->get(hash * 2 + 1)); |
1637 } | 1656 } |
1638 return undefined_value(); | 1657 return undefined_value(); |
1639 } | 1658 } |
1640 | 1659 |
1641 | 1660 |
1642 void Heap::SetNumberStringCache(Object* number, String* string) { | 1661 void Heap::SetNumberStringCache(Object* number, String* string) { |
1643 int hash; | 1662 int hash; |
1663 int mask = (number_string_cache()->length() >> 1) - 1; | |
1644 if (number->IsSmi()) { | 1664 if (number->IsSmi()) { |
1645 hash = smi_get_hash(Smi::cast(number)); | 1665 hash = smi_get_hash(Smi::cast(number)) & mask; |
1646 number_string_cache()->set(hash * 2, number, SKIP_WRITE_BARRIER); | 1666 number_string_cache()->set(hash * 2, number, SKIP_WRITE_BARRIER); |
1647 } else { | 1667 } else { |
1648 hash = double_get_hash(number->Number()); | 1668 hash = double_get_hash(number->Number()) & mask; |
1649 number_string_cache()->set(hash * 2, number); | 1669 number_string_cache()->set(hash * 2, number); |
1650 } | 1670 } |
1651 number_string_cache()->set(hash * 2 + 1, string); | 1671 number_string_cache()->set(hash * 2 + 1, string); |
1652 } | 1672 } |
1653 | 1673 |
1654 | 1674 |
1655 Object* Heap::SmiOrNumberFromDouble(double value, | 1675 Object* Heap::SmiOrNumberFromDouble(double value, |
1656 bool new_object, | 1676 bool new_object, |
1657 PretenureFlag pretenure) { | 1677 PretenureFlag pretenure) { |
1658 // We need to distinguish the minus zero value and this cannot be | 1678 // We need to distinguish the minus zero value and this cannot be |
(...skipping 2422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4081 void ExternalStringTable::TearDown() { | 4101 void ExternalStringTable::TearDown() { |
4082 new_space_strings_.Free(); | 4102 new_space_strings_.Free(); |
4083 old_space_strings_.Free(); | 4103 old_space_strings_.Free(); |
4084 } | 4104 } |
4085 | 4105 |
4086 | 4106 |
4087 List<Object*> ExternalStringTable::new_space_strings_; | 4107 List<Object*> ExternalStringTable::new_space_strings_; |
4088 List<Object*> ExternalStringTable::old_space_strings_; | 4108 List<Object*> ExternalStringTable::old_space_strings_; |
4089 | 4109 |
4090 } } // namespace v8::internal | 4110 } } // namespace v8::internal |
OLD | NEW |