Bug 204919 - The compiler thread should not adjust Identifier refCounts.
Summary: The compiler thread should not adjust Identifier refCounts.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-12-05 14:26 PST by Mark Lam
Modified: 2019-12-07 10:57 PST (History)
8 users (show)

See Also:


Attachments
proposed patch. (21.17 KB, patch)
2019-12-05 14:50 PST, Mark Lam
saam: review-
Details | Formatted Diff | Diff
proposed patch. (28.94 KB, patch)
2019-12-06 16:30 PST, Mark Lam
saam: review+
Details | Formatted Diff | Diff
patch for landing. (28.96 KB, patch)
2019-12-06 18:27 PST, Mark Lam
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2019-12-05 14:26:40 PST
<rdar://problem/57426861>
Comment 1 Mark Lam 2019-12-05 14:50:51 PST
Created attachment 384960 [details]
proposed patch.
Comment 2 Saam Barati 2019-12-05 15:02:01 PST
Comment on attachment 384960 [details]
proposed patch.

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

r- because of bug I noticed

> Source/JavaScriptCore/bytecode/GetByStatus.h:98
> +    using IdentifierKeepAlive = std::function<void(Box<Identifier>)>;

let's use WTF::SharedTask so that we don't repeatedly copy around the std::function struct. Instead, we just ref count it.

> Source/JavaScriptCore/dfg/DFGPlan.h:121
> +        m_identifiersKeptAliveForCleanUp.append(WTFMove(identifier));

let's add a branch here:
if (identifier)
    m_identifiersKeptAliveForCleanUp.append(WTFMove(identifier));

So we don't waste memory in the vector for null entries

> Source/JavaScriptCore/dfg/DFGWorklist.cpp:418
> +        m_cancelledPlans.clear();

I think this is wrong, unfortunately. Imagine we're in an API scenario (or web worker scenario). We have multiple VMs. We're now deleting Plans for other VMs. This will lead to the race happening still.

I suggest writing a function like:
deleteCancelledPlansForVM(VM&)

And I'll suggest again what I suggested in person, which is to assert that we're holding the current VM lock.
Comment 3 Mark Lam 2019-12-06 16:30:47 PST
Created attachment 385055 [details]
proposed patch.
Comment 4 Saam Barati 2019-12-06 17:04:44 PST
Comment on attachment 385055 [details]
proposed patch.

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

r=me

> Source/JavaScriptCore/dfg/DFGPlan.cpp:712
> +    // a cancelled plan needs to keep its m_vm pointer to let the mutator know ]

remove "]"

> Source/JavaScriptCore/dfg/DFGPlan.cpp:717
> +    // Similarly, plans may be cancelled from the GC thread. In that case, the
> +    // treatment is same as the above except that the cancelled plan will be
> +    // kept alive in the worklist's m_keptAliveCancelledPlansFromGCThread.

when the vector's are unified, this paragraph can be omitted

> Source/JavaScriptCore/dfg/DFGPlan.cpp:723
> +    // We rely on this all over the place to filter out Cancelled plans.

you should say what "this" is. Specifically, a bit comparison against VM pointer fails

> Source/JavaScriptCore/dfg/DFGWorklist.cpp:99
> +        bool isInMutator = m_plan->unnukedVM()->currentThreadIsHoldingAPILock();

let's remove this and just always add it to the vector based on what we talked about

> Source/JavaScriptCore/dfg/DFGWorklist.cpp:311
> +void removeCancelledPlans(VM& vm, HashSet<RefPtr<Plan>>& removedPlans, Vector& cancelledPlans)

once we have one vector, let's just put this below

> Source/JavaScriptCore/dfg/DFGWorklist.cpp:330
> +    HashSet<RefPtr<Plan>> removedPlans;

once the function is moved in here, you can conditionalize this on !ASSERT_DISABLED

> Source/JavaScriptCore/dfg/DFGWorklist.h:118
> +    Vector<RefPtr<Plan>, 4> m_keptAliveCancelledPlansFromGCThread;
> +    Vector<RefPtr<Plan>, 4> m_keptAliveCancelledPlansFromCompilerThread;

let's join these together and perhaps let's call it  something like "m_cancelledPlansPendingDestruction" or something like that
Comment 5 Mark Lam 2019-12-06 18:27:09 PST
Created attachment 385074 [details]
patch for landing.

Thanks for the review.  I've applied the changes Saam requested, and also fixed a missing JSLock acquisition in Debugger::detach().  This was causing the inspector tests to fail.

Let's try this on the EWS now.
Comment 6 Mark Lam 2019-12-06 22:08:58 PST
Landed in r253243: <http://trac.webkit.org/r253243>.
Comment 7 Mark Lam 2019-12-07 10:57:39 PST
+ Build fix landed in r253257: <http://trac.webkit.org/r253257>.