1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_HEAP_SCAVENGE_JOB_H_
6 #define V8_HEAP_SCAVENGE_JOB_H_
8 #include "src/cancelable-task.h"
9 #include "src/heap/gc-tracer.h"
18 // This class posts idle tasks and performs scavenges in the idle tasks.
21 class IdleTask : public CancelableIdleTask {
23 explicit IdleTask(Isolate* isolate, ScavengeJob* job)
24 : CancelableIdleTask(isolate), job_(job) {}
25 // CancelableIdleTask overrides.
26 void RunInternal(double deadline_in_seconds) override;
33 : idle_task_pending_(false),
34 idle_task_rescheduled_(false),
35 bytes_allocated_since_the_last_task_(0) {}
37 // Posts an idle task if the cumulative bytes allocated since the last
38 // idle task exceed kBytesAllocatedBeforeNextIdleTask.
39 void ScheduleIdleTaskIfNeeded(Heap* heap, int bytes_allocated);
41 // Posts an idle task ignoring the bytes allocated, but makes sure
42 // that the new idle task cannot reschedule again.
43 // This prevents infinite rescheduling.
44 void RescheduleIdleTask(Heap* heap);
46 bool IdleTaskPending() { return idle_task_pending_; }
47 void NotifyIdleTask() { idle_task_pending_ = false; }
48 bool IdleTaskRescheduled() { return idle_task_rescheduled_; }
50 static bool ReachedIdleAllocationLimit(size_t scavenge_speed_in_bytes_per_ms,
51 size_t new_space_size,
52 size_t new_space_capacity);
54 static bool EnoughIdleTimeForScavenge(double idle_time_ms,
55 size_t scavenge_speed_in_bytes_per_ms,
56 size_t new_space_size);
58 // If we haven't recorded any scavenger events yet, we use a conservative
59 // lower bound for the scavenger speed.
60 static const int kInitialScavengeSpeedInBytesPerMs = 256 * KB;
61 // Estimate of the average idle time that an idle task gets.
62 static const int kAverageIdleTimeMs = 5;
63 // The number of bytes to be allocated in new space before the next idle
65 static const size_t kBytesAllocatedBeforeNextIdleTask = 512 * KB;
66 // The minimum size of allocated new space objects to trigger a scavenge.
67 static const size_t kMinAllocationLimit = 512 * KB;
68 // The allocation limit cannot exceed this fraction of the new space capacity.
69 static const double kMaxAllocationLimitAsFractionOfNewSpace;
72 void ScheduleIdleTask(Heap* heap);
73 bool idle_task_pending_;
74 bool idle_task_rescheduled_;
75 int bytes_allocated_since_the_last_task_;
78 } // namespace v8::internal
80 #endif // V8_HEAP_SCAVENGE_JOB_H_