Make SharedImmutableStringsCache globally accessible singleton
Categories
(Core :: JavaScript Engine, task, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox109 | --- | fixed |
People
(Reporter: arai, Assigned: arai)
References
Details
Attachments
(2 files)
parser internally uses SharedImmutableStringsCache
, to allocate strings for ScriptSource
.
frontend::ParserBase::setSourceMapInfo
> ScriptSource::setDisplayURL
> ScriptSource::setDisplayURL
> ScriptSource::getOrCreateStringZ
> GetOrCreateStringZ
template <typename SharedT, typename CharT>
static SharedT GetOrCreateStringZ(JSContext* cx, ErrorContext* ec,
UniquePtr<CharT[], JS::FreePolicy>&& str) {
...
rt->sharedImmutableStrings().getOrCreate(std::move(str), lengthWithNull);
SharedImmutableStringsCache
itself is thread-safe, so possible option is to expose SharedImmutableStringsCache
and let the embedding pass it to FrontendContext
, and use it inside frontend code.
Assignee | ||
Comment 1•2 years ago
|
||
Given that SharedImmutableStringsCache
is already singleton held by top-level JSRuntime
,
we can make it globally accessible singleton and make it independent from JSRuntime
.
Assignee | ||
Comment 2•2 years ago
|
||
Also, same can be done for frontend::WellKnownParserAtoms
, maybe in separate bug.
Assignee | ||
Comment 3•2 years ago
|
||
Assignee | ||
Comment 4•2 years ago
|
||
Depends on D160204
Updated•2 years ago
|
Comment 6•2 years ago
|
||
Backed out for causing build bustages on ParserAtom.cpp.
- Backout link
- Push with failures
- Failure Log
- Failure line: /builds/worker/checkouts/gecko/js/src/frontend/ParserAtom.cpp:1316:3: error: use of undeclared identifier 'initialized_'
Comment 8•2 years ago
|
||
Backed out for causing failures at ParserAtom.cpp.
Backout link: https://hg.mozilla.org/integration/autoland/rev/b7164776589657b7d7fd40d32268b2a489eed789
Failure log: https://treeherder.mozilla.org/logviewer?job_id=396256209&repo=autoland&lineNumber=2452
Comment 9•2 years ago
|
||
Assignee | ||
Comment 10•2 years ago
|
||
Apparently, PAC doesn't meed the assumption, and there can be multiple top-level JSRuntime
s at the same time.
if that's the case, we should make the singleton initialization/free thread-safe and have ref-count.
Comment 11•2 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #10)
Apparently, PAC doesn't meed the assumption, and there can be multiple top-level
JSRuntime
s at the same time.
if that's the case, we should make the singleton initialization/free thread-safe and have ref-count.
Can we initialize the singleton in InitWithFailureDiagnostic
and destroy in JS_ShutDown
? That's what we do for other process-wide singletons.
Assignee | ||
Comment 12•2 years ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #11)
(In reply to Tooru Fujisawa [:arai] from comment #10)
Apparently, PAC doesn't meed the assumption, and there can be multiple top-level
JSRuntime
s at the same time.
if that's the case, we should make the singleton initialization/free thread-safe and have ref-count.Can we initialize the singleton in
InitWithFailureDiagnostic
and destroy inJS_ShutDown
? That's what we do for other process-wide singletons.
Sounds good :)
I'll move the init/free code there.
Assignee | ||
Comment 13•2 years ago
|
||
I'm seeing "self-hosted" string gets leaked on reftest:
it looks like the filename of self-hosted JS.
options.setFileAndLine("self-hosted", 1);
and actually, the leak happens locally even without the patch
Assignee | ||
Comment 14•2 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #13)
and actually, the leak happens locally even without the patch
without the patch, it leaks JSRuntime
.
WARNING: YOU ARE LEAKING THE WORLD (at least one JSRuntime and everything alive inside it, that is) AT JS_ShutDown TIME. FIX THIS!
and the patch moves SharedImmutableStringsCache
out of JSRuntime
and that results in UAF in cached string.
Assignee | ||
Comment 15•2 years ago
|
||
The same JS Runtime leak happens even without my patch on automation,
and the leak itself isn't treated as job failure.
So, possible options are:
- (a) somehow fix the leak itself
- (b) if the leak is intentional there (something related to test harness?):
- (b-1) support the case in
SharedImmutableStringsCache
destructor and tweak the lifetime of strings - (b-2) add some workaround to the assertion and just ignore the leak
- (b-1) support the case in
Assignee | ||
Comment 16•2 years ago
|
||
the safe option for (b-1) would be to add ref count to those singletons, and let either JS_Shutdown
or destroyRuntime
destruct those singletons,
instead of always destruct them in JS_Shutdown
.
Comment 17•2 years ago
|
||
We have code to not release certain things if there are still live runtimes at shutdown time, for example here. Maybe that works for this too? We don't support re-initializing the JS engine after a JS_Shutdown
(there are assertions IIRC).
Assignee | ||
Comment 18•2 years ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #17)
We have code to not release certain things if there are still live runtimes at shutdown time, for example here. Maybe that works for this too? We don't support re-initializing the JS engine after a
JS_Shutdown
(there are assertions IIRC).
Sounds good!
I'll revert the singleton handling and add the !JSRuntime::hasLiveRuntimes()
condition.
Comment 19•2 years ago
|
||
Comment 20•2 years ago
•
|
||
Backed out for causing spidermonkey bustages.
- Backout link
- Push with failures
- Failure Log
- Failure line: /builds/worker/checkouts/gecko/js/src/vm/SharedImmutableStringsCache.cpp:127:8: error: incomplete type 'JSRuntime' named in nested name specifier
And also this: https://treeherder.mozilla.org/logviewer?job_id=397546713&repo=autoland
Comment 21•2 years ago
|
||
Assignee | ||
Updated•2 years ago
|
Comment 22•2 years ago
|
||
Backed out for causing one of the issues above(https://bugzilla.mozilla.org/show_bug.cgi?id=1786834#c20)
- Backout link
- Push with failures
- Failure Log
- Failure line: ==2796==ERROR: AddressSanitizer: attempting to call malloc_usable_size() for pointer which is not owned: 0x7fa17fae9520
SUMMARY: AddressSanitizer: bad-malloc_usable_size /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:119:3 in malloc_usable_size
Comment 23•2 years ago
|
||
Comment 24•2 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/07efd170adbf
https://hg.mozilla.org/mozilla-central/rev/a1f696ec2548
Assignee | ||
Updated•2 years ago
|
Description
•