mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1160535 part 1 - Give JSFunction its own AllocKind. r=terrence
This commit is contained in:
parent
04170ac199
commit
31cda07653
@ -799,7 +799,7 @@ NewExportedFunction(JSContext* cx, const AsmJSModule::ExportedFunction& func,
|
||||
unsigned numArgs = func.isChangeHeap() ? 1 : func.numArgs();
|
||||
JSFunction* fun =
|
||||
NewNativeConstructor(cx, CallAsmJS, numArgs, name,
|
||||
JSFunction::ExtendedFinalizeKind, GenericObject,
|
||||
gc::AllocKind::FUNCTION_EXTENDED, GenericObject,
|
||||
JSFunction::ASMJS_CTOR);
|
||||
if (!fun)
|
||||
return nullptr;
|
||||
@ -832,7 +832,7 @@ HandleDynamicLinkFailure(JSContext* cx, CallArgs args, AsmJSModule& module, Hand
|
||||
return false;
|
||||
|
||||
RootedFunction fun(cx, NewScriptedFunction(cx, 0, JSFunction::INTERPRETED,
|
||||
name, JSFunction::FinalizeKind,
|
||||
name, gc::AllocKind::FUNCTION,
|
||||
TenuredObject));
|
||||
if (!fun)
|
||||
return false;
|
||||
@ -1095,7 +1095,7 @@ js::NewAsmJSModuleFunction(ExclusiveContext* cx, JSFunction* origFun, HandleObje
|
||||
: JSFunction::ASMJS_CTOR;
|
||||
JSFunction* moduleFun =
|
||||
NewNativeConstructor(cx, LinkAsmJS, origFun->nargs(), name,
|
||||
JSFunction::ExtendedFinalizeKind, TenuredObject,
|
||||
gc::AllocKind::FUNCTION_EXTENDED, TenuredObject,
|
||||
flags);
|
||||
if (!moduleFun)
|
||||
return nullptr;
|
||||
|
@ -7585,7 +7585,7 @@ ParseFunction(ModuleCompiler& m, ParseNode** fnOut)
|
||||
// This flows into FunctionBox, so must be tenured.
|
||||
RootedFunction fun(m.cx(),
|
||||
NewScriptedFunction(m.cx(), 0, JSFunction::INTERPRETED,
|
||||
name, JSFunction::FinalizeKind,
|
||||
name, gc::AllocKind::FUNCTION,
|
||||
TenuredObject));
|
||||
if (!fun)
|
||||
return false;
|
||||
|
@ -1096,7 +1096,7 @@ CreateObjectConstructor(JSContext* cx, JSProtoKey key)
|
||||
|
||||
/* Create the Object function now that we have a [[Prototype]] for it. */
|
||||
return NewNativeConstructor(cx, obj_construct, 1, HandlePropertyName(cx->names().Object),
|
||||
JSFunction::FinalizeKind, SingletonObject);
|
||||
gc::AllocKind::FUNCTION, SingletonObject);
|
||||
}
|
||||
|
||||
static JSObject*
|
||||
|
@ -1228,10 +1228,10 @@ Parser<ParseHandler>::newFunction(HandleAtom atom, FunctionSyntaxKind kind, Hand
|
||||
flags = JSFunction::INTERPRETED;
|
||||
break;
|
||||
}
|
||||
|
||||
gc::AllocKind allocKind = JSFunction::FinalizeKind;
|
||||
|
||||
gc::AllocKind allocKind = gc::AllocKind::FUNCTION;
|
||||
if (kind == Arrow || kind == Method)
|
||||
allocKind = JSFunction::ExtendedFinalizeKind;
|
||||
allocKind = gc::AllocKind::FUNCTION_EXTENDED;
|
||||
fun = NewFunctionWithProto(context, nullptr, 0, flags, NullPtr(), atom, proto,
|
||||
allocKind, TenuredObject);
|
||||
if (!fun)
|
||||
|
@ -79,7 +79,10 @@ enum InitialHeap {
|
||||
// miscompilations in GCC (fixed in 4.8.5 and 4.9.3). See also bug 1143966.
|
||||
enum class AllocKind {
|
||||
FIRST,
|
||||
OBJECT0 = FIRST,
|
||||
OBJECT_FIRST = FIRST,
|
||||
FUNCTION = FIRST,
|
||||
FUNCTION_EXTENDED,
|
||||
OBJECT0,
|
||||
OBJECT0_BACKGROUND,
|
||||
OBJECT2,
|
||||
OBJECT2_BACKGROUND,
|
||||
@ -110,13 +113,13 @@ enum class AllocKind {
|
||||
|
||||
static_assert(int(AllocKind::FIRST) == 0, "Various places depend on AllocKind starting at 0, "
|
||||
"please audit them carefully!");
|
||||
static_assert(int(AllocKind::OBJECT0) == 0, "Various places depend on AllocKind::OBJECT0 being 0, "
|
||||
"please audit them carefully!");
|
||||
static_assert(int(AllocKind::OBJECT_FIRST) == 0, "Various places depend on AllocKind::OBJECT_FIRST "
|
||||
"being 0, please audit them carefully!");
|
||||
|
||||
inline bool
|
||||
IsObjectAllocKind(AllocKind kind)
|
||||
{
|
||||
return kind >= AllocKind::OBJECT0 && kind <= AllocKind::OBJECT_LAST;
|
||||
return kind >= AllocKind::OBJECT_FIRST && kind <= AllocKind::OBJECT_LAST;
|
||||
}
|
||||
|
||||
inline bool
|
||||
@ -140,10 +143,10 @@ AllAllocKinds()
|
||||
|
||||
// Returns a sequence for use in a range-based for loop,
|
||||
// to iterate over all object alloc kinds.
|
||||
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT0, AllocKind::OBJECT_LIMIT))
|
||||
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT_FIRST, AllocKind::OBJECT_LIMIT))
|
||||
ObjectAllocKinds()
|
||||
{
|
||||
return mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT0, AllocKind::OBJECT_LIMIT);
|
||||
return mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT_FIRST, AllocKind::OBJECT_LIMIT);
|
||||
}
|
||||
|
||||
// Returns a sequence for use in a range-based for loop,
|
||||
@ -170,6 +173,8 @@ static inline JSGCTraceKind
|
||||
MapAllocToTraceKind(AllocKind kind)
|
||||
{
|
||||
static const JSGCTraceKind map[] = {
|
||||
JSTRACE_OBJECT, /* AllocKind::FUNCTION */
|
||||
JSTRACE_OBJECT, /* AllocKind::FUNCTION_EXTENDED */
|
||||
JSTRACE_OBJECT, /* AllocKind::OBJECT0 */
|
||||
JSTRACE_OBJECT, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
JSTRACE_OBJECT, /* AllocKind::OBJECT2 */
|
||||
|
@ -79,5 +79,5 @@ assertEq(tByteSize([1, 2, 3, 4, 5, 6, 7, 8]), s(112, 128));
|
||||
// Various forms of functions.
|
||||
assertEq(tByteSize(function () {}), s(32, 64));
|
||||
assertEq(tByteSize(function () {}.bind()), s(96, 128));
|
||||
assertEq(tByteSize(() => 1), s(48, 96));
|
||||
assertEq(tByteSize(() => 1), s(48, 80));
|
||||
assertEq(tByteSize(Math.sin), s(32, 64));
|
||||
|
@ -3482,7 +3482,7 @@ JS_DefineFunctions(JSContext* cx, HandleObject obj, const JSFunctionSpec* fs,
|
||||
JSFunction* fun = DefineFunction(cx, ctor, id,
|
||||
GenericNativeMethodDispatcher,
|
||||
fs->nargs + 1, flags,
|
||||
JSFunction::ExtendedFinalizeKind);
|
||||
gc::AllocKind::FUNCTION_EXTENDED);
|
||||
if (!fun)
|
||||
return false;
|
||||
|
||||
@ -4041,7 +4041,7 @@ CompileFunction(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
|
||||
}
|
||||
|
||||
fun.set(NewScriptedFunction(cx, 0, JSFunction::INTERPRETED, funAtom,
|
||||
JSFunction::FinalizeKind, TenuredObject,
|
||||
gc::AllocKind::FUNCTION, TenuredObject,
|
||||
enclosingDynamicScope));
|
||||
if (!fun)
|
||||
return false;
|
||||
|
@ -3262,7 +3262,7 @@ const Class ArrayObject::class_ = {
|
||||
nullptr, /* construct */
|
||||
nullptr, /* trace */
|
||||
{
|
||||
GenericCreateConstructor<ArrayConstructor, 1, JSFunction::FinalizeKind>,
|
||||
GenericCreateConstructor<ArrayConstructor, 1, gc::AllocKind::FUNCTION>,
|
||||
CreateArrayPrototype,
|
||||
array_static_methods,
|
||||
nullptr,
|
||||
|
@ -765,20 +765,18 @@ CreateLazyScriptsForCompartment(JSContext* cx)
|
||||
// currently stand in 1-1 relation with JSScripts; JSFunctions with the
|
||||
// same LazyScript may create different JSScripts due to relazification of
|
||||
// clones. See bug 1105306.
|
||||
for (gc::ZoneCellIter i(cx->zone(), JSFunction::FinalizeKind); !i.done(); i.next()) {
|
||||
JSObject* obj = i.get<JSObject>();
|
||||
for (gc::ZoneCellIter i(cx->zone(), AllocKind::FUNCTION); !i.done(); i.next()) {
|
||||
JSFunction* fun = &i.get<JSObject>()->as<JSFunction>();
|
||||
|
||||
// Sweeping is incremental; take care to not delazify functions that
|
||||
// are about to be finalized. GC things referenced by objects that are
|
||||
// about to be finalized (e.g., in slots) may already be freed.
|
||||
if (gc::IsAboutToBeFinalizedUnbarriered(&obj) ||
|
||||
obj->compartment() != cx->compartment() ||
|
||||
!obj->is<JSFunction>())
|
||||
if (gc::IsAboutToBeFinalizedUnbarriered(&fun) ||
|
||||
fun->compartment() != cx->compartment())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
JSFunction* fun = &obj->as<JSFunction>();
|
||||
if (fun->isInterpretedLazy()) {
|
||||
LazyScript* lazy = fun->lazyScriptOrNull();
|
||||
if (lazy && lazy->sourceObject() && !lazy->maybeScript() &&
|
||||
|
@ -3163,7 +3163,7 @@ const Class DateObject::class_ = {
|
||||
nullptr, /* construct */
|
||||
nullptr, /* trace */
|
||||
{
|
||||
GenericCreateConstructor<DateConstructor, 7, JSFunction::FinalizeKind>,
|
||||
GenericCreateConstructor<DateConstructor, 7, gc::AllocKind::FUNCTION>,
|
||||
GenericCreatePrototype,
|
||||
date_static_methods,
|
||||
nullptr,
|
||||
|
@ -490,7 +490,7 @@ ErrorObject::createProto(JSContext* cx, JSProtoKey key)
|
||||
ErrorObject::createConstructor(JSContext* cx, JSProtoKey key)
|
||||
{
|
||||
RootedObject ctor(cx);
|
||||
ctor = GenericCreateConstructor<Error, 1, JSFunction::ExtendedFinalizeKind>(cx, key);
|
||||
ctor = GenericCreateConstructor<Error, 1, gc::AllocKind::FUNCTION_EXTENDED>(cx, key);
|
||||
if (!ctor)
|
||||
return nullptr;
|
||||
|
||||
|
@ -424,7 +424,7 @@ js::DefineFunctionWithReserved(JSContext* cx, JSObject* objArg, const char* name
|
||||
if (!atom)
|
||||
return nullptr;
|
||||
Rooted<jsid> id(cx, AtomToId(atom));
|
||||
return DefineFunction(cx, obj, id, call, nargs, attrs, JSFunction::ExtendedFinalizeKind);
|
||||
return DefineFunction(cx, obj, id, call, nargs, attrs, gc::AllocKind::FUNCTION_EXTENDED);
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSFunction*)
|
||||
@ -443,8 +443,8 @@ js::NewFunctionWithReserved(JSContext* cx, JSNative native, unsigned nargs, unsi
|
||||
}
|
||||
|
||||
return (flags & JSFUN_CONSTRUCTOR) ?
|
||||
NewNativeConstructor(cx, native, nargs, atom, JSFunction::ExtendedFinalizeKind) :
|
||||
NewNativeFunction(cx, native, nargs, atom, JSFunction::ExtendedFinalizeKind);
|
||||
NewNativeConstructor(cx, native, nargs, atom, gc::AllocKind::FUNCTION_EXTENDED) :
|
||||
NewNativeFunction(cx, native, nargs, atom, gc::AllocKind::FUNCTION_EXTENDED);
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSFunction*)
|
||||
@ -457,8 +457,8 @@ js::NewFunctionByIdWithReserved(JSContext* cx, JSNative native, unsigned nargs,
|
||||
|
||||
RootedAtom atom(cx, JSID_TO_ATOM(id));
|
||||
return (flags & JSFUN_CONSTRUCTOR) ?
|
||||
NewNativeConstructor(cx, native, nargs, atom, JSFunction::ExtendedFinalizeKind) :
|
||||
NewNativeFunction(cx, native, nargs, atom, JSFunction::ExtendedFinalizeKind);
|
||||
NewNativeConstructor(cx, native, nargs, atom, gc::AllocKind::FUNCTION_EXTENDED) :
|
||||
NewNativeFunction(cx, native, nargs, atom, gc::AllocKind::FUNCTION_EXTENDED);
|
||||
}
|
||||
|
||||
JS_FRIEND_API(const Value&)
|
||||
|
@ -596,9 +596,9 @@ js::XDRInterpretedFunction(XDRState<mode>* xdr, HandleObject enclosingScope, Han
|
||||
return false;
|
||||
}
|
||||
|
||||
gc::AllocKind allocKind = JSFunction::FinalizeKind;
|
||||
gc::AllocKind allocKind = gc::AllocKind::FUNCTION;
|
||||
if (uint16_t(flagsword) & JSFunction::EXTENDED)
|
||||
allocKind = JSFunction::ExtendedFinalizeKind;
|
||||
allocKind = gc::AllocKind::FUNCTION_EXTENDED;
|
||||
fun = NewFunctionWithProto(cx, nullptr, 0, JSFunction::INTERPRETED,
|
||||
/* enclosingDynamicScope = */ NullPtr(), NullPtr(), proto,
|
||||
allocKind, TenuredObject);
|
||||
@ -654,9 +654,7 @@ js::CloneFunctionAndScript(JSContext* cx, HandleObject enclosingScope, HandleFun
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gc::AllocKind allocKind = JSFunction::FinalizeKind;
|
||||
if (srcFun->isExtended())
|
||||
allocKind = JSFunction::ExtendedFinalizeKind;
|
||||
gc::AllocKind allocKind = srcFun->getAllocKind();
|
||||
RootedFunction clone(cx, NewFunctionWithProto(cx, nullptr, 0,
|
||||
JSFunction::INTERPRETED, NullPtr(), NullPtr(),
|
||||
cloneProto, allocKind, TenuredObject));
|
||||
@ -784,7 +782,7 @@ CreateFunctionConstructor(JSContext* cx, JSProtoKey key)
|
||||
RootedObject functionCtor(cx,
|
||||
NewFunctionWithProto(cx, Function, 1, JSFunction::NATIVE_CTOR,
|
||||
NullPtr(), HandlePropertyName(cx->names().Function),
|
||||
functionProto, JSFunction::FinalizeKind, SingletonObject));
|
||||
functionProto, AllocKind::FUNCTION, SingletonObject));
|
||||
if (!functionCtor)
|
||||
return nullptr;
|
||||
|
||||
@ -804,7 +802,7 @@ CreateFunctionPrototype(JSContext* cx, JSProtoKey key)
|
||||
*/
|
||||
JSObject* functionProto_ =
|
||||
NewFunctionWithProto(cx, nullptr, 0, JSFunction::INTERPRETED,
|
||||
self, NullPtr(), objectProto, JSFunction::FinalizeKind,
|
||||
self, NullPtr(), objectProto, AllocKind::FUNCTION,
|
||||
SingletonObject);
|
||||
if (!functionProto_)
|
||||
return nullptr;
|
||||
@ -872,7 +870,7 @@ CreateFunctionPrototype(JSContext* cx, JSProtoKey key)
|
||||
// confused.
|
||||
RootedFunction throwTypeError(cx,
|
||||
NewFunctionWithProto(cx, ThrowTypeError, 0, JSFunction::NATIVE_FUN,
|
||||
NullPtr(), NullPtr(), functionProto, JSFunction::FinalizeKind,
|
||||
NullPtr(), NullPtr(), functionProto, AllocKind::FUNCTION,
|
||||
SingletonObject));
|
||||
if (!throwTypeError || !PreventExtensions(cx, throwTypeError))
|
||||
return nullptr;
|
||||
@ -1954,7 +1952,7 @@ FunctionConstructor(JSContext* cx, unsigned argc, Value* vp, GeneratorKind gener
|
||||
RootedFunction fun(cx, NewFunctionWithProto(cx, nullptr, 0,
|
||||
JSFunction::INTERPRETED_LAMBDA, global,
|
||||
anonymousAtom, proto,
|
||||
JSFunction::FinalizeKind, TenuredObject));
|
||||
AllocKind::FUNCTION, TenuredObject));
|
||||
if (!fun)
|
||||
return false;
|
||||
|
||||
@ -2003,7 +2001,7 @@ JSFunction::isBuiltinFunctionConstructor()
|
||||
|
||||
JSFunction*
|
||||
js::NewNativeFunction(ExclusiveContext* cx, Native native, unsigned nargs, HandleAtom atom,
|
||||
gc::AllocKind allocKind /* = JSFunction::FinalizeKind */,
|
||||
gc::AllocKind allocKind /* = AllocKind::FUNCTION */,
|
||||
NewObjectKind newKind /* = GenericObject */)
|
||||
{
|
||||
return NewFunctionWithProto(cx, native, nargs, JSFunction::NATIVE_FUN,
|
||||
@ -2012,7 +2010,7 @@ js::NewNativeFunction(ExclusiveContext* cx, Native native, unsigned nargs, Handl
|
||||
|
||||
JSFunction*
|
||||
js::NewNativeConstructor(ExclusiveContext* cx, Native native, unsigned nargs, HandleAtom atom,
|
||||
gc::AllocKind allocKind /* = JSFunction::FinalizeKind */,
|
||||
gc::AllocKind allocKind /* = AllocKind::FUNCTION */,
|
||||
NewObjectKind newKind /* = GenericObject */,
|
||||
JSFunction::Flags flags /* = JSFunction::NATIVE_CTOR */)
|
||||
{
|
||||
@ -2024,7 +2022,7 @@ js::NewNativeConstructor(ExclusiveContext* cx, Native native, unsigned nargs, Ha
|
||||
JSFunction*
|
||||
js::NewScriptedFunction(ExclusiveContext* cx, unsigned nargs,
|
||||
JSFunction::Flags flags, HandleAtom atom,
|
||||
gc::AllocKind allocKind /* = JSFunction::FinalizeKind */,
|
||||
gc::AllocKind allocKind /* = AllocKind::FUNCTION */,
|
||||
NewObjectKind newKind /* = GenericObject */,
|
||||
HandleObject enclosingDynamicScope /* = NullPtr() */)
|
||||
{
|
||||
@ -2037,12 +2035,10 @@ JSFunction*
|
||||
js::NewFunctionWithProto(ExclusiveContext* cx, Native native,
|
||||
unsigned nargs, JSFunction::Flags flags, HandleObject enclosingDynamicScope,
|
||||
HandleAtom atom, HandleObject proto,
|
||||
gc::AllocKind allocKind /* = JSFunction::FinalizeKind */,
|
||||
gc::AllocKind allocKind /* = AllocKind::FUNCTION */,
|
||||
NewObjectKind newKind /* = GenericObject */)
|
||||
{
|
||||
MOZ_ASSERT(allocKind == JSFunction::FinalizeKind || allocKind == JSFunction::ExtendedFinalizeKind);
|
||||
MOZ_ASSERT(sizeof(JSFunction) <= gc::Arena::thingSize(JSFunction::FinalizeKind));
|
||||
MOZ_ASSERT(sizeof(FunctionExtended) <= gc::Arena::thingSize(JSFunction::ExtendedFinalizeKind));
|
||||
MOZ_ASSERT(allocKind == AllocKind::FUNCTION || allocKind == AllocKind::FUNCTION_EXTENDED);
|
||||
MOZ_ASSERT_IF(native, !enclosingDynamicScope);
|
||||
|
||||
RootedObject funobj(cx);
|
||||
@ -2069,7 +2065,7 @@ js::NewFunctionWithProto(ExclusiveContext* cx, Native native,
|
||||
|
||||
RootedFunction fun(cx, &funobj->as<JSFunction>());
|
||||
|
||||
if (allocKind == JSFunction::ExtendedFinalizeKind)
|
||||
if (allocKind == AllocKind::FUNCTION_EXTENDED)
|
||||
flags = JSFunction::Flags(flags | JSFunction::EXTENDED);
|
||||
|
||||
/* Initialize all function members. */
|
||||
@ -2087,7 +2083,7 @@ js::NewFunctionWithProto(ExclusiveContext* cx, Native native,
|
||||
MOZ_ASSERT(native);
|
||||
fun->initNative(native, nullptr);
|
||||
}
|
||||
if (allocKind == JSFunction::ExtendedFinalizeKind)
|
||||
if (allocKind == AllocKind::FUNCTION_EXTENDED)
|
||||
fun->initializeExtended();
|
||||
fun->initAtom(atom);
|
||||
|
||||
@ -2169,7 +2165,7 @@ js::CloneFunctionObject(JSContext* cx, HandleFunction fun, HandleObject parent,
|
||||
MOZ_ASSERT(useSameScript || !fun->isInterpretedLazy());
|
||||
|
||||
uint16_t flags = fun->flags() & ~JSFunction::EXTENDED;
|
||||
if (allocKind == JSFunction::ExtendedFinalizeKind)
|
||||
if (allocKind == AllocKind::FUNCTION_EXTENDED)
|
||||
flags |= JSFunction::EXTENDED;
|
||||
|
||||
clone->setArgCount(fun->nargs());
|
||||
@ -2188,7 +2184,7 @@ js::CloneFunctionObject(JSContext* cx, HandleFunction fun, HandleObject parent,
|
||||
}
|
||||
clone->initAtom(fun->displayAtom());
|
||||
|
||||
if (allocKind == JSFunction::ExtendedFinalizeKind) {
|
||||
if (allocKind == AllocKind::FUNCTION_EXTENDED) {
|
||||
if (fun->isExtended() && fun->compartment() == cx->compartment()) {
|
||||
for (unsigned i = 0; i < FunctionExtended::NUM_EXTENDED_SLOTS; i++)
|
||||
clone->initExtendedSlot(i, fun->getExtendedSlot(i));
|
||||
@ -2256,7 +2252,7 @@ js::IdToFunctionName(JSContext* cx, HandleId id)
|
||||
|
||||
JSFunction*
|
||||
js::DefineFunction(JSContext* cx, HandleObject obj, HandleId id, Native native,
|
||||
unsigned nargs, unsigned flags, AllocKind allocKind /* = FinalizeKind */,
|
||||
unsigned nargs, unsigned flags, AllocKind allocKind /* = AllocKind::FUNCTION */,
|
||||
NewObjectKind newKind /* = GenericObject */)
|
||||
{
|
||||
GetterOp gop;
|
||||
|
@ -454,14 +454,6 @@ class JSFunction : public js::NativeObject
|
||||
return offsetof(JSFunction, u.nativeOrScript);
|
||||
}
|
||||
|
||||
#if JS_BITS_PER_WORD == 32
|
||||
static const js::gc::AllocKind FinalizeKind = js::gc::AllocKind::OBJECT2_BACKGROUND;
|
||||
static const js::gc::AllocKind ExtendedFinalizeKind = js::gc::AllocKind::OBJECT4_BACKGROUND;
|
||||
#else
|
||||
static const js::gc::AllocKind FinalizeKind = js::gc::AllocKind::OBJECT4_BACKGROUND;
|
||||
static const js::gc::AllocKind ExtendedFinalizeKind = js::gc::AllocKind::OBJECT8_BACKGROUND;
|
||||
#endif
|
||||
|
||||
inline void trace(JSTracer* trc);
|
||||
|
||||
/* Bound function accessors. */
|
||||
@ -485,8 +477,10 @@ class JSFunction : public js::NativeObject
|
||||
|
||||
public:
|
||||
inline bool isExtended() const {
|
||||
MOZ_ASSERT_IF(isTenured(), !!(flags() & EXTENDED) == (asTenured().getAllocKind() == ExtendedFinalizeKind));
|
||||
return !!(flags() & EXTENDED);
|
||||
bool extended = !!(flags() & EXTENDED);
|
||||
MOZ_ASSERT_IF(isTenured(),
|
||||
extended == (asTenured().getAllocKind() == js::gc::AllocKind::FUNCTION_EXTENDED));
|
||||
return extended;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -505,13 +499,13 @@ class JSFunction : public js::NativeObject
|
||||
|
||||
/* GC support. */
|
||||
js::gc::AllocKind getAllocKind() const {
|
||||
static_assert(FinalizeKind != ExtendedFinalizeKind,
|
||||
static_assert(js::gc::AllocKind::FUNCTION != js::gc::AllocKind::FUNCTION_EXTENDED,
|
||||
"extended/non-extended AllocKinds have to be different "
|
||||
"for getAllocKind() to have a reason to exist");
|
||||
|
||||
js::gc::AllocKind kind = FinalizeKind;
|
||||
js::gc::AllocKind kind = js::gc::AllocKind::FUNCTION;
|
||||
if (isExtended())
|
||||
kind = ExtendedFinalizeKind;
|
||||
kind = js::gc::AllocKind::FUNCTION_EXTENDED;
|
||||
MOZ_ASSERT_IF(isTenured(), kind == asTenured().getAllocKind());
|
||||
return kind;
|
||||
}
|
||||
@ -534,13 +528,13 @@ Generator(JSContext* cx, unsigned argc, Value* vp);
|
||||
// Allocate a new function backed by a JSNative.
|
||||
extern JSFunction*
|
||||
NewNativeFunction(ExclusiveContext* cx, JSNative native, unsigned nargs, HandleAtom atom,
|
||||
gc::AllocKind allocKind = JSFunction::FinalizeKind,
|
||||
gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
|
||||
NewObjectKind newKind = GenericObject);
|
||||
|
||||
// Allocate a new constructor backed by a JSNative.
|
||||
extern JSFunction*
|
||||
NewNativeConstructor(ExclusiveContext* cx, JSNative native, unsigned nargs, HandleAtom atom,
|
||||
gc::AllocKind allocKind = JSFunction::FinalizeKind,
|
||||
gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
|
||||
NewObjectKind newKind = GenericObject,
|
||||
JSFunction::Flags flags = JSFunction::NATIVE_CTOR);
|
||||
|
||||
@ -549,7 +543,7 @@ NewNativeConstructor(ExclusiveContext* cx, JSNative native, unsigned nargs, Hand
|
||||
// the global.
|
||||
extern JSFunction*
|
||||
NewScriptedFunction(ExclusiveContext* cx, unsigned nargs, JSFunction::Flags flags,
|
||||
HandleAtom atom, gc::AllocKind allocKind = JSFunction::FinalizeKind,
|
||||
HandleAtom atom, gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
|
||||
NewObjectKind newKind = GenericObject,
|
||||
HandleObject enclosingDynamicScope = NullPtr());
|
||||
|
||||
@ -560,7 +554,7 @@ NewScriptedFunction(ExclusiveContext* cx, unsigned nargs, JSFunction::Flags flag
|
||||
extern JSFunction*
|
||||
NewFunctionWithProto(ExclusiveContext* cx, JSNative native, unsigned nargs,
|
||||
JSFunction::Flags flags, HandleObject enclosingDynamicScope, HandleAtom atom,
|
||||
HandleObject proto, gc::AllocKind allocKind = JSFunction::FinalizeKind,
|
||||
HandleObject proto, gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
|
||||
NewObjectKind newKind = GenericObject);
|
||||
|
||||
extern JSAtom*
|
||||
@ -569,7 +563,7 @@ IdToFunctionName(JSContext* cx, HandleId id);
|
||||
extern JSFunction*
|
||||
DefineFunction(JSContext* cx, HandleObject obj, HandleId id, JSNative native,
|
||||
unsigned nargs, unsigned flags,
|
||||
gc::AllocKind allocKind = JSFunction::FinalizeKind,
|
||||
gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
|
||||
NewObjectKind newKind = GenericObject);
|
||||
|
||||
bool
|
||||
@ -617,7 +611,7 @@ CloneFunctionObjectUseSameScript(JSCompartment* compartment, HandleFunction fun,
|
||||
|
||||
extern JSFunction*
|
||||
CloneFunctionObject(JSContext* cx, HandleFunction fun, HandleObject parent,
|
||||
gc::AllocKind kind = JSFunction::FinalizeKind,
|
||||
gc::AllocKind kind = gc::AllocKind::FUNCTION,
|
||||
NewObjectKind newKindArg = GenericObject,
|
||||
HandleObject proto = NullPtr());
|
||||
|
||||
|
@ -80,8 +80,8 @@ CloneFunctionObjectIfNotSingleton(JSContext* cx, HandleFunction fun, HandleObjec
|
||||
|
||||
// These intermediate variables are needed to avoid link errors on some
|
||||
// platforms. Sigh.
|
||||
gc::AllocKind finalizeKind = JSFunction::FinalizeKind;
|
||||
gc::AllocKind extendedFinalizeKind = JSFunction::ExtendedFinalizeKind;
|
||||
gc::AllocKind finalizeKind = gc::AllocKind::FUNCTION;
|
||||
gc::AllocKind extendedFinalizeKind = gc::AllocKind::FUNCTION_EXTENDED;
|
||||
gc::AllocKind kind = fun->isExtended()
|
||||
? extendedFinalizeKind
|
||||
: finalizeKind;
|
||||
|
@ -270,6 +270,8 @@ static_assert(JS_ARRAY_LENGTH(slotsToThingKind) == SLOTS_TO_THING_KIND_LIMIT,
|
||||
MOZ_FOR_EACH(CHECK_MIN_THING_SIZE_INNER, (), (__VA_ARGS__ UINT32_MAX))
|
||||
|
||||
const uint32_t Arena::ThingSizes[] = CHECK_MIN_THING_SIZE(
|
||||
sizeof(JSFunction), /* AllocKind::FUNCTION */
|
||||
sizeof(FunctionExtended), /* AllocKind::FUNCTION_EXTENDED */
|
||||
sizeof(JSObject_Slots0), /* AllocKind::OBJECT0 */
|
||||
sizeof(JSObject_Slots0), /* AllocKind::OBJECT0_BACKGROUND */
|
||||
sizeof(JSObject_Slots2), /* AllocKind::OBJECT2 */
|
||||
@ -301,6 +303,8 @@ const uint32_t Arena::ThingSizes[] = CHECK_MIN_THING_SIZE(
|
||||
#define OFFSET(type) uint32_t(sizeof(ArenaHeader) + (ArenaSize - sizeof(ArenaHeader)) % sizeof(type))
|
||||
|
||||
const uint32_t Arena::FirstThingOffsets[] = {
|
||||
OFFSET(JSFunction), /* AllocKind::FUNCTION */
|
||||
OFFSET(FunctionExtended), /* AllocKind::FUNCTION_EXTENDED */
|
||||
OFFSET(JSObject_Slots0), /* AllocKind::OBJECT0 */
|
||||
OFFSET(JSObject_Slots0), /* AllocKind::OBJECT0_BACKGROUND */
|
||||
OFFSET(JSObject_Slots2), /* AllocKind::OBJECT2 */
|
||||
@ -365,6 +369,8 @@ static const FinalizePhase IncrementalFinalizePhases[] = {
|
||||
*/
|
||||
|
||||
static const AllocKind BackgroundPhaseObjects[] = {
|
||||
AllocKind::FUNCTION,
|
||||
AllocKind::FUNCTION_EXTENDED,
|
||||
AllocKind::OBJECT0_BACKGROUND,
|
||||
AllocKind::OBJECT2_BACKGROUND,
|
||||
AllocKind::OBJECT4_BACKGROUND,
|
||||
@ -588,6 +594,8 @@ FinalizeArenas(FreeOp* fop,
|
||||
ArenaLists::KeepArenasEnum keepArenas)
|
||||
{
|
||||
switch (thingKind) {
|
||||
case AllocKind::FUNCTION:
|
||||
case AllocKind::FUNCTION_EXTENDED:
|
||||
case AllocKind::OBJECT0:
|
||||
case AllocKind::OBJECT0_BACKGROUND:
|
||||
case AllocKind::OBJECT2:
|
||||
@ -2286,6 +2294,8 @@ UpdateCellPointers(MovingTracer* trc, ArenaHeader* arena)
|
||||
JSGCTraceKind traceKind = MapAllocToTraceKind(kind);
|
||||
|
||||
switch (kind) {
|
||||
case AllocKind::FUNCTION:
|
||||
case AllocKind::FUNCTION_EXTENDED:
|
||||
case AllocKind::OBJECT0:
|
||||
case AllocKind::OBJECT0_BACKGROUND:
|
||||
case AllocKind::OBJECT2:
|
||||
|
@ -96,6 +96,8 @@ IsNurseryAllocable(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
true, /* AllocKind::FUNCTION */
|
||||
true, /* AllocKind::FUNCTION_EXTENDED */
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT2 */
|
||||
@ -129,6 +131,8 @@ IsBackgroundFinalized(AllocKind kind)
|
||||
{
|
||||
MOZ_ASSERT(IsValidAllocKind(kind));
|
||||
static const bool map[] = {
|
||||
true, /* AllocKind::FUNCTION */
|
||||
true, /* AllocKind::FUNCTION_EXTENDED */
|
||||
false, /* AllocKind::OBJECT0 */
|
||||
true, /* AllocKind::OBJECT0_BACKGROUND */
|
||||
false, /* AllocKind::OBJECT2 */
|
||||
@ -287,9 +291,11 @@ GetGCKindSlots(AllocKind thingKind)
|
||||
{
|
||||
/* Using a switch in hopes that thingKind will usually be a compile-time constant. */
|
||||
switch (thingKind) {
|
||||
case AllocKind::FUNCTION:
|
||||
case AllocKind::OBJECT0:
|
||||
case AllocKind::OBJECT0_BACKGROUND:
|
||||
return 0;
|
||||
case AllocKind::FUNCTION_EXTENDED:
|
||||
case AllocKind::OBJECT2:
|
||||
case AllocKind::OBJECT2_BACKGROUND:
|
||||
return 2;
|
||||
|
@ -19,7 +19,7 @@ static inline AllocKind
|
||||
GetGCObjectKind(const Class* clasp)
|
||||
{
|
||||
if (clasp == FunctionClassPtr)
|
||||
return JSFunction::FinalizeKind;
|
||||
return AllocKind::FUNCTION;
|
||||
uint32_t nslots = JSCLASS_RESERVED_SLOTS(clasp);
|
||||
if (clasp->flags & JSCLASS_HAS_PRIVATE)
|
||||
nslots++;
|
||||
|
@ -1085,7 +1085,7 @@ NewObject(ExclusiveContext* cx, HandleObjectGroup group, gc::AllocKind kind,
|
||||
|
||||
MOZ_ASSERT(clasp != &ArrayObject::class_);
|
||||
MOZ_ASSERT_IF(clasp == &JSFunction::class_,
|
||||
kind == JSFunction::FinalizeKind || kind == JSFunction::ExtendedFinalizeKind);
|
||||
kind == AllocKind::FUNCTION || kind == AllocKind::FUNCTION_EXTENDED);
|
||||
|
||||
// For objects which can have fixed data following the object, only use
|
||||
// enough fixed slots to cover the number of reserved slots in the object,
|
||||
|
@ -823,7 +823,7 @@ InitClass(JSContext* cx, HandleObject obj, HandleObject parent_proto,
|
||||
const JSPropertySpec* ps, const JSFunctionSpec* fs,
|
||||
const JSPropertySpec* static_ps, const JSFunctionSpec* static_fs,
|
||||
NativeObject** ctorp = nullptr,
|
||||
gc::AllocKind ctorKind = JSFunction::FinalizeKind);
|
||||
gc::AllocKind ctorKind = gc::AllocKind::FUNCTION);
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
|
@ -6001,7 +6001,7 @@ DebuggerFrame_getArguments(JSContext* cx, unsigned argc, Value* vp)
|
||||
for (unsigned i = 0; i < fargc; i++) {
|
||||
RootedFunction getobj(cx);
|
||||
getobj = NewNativeFunction(cx, DebuggerArguments_getArg, 0, js::NullPtr(),
|
||||
JSFunction::ExtendedFinalizeKind);
|
||||
gc::AllocKind::FUNCTION_EXTENDED);
|
||||
if (!getobj)
|
||||
return false;
|
||||
id = INT_TO_JSID(i);
|
||||
|
@ -607,7 +607,7 @@ GlobalObject::getSelfHostedFunction(JSContext* cx, HandleAtom selfHostedName, Ha
|
||||
|
||||
JSFunction* fun =
|
||||
NewScriptedFunction(cx, nargs, JSFunction::INTERPRETED_LAZY,
|
||||
name, JSFunction::ExtendedFinalizeKind, SingletonObject);
|
||||
name, gc::AllocKind::FUNCTION_EXTENDED, SingletonObject);
|
||||
if (!fun)
|
||||
return false;
|
||||
fun->setIsSelfHostedBuiltin();
|
||||
|
@ -299,7 +299,7 @@ class GlobalObject : public NativeObject
|
||||
*/
|
||||
JSFunction*
|
||||
createConstructor(JSContext* cx, JSNative ctor, JSAtom* name, unsigned length,
|
||||
gc::AllocKind kind = JSFunction::FinalizeKind);
|
||||
gc::AllocKind kind = gc::AllocKind::FUNCTION);
|
||||
|
||||
/*
|
||||
* Create an object to serve as [[Prototype]] for instances of the given
|
||||
|
@ -279,7 +279,7 @@ const Class RegExpObject::class_ = {
|
||||
|
||||
// ClassSpec
|
||||
{
|
||||
GenericCreateConstructor<js::regexp_construct, 2, JSFunction::FinalizeKind>,
|
||||
GenericCreateConstructor<js::regexp_construct, 2, gc::AllocKind::FUNCTION>,
|
||||
CreateRegExpPrototype,
|
||||
nullptr,
|
||||
js::regexp_static_props,
|
||||
|
@ -196,7 +196,7 @@ SavedFrame::finishSavedFrameInit(JSContext* cx, HandleObject ctor, HandleObject
|
||||
|
||||
// ClassSpec
|
||||
{
|
||||
GenericCreateConstructor<SavedFrame::construct, 0, JSFunction::FinalizeKind>,
|
||||
GenericCreateConstructor<SavedFrame::construct, 0, gc::AllocKind::FUNCTION>,
|
||||
GenericCreatePrototype,
|
||||
SavedFrame::staticFunctions,
|
||||
nullptr,
|
||||
|
@ -1781,7 +1781,7 @@ CloneObject(JSContext* cx, HandleNativeObject selfHostedObject)
|
||||
// Arrow functions use the first extended slot for their lexical |this| value.
|
||||
MOZ_ASSERT(!selfHostedFunction->isArrow());
|
||||
js::gc::AllocKind kind = hasName
|
||||
? JSFunction::ExtendedFinalizeKind
|
||||
? gc::AllocKind::FUNCTION_EXTENDED
|
||||
: selfHostedFunction->getAllocKind();
|
||||
clone = CloneFunctionObject(cx, selfHostedFunction, cx->global(), kind, TenuredObject);
|
||||
// To be able to re-lazify the cloned function, its name in the
|
||||
|
@ -690,7 +690,7 @@ IMPL_SHARED_TYPED_ARRAY_COMBINED_UNWRAPPERS(Float64, double, double)
|
||||
#define SHARED_TYPED_ARRAY_CLASS_SPEC(_typedArray) \
|
||||
{ \
|
||||
GenericCreateConstructor<Shared##_typedArray##Object::class_constructor, 3, \
|
||||
JSFunction::FinalizeKind>, \
|
||||
gc::AllocKind::FUNCTION>, \
|
||||
Shared##_typedArray##Object::CreatePrototype, \
|
||||
nullptr, \
|
||||
nullptr, \
|
||||
|
@ -235,7 +235,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
|
||||
return NewFunctionWithProto(cx, class_constructor, 3,
|
||||
JSFunction::NATIVE_CTOR, NullPtr(),
|
||||
ClassName(key, cx),
|
||||
ctorProto, JSFunction::FinalizeKind,
|
||||
ctorProto, gc::AllocKind::FUNCTION,
|
||||
SingletonObject);
|
||||
}
|
||||
|
||||
@ -847,7 +847,7 @@ TypedArrayObject::sharedTypedArrayPrototypeClass = {
|
||||
nullptr, /* construct */
|
||||
nullptr, /* trace */
|
||||
{
|
||||
GenericCreateConstructor<TypedArrayConstructor, 3, JSFunction::FinalizeKind>,
|
||||
GenericCreateConstructor<TypedArrayConstructor, 3, gc::AllocKind::FUNCTION>,
|
||||
GenericCreatePrototype,
|
||||
TypedArrayObject::staticFunctions,
|
||||
nullptr,
|
||||
|
Loading…
Reference in New Issue
Block a user