Closed Bug 934500 Opened 11 years ago Closed 11 years ago

Don't eagerly create callsite clones in IonBuilder

Categories

(Core :: JavaScript Engine: JIT, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla28

People

(Reporter: bhackett1024, Assigned: bhackett1024)

References

Details

(Whiteboard: [qa-])

Attachments

(1 file, 1 obsolete file)

Attached patch patch (obsolete) — Splinter Review
Using callsite clones is an optimization rather than a requirement, and if the clone has never been created at the point of Ion compilation then there isn't much reason to do it eagerly.
Attachment #826787 - Flags: review?(jdemooij)
Attached patch updatedSplinter Review
Oops, missed a couple CloneFunctionAtCallsite uses in PJS stuff.
Assignee: nobody → bhackett1024
Attachment #826787 - Attachment is obsolete: true
Attachment #826787 - Flags: review?(jdemooij)
Attachment #826792 - Flags: review?(jdemooij)
Component: JavaScript Engine → JavaScript Engine: JIT
Comment on attachment 826792 [details] [diff] [review]
updated

Review of attachment 826792 [details] [diff] [review]:
-----------------------------------------------------------------

Forwarding to shu; I'm not very familiar with callsite cloning.

::: js/src/jscntxt.cpp
@@ +132,3 @@
>          return nullptr;
>  
> +    Table::Ptr p = table.lookup(Key(fun, script, pc - script->code));

Won't this race with the main thread?
Attachment #826792 - Flags: review?(jdemooij) → review?(shu)
Comment on attachment 826792 [details] [diff] [review]
updated

Review of attachment 826792 [details] [diff] [review]:
-----------------------------------------------------------------

The IonBuilder changes look pretty straightforward, but the race Jan found is a problem. See comments below.

::: js/src/jscntxt.cpp
@@ +132,3 @@
>          return nullptr;
>  
> +    Table::Ptr p = table.lookup(Key(fun, script, pc - script->code));

I agree with Jan here, it looks like it'll race. Replacing the lookup with readonlyThreadsafeLookup isn't enough, since the interpreter/baseline still mutates the callsite clone table.

A lock might be okay as contention should be pretty low between OMTC and the interpreter/baseline executing something that causes us to callsite clone.

That said, a longer term fix that would be nice is if we didn't clone the entire function into some compartment-wide table, but only cloned TypeScripts as we only care about the extra precision of observed types. Perhaps we can then keep the collection of TypeScripts for these clones somewhere else, such as on the TypeScript of the caller at the pc of the call. Since that collection will be pretty small in most cases, we can use a very simple data structure with atomic adds, like a linked list, and not worry about racing.

@@ +167,5 @@
> +    Key key(fun, script, pc - script->code);
> +    Table::AddPtr p = table.lookupForAdd(key);
> +    JS_ASSERT(!p);
> +
> +    if (!table.add(p, key, clone))

putNew, maybe?
Attachment #826792 - Flags: review?(shu)
Comment on attachment 826792 [details] [diff] [review]
updated

There is no race here yet, as IonBuilder still only runs on the main thread.  Before IonBuilder runs off thread I'll be adding a lock to protect changes to the callsite clone table.  With this change though the callsite clone table will only be changing on the main thread, so that (a) the main thread doesn't need to lock to read the table, (b) the main thread takes the lock when modifying the table, and (c) the compilation thread takes the lock when reading the table.

This is the synchronization strategy that will be used for pretty much all mutable state which can be accessed during compilation, and rather than adding locking piecemeal I want to take care of this later on once everything else is in place, e.g. here a problem is that IonBuilder has a bare JSCompartment pointer which it can do anything with; instead it should have a wrapper pointer which only exposes the interfaces the compiler needs and makes it easier to ensure that all the right locking is in place.
Attachment #826792 - Flags: review?(shu)
Comment on attachment 826792 [details] [diff] [review]
updated

Review of attachment 826792 [details] [diff] [review]:
-----------------------------------------------------------------

Looks fine to me. Still would prefer the putNew nit, and perhaps a comment to mark places in the source that would require locks once IonBuilder moves off-thread?
Attachment #826792 - Flags: review?(shu) → review+
https://hg.mozilla.org/mozilla-central/rev/d23caa617163
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28
Whiteboard: [qa-]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: