Reviewers: ulan, Hannes Payer,

Message:
The idea is to then call
  Heap::StartIncrementalMarking and
  Heap::AdvanceIncrementalMarking
from api.cc and not loose any callback/flag information.

It should also be general enough to call with different step actions.

WDYT?


Description:
GC: Refactor incremental marking interface from heap

BUG=

Please review this at https://codereview.chromium.org/1273483002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+52, -14 lines):
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/heap/incremental-marking.h
  M src/heap/incremental-marking.cc


Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 0432ee71fa0c329e6c1bf6e690883ab26f211a75..2bd2681eb7ac65980b74c4d89f150279093a6ab6 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -768,7 +768,8 @@ void Heap::PreprocessStackTraces() {
 void Heap::HandleGCRequest() {
   if (incremental_marking()->request_type() ==
       IncrementalMarking::COMPLETE_MARKING) {
-    CollectAllGarbage(Heap::kNoGCFlags, "GC interrupt");
+    CollectAllGarbage(Heap::kNoGCFlags, "GC interrupt",
+                      incremental_marking()->CallbackFlags());
     return;
   }
   DCHECK(FLAG_overapproximate_weak_closure);
@@ -1005,9 +1006,15 @@ int Heap::NotifyContextDisposed(bool dependant_context) {
 }


+void Heap::StartIncrementalMarking(int gc_flags,
+ const GCCallbackFlags gc_callback_flags) {
+  incremental_marking()->Start(gc_flags, gc_callback_flags);
+}
+
+
 void Heap::StartIdleIncrementalMarking() {
   gc_idle_time_handler_.ResetNoProgressCounter();
-  incremental_marking()->Start(kReduceMemoryFootprintMask);
+  StartIncrementalMarking(kReduceMemoryFootprintMask, kNoGCCallbackFlags);
 }


@@ -4789,13 +4796,21 @@ GCIdleTimeHandler::HeapState Heap::ComputeHeapState() {

 double Heap::AdvanceIncrementalMarking(
     intptr_t step_size_in_bytes, double deadline_in_ms,
-    IncrementalMarking::ForceCompletionAction completion) {
+    IncrementalMarking::StepActions step_actions) {
   DCHECK(!incremental_marking()->IsStopped());
+
+  if (step_size_in_bytes == 0) {
+    GCIdleTimeHandler::HeapState heap_state = ComputeHeapState();
+    size_t step_size_in_bytes = GCIdleTimeHandler::EstimateMarkingStepSize(
+ static_cast<size_t>(GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs),
+        heap_state.incremental_marking_speed_in_bytes_per_ms);
+  }
+
   double remaining_time_in_ms = 0.0;
   do {
-    incremental_marking()->Step(step_size_in_bytes,
-                                IncrementalMarking::NO_GC_VIA_STACK_GUARD,
- IncrementalMarking::FORCE_MARKING, completion);
+    incremental_marking()->Step(
+        step_size_in_bytes, step_actions.completion_action,
+        step_actions.force_marking, step_actions.force_completion);
remaining_time_in_ms = deadline_in_ms - MonotonicallyIncreasingTimeInMs();
   } while (remaining_time_in_ms >=
                2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs &&
@@ -4815,8 +4830,7 @@ bool Heap::PerformIdleTimeAction(GCIdleTimeAction action,
       break;
     case DO_INCREMENTAL_MARKING: {
       const double remaining_idle_time_in_ms = AdvanceIncrementalMarking(
-          action.parameter, deadline_in_ms,
-          IncrementalMarking::DO_NOT_FORCE_COMPLETION);
+ action.parameter, deadline_in_ms, IncrementalMarking::StepActions());
       if (remaining_idle_time_in_ms > 0.0) {
         action.additional_work = TryFinalizeIdleIncrementalMarking(
             remaining_idle_time_in_ms, heap_state.size_of_objects,
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index 54dfc7ae1a26da7fb32d5f3922da73012a72102a..feb3c87dba46d373ae39e6d31868b17dfabcf4e7 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -852,6 +852,13 @@ class Heap {
   // incremental steps.
   void StartIdleIncrementalMarking();

+  void StartIncrementalMarking(int gc_flags,
+                               const GCCallbackFlags gc_callback_flags);
+
+  double AdvanceIncrementalMarking(
+      intptr_t step_size_in_bytes, double deadline_in_ms,
+      IncrementalMarking::StepActions step_actions);
+
   inline void increment_scan_on_scavenge_pages() {
     scan_on_scavenge_pages_++;
     if (FLAG_gc_verbose) {
@@ -2228,10 +2235,6 @@ class Heap {

   GCIdleTimeHandler::HeapState ComputeHeapState();

-  double AdvanceIncrementalMarking(
-      intptr_t step_size_in_bytes, double deadline_in_ms,
-      IncrementalMarking::ForceCompletionAction completion);
-
   bool PerformIdleTimeAction(GCIdleTimeAction action,
                              GCIdleTimeHandler::HeapState heap_state,
                              double deadline_in_ms);
Index: src/heap/incremental-marking.cc
diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index 947c961af8993d6efc959d4d1c7765a1c2e352a1..b0d0b31c44a492ac52a737359b570eaec83981b9 100644
--- a/src/heap/incremental-marking.cc
+++ b/src/heap/incremental-marking.cc
@@ -470,7 +470,8 @@ static void PatchIncrementalMarkingRecordWriteStubs(
 }


-void IncrementalMarking::Start(int mark_compact_flags) {
+void IncrementalMarking::Start(int mark_compact_flags,
+                               const GCCallbackFlags gc_callback_flags) {
   if (FLAG_trace_incremental_marking) {
     PrintF("[IncrementalMarking] Start\n");
   }
@@ -482,6 +483,7 @@ void IncrementalMarking::Start(int mark_compact_flags) {

   ResetStepCounters();

+  gc_callback_flags_ = gc_callback_flags;
   was_activated_ = true;

   if (!heap_->mark_compact_collector()->sweeping_in_progress()) {
Index: src/heap/incremental-marking.h
diff --git a/src/heap/incremental-marking.h b/src/heap/incremental-marking.h
index 8fe341154fa0597113211ccc7dd8387a350a0c34..2173183a22133d444abb8d4d0b282da3b3b30947 100644
--- a/src/heap/incremental-marking.h
+++ b/src/heap/incremental-marking.h
@@ -26,6 +26,20 @@ class IncrementalMarking {

   enum GCRequestType { COMPLETE_MARKING, OVERAPPROXIMATION };

+  struct StepActions {
+    StepActions(
+        CompletionAction complete_action_ = NO_GC_VIA_STACK_GUARD,
+        ForceMarkingAction force_marking_ = DO_NOT_FORCE_MARKING,
+        ForceCompletionAction force_completion_ = DO_NOT_FORCE_COMPLETION)
+        : completion_action(complete_action_),
+          force_marking(force_marking_),
+          force_completion(force_completion_) {}
+
+    CompletionAction completion_action;
+    ForceMarkingAction force_marking;
+    ForceCompletionAction force_completion;
+  };
+
   explicit IncrementalMarking(Heap* heap);

   static void Initialize();
@@ -67,7 +81,8 @@ class IncrementalMarking {

   bool WasActivated();

-  void Start(int mark_compact_flags);
+  void Start(int mark_compact_flags,
+             const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags);

   void Stop();

@@ -185,6 +200,8 @@ class IncrementalMarking {

   Heap* heap() const { return heap_; }

+  GCCallbackFlags CallbackFlags() const { return gc_callback_flags_; }
+
  private:
   int64_t SpaceLeftInOldSpace();

@@ -243,6 +260,8 @@ class IncrementalMarking {

   GCRequestType request_type_;

+  GCCallbackFlags gc_callback_flags_;
+
   DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking);
 };
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to