Bug 1530251 - Remove nursery size parameter from GCRuntime::init r=jonco

Callers should use JS_SetGCParameter() instead.

Differential Revision: https://phabricator.services.mozilla.com/D47870

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Paul Bone 2019-10-03 05:52:54 +00:00
parent ba0077d908
commit 03339e515d
13 changed files with 25 additions and 33 deletions

View File

@ -137,7 +137,7 @@ impl Runtime {
}
let context = JS_NewContext(
DEFAULT_HEAPSIZE, ChunkSize as u32, ptr::null_mut());
DEFAULT_HEAPSIZE, ptr::null_mut());
assert!(!context.is_null());
JS::InitSelfHostedCode(context);
PARENT.set(context);
@ -160,7 +160,6 @@ impl Runtime {
assert_eq!(IsDebugBuild(), cfg!(feature = "debugmozjs"));
let js_context = JS_NewContext(DEFAULT_HEAPSIZE,
ChunkSize as u32,
JS_GetParentRuntime(PARENT.get()));
assert!(!js_context.is_null());
@ -559,12 +558,6 @@ impl Default for JS::RealmOptions {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
const ChunkShift: usize = 20;
const ChunkSize: usize = 1 << ChunkShift;
#[cfg(target_pointer_width = "32")]
const ChunkLocationOffset: usize = ChunkSize - 2 * 4 - 8;
pub trait GCMethods {
unsafe fn initial() -> Self;
unsafe fn write_barriers(v: *mut Self, prev: Self, next: Self);

View File

@ -1202,15 +1202,13 @@ void js::gc::DumpArenaInfo() {
#endif // JS_GC_ZEAL
bool GCRuntime::init(uint32_t maxbytes, uint32_t maxNurseryBytes) {
bool GCRuntime::init(uint32_t maxbytes) {
MOZ_ASSERT(SystemPageSize());
{
AutoLockGCBgAlloc lock(rt);
MOZ_ALWAYS_TRUE(tunables.setParameter(JSGC_MAX_BYTES, maxbytes, lock));
MOZ_ALWAYS_TRUE(
tunables.setParameter(JSGC_MAX_NURSERY_BYTES, maxNurseryBytes, lock));
const char* size = getenv("JSGC_MARK_STACK_LIMIT");
if (size) {

View File

@ -240,7 +240,7 @@ class GCRuntime {
public:
explicit GCRuntime(JSRuntime* rt);
MOZ_MUST_USE bool init(uint32_t maxbytes, uint32_t maxNurseryBytes);
MOZ_MUST_USE bool init(uint32_t maxbytes);
void finishRoots();
void finish();

View File

@ -38,7 +38,7 @@ static constexpr float MinHeapGrowthFactor =
GCSchedulingTunables::GCSchedulingTunables()
: gcMaxBytes_(0),
gcMinNurseryBytes_(TuningDefaults::GCMinNurseryBytes),
gcMaxNurseryBytes_(0),
gcMaxNurseryBytes_(JS::DefaultNurseryMaxBytes),
gcZoneAllocThresholdBase_(TuningDefaults::GCZoneAllocThresholdBase),
nonIncrementalFactor_(TuningDefaults::NonIncrementalFactor),
avoidInterruptFactor_(TuningDefaults::AvoidInterruptFactor),

View File

@ -64,10 +64,11 @@ virtual JSContext* createContext() override {
// OOM. (Actually, this only happens with nursery zeal, because normally
// the nursery will start out with only a single chunk before triggering a
// major GC.)
JSContext* cx = JS_NewContext(1024 * 1024, js::gc::ChunkSize);
JSContext* cx = JS_NewContext(1024 * 1024);
if (!cx) {
return nullptr;
}
JS_SetGCParameter(cx, JSGC_MAX_NURSERY_BYTES, js::gc::ChunkSize);
setNativeStackQuota(cx);
return cx;
}

View File

@ -365,7 +365,6 @@ JS_PUBLIC_API JSObject* JS_GetBoundFunctionTarget(JSFunction* fun) {
/************************************************************************/
JS_PUBLIC_API JSContext* JS_NewContext(uint32_t maxbytes,
uint32_t maxNurseryBytes,
JSRuntime* parentRuntime) {
MOZ_ASSERT(JS::detail::libraryInitState == JS::detail::InitState::Running,
"must call JS_Init prior to creating any JSContexts");
@ -375,7 +374,7 @@ JS_PUBLIC_API JSContext* JS_NewContext(uint32_t maxbytes,
parentRuntime = parentRuntime->parentRuntime;
}
return NewContext(maxbytes, maxNurseryBytes, parentRuntime);
return NewContext(maxbytes, parentRuntime);
}
JS_PUBLIC_API JSContext* JS_NewCooperativeContext(JSContext* siblingContext) {

View File

@ -338,8 +338,7 @@ extern JS_PUBLIC_API bool JS_IsBuiltinFunctionConstructor(JSFunction* fun);
// Create a new context (and runtime) for this thread.
extern JS_PUBLIC_API JSContext* JS_NewContext(
uint32_t maxbytes, uint32_t maxNurseryMaxBytes = JS::DefaultNurseryMaxBytes,
JSRuntime* parentRuntime = nullptr);
uint32_t maxbytes, JSRuntime* parentRuntime = nullptr);
// The methods below for controlling the active context in a cooperatively
// multithreaded runtime are not threadsafe, and the caller must ensure they

View File

@ -4024,12 +4024,13 @@ static bool ShellBuildId(JS::BuildIdCharVector* buildId);
static void WorkerMain(WorkerInput* input) {
MOZ_ASSERT(input->parentRuntime);
JSContext* cx = JS_NewContext(8L * 1024L * 1024L, 2L * 1024L * 1024L,
input->parentRuntime);
JSContext* cx = JS_NewContext(8L * 1024L * 1024L, input->parentRuntime);
if (!cx) {
return;
}
JS_SetGCParameter(cx, JSGC_MAX_NURSERY_BYTES, 2L * 1024L * 1024L);
ShellContext* sc = js_new<ShellContext>(cx);
if (!sc) {
return;
@ -11386,13 +11387,15 @@ int main(int argc, char** argv, char** envp) {
return 1;
}
size_t nurseryBytes = op.getIntOption("nursery-size") * 1024L * 1024L;
/* Use the same parameters as the browser in xpcjsruntime.cpp. */
JSContext* const cx = JS_NewContext(JS::DefaultHeapMaxBytes, nurseryBytes);
JSContext* const cx = JS_NewContext(JS::DefaultHeapMaxBytes);
if (!cx) {
return 1;
}
size_t nurseryBytes = op.getIntOption("nursery-size") * 1024L * 1024L;
JS_SetGCParameter(cx, JSGC_MAX_NURSERY_BYTES, nurseryBytes);
auto destroyCx = MakeScopeExit([cx] { JS_DestroyContext(cx); });
UniquePtr<ShellContext> sc = MakeUnique<ShellContext>(cx);

View File

@ -135,8 +135,7 @@ bool JSContext::init(ContextKind kind) {
return true;
}
JSContext* js::NewContext(uint32_t maxBytes, uint32_t maxNurseryBytes,
JSRuntime* parentRuntime) {
JSContext* js::NewContext(uint32_t maxBytes, JSRuntime* parentRuntime) {
AutoNoteSingleThreadedRegion anstr;
MOZ_RELEASE_ASSERT(!TlsContext.get());
@ -163,7 +162,7 @@ JSContext* js::NewContext(uint32_t maxBytes, uint32_t maxNurseryBytes,
return nullptr;
}
if (!runtime->init(cx, maxBytes, maxNurseryBytes)) {
if (!runtime->init(cx, maxBytes)) {
runtime->destroyRuntime();
js_delete(cx);
js_delete(runtime);

View File

@ -1049,8 +1049,7 @@ struct MOZ_RAII AutoResolving {
* Create and destroy functions for JSContext, which is manually allocated
* and exclusively owned.
*/
extern JSContext* NewContext(uint32_t maxBytes, uint32_t maxNurseryBytes,
JSRuntime* parentRuntime);
extern JSContext* NewContext(uint32_t maxBytes, JSRuntime* parentRuntime);
extern void DestroyContext(JSContext* cx);

View File

@ -193,8 +193,7 @@ JSRuntime::~JSRuntime() {
MOZ_ASSERT(numDebuggeeRealmsObservingCoverage_ == 0);
}
bool JSRuntime::init(JSContext* cx, uint32_t maxbytes,
uint32_t maxNurseryBytes) {
bool JSRuntime::init(JSContext* cx, uint32_t maxbytes) {
#ifdef DEBUG
MOZ_ASSERT(!initialized_);
initialized_ = true;
@ -208,7 +207,7 @@ bool JSRuntime::init(JSContext* cx, uint32_t maxbytes,
defaultFreeOp_ = cx->defaultFreeOp();
if (!gc.init(maxbytes, maxNurseryBytes)) {
if (!gc.init(maxbytes)) {
return false;
}

View File

@ -849,7 +849,7 @@ struct JSRuntime {
// to JSContext remains valid. The final GC triggered here depends on this.
void destroyRuntime();
bool init(JSContext* cx, uint32_t maxbytes, uint32_t maxNurseryBytes);
bool init(JSContext* cx, uint32_t maxbytes);
JSRuntime* thisFromCtor() { return this; }

View File

@ -155,11 +155,13 @@ nsresult CycleCollectedJSContext::Initialize(JSRuntime* aParentRuntime,
MOZ_ASSERT(!mJSContext);
mozilla::dom::InitScriptSettings();
mJSContext = JS_NewContext(aMaxBytes, aMaxNurseryBytes, aParentRuntime);
mJSContext = JS_NewContext(aMaxBytes, aParentRuntime);
if (!mJSContext) {
return NS_ERROR_OUT_OF_MEMORY;
}
JS_SetGCParameter(mJSContext, JSGC_MAX_NURSERY_BYTES, aMaxNurseryBytes);
mRuntime = CreateRuntime(mJSContext);
InitializeCommon();