Remove pointer from WellKnownAtomInfo
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
People
(Reporter: arai, Assigned: arai)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
In order to reduce the memory consumption around the WellKnownAtom works,
it's better removing pointers from WellKnownAtomInfo
array, so that the array content can be shared between multiple processes.
the idea is to use create large string as a concatenation of all well-known atoms,
and use index into the string WellKnownAtomInfo
field, instead of pointer.
xpt codegen already does the similar.
Assignee | ||
Comment 1•1 year ago
|
||
There's one issue with this approach.
Given that all well-known atom stings are stored into large char array, compiler cannot deduplicate the other string literals against the substring of the large char array,
and it can result in having duplicate strings in the binary, and affect the binary size.
const char const char js::wellKnownAtomStrings[] = {
'a','b','o','r','t','\0',
'a','d','d','\0',
...
};
...
const char* const s = "abort"; // this is not deduplicated with wellKnownAtomStrings substring.
So, any code that uses string literal needs to be rewritten to directly refer the large char array.
For example with the following functions and macros provided:
struct WellKnownAtomInfo {
uint32_t offset;
uint32_t length;
mozilla::HashNumber hash;
};
extern const char wellKnownAtomStrings[];
extern WellKnownAtomInfo wellKnownAtomInfos[];
inline const WellKnownAtomInfo& GetWellKnownAtomInfo(WellKnownAtomId atomId) {
return wellKnownAtomInfos[uint32_t(atomId)];
}
inline constexpr const char* GetWellKnownAtomString(
const WellKnownAtomInfo& info) {
return wellKnownAtomStrings + info.offset;
}
inline constexpr const char* GetWellKnownAtomString(WellKnownAtomId atomId) {
return GetWellKnownAtomString(GetWellKnownAtomInfo(atomId));
}
#define JSSTR(ID) GetWellKnownAtomString(js::WellKnownAtomId::ID)
and then use the macro:
const char* const s = JSSTR(abort); // this refers the substring of wellKnownAtomStrings
this is similar to the situation where we were using js_something_str
to deduplicate the strings.
Assignee | ||
Comment 2•1 year ago
|
||
there are many affected code, such as profiler entry's label:
AutoJSMethodProfilerEntry pseudoFrame(cx, "Array.prototype", "lastIndexOf");
or error message:
auto* unwrapped = UnwrapAndTypeCheckThis<DateObject>(cx, args, "toISOString");
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr,
JSMSG_INVALID_OPTION_VALUE, "timeZoneName",
this also affects class and proprety/function definitions, but that can be solved by bug 1847677.
Description
•