Commit e38e561b authored by Jon Coppeard's avatar Jon Coppeard
Browse files

Bug 1895661 - Part 1: Move GC zeal functions to JS namespace and add separate...

Bug 1895661 - Part 1: Move GC zeal functions to JS namespace and add separate constants for browser and shell frequency r=sfink

Sensible defaults are very different for the browser and the shell so I added
separate constants. I think the JS testing functions can get called from the
browser and so may pick the wrong default but it's not too serious.

Differential Revision: https://phabricator.services.mozilla.com/D210058
parent a9fd5668
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -272,7 +272,7 @@ void LoadGCZealOptions(const char* /* aPrefName */, void* /* aClosure */) {
  int32_t frequency =
      GetPref<int32_t>(PREF_JS_OPTIONS_PREFIX PREF_GCZEAL ".frequency", -1);
  if (frequency < 0) {
    frequency = JS_DEFAULT_ZEAL_FREQ;
    frequency = JS::BrowserDefaultGCZealFrequency;
  }

  RuntimeService::SetDefaultGCZeal(uint8_t(gczeal), uint32_t(frequency));
@@ -730,7 +730,7 @@ bool InitJSContextForWorker(WorkerPrivate* aWorkerPrivate,
  JS::SetCTypesActivityCallback(aWorkerCx, CTypesActivityCallback);

#ifdef JS_GC_ZEAL
  JS_SetGCZeal(aWorkerCx, settings.gcZeal, settings.gcZealFrequency);
  JS::SetGCZeal(aWorkerCx, settings.gcZeal, settings.gcZealFrequency);
#endif

  return true;
+1 −1
Original line number Diff line number Diff line
@@ -5693,7 +5693,7 @@ void WorkerPrivate::UpdateGCZealInternal(JSContext* aCx, uint8_t aGCZeal,
                                         uint32_t aFrequency) {
  auto data = mWorkerThreadAccessible.Access();

  JS_SetGCZeal(aCx, aGCZeal, aFrequency);
  JS::SetGCZeal(aCx, aGCZeal, aFrequency);

  for (uint32_t index = 0; index < data->mChildWorkers.Length(); index++) {
    data->mChildWorkers[index]->UpdateGCZeal(aGCZeal, aFrequency);
+1 −1
Original line number Diff line number Diff line
@@ -371,7 +371,7 @@ void WorkletThread::EnsureCycleCollectedJSContext(
  // FIXME: JS_SetSecurityCallbacks
  // FIXME: JS::SetAsyncTaskCallbacks
  // FIXME: JS::SetCTypesActivityCallback
  // FIXME: JS_SetGCZeal
  // FIXME: JS::SetGCZeal

  // A thread lives strictly longer than its JSRuntime so we can safely
  // store a raw pointer as the callback's closure argument on the JSRuntime.
+1 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ static bool GCZeal(JSContext* cx, unsigned argc, JS::Value* vp) {
  uint32_t zeal;
  if (!ToUint32(cx, args.get(0), &zeal)) return false;

  JS_SetGCZeal(cx, uint8_t(zeal), JS_DEFAULT_ZEAL_FREQ);
  JS::SetGCZeal(cx, uint8_t(zeal), JS::ShellDefaultGCZealFrequency);
  return true;
}
#endif
+13 −8
Original line number Diff line number Diff line
@@ -1379,18 +1379,23 @@ extern JS_PUBLIC_API void FinalizeDeadNurseryObject(JSContext* cx,

#ifdef JS_GC_ZEAL

#  define JS_DEFAULT_ZEAL_FREQ 100
namespace JS {

static constexpr uint32_t ShellDefaultGCZealFrequency = 100;
static constexpr uint32_t BrowserDefaultGCZealFrequency = 5000;

extern JS_PUBLIC_API void JS_GetGCZealBits(JSContext* cx, uint32_t* zealBits,
extern JS_PUBLIC_API void GetGCZealBits(JSContext* cx, uint32_t* zealBits,
                                        uint32_t* frequency,
                                        uint32_t* nextScheduled);

extern JS_PUBLIC_API void JS_SetGCZeal(JSContext* cx, uint8_t zeal,
extern JS_PUBLIC_API void SetGCZeal(JSContext* cx, uint8_t zeal,
                                    uint32_t frequency);

extern JS_PUBLIC_API void JS_UnsetGCZeal(JSContext* cx, uint8_t zeal);
extern JS_PUBLIC_API void UnsetGCZeal(JSContext* cx, uint8_t zeal);

extern JS_PUBLIC_API void JS_ScheduleGC(JSContext* cx, uint32_t count);
extern JS_PUBLIC_API void ScheduleGC(JSContext* cx, uint32_t count);

}  // namespace JS

#endif

Loading