Bug 817818 - Miscellaneous rooting fixes. r=terrence

--HG--
extra : rebase_source : 0b26361bc48a8c6879b85d9fa356e94f48b7b980
This commit is contained in:
Steve Fink 2012-12-17 11:55:15 -08:00
parent 2cb1932439
commit a11c81e2f5
8 changed files with 75 additions and 72 deletions

View File

@ -337,8 +337,6 @@ namespace js {
* rooted.
*/
typedef JSObject * RawObject;
typedef JSFunction * RawFunction;
typedef JSScript * RawScript;
typedef JSString * RawString;
typedef jsid RawId;
typedef JS::Value RawValue;
@ -518,18 +516,18 @@ class Unrooted
* This macro simplifies declaration of the required matching raw-pointer for
* optimized builds and Unrooted<T> template for debug builds.
*/
# define ForwardDeclare(type) \
class type; \
typedef Unrooted<type*> Unrooted##type; \
# define ForwardDeclare(type) \
class type; \
typedef Unrooted<type*> Unrooted##type; \
typedef type * Raw##type
# define ForwardDeclareJS(type) \
struct JS##type; \
namespace js { \
typedef Unrooted<JS##type*> Unrooted##type; \
typedef JS##type * Raw##type; \
} \
struct JS##type
# define ForwardDeclareJS(type) \
class JS##type; \
namespace js { \
typedef js::Unrooted<JS##type*> Unrooted##type; \
typedef JS##type * Raw##type; \
} \
class JS##type
template <typename T>
T DropUnrooted(Unrooted<T> &unrooted)
@ -553,18 +551,18 @@ inline RawId DropUnrooted(RawId &id) { return id; }
#else /* NDEBUG */
/* In opt builds |UnrootedFoo| is a real |Foo*|. */
# define ForwardDeclare(type) \
class type; \
typedef type * Unrooted##type; \
# define ForwardDeclare(type) \
class type; \
typedef type * Unrooted##type; \
typedef type * Raw##type
# define ForwardDeclareJS(type) \
struct JS##type; \
class JS##type; \
namespace js { \
typedef JS##type * Unrooted##type; \
typedef JS##type * Raw##type; \
} \
struct JS##type
class JS##type
template <typename T>
class Unrooted
@ -958,6 +956,9 @@ class CompilerRootNode
} /* namespace js */
ForwardDeclareJS(Script);
ForwardDeclareJS(Function);
#endif /* __cplusplus */
#endif /* jsgc_root_h___ */

View File

@ -159,7 +159,7 @@ ScriptFilename(const UnrootedScript script)
}
static const char *
FunctionName(JSContext *cx, const JSFunction *fun, JSAutoByteString* bytes)
FunctionName(JSContext *cx, UnrootedFunction fun, JSAutoByteString* bytes)
{
if (!fun)
return Probes::nullName;
@ -176,7 +176,7 @@ FunctionName(JSContext *cx, const JSFunction *fun, JSAutoByteString* bytes)
* a number of usually unused lines of code would cause.
*/
void
Probes::DTraceEnterJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script)
Probes::DTraceEnterJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script)
{
JSAutoByteString funNameBytes;
JAVASCRIPT_FUNCTION_ENTRY(ScriptFilename(script), Probes::nullName,
@ -184,7 +184,7 @@ Probes::DTraceEnterJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script)
}
void
Probes::DTraceExitJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script)
Probes::DTraceExitJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script)
{
JSAutoByteString funNameBytes;
JAVASCRIPT_FUNCTION_RETURN(ScriptFilename(script), Probes::nullName,
@ -243,7 +243,7 @@ Probes::ETWShutdown()
}
bool
Probes::ETWEnterJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script, int counter)
Probes::ETWEnterJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script, int counter)
{
int lineno = script ? script->lineno : -1;
JSAutoByteString bytes;
@ -253,7 +253,7 @@ Probes::ETWEnterJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script, int
}
bool
Probes::ETWExitJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script, int counter)
Probes::ETWExitJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script, int counter)
{
int lineno = script ? script->lineno : -1;
JSAutoByteString bytes;
@ -263,7 +263,7 @@ Probes::ETWExitJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script, int
}
bool
Probes::ETWCreateObject(JSContext *cx, JSObject *obj)
Probes::ETWCreateObject(JSContext *cx, UnrootedObject obj)
{
int lineno;
const char * script_filename;
@ -275,14 +275,14 @@ Probes::ETWCreateObject(JSContext *cx, JSObject *obj)
}
bool
Probes::ETWFinalizeObject(JSObject *obj)
Probes::ETWFinalizeObject(UnrootedObject obj)
{
return EventWriteEvtObjectFinalize(ObjectClassname(obj),
reinterpret_cast<uint64_t_t>(obj)) == ERROR_SUCCESS;
}
bool
Probes::ETWResizeObject(JSContext *cx, JSObject *obj, size_t oldSize, size_t newSize)
Probes::ETWResizeObject(JSContext *cx, UnrootedObject obj, size_t oldSize, size_t newSize)
{
int lineno;
const char *script_filename;
@ -294,7 +294,7 @@ Probes::ETWResizeObject(JSContext *cx, JSObject *obj, size_t oldSize, size_t new
}
bool
Probes::ETWCreateString(JSContext *cx, JSString *string, size_t length)
Probes::ETWCreateString(JSContext *cx, UnrootedString string, size_t length)
{
int lineno;
const char *script_filename;
@ -306,7 +306,7 @@ Probes::ETWCreateString(JSContext *cx, JSString *string, size_t length)
}
bool
Probes::ETWFinalizeString(JSString *string)
Probes::ETWFinalizeString(UnrootedString string)
{
return EventWriteEvtStringFinalize(reinterpret_cast<uint64_t>(string),
string->length()) == ERROR_SUCCESS;
@ -325,7 +325,7 @@ Probes::ETWCompileScriptEnd(const char *filename, int lineno)
}
bool
Probes::ETWCalloutBegin(JSContext *cx, JSFunction *fun)
Probes::ETWCalloutBegin(JSContext *cx, UnrootedFunction fun)
{
const char *script_filename;
int lineno;
@ -339,7 +339,7 @@ Probes::ETWCalloutBegin(JSContext *cx, JSFunction *fun)
}
bool
Probes::ETWCalloutEnd(JSContext *cx, JSFunction *fun)
Probes::ETWCalloutEnd(JSContext *cx, UnrootedFunction fun)
{
const char *script_filename;
int lineno;
@ -406,7 +406,7 @@ Probes::ETWGCEndSweepPhase(JSCompartment *compartment)
}
bool
Probes::ETWCustomMark(JSString *string)
Probes::ETWCustomMark(UnrootedString string)
{
const jschar *chars = string->getCharsZ(NULL);
return !chars || EventWriteEvtCustomString(chars) == ERROR_SUCCESS;

View File

@ -92,10 +92,10 @@ bool callTrackingActive(JSContext *);
bool wantNativeAddressInfo(JSContext *);
/* Entering a JS function */
bool enterScript(JSContext *, UnrootedScript , JSFunction *, StackFrame *);
bool enterScript(JSContext *, UnrootedScript, UnrootedFunction , StackFrame *);
/* About to leave a JS function */
bool exitScript(JSContext *, UnrootedScript , JSFunction *, StackFrame *);
bool exitScript(JSContext *, UnrootedScript, UnrootedFunction , StackFrame *);
/* Executing a script */
bool startExecution(UnrootedScript script);
@ -147,10 +147,10 @@ bool compileScriptBegin(const char *filename, int lineno);
bool compileScriptEnd(const char *filename, int lineno);
/* About to make a call from JS into native code */
bool calloutBegin(JSContext *cx, JSFunction *fun);
bool calloutBegin(JSContext *cx, UnrootedFunction fun);
/* Native code called by JS has terminated */
bool calloutEnd(JSContext *cx, JSFunction *fun);
bool calloutEnd(JSContext *cx, UnrootedFunction fun);
/* Unimplemented */
bool acquireMemory(JSContext *cx, void *address, size_t nbytes);
@ -240,8 +240,8 @@ discardExecutableRegion(void *start, size_t size);
* marshalling required for these probe points is expensive enough that it
* shouldn't really matter.
*/
void DTraceEnterJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script);
void DTraceExitJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script);
void DTraceEnterJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script);
void DTraceExitJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script);
/*
* Internal: ETW-specific probe functions
@ -252,8 +252,8 @@ bool ETWCreateRuntime(JSRuntime *rt);
bool ETWDestroyRuntime(JSRuntime *rt);
bool ETWShutdown();
bool ETWCallTrackingActive();
bool ETWEnterJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script, int counter);
bool ETWExitJSFun(JSContext *cx, JSFunction *fun, UnrootedScript script, int counter);
bool ETWEnterJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script, int counter);
bool ETWExitJSFun(JSContext *cx, UnrootedFunction fun, UnrootedScript script, int counter);
bool ETWCreateObject(JSContext *cx, JSObject *obj);
bool ETWFinalizeObject(JSObject *obj);
bool ETWResizeObject(JSContext *cx, JSObject *obj, size_t oldSize, size_t newSize);
@ -261,8 +261,8 @@ bool ETWCreateString(JSContext *cx, JSString *string, size_t length);
bool ETWFinalizeString(JSString *string);
bool ETWCompileScriptBegin(const char *filename, int lineno);
bool ETWCompileScriptEnd(const char *filename, int lineno);
bool ETWCalloutBegin(JSContext *cx, JSFunction *fun);
bool ETWCalloutEnd(JSContext *cx, JSFunction *fun);
bool ETWCalloutBegin(JSContext *cx, UnrootedFunction fun);
bool ETWCalloutEnd(JSContext *cx, UnrootedFunction fun);
bool ETWAcquireMemory(JSContext *cx, void *address, size_t nbytes);
bool ETWReleaseMemory(JSContext *cx, void *address, size_t nbytes);
bool ETWGCStart();
@ -312,7 +312,7 @@ Probes::wantNativeAddressInfo(JSContext *cx)
}
inline bool
Probes::enterScript(JSContext *cx, UnrootedScript script, JSFunction *maybeFun,
Probes::enterScript(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun,
StackFrame *fp)
{
bool ok = true;
@ -339,7 +339,7 @@ Probes::enterScript(JSContext *cx, UnrootedScript script, JSFunction *maybeFun,
}
inline bool
Probes::exitScript(JSContext *cx, UnrootedScript script, JSFunction *maybeFun,
Probes::exitScript(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun,
StackFrame *fp)
{
bool ok = true;
@ -512,7 +512,7 @@ Probes::compileScriptEnd(const char *filename, int lineno)
}
inline bool
Probes::calloutBegin(JSContext *cx, JSFunction *fun)
Probes::calloutBegin(JSContext *cx, UnrootedFunction fun)
{
bool ok = true;
@ -525,7 +525,7 @@ Probes::calloutBegin(JSContext *cx, JSFunction *fun)
}
inline bool
Probes::calloutEnd(JSContext *cx, JSFunction *fun)
Probes::calloutEnd(JSContext *cx, UnrootedFunction fun)
{
bool ok = true;

View File

@ -304,6 +304,7 @@ Shape::replaceLastProperty(JSContext *cx, const StackBaseShape &base,
}
StackShape child(shape);
StackShape::AutoRooter childRoot(cx, &child);
{
UnrootedUnownedBaseShape nbase = BaseShape::getUnowned(cx, base);
if (!nbase)

View File

@ -3985,10 +3985,11 @@ PrintHelpString(JSContext *cx, jsval v)
static bool
PrintHelp(JSContext *cx, HandleObject obj)
{
jsval usage, help;
if (!JS_LookupProperty(cx, obj, "usage", &usage))
RootedValue usage(cx);
if (!JS_LookupProperty(cx, obj, "usage", usage.address()))
return false;
if (!JS_LookupProperty(cx, obj, "help", &help))
RootedValue help(cx);
if (!JS_LookupProperty(cx, obj, "help", help.address()))
return false;
if (JSVAL_IS_VOID(usage) || JSVAL_IS_VOID(help))

View File

@ -70,7 +70,7 @@ SPSProfiler::enable(bool enabled)
/* Lookup the string for the function/script, creating one if necessary */
const char*
SPSProfiler::profileString(JSContext *cx, JSScript *script, JSFunction *maybeFun)
SPSProfiler::profileString(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun)
{
JS_ASSERT(strings.initialized());
ProfileStringMap::AddPtr s = strings.lookupForAdd(script);
@ -87,7 +87,7 @@ SPSProfiler::profileString(JSContext *cx, JSScript *script, JSFunction *maybeFun
}
void
SPSProfiler::onScriptFinalized(JSScript *script)
SPSProfiler::onScriptFinalized(UnrootedScript script)
{
/*
* This function is called whenever a script is destroyed, regardless of
@ -106,7 +106,7 @@ SPSProfiler::onScriptFinalized(JSScript *script)
}
bool
SPSProfiler::enter(JSContext *cx, JSScript *script, JSFunction *maybeFun)
SPSProfiler::enter(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun)
{
const char *str = profileString(cx, script, maybeFun);
if (str == NULL)
@ -119,7 +119,7 @@ SPSProfiler::enter(JSContext *cx, JSScript *script, JSFunction *maybeFun)
}
void
SPSProfiler::exit(JSContext *cx, JSScript *script, JSFunction *maybeFun)
SPSProfiler::exit(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun)
{
pop();
@ -139,7 +139,7 @@ SPSProfiler::exit(JSContext *cx, JSScript *script, JSFunction *maybeFun)
}
void
SPSProfiler::push(const char *string, void *sp, JSScript *script, jsbytecode *pc)
SPSProfiler::push(const char *string, void *sp, UnrootedScript script, jsbytecode *pc)
{
/* these operations cannot be re-ordered, so volatile-ize operations */
volatile ProfileEntry *stack = stack_;
@ -171,7 +171,7 @@ SPSProfiler::pop()
* AddPtr held while invoking allocProfileString.
*/
const char*
SPSProfiler::allocProfileString(JSContext *cx, JSScript *script, JSFunction *maybeFun)
SPSProfiler::allocProfileString(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun)
{
DebugOnly<uint64_t> gcBefore = cx->runtime->gcNumber;
StringBuffer buf(cx);
@ -224,7 +224,7 @@ JMChunkInfo::JMChunkInfo(mjit::JSActiveFrame *frame,
{}
jsbytecode*
SPSProfiler::ipToPC(JSScript *script, size_t ip)
SPSProfiler::ipToPC(UnrootedScript script, size_t ip)
{
if (!jminfo.initialized())
return NULL;
@ -252,7 +252,7 @@ SPSProfiler::ipToPC(JSScript *script, size_t ip)
}
jsbytecode*
JMChunkInfo::convert(JSScript *script, size_t ip)
JMChunkInfo::convert(UnrootedScript script, size_t ip)
{
if (mainStart <= ip && ip < mainEnd) {
size_t offset = 0;
@ -350,7 +350,7 @@ SPSProfiler::registerScript(mjit::JSActiveFrame *frame,
bool
SPSProfiler::registerICCode(mjit::JITChunk *chunk,
JSScript *script, jsbytecode *pc,
UnrootedScript script, jsbytecode *pc,
void *base, size_t size)
{
JS_ASSERT(jminfo.initialized());

View File

@ -135,9 +135,9 @@ class SPSProfiler
bool slowAssertions;
bool enabled_;
const char *allocProfileString(JSContext *cx, JSScript *script,
JSFunction *function);
void push(const char *string, void *sp, JSScript *script, jsbytecode *pc);
const char *allocProfileString(JSContext *cx, UnrootedScript script,
UnrootedFunction function);
void push(const char *string, void *sp, UnrootedScript script, jsbytecode *pc);
void pop();
public:
@ -164,9 +164,9 @@ class SPSProfiler
* - exit: this function has ceased execution, and no further
* entries/exits will be made
*/
bool enter(JSContext *cx, JSScript *script, JSFunction *maybeFun);
void exit(JSContext *cx, JSScript *script, JSFunction *maybeFun);
void updatePC(JSScript *script, jsbytecode *pc) {
bool enter(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun);
void exit(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun);
void updatePC(UnrootedScript script, jsbytecode *pc) {
if (enabled() && *size_ - 1 < max_) {
JS_ASSERT(*size_ > 0);
JS_ASSERT(stack_[*size_ - 1].script() == script);
@ -199,7 +199,7 @@ class SPSProfiler
mjit::PCLengthEntry *pcLengths,
mjit::JITChunk *chunk);
jsbytecode *convert(JSScript *script, size_t ip);
jsbytecode *convert(UnrootedScript script, size_t ip);
};
struct JMScriptInfo
@ -232,9 +232,9 @@ class SPSProfiler
mjit::JSActiveFrame **inlineFrames);
void discardMJITCode(mjit::JITScript *jscr,
mjit::JITChunk *chunk, void* address);
bool registerICCode(mjit::JITChunk *chunk, JSScript *script, jsbytecode* pc,
bool registerICCode(mjit::JITChunk *chunk, UnrootedScript script, jsbytecode* pc,
void *start, size_t size);
jsbytecode *ipToPC(JSScript *script, size_t ip);
jsbytecode *ipToPC(UnrootedScript script, size_t ip);
private:
JMChunkInfo *registerScript(mjit::JSActiveFrame *frame,
@ -243,12 +243,12 @@ class SPSProfiler
void unregisterScript(UnrootedScript script, mjit::JITChunk *chunk);
public:
#else
jsbytecode *ipToPC(JSScript *script, size_t ip) { return NULL; }
jsbytecode *ipToPC(UnrootedScript script, size_t ip) { return NULL; }
#endif
void setProfilingStack(ProfileEntry *stack, uint32_t *size, uint32_t max);
const char *profileString(JSContext *cx, JSScript *script, JSFunction *maybeFun);
void onScriptFinalized(JSScript *script);
const char *profileString(JSContext *cx, UnrootedScript script, UnrootedFunction maybeFun);
void onScriptFinalized(UnrootedScript script);
/* meant to be used for testing, not recommended to call in normal code */
size_t stringsCount() { return strings.count(); }
@ -367,7 +367,7 @@ class SPSInstrumentation
* instrumentation should be emitted. This updates internal state to flag
* that further instrumentation should actually be emitted.
*/
void setPushed(JSScript *script) {
void setPushed(UnrootedScript script) {
if (!enabled())
return;
JS_ASSERT(frame->left == 0);
@ -378,7 +378,7 @@ class SPSInstrumentation
* Flags entry into a JS function for the first time. Before this is called,
* no instrumentation is emitted, but after this instrumentation is emitted.
*/
bool push(JSContext *cx, JSScript *script, Assembler &masm, Register scratch) {
bool push(JSContext *cx, UnrootedScript script, Assembler &masm, Register scratch) {
if (!enabled())
return true;
const char *string = profiler_->profileString(cx, script,
@ -395,7 +395,7 @@ class SPSInstrumentation
* sets the current PC to something non-null, however, so as soon as JIT
* code is reentered this updates the current pc to NULL.
*/
void pushManual(JSScript *script, Assembler &masm, Register scratch) {
void pushManual(UnrootedScript script, Assembler &masm, Register scratch) {
if (!enabled())
return;
masm.spsUpdatePCIdx(profiler_, ProfileEntry::NullPCIndex, scratch);

View File

@ -1743,7 +1743,7 @@ DebugScopes::onPopCall(StackFrame *fp, JSContext *cx)
if (!scopes)
return;
DebugScopeObject *debugScope = NULL;
Rooted<DebugScopeObject*> debugScope(cx, NULL);
if (fp->fun()->isHeavyweight()) {
/*