Refactor Code/CodeTier/etc to be ready for partial tiering
Categories
(Core :: JavaScript: WebAssembly, enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox129 | --- | fixed |
People
(Reporter: jseward, Assigned: jseward)
References
(Blocks 1 open bug)
Details
Crash Data
Attachments
(16 files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review |
Refactor Code/CodeTier/etc to be ready for partial tiering. This is a
follow-on from bug 1891182.
Comment 1•1 year ago
|
||
LazyStubTier contains the JIT code for lazy stubs. It is dynamically
grow-able as new stubs are generated. Right now each LST contains
only stubs for a single tier of code, hence it lives on CodeTier.
This commit changes this so that LST contains code from either
tier, and so can live on Code instead of CodeTier. This removes
the need to have complex locking logic when committing a new
tier, as it needed to try to acquire the per-tier lock in a
careful order.
There's no issue with the different tiers intermingling in the
same JIT pages, as we never serialize them or free them.
The class is not renamed from LazyStubTier to LazyStubs (as you
might expect) as the class wil be removed in a later patch.
Comment 2•1 year ago
|
||
MetadataTier and CodeTier are 1:1, and so there's no point
in having separate classes for them. This patch merges them
to reduce the number of concepts in our code hierarchy to
worry about. Some references to metadataTier still remain,
but will be cleaned up in future patches.
Depends on D213137
Comment 3•1 year ago
|
||
CodeTier contains JIT code for a tier of execution of a module. It's
semantically a pair of (metadata, codesegment*). I intend to evolve
this class into the generic container of code for either 'full tiers',
'partial tiers', or 'lazy stubs'. So this commit renames the class
to something generic. CodeSegment would be a good candidate, but it's
already taken.
Depends on D213138
Comment 4•1 year ago
|
||
CS was already conceptually shared when used by lazy stubs, as each
lazy stub segment could be referenced by multiple lazy func exports
through an index. A future commit will make this more explicit, so
I'm changing this to be ref-counted in advance.
Depends on D213139
Comment 5•1 year ago
|
||
I intend to replace LazyStubSegment with CodeBlock, by using the list of
CodeRange's on CodeBlock instead of having them live on CodeSegment. This
will allow us to turn CodeSegment into a truly immutable code allocation
that doesn't care about what's stored in it.
The first step is to have CodeBlock be generic about whether it holds
a ModuleSegment or a LazyStubSegment. Future steps will get rid of the
difference.
Depends on D213140
Comment 6•1 year ago
|
||
This furthers the goal of removing LazyStubSegment, by creating a CodeBlock for
each new LazyStubSegment and putting the code ranges for each lazy stub in that
new code block. This duplicates the code ranges on LSS, but those will be removed
later.
Depends on D213141
Comment 7•1 year ago
|
||
Now that we have a code block for every new chuck of lazy stubs we generate, we
can use that for finding a code range instead of LazyStubSegment.
Depends on D213142
Comment 8•1 year ago
|
||
Now that we have CodeBlock as the authoritative source of code ranges, we
can use CodeBlock in the process global map instead of CodeSegments.
Depends on D213143
Comment 9•1 year ago
|
||
Merge ModuleSegment and LazyStubSegment into a unified CodeSegment class.
CodeSegment is now just a container of linked JIT code memory. It may either
be created from a MacroAssembler + LinkData, or else from just a byte capacity
that allows for it to accept dynamically generated code.
- Initialization logic is re-ordered so that sending code ranges to the profiler
happens when initializing Code, not CodeSegment. This allows dropping the dependency
on Metadata from CodeSegment. - trapCode* is moved from ModuleSegment to Code. This removes the last special piece of
metadata that lives on CodeSegment. This is safe because the trap code generated per
tier is the same.
Depends on D213144
Comment 10•1 year ago
|
||
LazyStubTier has useful infrastructure needed for demand generating
new code, so this commit flattens it into Code so we can re-use it.
This unlocks an opportunity to simplify how commiting a tier2 works,
because all of the data is now in one place (Code). This commit
simplifies this logic too.
Depends on D213145
Comment 11•1 year ago
|
||
This commit reworks the creation of Code so that tier1 is provided at
init(), not the constructor. This lets us store tier1, and tier2 in the
Code vector of blocks, giving us a unified list of all the code blocks
inside of a code. The list of code segments is renamed to show that they
are only for lazy stubs, to avoid confusion.
Depends on D213146
Comment 12•1 year ago
|
||
Take the ThreadSafeCodeBlockMap from WasmProcess.cpp, and generalize it so
that we can have more than one per-process. Then embed one in wasm::Code,
and use that for all PC-based metadata lookups we have.
This allows us to avoid having to iterate over all CodeBlocks (which requires
taking a lock), when we're looking up a piece of metadata.
Depends on D213147
Comment 13•1 year ago
|
||
CodeBlock::funcToCodeRange_ only works because CodeBlock's for a tier of code are
'complete' and contain all funcs in the module. This won't be the case when we
support partial tiers, or move the imported function wrappers to their own block.
This commit reworks funcToCodeRange_ to be an abstract class that may or may not
be a dense vector. Right now only a dense vector is supported, but a sparse hash
map could be added in the future.
Depends on D213148
Comment 14•1 year ago
|
||
This commit reworks the logic in ModuleGenerator so that it's ready
to generate multiple code blocks. The existing code path for a
single 'complete tier' is made into a new method.
Depends on D213149
Comment 15•1 year ago
|
||
Generate all of the stubs that don't depend on any tier-specific data in
one chunk at the beginning of the CodeBlock. The tier-specific stubs (entry
stubs) are generated separately at the end of the CodeBlock.
The purpose of this is to prepare ModuleGenerator for generating tier
-independent data into a separate CodeBlock from the rest of the module
code.
Depends on D213150
Comment 16•1 year ago
|
||
TODO: document
Depends on D213151
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Comment 17•1 year ago
|
||
Comment 18•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/7f2ace29e124
https://hg.mozilla.org/mozilla-central/rev/1de85a4ce7ae
https://hg.mozilla.org/mozilla-central/rev/97276733ce7a
https://hg.mozilla.org/mozilla-central/rev/621c4254adf7
https://hg.mozilla.org/mozilla-central/rev/23f8fa8e529f
https://hg.mozilla.org/mozilla-central/rev/7e13f23fb1c9
https://hg.mozilla.org/mozilla-central/rev/ca74887894e6
https://hg.mozilla.org/mozilla-central/rev/38d3fe022100
https://hg.mozilla.org/mozilla-central/rev/78c1ed882b98
https://hg.mozilla.org/mozilla-central/rev/b438aa6a0a81
https://hg.mozilla.org/mozilla-central/rev/77d395f4c562
https://hg.mozilla.org/mozilla-central/rev/3b80e07c38bd
https://hg.mozilla.org/mozilla-central/rev/3e72652d9496
https://hg.mozilla.org/mozilla-central/rev/ff59e2597abb
https://hg.mozilla.org/mozilla-central/rev/0d18640a68ae
https://hg.mozilla.org/mozilla-central/rev/ce76b2fd1fdd
https://hg.mozilla.org/mozilla-central/rev/6b2961327cb5
Comment 19•1 year ago
|
||
This caused crashes with [@ js::wasm::CodeBlock::lookupFuncExport] and will be backed out in the next Nightly. Example: bp-dfde5488-c443-4b05-95eb-543630240701
Comment 20•1 year ago
|
||
Comment 21•1 year ago
|
||
Backed out for causing wasm crashes.
Updated•1 year ago
|
Comment 22•1 year ago
|
||
This looks like a race condition where:
- Tiering is used
- A wasm import function wrapper is implicitly exported through a funcref
- The wrapper is called, creating an on-demand lazy function export
- Tier-2 is finished compiling after this
We don't have any tests for this, and adding a test requires some new features in the harness to reliably trigger this. I added them locally and was able to reproduce this issue, and fix it.
https://treeherder.mozilla.org/jobs?repo=try&revision=6fb72a4314275e357cc608b6f34599e6b4e121a5
Comment 23•1 year ago
|
||
Comment 24•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/19c4b619cb0d
https://hg.mozilla.org/mozilla-central/rev/94b66174cb5f
https://hg.mozilla.org/mozilla-central/rev/bb38a0de22c1
https://hg.mozilla.org/mozilla-central/rev/5898ecc3f282
https://hg.mozilla.org/mozilla-central/rev/e54a28c570c6
https://hg.mozilla.org/mozilla-central/rev/4e2ed3c03b44
https://hg.mozilla.org/mozilla-central/rev/35cf07d63c5e
https://hg.mozilla.org/mozilla-central/rev/cdf90f731b5c
https://hg.mozilla.org/mozilla-central/rev/6f488caf8db3
https://hg.mozilla.org/mozilla-central/rev/3dcc782b8bfe
https://hg.mozilla.org/mozilla-central/rev/ecf9a3197b5b
https://hg.mozilla.org/mozilla-central/rev/ff8cad43732b
https://hg.mozilla.org/mozilla-central/rev/87d34d2a98bb
https://hg.mozilla.org/mozilla-central/rev/e36dc8935bc0
https://hg.mozilla.org/mozilla-central/rev/072f3c8e0d5c
https://hg.mozilla.org/mozilla-central/rev/4704a988a3c4
https://hg.mozilla.org/mozilla-central/rev/d6d2376f4bbd
Description
•