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 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 | 1550 |
1551 // Evacuation candidates are swept by evacuator. Needs to return a valid | 1551 // Evacuation candidates are swept by evacuator. Needs to return a valid |
1552 // result before _and_ after evacuation has finished. | 1552 // result before _and_ after evacuation has finished. |
1553 static bool ShouldBeSweptLazily(Page* p) { | 1553 static bool ShouldBeSweptLazily(Page* p) { |
1554 return !p->IsEvacuationCandidate() && | 1554 return !p->IsEvacuationCandidate() && |
1555 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && | 1555 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && |
1556 !p->WasSweptPrecisely(); | 1556 !p->WasSweptPrecisely(); |
1557 } | 1557 } |
1558 | 1558 |
1559 void SetPagesToSweep(Page* first) { | 1559 void SetPagesToSweep(Page* first) { |
| 1560 if (first == &anchor_) first = NULL; |
1560 first_unswept_page_ = first; | 1561 first_unswept_page_ = first; |
1561 } | 1562 } |
1562 | 1563 |
1563 bool AdvanceSweeper(intptr_t bytes_to_sweep); | 1564 bool AdvanceSweeper(intptr_t bytes_to_sweep); |
1564 | 1565 |
1565 bool IsSweepingComplete() { | 1566 bool IsSweepingComplete() { |
1566 return !first_unswept_page_->is_valid(); | 1567 return !first_unswept_page_->is_valid(); |
1567 } | 1568 } |
1568 | 1569 |
1569 Page* FirstPage() { return anchor_.next_page(); } | 1570 Page* FirstPage() { return anchor_.next_page(); } |
1570 Page* LastPage() { return anchor_.prev_page(); } | 1571 Page* LastPage() { return anchor_.prev_page(); } |
1571 | 1572 |
1572 bool IsFragmented(Page* p) { | 1573 // Returns zero for pages that have so little fragmentation that it is not |
| 1574 // worth defragmenting them. Otherwise a positive integer that gives an |
| 1575 // estimate of fragmentation on an arbitrary scale. |
| 1576 int Fragmentation(Page* p) { |
1573 FreeList::SizeStats sizes; | 1577 FreeList::SizeStats sizes; |
1574 free_list_.CountFreeListItems(p, &sizes); | 1578 free_list_.CountFreeListItems(p, &sizes); |
1575 | 1579 |
1576 intptr_t ratio; | 1580 intptr_t ratio; |
1577 intptr_t ratio_threshold; | 1581 intptr_t ratio_threshold; |
1578 if (identity() == CODE_SPACE) { | 1582 if (identity() == CODE_SPACE) { |
1579 ratio = (sizes.medium_size_ * 10 + sizes.large_size_ * 2) * 100 / | 1583 ratio = (sizes.medium_size_ * 10 + sizes.large_size_ * 2) * 100 / |
1580 Page::kObjectAreaSize; | 1584 Page::kObjectAreaSize; |
1581 ratio_threshold = 10; | 1585 ratio_threshold = 10; |
1582 } else { | 1586 } else { |
(...skipping 14 matching lines...) Expand all Loading... |
1597 Page::kObjectAreaSize, | 1601 Page::kObjectAreaSize, |
1598 static_cast<int>(sizes.large_size_), | 1602 static_cast<int>(sizes.large_size_), |
1599 static_cast<double>(sizes.large_size_ * 100) / | 1603 static_cast<double>(sizes.large_size_ * 100) / |
1600 Page::kObjectAreaSize, | 1604 Page::kObjectAreaSize, |
1601 static_cast<int>(sizes.huge_size_), | 1605 static_cast<int>(sizes.huge_size_), |
1602 static_cast<double>(sizes.huge_size_ * 100) / | 1606 static_cast<double>(sizes.huge_size_ * 100) / |
1603 Page::kObjectAreaSize, | 1607 Page::kObjectAreaSize, |
1604 (ratio > ratio_threshold) ? "[fragmented]" : ""); | 1608 (ratio > ratio_threshold) ? "[fragmented]" : ""); |
1605 } | 1609 } |
1606 | 1610 |
1607 return (ratio > ratio_threshold) || | 1611 if (FLAG_always_compact && sizes.Total() != Page::kObjectAreaSize) { |
1608 (FLAG_always_compact && sizes.Total() != Page::kObjectAreaSize); | 1612 return 1; |
| 1613 } |
| 1614 if (ratio <= ratio_threshold) return 0; // Not fragmented. |
| 1615 |
| 1616 return static_cast<int>(ratio - ratio_threshold); |
1609 } | 1617 } |
1610 | 1618 |
1611 void EvictEvacuationCandidatesFromFreeLists(); | 1619 void EvictEvacuationCandidatesFromFreeLists(); |
1612 | 1620 |
1613 bool CanExpand(); | 1621 bool CanExpand(); |
1614 | 1622 |
| 1623 // Returns the number of total pages in this space. |
| 1624 int CountTotalPages(); |
| 1625 |
1615 protected: | 1626 protected: |
1616 // Maximum capacity of this space. | 1627 // Maximum capacity of this space. |
1617 intptr_t max_capacity_; | 1628 intptr_t max_capacity_; |
1618 | 1629 |
1619 // Accounting information for this space. | 1630 // Accounting information for this space. |
1620 AllocationStats accounting_stats_; | 1631 AllocationStats accounting_stats_; |
1621 | 1632 |
1622 // The dummy page that anchors the double linked list of pages. | 1633 // The dummy page that anchors the double linked list of pages. |
1623 Page anchor_; | 1634 Page anchor_; |
1624 | 1635 |
(...skipping 17 matching lines...) Expand all Loading... |
1642 // it cannot allocate requested number of pages from OS. | 1653 // it cannot allocate requested number of pages from OS. |
1643 bool Expand(); | 1654 bool Expand(); |
1644 | 1655 |
1645 // Generic fast case allocation function that tries linear allocation at the | 1656 // Generic fast case allocation function that tries linear allocation at the |
1646 // address denoted by top in allocation_info_. | 1657 // address denoted by top in allocation_info_. |
1647 inline HeapObject* AllocateLinearly(int size_in_bytes); | 1658 inline HeapObject* AllocateLinearly(int size_in_bytes); |
1648 | 1659 |
1649 // Slow path of AllocateRaw. This function is space-dependent. | 1660 // Slow path of AllocateRaw. This function is space-dependent. |
1650 MUST_USE_RESULT virtual HeapObject* SlowAllocateRaw(int size_in_bytes); | 1661 MUST_USE_RESULT virtual HeapObject* SlowAllocateRaw(int size_in_bytes); |
1651 | 1662 |
1652 #ifdef DEBUG | |
1653 // Returns the number of total pages in this space. | |
1654 int CountTotalPages(); | |
1655 #endif | |
1656 | |
1657 friend class PageIterator; | 1663 friend class PageIterator; |
1658 }; | 1664 }; |
1659 | 1665 |
1660 | 1666 |
1661 class NumberAndSizeInfo BASE_EMBEDDED { | 1667 class NumberAndSizeInfo BASE_EMBEDDED { |
1662 public: | 1668 public: |
1663 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 1669 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
1664 | 1670 |
1665 int number() const { return number_; } | 1671 int number() const { return number_; } |
1666 void increment_number(int num) { number_ += num; } | 1672 void increment_number(int num) { number_ += num; } |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2623 } | 2629 } |
2624 // Must be small, since an iteration is used for lookup. | 2630 // Must be small, since an iteration is used for lookup. |
2625 static const int kMaxComments = 64; | 2631 static const int kMaxComments = 64; |
2626 }; | 2632 }; |
2627 #endif | 2633 #endif |
2628 | 2634 |
2629 | 2635 |
2630 } } // namespace v8::internal | 2636 } } // namespace v8::internal |
2631 | 2637 |
2632 #endif // V8_SPACES_H_ | 2638 #endif // V8_SPACES_H_ |
OLD | NEW |