Bug 132166 - GC should be able to remove things from the DFG worklist and cancel on-going compilations if it knows that the compilation would already be invalidated
Summary: GC should be able to remove things from the DFG worklist and cancel on-going ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Filip Pizlo
URL:
Keywords:
: 132236 (view as bug list)
Depends on: 132167
Blocks:
  Show dependency treegraph
 
Reported: 2014-04-24 20:45 PDT by Filip Pizlo
Modified: 2014-04-28 12:13 PDT (History)
11 users (show)

See Also:


Attachments
I am afraid to try running this patch (13.27 KB, patch)
2014-04-25 19:51 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
possibly done (14.85 KB, patch)
2014-04-26 20:49 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
more (18.18 KB, patch)
2014-04-27 11:35 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
all the pieces are in place (27.57 KB, patch)
2014-04-27 12:59 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
might actually be done (31.73 KB, patch)
2014-04-27 15:03 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
and now, plans are cancellable at *any* time (32.57 KB, patch)
2014-04-27 18:38 PDT, Filip Pizlo
no flags Details | Formatted Diff | Diff
the patch (34.17 KB, patch)
2014-04-27 20:26 PDT, Filip Pizlo
oliver: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Filip Pizlo 2014-04-24 20:45:01 PDT
This will be fun.
Comment 1 Filip Pizlo 2014-04-25 19:51:32 PDT
Created attachment 230233 [details]
I am afraid to try running this patch
Comment 2 Filip Pizlo 2014-04-26 20:49:39 PDT
Created attachment 230253 [details]
possibly done
Comment 3 Filip Pizlo 2014-04-26 22:08:32 PDT
This appears to help but the fact that we may have a running plan hurts us.  It would be even cooler if we could cancel the running plans.
Comment 4 Filip Pizlo 2014-04-27 11:35:19 PDT
Created attachment 230262 [details]
more

Adding cancellation to DFG::Safepoint
Comment 5 Filip Pizlo 2014-04-27 12:59:49 PDT
Created attachment 230265 [details]
all the pieces are in place
Comment 6 Filip Pizlo 2014-04-27 15:03:45 PDT
Created attachment 230269 [details]
might actually be done
Comment 7 Filip Pizlo 2014-04-27 17:48:01 PDT
*** Bug 132236 has been marked as a duplicate of this bug. ***
Comment 8 Filip Pizlo 2014-04-27 18:38:01 PDT
Created attachment 230273 [details]
and now, plans are cancellable at *any* time

There is no escape from the GC cancellation monster.
Comment 9 Filip Pizlo 2014-04-27 20:26:26 PDT
Created attachment 230276 [details]
the patch
Comment 10 WebKit Commit Bot 2014-04-27 20:29:32 PDT
Attachment 230276 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/dfg/DFGPlan.cpp:127:  Wrong number of spaces before statement. (expected: 8)  [whitespace/indent] [4]
Total errors found: 1 in 20 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 Oliver Hunt 2014-04-28 09:24:45 PDT
Comment on attachment 230276 [details]
the patch

yay!
Comment 12 Mark Hahnenberg 2014-04-28 09:56:35 PDT
Comment on attachment 230276 [details]
the patch

View in context: https://bugs.webkit.org/attachment.cgi?id=230276&action=review

What are some good stress tests for this stuff? gbemu? Our compiler-heavy benchmarks on platforms with <= 2 cores? Maybe something with a bunch of workers all doing compilation?

> Source/JavaScriptCore/dfg/DFGSafepoint.cpp:105
> +        return true; // We were cancelled during a previous GC, so let's not mess with it this time around - pretend it's live and move on.

I don't understand this. Can you elaborate?

> Source/JavaScriptCore/dfg/DFGWorklist.cpp:272
> +            Deque<RefPtr<Plan>> newQueue;
> +            while (!m_queue.isEmpty()) {
> +                RefPtr<Plan> plan = m_queue.takeFirst();
> +                if (plan->stage != Plan::Cancelled)
> +                    continue;
> +                newQueue.append(plan);
> +            }
> +            m_queue.swap(newQueue);

Hmm, I'm confused by this code. What I see is:

(1) Create a new queue with all of the plans whose stage == Cancelled.
(2) Replace the old work queue with just the new queue of cancelled items.

I would think we would want to throw away the Cancelled plans and keep the non-cancelled ones. Is this what we're doing and I'm just being dense?

> Source/JavaScriptCore/heap/Heap.cpp:638
> +    GCPHASE(FinalizerDFGWorklists);

s/FinalizerDFGWorklists/FinalizeDFGWorklists/ ?
Comment 13 Filip Pizlo 2014-04-28 11:31:37 PDT
(In reply to comment #12)
> (From update of attachment 230276 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=230276&action=review
> 
> What are some good stress tests for this stuff? gbemu? Our compiler-heavy benchmarks on platforms with <= 2 cores? Maybe something with a bunch of workers all doing compilation?

Our stress testing infrastructure can already do this, more-or-less.

> 
> > Source/JavaScriptCore/dfg/DFGSafepoint.cpp:105
> > +        return true; // We were cancelled during a previous GC, so let's not mess with it this time around - pretend it's live and move on.
> 
> I don't understand this. Can you elaborate?

The GC doesn't remove safepoints.  The GC cannot force forward progress in the compiler thread.  So, after we cancel the plan associated with a safepoint (i.e. cancel the safepoint), a subsequent GC may still see the same safepoint - in a cancelled state - with a cancelled plan.  This code gracefully ignores such safepoints since there is nothing left to do for them and they do not reference any GC memory anymore.

> 
> > Source/JavaScriptCore/dfg/DFGWorklist.cpp:272
> > +            Deque<RefPtr<Plan>> newQueue;
> > +            while (!m_queue.isEmpty()) {
> > +                RefPtr<Plan> plan = m_queue.takeFirst();
> > +                if (plan->stage != Plan::Cancelled)
> > +                    continue;
> > +                newQueue.append(plan);
> > +            }
> > +            m_queue.swap(newQueue);
> 
> Hmm, I'm confused by this code. What I see is:
> 
> (1) Create a new queue with all of the plans whose stage == Cancelled.
> (2) Replace the old work queue with just the new queue of cancelled items.
> 
> I would think we would want to throw away the Cancelled plans and keep the non-cancelled ones. Is this what we're doing and I'm just being dense?

Yeah, the logic was inverted.  Thanks for catching it!

> 
> > Source/JavaScriptCore/heap/Heap.cpp:638
> > +    GCPHASE(FinalizerDFGWorklists);
> 
> s/FinalizerDFGWorklists/FinalizeDFGWorklists/ ?

Lol I will change.
Comment 14 Filip Pizlo 2014-04-28 12:13:22 PDT
Landed in http://trac.webkit.org/changeset/167897