Closed Bug 1743623 Opened 2 years ago Closed 2 years ago

Revisit SpiderMonkey-related preferences used by workers

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
98 Branch
Tracking Status
firefox98 --- fixed

People

(Reporter: arai, Assigned: arai)

References

(Regressed 1 open bug)

Details

Attachments

(5 files)

We have about:config preferences that affects SpiderMonkey behavior, in javascript.options.*.

There are 2 kind of options that's used by both main thread and workers:

  • Prefs reflected to JS::ContextOptions
  • Prefs reflected to JS::RealmCreationOptions

Prefs reflected to JS::ContextOptions are read directly both from main thread and workers

https://searchfox.org/mozilla-central/rev/4c184ca81b28f1ccffbfd08f465709b95bcb4aa1/js/xpconnect/src/XPCPrefableContextOptions.h#20-70

template <typename T>
void SetPrefableContextOptions(JS::ContextOptions& options, T load) {
  options
      .setAsmJS(load(PREF_NAMES("asmjs")))
...

called from main thread:

https://searchfox.org/mozilla-central/rev/4c184ca81b28f1ccffbfd08f465709b95bcb4aa1/js/xpconnect/src/XPCJSContext.cpp#957

static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
...
  SetPrefableContextOptions(contextOptions,
                            [](const char* jsPref, const char* workerPref) {
                              return Preferences::GetBool(jsPref);
                            });

and workers:

https://searchfox.org/mozilla-central/rev/4c184ca81b28f1ccffbfd08f465709b95bcb4aa1/dom/workers/RuntimeService.cpp#283

bool GetWorkerBoolPref(const char* jsPref, const char* workerPref) {
  using PrefHelper = PrefTraits<bool>;

  if (PrefHelper::Exists(workerPref)) {
    return PrefHelper::Get(workerPref);
  }

  if (PrefHelper::Exists(jsPref)) {
    return PrefHelper::Get(jsPref);
  }

  return PrefHelper::kDefaultValue;
}
...
void LoadContextOptions(const char* aPrefName, void* /* aClosure */) {
...
  xpc::SetPrefableContextOptions(contextOptions, GetWorkerBoolPref);

Prefs reflected to JS::RealmCreationOptions are read only from main thread, into Atomic<bool>, and read from workers via the Atomic<bool>.

https://searchfox.org/mozilla-central/rev/4c184ca81b28f1ccffbfd08f465709b95bcb4aa1/js/xpconnect/src/XPCJSContext.cpp#931-940

static mozilla::Atomic<bool> sSharedMemoryEnabled(false);
...
static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
...
  sSharedMemoryEnabled =
      Preferences::GetBool(JS_OPTIONS_DOT_STR "shared_memory");
void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) {
  options.creationOptions()
      .setSharedMemoryAndAtomicsEnabled(sSharedMemoryEnabled)
...

Then, prefs directly read from workers have special handling. It allows overriding the main-thread pref value by dom.workers.options.* prefs.

https://searchfox.org/mozilla-central/rev/4c184ca81b28f1ccffbfd08f465709b95bcb4aa1/dom/workers/RuntimeService.cpp#201-251

template <typename T>
T GetWorkerPref(const nsACString& aPref,
                const T aDefault = PrefTraits<T>::kDefaultValue,
                bool* aPresent = nullptr) {
  AssertIsOnMainThread();

  using PrefHelper = PrefTraits<T>;

  T result;
  bool present = true;

  nsAutoCString prefName;
  prefName.AssignLiteral(PREF_WORKERS_OPTIONS_PREFIX);
  prefName.Append(aPref);

  if (PrefHelper::Exists(prefName.get())) {
    result = PrefHelper::Get(prefName.get());
  } else {
    prefName.AssignLiteral(PREF_JS_OPTIONS_PREFIX);
    prefName.Append(aPref);

    if (PrefHelper::Exists(prefName.get())) {
      result = PrefHelper::Get(prefName.get());...
}

bool GetWorkerBoolPref(const char* jsPref, const char* workerPref) {
  using PrefHelper = PrefTraits<bool>;

  if (PrefHelper::Exists(workerPref)) {
    return PrefHelper::Get(workerPref);
  }

  if (PrefHelper::Exists(jsPref)) {
    return PrefHelper::Get(jsPref);
  }
...

There are following issues:

  • only some configuration can be overridden for workers, and it's not clear which is which, from the pref name, or the purpose (for example, experimental feature prefs spans across JS::ContextOptions and JS::RealmCreationOptions)
  • there's no actual usage/consumer of the "override" behavior (at least I don't see any)
  • there's no description about the "override" behavior around the code

We should revisit this design, and either:

  • clearly document the behavior, with some tests
  • remove the behavior

I'll remove the override behavior

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED

Also fixed the case of the preference name (gcZeal => gczeal).

Depends on D133976

Flags: in-testsuite-
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/cee175fa09e7
Part 1: Remove worker-specific override from JS context options. r=jandem
https://hg.mozilla.org/integration/autoland/rev/824c5cd5ea17
Part 2: Remove worker-specific override from JS GC memory options. r=dom-worker-reviewers,smaug
https://hg.mozilla.org/integration/autoland/rev/51820e97c1eb
Part 3: Remove worker-specific override from JS GC zeal options. r=dom-worker-reviewers,smaug
https://hg.mozilla.org/integration/autoland/rev/2f2368b8f931
Part 4: Stop registering callback for worker override. r=jandem
https://hg.mozilla.org/integration/autoland/rev/f671659046b1
Part 5: Initialize classStaticBlocks_ field. r=jandem

Backed out for causing hybrid bustages on RuntimeService

Backout link : https://hg.mozilla.org/integration/autoland/rev/2c5b36d37c1c886386f0f685e364d0c53f0f0219

Push with failures : https://treeherder.mozilla.org/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception%2Crunnable&revision=f671659046b10e7339c683bc5d18c875493b1925&selectedTaskRun=GvliAHqhR-Wxb52-smo9rw.0

Link to failure log : https://treeherder.mozilla.org/logviewer?job_id=363709918&repo=autoland

Failure message:
/builds/worker/checkouts/gecko/dom/workers/RuntimeService.cpp:166:30: error: unused variable 'kDefaultValue' [-Werror,-Wunused-const-variable]

Flags: needinfo?(arai.unmht)
Flags: needinfo?(arai.unmht)
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/fe3db4065f77
Part 1: Remove worker-specific override from JS context options. r=jandem
https://hg.mozilla.org/integration/autoland/rev/f9891534f80f
Part 2: Remove worker-specific override from JS GC memory options. r=dom-worker-reviewers,smaug
https://hg.mozilla.org/integration/autoland/rev/f5d5f154bb33
Part 3: Remove worker-specific override from JS GC zeal options. r=dom-worker-reviewers,smaug
https://hg.mozilla.org/integration/autoland/rev/19ac6f4ff625
Part 4: Stop registering callback for worker override. r=jandem
https://hg.mozilla.org/integration/autoland/rev/5873688a4ba0
Part 5: Initialize classStaticBlocks_ field. r=jandem
Regressions: 1891277
No longer blocks: 1371162
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: