Open Bug 1866643 Opened 1 year ago Updated 1 year ago

Remove pointer from WellKnownAtomInfo

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

ASSIGNED

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.

Blocks: 1848322
Depends on: 1866644

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.

there are many affected code, such as profiler entry's label:

https://searchfox.org/mozilla-central/rev/f030995a79461379153293c0e07f4982afe9ac28/js/src/builtin/Array.cpp#4302

AutoJSMethodProfilerEntry pseudoFrame(cx, "Array.prototype", "lastIndexOf");

or error message:

https://searchfox.org/mozilla-central/rev/f030995a79461379153293c0e07f4982afe9ac28/js/src/jsdate.cpp#3054

auto* unwrapped = UnwrapAndTypeCheckThis<DateObject>(cx, args, "toISOString");

https://searchfox.org/mozilla-central/rev/f030995a79461379153293c0e07f4982afe9ac28/js/src/builtin/temporal/Temporal.cpp#1345-1346

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.

You need to log in before you can comment on or make changes to this bug.