Bug 22308

Summary: Improve Worker GC behavior
Product: WebKit Reporter: Alexey Proskuryakov <ap>
Component: WebCore JavaScriptAssignee: Alexey Proskuryakov <ap>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.5   
Attachments:
Description Flags
proposed patch darin: review+

Description Alexey Proskuryakov 2008-11-17 06:18:07 PST
Here is what Firefox beta does, and what I suggest that we do as well.

Worker object is GC protected if:
- there is JS executing in its thread,
- there are pending messages in any direction, or
- there is an active object in worker thread, such as a timer, async XHR etc.

A particular feature of this approach is that workers that have made a setInterval() call, or just run a tight loop, will not be collected until their owner is destroyed, even if there is no way left for them to communicate in either direction. This can be seen as a problem leading to likely resource leakage, or as a feature.

There will also be a terminate() call to manually shut down a worker, which Firefox doesn't currently provide.
Comment 1 Alexey Proskuryakov 2008-11-17 06:27:48 PST
Created attachment 25211 [details]
proposed patch
Comment 2 Darin Adler 2008-11-17 09:23:49 PST
Comment on attachment 25211 [details]
proposed patch

> +        Made hasPendingActivity() virtul, letting Worker add behavior to it.

Misspelled virtual here.

> +    m_workerContext->thread()->messagingProxy()->reportWorkerThreadActivity(false, m_workerContext->hasPendingActivity());

The use of booleans makes this a little hard to read. It's not obvious what that false means. We can use enums to construct named booleans which help make call sites like this easier to read.

r=me
Comment 3 Alexey Proskuryakov 2008-11-18 00:45:30 PST
Committed revision 38549.

(In reply to comment #2)
> > +    m_workerContext->thread()->messagingProxy()->reportWorkerThreadActivity(false, m_workerContext->hasPendingActivity());
> 
> The use of booleans makes this a little hard to read. It's not obvious what
> that false means. We can use enums to construct named booleans which help make
> call sites like this easier to read.

I've split this into two functions, reportWorkerThreadActivity and confirmWorkerThreadMessage.