Split string allocation code for atom and non-atom case
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox98 | --- | fixed |
People
(Reporter: arai, Assigned: arai)
References
Details
Attachments
(5 files)
There are cx->zone()->isAtomsZone() branch deep inside string allocation code.
The condition becomes true only when the caller has AutoAllocInAtomsZone or JSContext::enterAtomsZone.
and now we have very limited set of callsite that allocates atoms.
we should be able to split the allocation code for each, maybe by templatizing the functions if necessary, to optimize both atom case and non-atom case.
template <js::AllowGC allowGC, typename CharT>
MOZ_ALWAYS_INLINE JSLinearString* JSLinearString::new_(
JSContext* cx, js::UniquePtr<CharT[], JS::FreePolicy> chars, size_t length,
js::gc::InitialHeap heap) {
if (!validateLength(cx, length)) {
return nullptr;
}
JSLinearString* str;
if (cx->zone()->isAtomsZone()) {
str = js::Allocate<js::NormalAtom, allowGC>(cx);
} else {
str = js::AllocateString<JSLinearString, allowGC>(cx, heap);
}
template <js::AllowGC allowGC>
MOZ_ALWAYS_INLINE JSThinInlineString* JSThinInlineString::new_(
JSContext* cx, js::gc::InitialHeap heap) {
if (cx->zone()->isAtomsZone()) {
return (JSThinInlineString*)(js::Allocate<js::NormalAtom, allowGC>(cx));
}
return js::AllocateString<JSThinInlineString, allowGC>(cx, heap);
template <js::AllowGC allowGC>
MOZ_ALWAYS_INLINE JSFatInlineString* JSFatInlineString::new_(
JSContext* cx, js::gc::InitialHeap heap) {
if (cx->zone()->isAtomsZone()) {
return (JSFatInlineString*)(js::Allocate<js::FatInlineAtom, allowGC>(cx));
}
return js::AllocateString<JSFatInlineString, allowGC>(cx, heap);
| Assignee | ||
Comment 1•4 years ago
|
||
To avoid duplicate steps through the atomization process:
- If the function assumes the input doesn't match static strings
(static strings case is already handled), appendNoStatic - If the function assumes the length is valid, append
ValidLength
Depends on D135099
| Assignee | ||
Comment 2•4 years ago
|
||
Split cx->zone()->isAtomsZone() branch into 2 functions, for atom case and
non-atom case.
Also removed reduncent steps (static string lookup, length validation,
deflation) from atom case, based on the atomization progress.
Depends on D135100
| Assignee | ||
Comment 3•4 years ago
|
||
Depends on D135101
| Assignee | ||
Comment 4•4 years ago
|
||
Depends on D135102
| Assignee | ||
Comment 5•4 years ago
|
||
Depends on D135103
| Assignee | ||
Comment 6•4 years ago
|
||
the stack of bug 1745664, bug 1746382, and this bug improves the atomization performance by 2% for both self-case (InstantiateMarkedAtomsAsPermanent) and normal case (InstantiateMarkedAtoms).
Updated•4 years ago
|
Comment 8•4 years ago
|
||
Backed out for causing multiple failures. CLOSED TREE
Backout link: https://hg.mozilla.org/integration/autoland/rev/5f0294c305465f40899be2e0fcc508de594c5b45
Link to failure log:
https://treeherder.mozilla.org/logviewer?job_id=364446492&repo=autoland&lineNumber=97820
https://treeherder.mozilla.org/logviewer?job_id=364446456&repo=autoland&lineNumber=89217
https://treeherder.mozilla.org/logviewer?job_id=364446482&repo=autoland&lineNumber=81388
https://treeherder.mozilla.org/logviewer?job_id=364448493&repo=autoland&lineNumber=1513
https://treeherder.mozilla.org/logviewer?job_id=364448500&repo=autoland&lineNumber=804
https://treeherder.mozilla.org/logviewer?job_id=364448486&repo=autoland&lineNumber=1677
https://treeherder.mozilla.org/logviewer?job_id=364448542&repo=autoland&lineNumber=1711
https://treeherder.mozilla.org/logviewer?job_id=364448521&repo=autoland&lineNumber=1697
| Assignee | ||
Comment 9•4 years ago
|
||
turns out that we have yet another place that atomizes strings without zone, in Gecko side.
// static
XPCJSContext* XPCJSContext::NewXPCJSContext() {
XPCJSContext* self = new XPCJSContext();
nsresult rv = self->Initialize();
nsresult XPCJSContext::Initialize() {
...
nsresult rv =
CycleCollectedJSContext::Initialize(nullptr, JS::DefaultHeapMaxBytes);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_ASSERT(Context());
JSContext* cx = Context();
...
MOZ_RELEASE_ASSERT(Runtime()->InitializeStrings(cx),
"InitializeStrings failed");
bool XPCJSRuntime::InitializeStrings(JSContext* cx) {
// if it is our first context then we need to generate our string ids
if (JSID_IS_VOID(mStrIDs[0])) {
RootedString str(cx);
for (unsigned i = 0; i < XPCJSContext::IDX_TOTAL_COUNT; i++) {
str = JS_AtomizeAndPinString(cx, mStrings[i]);
This could also be true in other embedding...
Comment 10•4 years ago
|
||
We also encounter the issue bellow. Can you take a look also at this ?
Updated•4 years ago
|
| Assignee | ||
Updated•4 years ago
|
Comment 11•4 years ago
|
||
Comment 12•4 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/e23ecacc7e1a
https://hg.mozilla.org/mozilla-central/rev/008f15149504
https://hg.mozilla.org/mozilla-central/rev/7bb53daa9da3
https://hg.mozilla.org/mozilla-central/rev/d772c5df1e8f
https://hg.mozilla.org/mozilla-central/rev/7b575dd3ddc2
Description
•