1415 {
1419
1420
1421
1422 const intptr_t allocated_since_previous_gc =
1424 intptr_t grow_heap;
1425 if (allocated_since_previous_gc > 0) {
1426 intptr_t garbage =
1427 before.CombinedUsedInWords() - after.CombinedUsedInWords();
1428
1430
1431
1433 1.0, garbage / static_cast<double>(allocated_since_previous_gc));
1434
1435 const int garbage_ratio = static_cast<int>(k * 100);
1436
1437
1438 double t = 1.0 - desired_utilization_;
1439
1440 if (gc_time_fraction > garbage_collection_time_ratio_) {
1441 t += (gc_time_fraction - garbage_collection_time_ratio_) / 100.0;
1442 }
1443
1444
1445
1446 const intptr_t grow_pages =
1447 (static_cast<intptr_t>(after.CombinedUsedInWords() /
1448 desired_utilization_) -
1449 (after.CombinedUsedInWords())) /
1451 if (garbage_ratio == 0) {
1452
1453
1454
1455 grow_heap =
1456 Utils::Maximum(
static_cast<intptr_t
>(heap_growth_max_), grow_pages);
1457 } else if (garbage_collection_time_ratio_ == 0) {
1458
1459 grow_heap =
1460 Utils::Maximum(
static_cast<intptr_t
>(heap_growth_max_), grow_pages);
1461 } else {
1462
1463
1464 intptr_t
max = heap_growth_max_;
1466 intptr_t local_grow_heap = 0;
1468 local_grow_heap = (
max +
min) / 2;
1469 const intptr_t limit =
1471 const intptr_t allocated_before_next_gc =
1472 limit - (after.CombinedUsedInWords());
1473 const double estimated_garbage = k * allocated_before_next_gc;
1474 if (t <= estimated_garbage / limit) {
1475 max = local_grow_heap - 1;
1476 } else {
1477 min = local_grow_heap + 1;
1478 }
1479 }
1480 local_grow_heap = (
max +
min) / 2;
1481 grow_heap = local_grow_heap;
1483
1484
1485 if (grow_heap >= heap_growth_max_) {
1487 }
1488 }
1489 } else {
1490 grow_heap = 0;
1491 }
1492 last_usage_ = after;
1493
1494 intptr_t max_capacity_in_words = heap_->
old_space()->max_capacity_in_words_;
1495 if (max_capacity_in_words != 0) {
1497
1498 double f =
static_cast<double>(after.CombinedUsedInWords() +
1500 static_cast<double>(max_capacity_in_words);
1502
1504
1507
1508 grow_heap =
static_cast<intptr_t
>(grow_heap *
f);
1509
1512 }
1513
1514 RecordUpdate(before, after, grow_heap, "gc");
1515}
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