Bug 869733 - Tenure all clones caused by Lambda creation; r=shu

--HG--
extra : rebase_source : 7e22802f9e1bc6eec5f9a5ebe2d5bfb004f88a30
This commit is contained in:
Terrence Cole 2013-05-10 15:50:49 -07:00
parent 5c20b49b4e
commit 85749efb32
6 changed files with 27 additions and 16 deletions

View File

@ -415,12 +415,14 @@ template bool
js::XDRInterpretedFunction(XDRState<XDR_DECODE> *, HandleObject, HandleScript, MutableHandleObject);
JSObject *
js::CloneInterpretedFunction(JSContext *cx, HandleObject enclosingScope, HandleFunction srcFun)
js::CloneInterpretedFunction(JSContext *cx, HandleObject enclosingScope, HandleFunction srcFun,
NewObjectKind newKind /* = GenericObject */)
{
/* NB: Keep this in sync with XDRInterpretedFunction. */
RootedFunction clone(cx, NewFunction(cx, NullPtr(), NULL, 0,
JSFunction::INTERPRETED, NullPtr(), NullPtr()));
JSFunction::INTERPRETED, NullPtr(), NullPtr(),
JSFunction::FinalizeKind, newKind));
if (!clone)
return NULL;
@ -1493,7 +1495,8 @@ js::NewFunction(JSContext *cx, HandleObject funobjArg, Native native, unsigned n
}
JSFunction *
js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent, gc::AllocKind allocKind)
js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent, gc::AllocKind allocKind,
NewObjectKind newKindArg /* = GenericObject */)
{
JS_ASSERT(parent);
JS_ASSERT(!fun->isBoundFunction());
@ -1501,7 +1504,7 @@ js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
bool useSameScript = cx->compartment == fun->compartment() &&
!fun->hasSingletonType() &&
!types::UseNewTypeForClone(fun);
NewObjectKind newKind = useSameScript ? GenericObject : SingletonObject;
NewObjectKind newKind = useSameScript ? newKindArg : SingletonObject;
JSObject *cloneobj = NewObjectWithClassProto(cx, &FunctionClass, NULL, SkipScopeParent(parent),
allocKind, newKind);
if (!cloneobj)
@ -1553,7 +1556,7 @@ js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
* (JS_CloneFunctionObject) which dynamically ensures that 'script' has
* no enclosing lexical scope (only the global scope).
*/
if (cloneRoot->isInterpreted() && !CloneFunctionScript(cx, fun, cloneRoot))
if (cloneRoot->isInterpreted() && !CloneFunctionScript(cx, fun, cloneRoot, newKindArg))
return NULL;
return cloneRoot;

View File

@ -390,7 +390,8 @@ class FunctionExtended : public JSFunction
extern JSFunction *
CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
gc::AllocKind kind = JSFunction::FinalizeKind);
gc::AllocKind kind = JSFunction::FinalizeKind,
NewObjectKind newKindArg = GenericObject);
} // namespace js
@ -418,7 +419,8 @@ XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope,
HandleScript enclosingScript, MutableHandleObject objp);
extern JSObject *
CloneInterpretedFunction(JSContext *cx, HandleObject enclosingScope, HandleFunction fun);
CloneInterpretedFunction(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
NewObjectKind newKind = GenericObject);
/*
* Report an error that call.thisv is not compatible with the specified class,

View File

@ -169,7 +169,8 @@ SkipScopeParent(JSObject *parent)
}
inline JSFunction *
CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObject parent)
CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObject parent,
NewObjectKind newKind = GenericObject)
{
/*
* For attempts to clone functions at a function definition opcode,
@ -202,7 +203,7 @@ CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObjec
gc::AllocKind kind = fun->isExtended()
? extendedFinalizeKind
: finalizeKind;
return CloneFunctionObject(cx, fun, parent, kind);
return CloneFunctionObject(cx, fun, parent, kind, newKind);
}
} /* namespace js */

View File

@ -3381,7 +3381,7 @@ js::GetScopeNameForTypeOf(JSContext *cx, HandleObject scopeChain, HandleProperty
JSObject *
js::Lambda(JSContext *cx, HandleFunction fun, HandleObject parent)
{
RootedObject clone(cx, CloneFunctionObjectIfNotSingleton(cx, fun, parent));
RootedObject clone(cx, CloneFunctionObjectIfNotSingleton(cx, fun, parent, TenuredObject));
if (!clone)
return NULL;

View File

@ -2219,7 +2219,8 @@ Rebase(JSScript *dst, JSScript *src, T *srcp)
}
JSScript *
js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, HandleScript src)
js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, HandleScript src,
NewObjectKind newKind /* = GenericObject */)
{
/* NB: Keep this in sync with XDRScript. */
@ -2271,7 +2272,8 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
else
enclosingScope = fun;
clone = CloneInterpretedFunction(cx, enclosingScope, innerFun);
clone = CloneInterpretedFunction(cx, enclosingScope, innerFun,
src->selfHosted ? TenuredObject : newKind);
} else {
/*
* Clone object literals emitted for the JSOP_NEWOBJECT opcode. We only emit that
@ -2385,7 +2387,8 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
}
bool
js::CloneFunctionScript(JSContext *cx, HandleFunction original, HandleFunction clone)
js::CloneFunctionScript(JSContext *cx, HandleFunction original, HandleFunction clone,
NewObjectKind newKind /* = GenericObject */)
{
JS_ASSERT(clone->isInterpreted());
@ -2399,7 +2402,7 @@ js::CloneFunctionScript(JSContext *cx, HandleFunction original, HandleFunction c
clone->mutableScript().init(NULL);
JSScript *cscript = CloneScript(cx, scope, clone, script);
JSScript *cscript = CloneScript(cx, scope, clone, script, newKind);
if (!cscript)
return false;

View File

@ -1290,10 +1290,12 @@ inline void
CurrentScriptFileLineOrigin(JSContext *cx, unsigned *linenop, LineOption = NOT_CALLED_FROM_JSOP_EVAL);
extern JSScript *
CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, HandleScript script);
CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, HandleScript script,
NewObjectKind newKind = GenericObject);
bool
CloneFunctionScript(JSContext *cx, HandleFunction original, HandleFunction clone);
CloneFunctionScript(JSContext *cx, HandleFunction original, HandleFunction clone,
NewObjectKind newKind = GenericObject);
/*
* NB: after a successful XDR_DECODE, XDRScript callers must do any required