Closed
Bug 618484
Opened 14 years ago
Closed 14 years ago
Workers: Allow ChromeWorkers access to XPCOM objects
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
Tracking | Status | |
---|---|---|
blocking2.0 | --- | beta9+ |
People
(Reporter: bent.mozilla, Assigned: bent.mozilla)
Details
(Keywords: dev-doc-complete, Whiteboard: [hardblocker])
Attachments
(1 file, 1 obsolete file)
53.23 KB,
patch
|
jst
:
review+
jorendorff
:
review+
|
Details | Diff | Splinter Review |
From an email thread, here's our plan for allowing ChromeWorkers more access to XPCOM:
1. Allow postMessage to pass XPCWrappedNatives to ChromeWorkers only, provided that the underlying object is marked with nsIClassInfo.THREADSAFE.
2. Expose a new "XPCOM" global object to ChromeWorkers only. This object will have "createInstance" and "getService" functions, taking a single contract id string argument. When these functions are called we will create/get the object on the worker thread. We will then QI to nsIClassInfo. If the QI fails or if the object is not marked with nsIClassInfo.THREADSAFE we will abort. Otherwise we will wrap the object and define all interfaces indicated by nsIClassInfo::GetInterfaces before returning it. We will not expose "Components" or "Components.interfaces" etc., so QI will not be available.
Patch attached that implements this.
This originally sprung up in response to bug 608142.
Attachment #496975 -
Flags: review?(mrbkap)
Assignee | ||
Updated•14 years ago
|
Attachment #496975 -
Flags: review?(jorendorff)
Comment 2•14 years ago
|
||
Yup, this is effectively what will restore the ability to create XPCOM objects in JS off the main thread, which was possible (though unsafe) in 3.6.
blocking2.0: ? → beta9+
Comment 3•14 years ago
|
||
Comment on attachment 496975 [details] [diff] [review]
Patch, v1
r=me on the security manager changes.
Attachment #496975 -
Flags: review?(mrbkap) → review+
Assignee | ||
Comment 4•14 years ago
|
||
Comment on attachment 496975 [details] [diff] [review]
Patch, v1
Johnny, can you review the dom/src/threads changes?
Attachment #496975 -
Flags: review?(jst)
Comment 5•14 years ago
|
||
Comment on attachment 496975 [details] [diff] [review]
Patch, v1
Just as an API thing, I'd rather see a single extra argument everywhere of type JSStructuredCloneCallbacks *, rather than asking for the appropriate minimal subsets of the callbacks, in two or three arguments.
r=me for the js/src bits, with or without that change.
Attachment #496975 -
Flags: review?(jorendorff) → review+
Assignee | ||
Comment 6•14 years ago
|
||
Ok, this patch fixes two things.
First, we no longer abort on trying to create non-threadsafe components. Johnny had the brilliant idea that we could just sync-wait for the main thread to make and test the instance for threadsafety before actually doing it on the worker. We keep a cache of threadsafe contract IDs too.
Second, I've changed the structured clone API a little more so that we can pass a void* to the callbacks. This lets us avoid leaks that could happen if we're serializing wrapped natives and AddRef'ing as we go. If something failed later, or if the buffer gets deleted without deserializing, then we'd leak all the wrapped natives. This way we can grab a list of all the wrapped natives and only AddRef if everything succeeds. Jorendorff, you ok with these changes?
Attachment #496975 -
Attachment is obsolete: true
Attachment #498544 -
Flags: review?(jst)
Attachment #498544 -
Flags: review?(jorendorff)
Attachment #496975 -
Flags: review?(jst)
Comment 7•14 years ago
|
||
Comment on attachment 498544 [details] [diff] [review]
Patch, v2
- In WriteStructuredClone():
+ if (NS_SUCCEEDED(classInfo->GetFlags(&flags)) &&
+ (flags & nsIClassInfo::THREADSAFE)) {
+ // Write the raw pointer into the stream, and add it to the list we're
Looks like that comment ends mid-sentence.
r=jst
Attachment #498544 -
Flags: review?(jst) → review+
Updated•14 years ago
|
Whiteboard: hardblocker
Comment 8•14 years ago
|
||
Comment on attachment 498544 [details] [diff] [review]
Patch, v2
>+JS_WriteStructuredClone(JSContext *cx, jsval v, uint64 **bufp, size_t *nbytesp,
>+ const JSStructuredCloneCallbacks *optionalCallbacks,
>+ void *closure)
Well she ain't gonna win any beauty contests, that's for sure. ;)
r=me on the new js/src bits.
Attachment #498544 -
Flags: review?(jorendorff) → review+
Updated•14 years ago
|
Whiteboard: hardblocker → [hardblocker]
Assignee | ||
Comment 9•14 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Summary: Allow ChromeWorkers access to XPCOM objects → Workers: Allow ChromeWorkers access to XPCOM objects
Updated•14 years ago
|
Keywords: dev-doc-needed
Comment 10•14 years ago
|
||
These revisions to the ChromeWorker documentation have been made. Please take a look and let me know if I've missed anything.
https://developer.mozilla.org/en/DOM/ChromeWorker
Keywords: dev-doc-needed → dev-doc-complete
Comment 11•14 years ago
|
||
Creating a thread is a bad example for something to send to a worker imo, since there really isn't anything useful you can do with it. Can we use something else in the example?
Comment 12•14 years ago
|
||
Yeah, a really good example would be doing disk I/O of a large file, so that it doesn't block the UI.
Comment 13•14 years ago
|
||
I'll see if I can put together a more useful example. I used the tests as a basis for the one that's currently there. If anyone has some code I can use, awesome. Otherwise this'll take a bit of time. :)
Assignee | ||
Comment 14•14 years ago
|
||
I'll try to collaborate with bz today to get some file/stream example code hashed out.
Comment 15•14 years ago
|
||
bent: if you do that, you two will be my heroes. Thanks!
Comment 16•14 years ago
|
||
This works fine with threadsafe xpcom objects (or objects marked as such to make it work).
What is still missing is a way to hand off an xpcom object to a different thread. It is a common task to prepare an object on a thread and then hand it off to where it came from. Any chance this will be possible in the 2.0 timeframe?
Assignee | ||
Comment 17•14 years ago
|
||
(In reply to comment #16)
> What is still missing is a way to hand off an xpcom object to a different
> thread. It is a common task to prepare an object on a thread and then hand it
> off to where it came from. Any chance this will be possible in the 2.0
> timeframe?
This is possible now (provided that the XPCOM object is marked threadsafe).
Comment 18•14 years ago
|
||
(In reply to comment #17)
> This is possible now (provided that the XPCOM object is marked threadsafe).
Thats exactly the point :-) The object I am working with is not marked threadsafe, and since its very complex it seems it cannot be marked threadsafe without some sort of modification (createInstance fails).
It would be good if I could create the non-threadsafe components in a worker so I can fill its info. Then I'd like to hand over the object and everything it accesses back to the main thread and end the worker.
Comment 19•14 years ago
|
||
What object is this? In general, if an object can't be marked threadsafe, then accessing it on multiple threads is rather unsafe, no?
Comment 20•14 years ago
|
||
(In reply to comment #19)
> What object is this? In general, if an object can't be marked threadsafe, then
> accessing it on multiple threads is rather unsafe, no?
Its our implementation of calIEvent. I may be mistaking, but threadsafe means it can be accessed by multiple threads at the same time, right? I only need access from one thread at a time and after the object is initialized and sent to the main thread, I don't want to access it from the worker again.
Maybe a different scenario, but what if a developer wants to make use of core xpcom components that are not threadsafe, to initialize a different component that is marked threadsafe?
Comment 21•14 years ago
|
||
Some objects are fine with at-most-one-thread-at-a-time; other code depends on being on the same thread, for TLS or JSThread or similar reasons.
The developer mooted in your second paragraph should initialize on the main thread and pass to the worker once it's done.
Comment 22•14 years ago
|
||
> but threadsafe means it can be accessed by multiple threads at the same time,
> right?
Yes, but perhaps not for all of the object's functionality. There are "threadsafe" Gecko components that are not necessarily OK with being entered via the same API call on multiple threads at once...
Perhaps we need a better label for this sort of thing.
Comment 23•14 years ago
|
||
Are there still plans for file/stream example code? I wanted to give this a try today, but I gave up when I realized that nsIScriptableInputStream doesn't appear to be thread-safe.
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•