OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 #ifdef DEBUG | 1691 #ifdef DEBUG |
1692 if (FLAG_gc_verbose) { | 1692 if (FLAG_gc_verbose) { |
1693 PrintF("relocate %p -> %p\n", obj->address(), new_addr); | 1693 PrintF("relocate %p -> %p\n", obj->address(), new_addr); |
1694 } | 1694 } |
1695 #endif | 1695 #endif |
1696 | 1696 |
1697 return obj_size; | 1697 return obj_size; |
1698 } | 1698 } |
1699 | 1699 |
1700 | 1700 |
| 1701 // Not used for objects in data space as it doesn't handle heap number alignment |
| 1702 // issues. |
1701 int MarkCompactCollector::RelocateOldNonCodeObject(HeapObject* obj, | 1703 int MarkCompactCollector::RelocateOldNonCodeObject(HeapObject* obj, |
1702 PagedSpace* space) { | 1704 PagedSpace* space) { |
1703 // Recover map pointer. | 1705 // Recover map pointer. |
1704 MapWord encoding = obj->map_word(); | 1706 MapWord encoding = obj->map_word(); |
1705 Address map_addr = encoding.DecodeMapAddress(Heap::map_space()); | 1707 Address map_addr = encoding.DecodeMapAddress(Heap::map_space()); |
1706 ASSERT(Heap::map_space()->Contains(map_addr)); | 1708 ASSERT(Heap::map_space()->Contains(map_addr)); |
1707 | 1709 |
1708 // Get forwarding address before resetting map pointer. | 1710 // Get forwarding address before resetting map pointer. |
1709 Address new_addr = GetForwardingAddressInOldSpace(obj); | 1711 Address new_addr = GetForwardingAddressInOldSpace(obj); |
1710 | 1712 |
1711 // Reset the map pointer. | 1713 // Reset the map pointer. |
1712 int obj_size = RestoreMap(obj, space, new_addr, map_addr); | 1714 int obj_size = RestoreMap(obj, space, new_addr, map_addr); |
1713 | 1715 |
1714 Address old_addr = obj->address(); | 1716 Address old_addr = obj->address(); |
1715 | 1717 |
1716 if (new_addr != old_addr) { | 1718 if (new_addr != old_addr) { |
1717 memmove(new_addr, old_addr, obj_size); // Copy contents | 1719 memmove(new_addr, old_addr, obj_size); // Copy contents. |
1718 } | 1720 } |
1719 | 1721 |
1720 ASSERT(!HeapObject::FromAddress(new_addr)->IsCode()); | 1722 ASSERT(!HeapObject::FromAddress(new_addr)->IsCode()); |
1721 | 1723 |
1722 return obj_size; | 1724 return obj_size; |
1723 } | 1725 } |
1724 | 1726 |
1725 | 1727 |
1726 int MarkCompactCollector::RelocateOldPointerObject(HeapObject* obj) { | 1728 int MarkCompactCollector::RelocateOldPointerObject(HeapObject* obj) { |
1727 return RelocateOldNonCodeObject(obj, Heap::old_pointer_space()); | 1729 return RelocateOldNonCodeObject(obj, Heap::old_pointer_space()); |
1728 } | 1730 } |
1729 | 1731 |
1730 | 1732 |
1731 int MarkCompactCollector::RelocateOldDataObject(HeapObject* obj) { | 1733 int MarkCompactCollector::RelocateOldDataObject(HeapObject* obj) { |
1732 return RelocateOldNonCodeObject(obj, Heap::old_data_space()); | 1734 // Recover map pointer. |
| 1735 MapWord encoding = obj->map_word(); |
| 1736 Address map_addr = encoding.DecodeMapAddress(Heap::map_space()); |
| 1737 ASSERT(Heap::map_space()->Contains(map_addr)); |
| 1738 |
| 1739 // Get forwarding address before resetting map pointer. |
| 1740 Address new_addr = GetForwardingAddressInOldSpace(obj); |
| 1741 |
| 1742 // Reset the map pointer. |
| 1743 int obj_size = RestoreMap(obj, Heap::old_data_space(), new_addr, map_addr); |
| 1744 |
| 1745 Address old_addr = obj->address(); |
| 1746 |
| 1747 if (new_addr != old_addr) { |
| 1748 if (HeapNumber::NeedsSpecialCopying(obj_size, new_addr, old_addr)) { |
| 1749 memmove(new_addr, old_addr, kPointerSize); // Copy map. |
| 1750 HeapNumber::cast(HeapObject::FromAddress(new_addr))->set_value( |
| 1751 HeapNumber::cast(obj)->value()); |
| 1752 } else { |
| 1753 memmove(new_addr, old_addr, obj_size); // Copy contents. |
| 1754 } |
| 1755 } |
| 1756 |
| 1757 ASSERT(!HeapObject::FromAddress(new_addr)->IsCode()); |
| 1758 |
| 1759 return obj_size; |
1733 } | 1760 } |
1734 | 1761 |
1735 | 1762 |
1736 int MarkCompactCollector::RelocateCellObject(HeapObject* obj) { | 1763 int MarkCompactCollector::RelocateCellObject(HeapObject* obj) { |
1737 return RelocateOldNonCodeObject(obj, Heap::cell_space()); | 1764 return RelocateOldNonCodeObject(obj, Heap::cell_space()); |
1738 } | 1765 } |
1739 | 1766 |
1740 | 1767 |
1741 int MarkCompactCollector::RelocateCodeObject(HeapObject* obj) { | 1768 int MarkCompactCollector::RelocateCodeObject(HeapObject* obj) { |
1742 // Recover map pointer. | 1769 // Recover map pointer. |
(...skipping 21 matching lines...) Expand all Loading... |
1764 LOG(CodeMoveEvent(old_addr, new_addr)); | 1791 LOG(CodeMoveEvent(old_addr, new_addr)); |
1765 } | 1792 } |
1766 | 1793 |
1767 return obj_size; | 1794 return obj_size; |
1768 } | 1795 } |
1769 | 1796 |
1770 | 1797 |
1771 int MarkCompactCollector::RelocateNewObject(HeapObject* obj) { | 1798 int MarkCompactCollector::RelocateNewObject(HeapObject* obj) { |
1772 int obj_size = obj->Size(); | 1799 int obj_size = obj->Size(); |
1773 | 1800 |
1774 // Get forwarding address | 1801 // Get forwarding address. |
1775 Address old_addr = obj->address(); | 1802 Address old_addr = obj->address(); |
1776 int offset = Heap::new_space()->ToSpaceOffsetForAddress(old_addr); | 1803 int offset = Heap::new_space()->ToSpaceOffsetForAddress(old_addr); |
1777 | 1804 |
1778 Address new_addr = | 1805 Address new_addr = |
1779 Memory::Address_at(Heap::new_space()->FromSpaceLow() + offset); | 1806 Memory::Address_at(Heap::new_space()->FromSpaceLow() + offset); |
1780 | 1807 |
1781 #ifdef DEBUG | 1808 #ifdef DEBUG |
1782 if (Heap::new_space()->FromSpaceContains(new_addr)) { | 1809 if (Heap::new_space()->FromSpaceContains(new_addr)) { |
1783 ASSERT(Heap::new_space()->FromSpaceOffsetForAddress(new_addr) <= | 1810 ASSERT(Heap::new_space()->FromSpaceOffsetForAddress(new_addr) <= |
1784 Heap::new_space()->ToSpaceOffsetForAddress(old_addr)); | 1811 Heap::new_space()->ToSpaceOffsetForAddress(old_addr)); |
1785 } else { | 1812 } else { |
1786 ASSERT(Heap::TargetSpace(obj) == Heap::old_pointer_space() || | 1813 ASSERT(Heap::TargetSpace(obj) == Heap::old_pointer_space() || |
1787 Heap::TargetSpace(obj) == Heap::old_data_space()); | 1814 Heap::TargetSpace(obj) == Heap::old_data_space()); |
1788 } | 1815 } |
1789 #endif | 1816 #endif |
1790 | 1817 |
1791 // New and old addresses cannot overlap. | 1818 if (HeapNumber::NeedsSpecialCopying(obj_size, new_addr, old_addr)) { |
1792 memcpy(reinterpret_cast<void*>(new_addr), | 1819 memcpy(reinterpret_cast<void*>(new_addr), |
1793 reinterpret_cast<void*>(old_addr), | 1820 reinterpret_cast<void*>(old_addr), |
1794 obj_size); | 1821 kPointerSize); |
| 1822 HeapNumber::cast(HeapObject::FromAddress(new_addr))->set_value( |
| 1823 HeapNumber::cast(obj)->value()); |
| 1824 } else { |
| 1825 // New and old addresses cannot overlap. |
| 1826 memcpy(reinterpret_cast<void*>(new_addr), |
| 1827 reinterpret_cast<void*>(old_addr), |
| 1828 obj_size); |
| 1829 } |
1795 | 1830 |
1796 #ifdef DEBUG | 1831 #ifdef DEBUG |
1797 if (FLAG_gc_verbose) { | 1832 if (FLAG_gc_verbose) { |
1798 PrintF("relocate %p -> %p\n", old_addr, new_addr); | 1833 PrintF("relocate %p -> %p\n", old_addr, new_addr); |
1799 } | 1834 } |
1800 #endif | 1835 #endif |
1801 | 1836 |
1802 return obj_size; | 1837 return obj_size; |
1803 } | 1838 } |
1804 | 1839 |
1805 | 1840 |
1806 // ------------------------------------------------------------------------- | 1841 // ------------------------------------------------------------------------- |
1807 // Phase 5: rebuild remembered sets | 1842 // Phase 5: rebuild remembered sets |
1808 | 1843 |
1809 void MarkCompactCollector::RebuildRSets() { | 1844 void MarkCompactCollector::RebuildRSets() { |
1810 #ifdef DEBUG | 1845 #ifdef DEBUG |
1811 ASSERT(state_ == RELOCATE_OBJECTS); | 1846 ASSERT(state_ == RELOCATE_OBJECTS); |
1812 state_ = REBUILD_RSETS; | 1847 state_ = REBUILD_RSETS; |
1813 #endif | 1848 #endif |
1814 Heap::RebuildRSets(); | 1849 Heap::RebuildRSets(); |
1815 } | 1850 } |
1816 | 1851 |
1817 } } // namespace v8::internal | 1852 } } // namespace v8::internal |
OLD | NEW |