| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 Address body() { return address() + kObjectStartOffset; } | 364 Address body() { return address() + kObjectStartOffset; } |
| 365 | 365 |
| 366 Address body_limit() { return address() + size(); } | 366 Address body_limit() { return address() + size(); } |
| 367 | 367 |
| 368 int body_size() { return size() - kObjectStartOffset; } | 368 int body_size() { return size() - kObjectStartOffset; } |
| 369 | 369 |
| 370 bool Contains(Address addr) { | 370 bool Contains(Address addr) { |
| 371 return addr >= body() && addr < address() + size(); | 371 return addr >= body() && addr < address() + size(); |
| 372 } | 372 } |
| 373 | 373 |
| 374 // Checks whether addr can be a limit of addresses in this page. |
| 375 // It's a limit if it's in the page, or if it's just after the |
| 376 // last byte of the page. |
| 377 bool ContainsLimit(Address addr) { |
| 378 return addr >= body() && addr <= address() + size(); |
| 379 } |
| 380 |
| 374 enum MemoryChunkFlags { | 381 enum MemoryChunkFlags { |
| 375 IS_EXECUTABLE, | 382 IS_EXECUTABLE, |
| 376 WAS_SWEPT_CONSERVATIVELY, | 383 WAS_SWEPT_CONSERVATIVELY, |
| 377 CONTAINS_ONLY_DATA, | 384 CONTAINS_ONLY_DATA, |
| 378 POINTERS_TO_HERE_ARE_INTERESTING, | 385 POINTERS_TO_HERE_ARE_INTERESTING, |
| 379 POINTERS_FROM_HERE_ARE_INTERESTING, | 386 POINTERS_FROM_HERE_ARE_INTERESTING, |
| 380 SCAN_ON_SCAVENGE, | 387 SCAN_ON_SCAVENGE, |
| 381 IN_FROM_SPACE, // Mutually exclusive with IN_TO_SPACE. | 388 IN_FROM_SPACE, // Mutually exclusive with IN_TO_SPACE. |
| 382 IN_TO_SPACE, // All pages in new space has one of these two set. | 389 IN_TO_SPACE, // All pages in new space has one of these two set. |
| 383 NUM_MEMORY_CHUNK_FLAGS | 390 NUM_MEMORY_CHUNK_FLAGS |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 accounting_stats_.ExpandSpace(size); | 1329 accounting_stats_.ExpandSpace(size); |
| 1323 } | 1330 } |
| 1324 | 1331 |
| 1325 // Releases half of unused pages. | 1332 // Releases half of unused pages. |
| 1326 void Shrink(); | 1333 void Shrink(); |
| 1327 | 1334 |
| 1328 // Ensures that the capacity is at least 'capacity'. Returns false on failure. | 1335 // Ensures that the capacity is at least 'capacity'. Returns false on failure. |
| 1329 bool EnsureCapacity(int capacity); | 1336 bool EnsureCapacity(int capacity); |
| 1330 | 1337 |
| 1331 // The dummy page that anchors the linked list of pages. | 1338 // The dummy page that anchors the linked list of pages. |
| 1332 Page *anchor() { return &anchor_; } | 1339 Page* anchor() { return &anchor_; } |
| 1333 | 1340 |
| 1334 #ifdef ENABLE_HEAP_PROTECTION | 1341 #ifdef ENABLE_HEAP_PROTECTION |
| 1335 // Protect/unprotect the space by marking it read-only/writable. | 1342 // Protect/unprotect the space by marking it read-only/writable. |
| 1336 void Protect(); | 1343 void Protect(); |
| 1337 void Unprotect(); | 1344 void Unprotect(); |
| 1338 #endif | 1345 #endif |
| 1339 | 1346 |
| 1340 #ifdef DEBUG | 1347 #ifdef DEBUG |
| 1341 // Print meta info and objects in this space. | 1348 // Print meta info and objects in this space. |
| 1342 virtual void Print(); | 1349 virtual void Print(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 } | 1509 } |
| 1503 | 1510 |
| 1504 inline void set_prev_page(NewSpacePage* page) { | 1511 inline void set_prev_page(NewSpacePage* page) { |
| 1505 set_prev_chunk(page); | 1512 set_prev_chunk(page); |
| 1506 } | 1513 } |
| 1507 | 1514 |
| 1508 SemiSpace* semi_space() { | 1515 SemiSpace* semi_space() { |
| 1509 return reinterpret_cast<SemiSpace*>(owner()); | 1516 return reinterpret_cast<SemiSpace*>(owner()); |
| 1510 } | 1517 } |
| 1511 | 1518 |
| 1519 bool is_anchor() { return !this->InNewSpace(); } |
| 1520 |
| 1521 // Finds the NewSpacePage containg the given address. |
| 1522 static inline NewSpacePage* FromAddress(Address address_in_page) { |
| 1523 Address page_start = |
| 1524 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) & |
| 1525 ~Page::kPageAlignmentMask); |
| 1526 NewSpacePage* page = reinterpret_cast<NewSpacePage*>(page_start); |
| 1527 ASSERT(page->InNewSpace()); |
| 1528 return page; |
| 1529 } |
| 1530 |
| 1531 // Find the page for a limit address. A limit address is either an address |
| 1532 // inside a page, or the address right after the last byte of a page. |
| 1533 static inline NewSpacePage* FromLimit(Address address_limit) { |
| 1534 return NewSpacePage::FromAddress(address_limit - 1); |
| 1535 } |
| 1536 |
| 1512 private: | 1537 private: |
| 1513 NewSpacePage(SemiSpace* owner) { | 1538 // Create a NewSpacePage object that is only used as anchor |
| 1539 // for the doubly-linked list of real pages. |
| 1540 explicit NewSpacePage(SemiSpace* owner) { |
| 1514 InitializeAsAnchor(owner); | 1541 InitializeAsAnchor(owner); |
| 1515 } | 1542 } |
| 1516 | 1543 |
| 1517 // Finds the NewSpacePage containg the given address. | |
| 1518 static NewSpacePage* FromAddress(Address address_in_page) { | |
| 1519 Address page_start = | |
| 1520 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) & | |
| 1521 ~Page::kPageAlignmentMask); | |
| 1522 return reinterpret_cast<NewSpacePage*>(page_start); | |
| 1523 } | |
| 1524 | |
| 1525 static NewSpacePage* Initialize(Heap* heap, | 1544 static NewSpacePage* Initialize(Heap* heap, |
| 1526 Address start, | 1545 Address start, |
| 1527 SemiSpace* semi_space); | 1546 SemiSpace* semi_space); |
| 1528 | 1547 |
| 1529 // Intialize a fake NewSpacePage used as sentinel at the ends | 1548 // Intialize a fake NewSpacePage used as sentinel at the ends |
| 1530 // of a doubly-linked list of real NewSpacePages. | 1549 // of a doubly-linked list of real NewSpacePages. |
| 1531 // Only uses the prev/next links. | 1550 // Only uses the prev/next links, and sets flags to not be in new-space. |
| 1532 void InitializeAsAnchor(SemiSpace* owner); | 1551 void InitializeAsAnchor(SemiSpace* owner); |
| 1533 | 1552 |
| 1534 friend class SemiSpace; | 1553 friend class SemiSpace; |
| 1535 friend class SemiSpaceIterator; | 1554 friend class SemiSpaceIterator; |
| 1536 }; | 1555 }; |
| 1537 | 1556 |
| 1538 | 1557 |
| 1539 // ----------------------------------------------------------------------------- | 1558 // ----------------------------------------------------------------------------- |
| 1540 // SemiSpace in young generation | 1559 // SemiSpace in young generation |
| 1541 // | 1560 // |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 // Grow the semispace to the new capacity. The new capacity | 1592 // Grow the semispace to the new capacity. The new capacity |
| 1574 // requested must be larger than the current capacity. | 1593 // requested must be larger than the current capacity. |
| 1575 bool GrowTo(int new_capacity); | 1594 bool GrowTo(int new_capacity); |
| 1576 | 1595 |
| 1577 // Shrinks the semispace to the new capacity. The new capacity | 1596 // Shrinks the semispace to the new capacity. The new capacity |
| 1578 // requested must be more than the amount of used memory in the | 1597 // requested must be more than the amount of used memory in the |
| 1579 // semispace and less than the current capacity. | 1598 // semispace and less than the current capacity. |
| 1580 bool ShrinkTo(int new_capacity); | 1599 bool ShrinkTo(int new_capacity); |
| 1581 | 1600 |
| 1582 // Returns the start address of the first page of the space. | 1601 // Returns the start address of the first page of the space. |
| 1583 Address low() { | 1602 Address space_low() { |
| 1584 ASSERT(anchor_.next_page() != &anchor_); | 1603 ASSERT(anchor_.next_page() != &anchor_); |
| 1585 return anchor_.next_page()->body(); | 1604 return anchor_.next_page()->body(); |
| 1586 } | 1605 } |
| 1587 | 1606 |
| 1588 // Returns the start address of the current page of the space. | 1607 // Returns the start address of the current page of the space. |
| 1589 Address page_low() { | 1608 Address page_low() { |
| 1590 ASSERT(anchor_.next_page() != &anchor_); | 1609 ASSERT(anchor_.next_page() != &anchor_); |
| 1591 return current_page_->body(); | 1610 return current_page_->body(); |
| 1592 } | 1611 } |
| 1593 | 1612 |
| 1594 // Returns one past the end address of the space. | 1613 // Returns one past the end address of the space. |
| 1595 Address high() { | 1614 Address space_high() { |
| 1596 // TODO(gc): Change when there is more than one page. | 1615 return anchor_.prev_page()->body_limit(); |
| 1616 } |
| 1617 |
| 1618 // Returns one past the end address of the current page of the space. |
| 1619 Address page_high() { |
| 1597 return current_page_->body_limit(); | 1620 return current_page_->body_limit(); |
| 1598 } | 1621 } |
| 1599 | 1622 |
| 1623 bool AdvancePage() { |
| 1624 NewSpacePage* next_page = current_page_->next_page(); |
| 1625 if (next_page == &anchor_) return false; |
| 1626 current_page_ = next_page; |
| 1627 return true; |
| 1628 } |
| 1629 |
| 1600 // Resets the space to using the first page. | 1630 // Resets the space to using the first page. |
| 1601 void Reset(); | 1631 void Reset(); |
| 1602 | 1632 |
| 1603 // Age mark accessors. | 1633 // Age mark accessors. |
| 1604 Address age_mark() { return age_mark_; } | 1634 Address age_mark() { return age_mark_; } |
| 1605 void set_age_mark(Address mark) { age_mark_ = mark; } | 1635 void set_age_mark(Address mark) { age_mark_ = mark; } |
| 1606 | 1636 |
| 1607 // The offset of an address from the beginning of the space. | |
| 1608 int SpaceOffsetForAddress(Address addr) { | |
| 1609 return static_cast<int>(addr - low()); | |
| 1610 } | |
| 1611 | |
| 1612 // If we don't have these here then SemiSpace will be abstract. However | 1637 // If we don't have these here then SemiSpace will be abstract. However |
| 1613 // they should never be called. | 1638 // they should never be called. |
| 1614 virtual intptr_t Size() { | 1639 virtual intptr_t Size() { |
| 1615 UNREACHABLE(); | 1640 UNREACHABLE(); |
| 1616 return 0; | 1641 return 0; |
| 1617 } | 1642 } |
| 1618 | 1643 |
| 1619 virtual bool ReserveSpace(int bytes) { | 1644 virtual bool ReserveSpace(int bytes) { |
| 1620 UNREACHABLE(); | 1645 UNREACHABLE(); |
| 1621 return false; | 1646 return false; |
| 1622 } | 1647 } |
| 1623 | 1648 |
| 1624 bool is_committed() { return committed_; } | 1649 bool is_committed() { return committed_; } |
| 1625 bool Commit(); | 1650 bool Commit(); |
| 1626 bool Uncommit(); | 1651 bool Uncommit(); |
| 1627 | 1652 |
| 1628 NewSpacePage* first_page() { return NewSpacePage::FromAddress(start_); } | 1653 NewSpacePage* first_page() { return anchor_.next_page(); } |
| 1629 NewSpacePage* current_page() { return current_page_; } | 1654 NewSpacePage* current_page() { return current_page_; } |
| 1630 | 1655 |
| 1631 #ifdef ENABLE_HEAP_PROTECTION | 1656 #ifdef ENABLE_HEAP_PROTECTION |
| 1632 // Protect/unprotect the space by marking it read-only/writable. | 1657 // Protect/unprotect the space by marking it read-only/writable. |
| 1633 virtual void Protect() {} | 1658 virtual void Protect() {} |
| 1634 virtual void Unprotect() {} | 1659 virtual void Unprotect() {} |
| 1635 #endif | 1660 #endif |
| 1636 | 1661 |
| 1637 #ifdef DEBUG | 1662 #ifdef DEBUG |
| 1638 virtual void Print(); | 1663 virtual void Print(); |
| 1639 virtual void Verify(); | 1664 virtual void Verify(); |
| 1665 static void ValidateRange(Address from, Address to); |
| 1640 #endif | 1666 #endif |
| 1641 | 1667 |
| 1642 // Returns the current capacity of the semi space. | 1668 // Returns the current capacity of the semi space. |
| 1643 int Capacity() { return capacity_; } | 1669 int Capacity() { return capacity_; } |
| 1644 | 1670 |
| 1645 // Returns the maximum capacity of the semi space. | 1671 // Returns the maximum capacity of the semi space. |
| 1646 int MaximumCapacity() { return maximum_capacity_; } | 1672 int MaximumCapacity() { return maximum_capacity_; } |
| 1647 | 1673 |
| 1648 // Returns the initial capacity of the semi space. | 1674 // Returns the initial capacity of the semi space. |
| 1649 int InitialCapacity() { return initial_capacity_; } | 1675 int InitialCapacity() { return initial_capacity_; } |
| 1650 | 1676 |
| 1651 SemiSpaceId id() { return id_; } | 1677 SemiSpaceId id() { return id_; } |
| 1652 | 1678 |
| 1653 static void Swap(SemiSpace* from, SemiSpace* to); | 1679 static void Swap(SemiSpace* from, SemiSpace* to); |
| 1654 | 1680 |
| 1655 private: | 1681 private: |
| 1656 // Flips the semispace between being from-space and to-space. | 1682 // Flips the semispace between being from-space and to-space. |
| 1657 // Copies the flags into the masked positions on all pages in the space. | 1683 // Copies the flags into the masked positions on all pages in the space. |
| 1658 void FlipPages(intptr_t flags, intptr_t flag_mask); | 1684 void FlipPages(intptr_t flags, intptr_t flag_mask); |
| 1659 | 1685 |
| 1686 NewSpacePage* anchor() { return &anchor_; } |
| 1687 |
| 1660 // The current and maximum capacity of the space. | 1688 // The current and maximum capacity of the space. |
| 1661 int capacity_; | 1689 int capacity_; |
| 1662 int maximum_capacity_; | 1690 int maximum_capacity_; |
| 1663 int initial_capacity_; | 1691 int initial_capacity_; |
| 1664 | 1692 |
| 1665 // The start address of the space. | 1693 // The start address of the space. |
| 1666 Address start_; | 1694 Address start_; |
| 1667 // Used to govern object promotion during mark-compact collection. | 1695 // Used to govern object promotion during mark-compact collection. |
| 1668 Address age_mark_; | 1696 Address age_mark_; |
| 1669 | 1697 |
| 1670 // Masks and comparison values to test for containment in this semispace. | 1698 // Masks and comparison values to test for containment in this semispace. |
| 1671 uintptr_t address_mask_; | 1699 uintptr_t address_mask_; |
| 1672 uintptr_t object_mask_; | 1700 uintptr_t object_mask_; |
| 1673 uintptr_t object_expected_; | 1701 uintptr_t object_expected_; |
| 1674 | 1702 |
| 1675 bool committed_; | 1703 bool committed_; |
| 1676 SemiSpaceId id_; | 1704 SemiSpaceId id_; |
| 1677 | 1705 |
| 1678 NewSpacePage anchor_; | 1706 NewSpacePage anchor_; |
| 1679 NewSpacePage* current_page_; | 1707 NewSpacePage* current_page_; |
| 1680 | 1708 |
| 1709 friend class SemiSpaceIterator; |
| 1710 friend class NewSpacePageIterator; |
| 1681 public: | 1711 public: |
| 1682 TRACK_MEMORY("SemiSpace") | 1712 TRACK_MEMORY("SemiSpace") |
| 1683 }; | 1713 }; |
| 1684 | 1714 |
| 1685 | 1715 |
| 1686 // A SemiSpaceIterator is an ObjectIterator that iterates over the active | 1716 // A SemiSpaceIterator is an ObjectIterator that iterates over the active |
| 1687 // semispace of the heap's new space. It iterates over the objects in the | 1717 // semispace of the heap's new space. It iterates over the objects in the |
| 1688 // semispace from a given start address (defaulting to the bottom of the | 1718 // semispace from a given start address (defaulting to the bottom of the |
| 1689 // semispace) to the top of the semispace. New objects allocated after the | 1719 // semispace) to the top of the semispace. New objects allocated after the |
| 1690 // iterator is created are not iterated. | 1720 // iterator is created are not iterated. |
| 1691 class SemiSpaceIterator : public ObjectIterator { | 1721 class SemiSpaceIterator : public ObjectIterator { |
| 1692 public: | 1722 public: |
| 1693 // Create an iterator over the objects in the given space. If no start | 1723 // Create an iterator over the objects in the given space. If no start |
| 1694 // address is given, the iterator starts from the bottom of the space. If | 1724 // address is given, the iterator starts from the bottom of the space. If |
| 1695 // no size function is given, the iterator calls Object::Size(). | 1725 // no size function is given, the iterator calls Object::Size(). |
| 1726 |
| 1727 // Iterate over all of allocated to-space. |
| 1696 explicit SemiSpaceIterator(NewSpace* space); | 1728 explicit SemiSpaceIterator(NewSpace* space); |
| 1729 // Iterate over all of allocated to-space, with a custome size function. |
| 1697 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func); | 1730 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func); |
| 1731 // Iterate over part of allocated to-space, from start to the end |
| 1732 // of allocation. |
| 1698 SemiSpaceIterator(NewSpace* space, Address start); | 1733 SemiSpaceIterator(NewSpace* space, Address start); |
| 1734 // Iterate from one address to another in the same semi-space. |
| 1735 SemiSpaceIterator(Address from, Address to); |
| 1699 | 1736 |
| 1700 HeapObject* Next() { | 1737 HeapObject* Next() { |
| 1738 if (current_ == limit_) return NULL; |
| 1701 if (current_ == current_page_limit_) { | 1739 if (current_ == current_page_limit_) { |
| 1702 // TODO(gc): Add something here when we have more than one page. | 1740 NewSpacePage* page = NewSpacePage::FromAddress(current_ - 1); |
| 1741 page = page->next_page(); |
| 1742 ASSERT(!page->is_anchor()); |
| 1743 current_ = page->body(); |
| 1744 if (current_ == limit_) return NULL; |
| 1703 } | 1745 } |
| 1704 if (current_ == limit_) return NULL; | |
| 1705 | 1746 |
| 1706 HeapObject* object = HeapObject::FromAddress(current_); | 1747 HeapObject* object = HeapObject::FromAddress(current_); |
| 1707 int size = (size_func_ == NULL) ? object->Size() : size_func_(object); | 1748 int size = (size_func_ == NULL) ? object->Size() : size_func_(object); |
| 1708 | 1749 |
| 1709 current_ += size; | 1750 current_ += size; |
| 1710 return object; | 1751 return object; |
| 1711 } | 1752 } |
| 1712 | 1753 |
| 1713 // Implementation of the ObjectIterator functions. | 1754 // Implementation of the ObjectIterator functions. |
| 1714 virtual HeapObject* next_object() { return Next(); } | 1755 virtual HeapObject* next_object() { return Next(); } |
| 1715 | 1756 |
| 1716 private: | 1757 private: |
| 1717 void Initialize(NewSpace* space, | 1758 void Initialize(Address start, |
| 1718 Address start, | |
| 1719 Address end, | 1759 Address end, |
| 1720 HeapObjectCallback size_func); | 1760 HeapObjectCallback size_func); |
| 1721 | 1761 |
| 1722 // The semispace. | |
| 1723 SemiSpace* space_; | |
| 1724 // The current iteration point. | 1762 // The current iteration point. |
| 1725 Address current_; | 1763 Address current_; |
| 1726 // The end of the current page. | 1764 // The end of the current page. |
| 1727 Address current_page_limit_; | 1765 Address current_page_limit_; |
| 1728 // The end of iteration. | 1766 // The end of iteration. |
| 1729 Address limit_; | 1767 Address limit_; |
| 1730 // The callback function. | 1768 // The callback function. |
| 1731 HeapObjectCallback size_func_; | 1769 HeapObjectCallback size_func_; |
| 1732 }; | 1770 }; |
| 1733 | 1771 |
| 1734 | 1772 |
| 1735 // ----------------------------------------------------------------------------- | 1773 // ----------------------------------------------------------------------------- |
| 1774 // A PageIterator iterates the pages in a semi-space. |
| 1775 class NewSpacePageIterator BASE_EMBEDDED { |
| 1776 public: |
| 1777 // Make an iterator that runs over all pages in the given semispace, |
| 1778 // even those not used in allocation. |
| 1779 explicit inline NewSpacePageIterator(SemiSpace* space); |
| 1780 // Make iterator that iterates from the page containing start |
| 1781 // to the page that contains limit in the same semispace. |
| 1782 inline NewSpacePageIterator(Address start, Address limit); |
| 1783 |
| 1784 inline bool has_next(); |
| 1785 inline NewSpacePage* next(); |
| 1786 |
| 1787 private: |
| 1788 NewSpacePage* prev_page_; // Previous page returned. |
| 1789 // Next page that will be returned. Cached here so that we can use this |
| 1790 // iterator for operations that deallocate pages. |
| 1791 NewSpacePage* next_page_; |
| 1792 // Last page returned. |
| 1793 NewSpacePage* last_page_; |
| 1794 }; |
| 1795 |
| 1796 |
| 1797 // ----------------------------------------------------------------------------- |
| 1736 // The young generation space. | 1798 // The young generation space. |
| 1737 // | 1799 // |
| 1738 // The new space consists of a contiguous pair of semispaces. It simply | 1800 // The new space consists of a contiguous pair of semispaces. It simply |
| 1739 // forwards most functions to the appropriate semispace. | 1801 // forwards most functions to the appropriate semispace. |
| 1740 | 1802 |
| 1741 class NewSpace : public Space { | 1803 class NewSpace : public Space { |
| 1742 public: | 1804 public: |
| 1743 // Constructor. | 1805 // Constructor. |
| 1744 explicit NewSpace(Heap* heap) | 1806 explicit NewSpace(Heap* heap) |
| 1745 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 1807 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 ASSERT(to_space_.Capacity() == from_space_.Capacity()); | 1873 ASSERT(to_space_.Capacity() == from_space_.Capacity()); |
| 1812 return to_space_.Capacity(); | 1874 return to_space_.Capacity(); |
| 1813 } | 1875 } |
| 1814 | 1876 |
| 1815 // Return the total amount of memory committed for new space. | 1877 // Return the total amount of memory committed for new space. |
| 1816 intptr_t CommittedMemory() { | 1878 intptr_t CommittedMemory() { |
| 1817 if (from_space_.is_committed()) return 2 * Capacity(); | 1879 if (from_space_.is_committed()) return 2 * Capacity(); |
| 1818 return Capacity(); | 1880 return Capacity(); |
| 1819 } | 1881 } |
| 1820 | 1882 |
| 1821 // Return the available bytes without growing in the active semispace. | 1883 // Return the available bytes without growing or switching page in the |
| 1822 intptr_t Available() { return Capacity() - Size(); } | 1884 // active semispace. |
| 1885 intptr_t Available() { |
| 1886 return allocation_info_.limit - allocation_info_.top; |
| 1887 } |
| 1823 | 1888 |
| 1824 // Return the maximum capacity of a semispace. | 1889 // Return the maximum capacity of a semispace. |
| 1825 int MaximumCapacity() { | 1890 int MaximumCapacity() { |
| 1826 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); | 1891 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); |
| 1827 return to_space_.MaximumCapacity(); | 1892 return to_space_.MaximumCapacity(); |
| 1828 } | 1893 } |
| 1829 | 1894 |
| 1830 // Returns the initial capacity of a semispace. | 1895 // Returns the initial capacity of a semispace. |
| 1831 int InitialCapacity() { | 1896 int InitialCapacity() { |
| 1832 ASSERT(to_space_.InitialCapacity() == from_space_.InitialCapacity()); | 1897 ASSERT(to_space_.InitialCapacity() == from_space_.InitialCapacity()); |
| 1833 return to_space_.InitialCapacity(); | 1898 return to_space_.InitialCapacity(); |
| 1834 } | 1899 } |
| 1835 | 1900 |
| 1836 // Return the address of the allocation pointer in the active semispace. | 1901 // Return the address of the allocation pointer in the active semispace. |
| 1837 Address top() { return allocation_info_.top; } | 1902 Address top() { return allocation_info_.top; } |
| 1838 // Return the address of the first object in the active semispace. | 1903 // Return the address of the first object in the active semispace. |
| 1839 Address bottom() { return to_space_.low(); } | 1904 Address bottom() { return to_space_.space_low(); } |
| 1840 | 1905 |
| 1841 // Get the age mark of the inactive semispace. | 1906 // Get the age mark of the inactive semispace. |
| 1842 Address age_mark() { return from_space_.age_mark(); } | 1907 Address age_mark() { return from_space_.age_mark(); } |
| 1843 // Set the age mark in the active semispace. | 1908 // Set the age mark in the active semispace. |
| 1844 void set_age_mark(Address mark) { to_space_.set_age_mark(mark); } | 1909 void set_age_mark(Address mark) { to_space_.set_age_mark(mark); } |
| 1845 | 1910 |
| 1846 // The start address of the space and a bit mask. Anding an address in the | 1911 // The start address of the space and a bit mask. Anding an address in the |
| 1847 // new space with the mask will result in the start address. | 1912 // new space with the mask will result in the start address. |
| 1848 Address start() { return start_; } | 1913 Address start() { return start_; } |
| 1849 uintptr_t mask() { return address_mask_; } | 1914 uintptr_t mask() { return address_mask_; } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1866 MUST_USE_RESULT MaybeObject* AllocateRaw(int size_in_bytes) { | 1931 MUST_USE_RESULT MaybeObject* AllocateRaw(int size_in_bytes) { |
| 1867 return AllocateRawInternal(size_in_bytes); | 1932 return AllocateRawInternal(size_in_bytes); |
| 1868 } | 1933 } |
| 1869 | 1934 |
| 1870 // Reset the allocation pointer to the beginning of the active semispace. | 1935 // Reset the allocation pointer to the beginning of the active semispace. |
| 1871 void ResetAllocationInfo(); | 1936 void ResetAllocationInfo(); |
| 1872 | 1937 |
| 1873 void LowerInlineAllocationLimit(intptr_t step) { | 1938 void LowerInlineAllocationLimit(intptr_t step) { |
| 1874 inline_alloction_limit_step_ = step; | 1939 inline_alloction_limit_step_ = step; |
| 1875 if (step == 0) { | 1940 if (step == 0) { |
| 1876 allocation_info_.limit = to_space_.high(); | 1941 allocation_info_.limit = to_space_.page_high(); |
| 1877 } else { | 1942 } else { |
| 1878 allocation_info_.limit = Min( | 1943 allocation_info_.limit = Min( |
| 1879 allocation_info_.top + inline_alloction_limit_step_, | 1944 allocation_info_.top + inline_alloction_limit_step_, |
| 1880 allocation_info_.limit); | 1945 allocation_info_.limit); |
| 1881 } | 1946 } |
| 1882 top_on_previous_step_ = allocation_info_.top; | 1947 top_on_previous_step_ = allocation_info_.top; |
| 1883 } | 1948 } |
| 1884 | 1949 |
| 1885 // Get the extent of the inactive semispace (for use as a marking stack). | 1950 // Get the extent of the inactive semispace (for use as a marking stack, |
| 1886 Address FromSpaceLow() { return from_space_.low(); } | 1951 // or to zap it). |
| 1887 Address FromSpaceHigh() { return from_space_.high(); } | 1952 Address FromSpacePageLow() { return from_space_.page_low(); } |
| 1953 Address FromSpaceLow() { return from_space_.space_low(); } |
| 1954 Address FromSpaceHigh() { return from_space_.space_high(); } |
| 1888 | 1955 |
| 1889 // Get the extent of the active semispace (to sweep newly copied objects | 1956 // Get the extent of the active semispace's pages' memory. |
| 1890 // during a scavenge collection). | 1957 Address ToSpaceLow() { return to_space_.space_low(); } |
| 1891 Address ToSpaceLow() { return to_space_.low(); } | 1958 Address ToSpaceHigh() { return to_space_.space_high(); } |
| 1892 Address ToSpaceHigh() { return to_space_.high(); } | |
| 1893 | |
| 1894 // Offsets from the beginning of the semispaces. | |
| 1895 int ToSpaceOffsetForAddress(Address a) { | |
| 1896 return to_space_.SpaceOffsetForAddress(a); | |
| 1897 } | |
| 1898 int FromSpaceOffsetForAddress(Address a) { | |
| 1899 return from_space_.SpaceOffsetForAddress(a); | |
| 1900 } | |
| 1901 | 1959 |
| 1902 inline bool ToSpaceContains(Address address) { | 1960 inline bool ToSpaceContains(Address address) { |
| 1903 MemoryChunk* page = MemoryChunk::FromAddress(address); | 1961 MemoryChunk* page = MemoryChunk::FromAddress(address); |
| 1904 return page->is_valid() && page->InToSpace(); | 1962 return page->is_valid() && page->InToSpace(); |
| 1905 } | 1963 } |
| 1906 | 1964 |
| 1907 inline bool FromSpaceContains(Address address) { | 1965 inline bool FromSpaceContains(Address address) { |
| 1908 MemoryChunk* page = MemoryChunk::FromAddress(address); | 1966 MemoryChunk* page = MemoryChunk::FromAddress(address); |
| 1909 return page->is_valid() && page->InFromSpace(); | 1967 return page->is_valid() && page->InFromSpace(); |
| 1910 } | 1968 } |
| 1911 | 1969 |
| 1912 // True if the object is a heap object in the address range of the | 1970 // True if the object is a heap object in the address range of the |
| 1913 // respective semispace (not necessarily below the allocation pointer of the | 1971 // respective semispace (not necessarily below the allocation pointer of the |
| 1914 // semispace). | 1972 // semispace). |
| 1915 bool ToSpaceContains(Object* o) { | 1973 bool ToSpaceContains(Object* o) { |
| 1916 if (o->IsSmi()) return false; | 1974 if (o->IsSmi()) return false; |
| 1917 Address address = reinterpret_cast<Address>(o); | 1975 Address address = reinterpret_cast<Address>(o); |
| 1918 return ToSpaceContains(address); | 1976 return ToSpaceContains(address); |
| 1919 } | 1977 } |
| 1920 | 1978 |
| 1921 bool FromSpaceContains(Object* o) { | 1979 bool FromSpaceContains(Object* o) { |
| 1922 if (o->IsSmi()) return false; | 1980 if (o->IsSmi()) return false; |
| 1923 Address address = reinterpret_cast<Address>(o); | 1981 Address address = reinterpret_cast<Address>(o); |
| 1924 return FromSpaceContains(address); | 1982 return FromSpaceContains(address); |
| 1925 } | 1983 } |
| 1926 | 1984 |
| 1985 // Try to switch the active semispace to a new, empty, page. |
| 1986 // Returns false if this isn't possible or reasonable (i.e., there |
| 1987 // are no pages, or the current page is already empty), or true |
| 1988 // if successful. |
| 1989 bool AddFreshPage(); |
| 1990 |
| 1927 virtual bool ReserveSpace(int bytes); | 1991 virtual bool ReserveSpace(int bytes); |
| 1928 | 1992 |
| 1929 // Resizes a sequential string which must be the most recent thing that was | 1993 // Resizes a sequential string which must be the most recent thing that was |
| 1930 // allocated in new space. | 1994 // allocated in new space. |
| 1931 template <typename StringType> | 1995 template <typename StringType> |
| 1932 inline void ShrinkStringAtAllocationBoundary(String* string, int len); | 1996 inline void ShrinkStringAtAllocationBoundary(String* string, int len); |
| 1933 | 1997 |
| 1934 #ifdef ENABLE_HEAP_PROTECTION | 1998 #ifdef ENABLE_HEAP_PROTECTION |
| 1935 // Protect/unprotect the space by marking it read-only/writable. | 1999 // Protect/unprotect the space by marking it read-only/writable. |
| 1936 virtual void Protect(); | 2000 virtual void Protect(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1976 | 2040 |
| 1977 NewSpacePage* ActivePage() { | 2041 NewSpacePage* ActivePage() { |
| 1978 return to_space_.current_page(); | 2042 return to_space_.current_page(); |
| 1979 } | 2043 } |
| 1980 | 2044 |
| 1981 NewSpacePage* InactivePage() { | 2045 NewSpacePage* InactivePage() { |
| 1982 return from_space_.current_page(); | 2046 return from_space_.current_page(); |
| 1983 } | 2047 } |
| 1984 | 2048 |
| 1985 private: | 2049 private: |
| 2050 // Update allocation info to match the current to-space page. |
| 2051 void UpdateAllocationInfo(); |
| 2052 |
| 1986 Address chunk_base_; | 2053 Address chunk_base_; |
| 1987 uintptr_t chunk_size_; | 2054 uintptr_t chunk_size_; |
| 1988 | 2055 |
| 1989 // The semispaces. | 2056 // The semispaces. |
| 1990 SemiSpace to_space_; | 2057 SemiSpace to_space_; |
| 1991 SemiSpace from_space_; | 2058 SemiSpace from_space_; |
| 1992 | 2059 |
| 1993 // Start address and bit mask for containment testing. | 2060 // Start address and bit mask for containment testing. |
| 1994 Address start_; | 2061 Address start_; |
| 1995 uintptr_t address_mask_; | 2062 uintptr_t address_mask_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 virtual void PrepareForMarkCompact(bool will_compact); | 2115 virtual void PrepareForMarkCompact(bool will_compact); |
| 2049 | 2116 |
| 2050 public: | 2117 public: |
| 2051 TRACK_MEMORY("OldSpace") | 2118 TRACK_MEMORY("OldSpace") |
| 2052 }; | 2119 }; |
| 2053 | 2120 |
| 2054 | 2121 |
| 2055 // For contiguous spaces, top should be in the space (or at the end) and limit | 2122 // For contiguous spaces, top should be in the space (or at the end) and limit |
| 2056 // should be the end of the space. | 2123 // should be the end of the space. |
| 2057 #define ASSERT_SEMISPACE_ALLOCATION_INFO(info, space) \ | 2124 #define ASSERT_SEMISPACE_ALLOCATION_INFO(info, space) \ |
| 2058 ASSERT((space).low() <= (info).top \ | 2125 ASSERT((space).page_low() <= (info).top \ |
| 2059 && (info).top <= (space).high() \ | 2126 && (info).top <= (space).page_high() \ |
| 2060 && (info).limit <= (space).high()) | 2127 && (info).limit <= (space).page_high()) |
| 2061 | 2128 |
| 2062 | 2129 |
| 2063 // ----------------------------------------------------------------------------- | 2130 // ----------------------------------------------------------------------------- |
| 2064 // Old space for objects of a fixed size | 2131 // Old space for objects of a fixed size |
| 2065 | 2132 |
| 2066 class FixedSpace : public PagedSpace { | 2133 class FixedSpace : public PagedSpace { |
| 2067 public: | 2134 public: |
| 2068 FixedSpace(Heap* heap, | 2135 FixedSpace(Heap* heap, |
| 2069 intptr_t max_capacity, | 2136 intptr_t max_capacity, |
| 2070 AllocationSpace id, | 2137 AllocationSpace id, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2371 } | 2438 } |
| 2372 // Must be small, since an iteration is used for lookup. | 2439 // Must be small, since an iteration is used for lookup. |
| 2373 static const int kMaxComments = 64; | 2440 static const int kMaxComments = 64; |
| 2374 }; | 2441 }; |
| 2375 #endif | 2442 #endif |
| 2376 | 2443 |
| 2377 | 2444 |
| 2378 } } // namespace v8::internal | 2445 } } // namespace v8::internal |
| 2379 | 2446 |
| 2380 #endif // V8_SPACES_H_ | 2447 #endif // V8_SPACES_H_ |
| OLD | NEW |