1602 {
1606
1607
1608
1609 const intptr_t allocated_since_previous_gc =
1611 intptr_t grow_heap;
1612 if (allocated_since_previous_gc > 0) {
1613 intptr_t garbage =
1614 before.CombinedUsedInWords() - after.CombinedUsedInWords();
1615
1617
1618
1620 1.0, garbage / static_cast<double>(allocated_since_previous_gc));
1621
1622 const int garbage_ratio = static_cast<int>(k * 100);
1623
1624
1625 double t = 1.0 - desired_utilization_;
1626
1627 if (gc_time_fraction > garbage_collection_time_ratio_) {
1628 t += (gc_time_fraction - garbage_collection_time_ratio_) / 100.0;
1629 }
1630
1631
1632
1633 const intptr_t grow_pages =
1634 (static_cast<intptr_t>(after.CombinedUsedInWords() /
1635 desired_utilization_) -
1636 (after.CombinedUsedInWords())) /
1638 if (garbage_ratio == 0) {
1639
1640
1641
1642 grow_heap =
1643 Utils::Maximum(
static_cast<intptr_t
>(heap_growth_max_), grow_pages);
1644 } else if (garbage_collection_time_ratio_ == 0) {
1645
1646 grow_heap =
1647 Utils::Maximum(
static_cast<intptr_t
>(heap_growth_max_), grow_pages);
1648 } else {
1649
1650
1651 intptr_t
max = heap_growth_max_;
1653 intptr_t local_grow_heap = 0;
1655 local_grow_heap = (
max +
min) / 2;
1656 const intptr_t limit =
1658 const intptr_t allocated_before_next_gc =
1659 limit - (after.CombinedUsedInWords());
1660 const double estimated_garbage = k * allocated_before_next_gc;
1661 if (t <= estimated_garbage / limit) {
1662 max = local_grow_heap - 1;
1663 } else {
1664 min = local_grow_heap + 1;
1665 }
1666 }
1667 local_grow_heap = (
max +
min) / 2;
1668 grow_heap = local_grow_heap;
1670
1671
1672 if (grow_heap >= heap_growth_max_) {
1674 }
1675 }
1676 } else {
1677 grow_heap = 0;
1678 }
1679 last_usage_ = after;
1680
1681 intptr_t max_capacity_in_words = heap_->
old_space()->max_capacity_in_words_;
1682 if (max_capacity_in_words != 0) {
1684
1685 double f =
static_cast<double>(after.CombinedUsedInWords() +
1687 static_cast<double>(max_capacity_in_words);
1689
1691
1694
1695 grow_heap =
static_cast<intptr_t
>(grow_heap *
f);
1696
1699 }
1700
1701 RecordUpdate(before, after, grow_heap, "gc");
1702}
void AddGarbageCollectionTime(int64_t start, int64_t end)
int GarbageCollectionTimeFraction()
intptr_t CombinedUsedInWords() const
static constexpr T Maximum(T x, T y)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
static constexpr intptr_t kPageSize