Move the global lexical environment from GlobalObject to Realm
Categories
(Core :: JavaScript Engine, task, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox68 | --- | fixed |
People
(Reporter: jandem, Assigned: jandem)
References
Details
Attachments
(2 files)
The global lexical is stored in a GlobalObject reserved slot but that makes it hard to read from JIT code. The current code is wrong because GlobalObject::offsetOfLexicalEnvironmentSlot doesn't account for the global having a private slot (XPConnect globals!).
We should move it to the Realm. That also eliminates a dereference, unboxing, and isFixedSlot lookup in C++.
Longer term we should consider moving all these special slots from GlobalObject to Realm.
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Comment 1•6 years ago
|
||
This way it's easier and faster to access, especially from JIT code.
The old code in GlobalObject::offsetOfLexicalEnvironmentSlot was wrong because
it didn't account for the global having a private slot (XPConnect globals!).
Assignee | ||
Comment 2•6 years ago
|
||
Depends on D26083
Assignee | ||
Comment 3•6 years ago
|
||
Hey Jon, I'm not sure whether using HeapPtr (instead of ReadBarriered) for Realm::lexicalEnvironment_ is okay?
I think it is because we trace the lexical environment whenever we trace the global so it's very similar to the old code reading it out of a GlobalObject slot without a read barrier?
Assignee | ||
Comment 4•6 years ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #3)
I think it is because we trace the lexical environment whenever we trace the global so it's very similar to the old code reading it out of a GlobalObject slot without a read barrier?
Hm that probably isn't true because getting the global could have triggered the barrier.
The problem is that cx->global() is smart enough not to trigger the read barrier, but it would be unfortunate having to copy that mechanism for the lexical environment and other things in the future.
Comment 5•6 years ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #3)
(Posting the comment I wrote before I saw your last comment)
At the moment we have the situation where we ensure globals from all on-stack realms get marked. With this change that would also mark the lexical environment. So I think we don't need a barrier as long is it's a realm we have entered. Can we assert that?
Is the lexical environment still logically part of the global but stored externally or is it part of the realm now? If it's the former HeapPtr is fine but we need a comment about why it's OK to skip the global read barrier when reading the lexical environment. If it's the latter it would be better as ReadBarriered and traced from Realm::traceRoots() as we do for the global (also with unbarrieredGet() to read). In general I prefer ReadBarriered for weak pointers for documentation even if we always skip the barrier.
Comment 6•6 years ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #4)
it would be unfortunate having to copy that mechanism for the lexical environment and other things in the future.
Hmm, I see what you mean, it's not great.
Assignee | ||
Comment 7•6 years ago
|
||
(In reply to Jon Coppeard (:jonco) from comment #5)
So I think we don't need a barrier as long is it's a realm we have entered. Can we assert that?
Not easily, unfortunately, because Realm::enterRealmDepthIgnoringJit_ does not account for realm entering in JIT code.
I'll think about it more. Maybe I should use a ReadBarriered and use unsafeGet in JSContext::globalLexicalEnvironment (to be added) and GlobalObject::lexicalEnvironment.
Thanks!
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Comment 8•6 years ago
|
||
@Jon: I updated the patch. This version is much simpler and I think still good enough.
Updated•6 years ago
|
Comment 10•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/1eaf2a656e3f
https://hg.mozilla.org/mozilla-central/rev/1e3fc1d21f8a
Description
•