Bug 1031168 - Trace the source strings in SavedStacks::PCLocationMap. r=terrence

This commit is contained in:
Nick Fitzgerald 2014-07-02 19:10:44 -07:00
parent 21f4c1ac83
commit c2589946c7
5 changed files with 75 additions and 12 deletions

View File

@ -800,6 +800,7 @@ struct TypeObjectAddendum;
typedef PreBarriered<JSObject*> PreBarrieredObject;
typedef PreBarriered<JSScript*> PreBarrieredScript;
typedef PreBarriered<jit::JitCode*> PreBarrieredJitCode;
typedef PreBarriered<JSAtom*> PreBarrieredAtom;
typedef RelocatablePtr<JSObject*> RelocatablePtrObject;
typedef RelocatablePtr<JSScript*> RelocatablePtrScript;

View File

@ -0,0 +1,9 @@
loadFile("\
saveStack();\
gcPreserveCode = function() {};\
gc();\
saveStack() == 3\
");
function loadFile(lfVarx) {
evaluate(lfVarx);
}

View File

@ -556,8 +556,7 @@ JSCompartment::markCrossCompartmentWrappers(JSTracer *trc)
void
JSCompartment::trace(JSTracer *trc)
{
// At the moment, this is merely ceremonial, but any live-compartment-only tracing should go
// here.
savedStacks_.trace(trc);
}
void

View File

@ -12,6 +12,7 @@
#include "jsfriendapi.h"
#include "jsnum.h"
#include "gc/Marking.h"
#include "vm/GlobalObject.h"
#include "vm/StringBuffer.h"
@ -442,6 +443,19 @@ SavedStacks::sweep(JSRuntime *rt)
}
}
void
SavedStacks::trace(JSTracer *trc)
{
if (!pcLocationMap.initialized())
return;
// Mark each of the source strings in our pc to location cache.
for (PCLocationMap::Enum e(pcLocationMap); !e.empty(); e.popFront()) {
LocationValue &loc = e.front().value();
MarkString(trc, &loc.source, "SavedStacks::PCLocationMap's memoized script source name");
}
}
uint32_t
SavedStacks::count()
{
@ -486,14 +500,14 @@ SavedStacks::insertFrames(JSContext *cx, ScriptFrameIter &iter, MutableHandleSav
if (!insertFrames(cx, ++iter, &parentFrame))
return false;
LocationValue location;
AutoLocationValueRooter location(cx);
if (!getLocation(cx, script, pc, &location))
return false;
SavedFrame::AutoLookupRooter lookup(cx,
location.source,
location.line,
location.column,
location.get().source,
location.get().line,
location.get().column,
callee ? callee->displayAtom() : nullptr,
parentFrame,
compartment->principals);
@ -589,7 +603,7 @@ SavedStacks::sweepPCLocationMap()
bool
SavedStacks::getLocation(JSContext *cx, JSScript *script, jsbytecode *pc,
LocationValue *locationp)
MutableHandleLocationValue locationp)
{
PCKey key(script, pc);
PCLocationMap::AddPtr p = pcLocationMap.lookupForAdd(key);
@ -608,7 +622,7 @@ SavedStacks::getLocation(JSContext *cx, JSScript *script, jsbytecode *pc,
return false;
}
*locationp = p->value();
locationp.set(p->value());
return true;
}

View File

@ -106,6 +106,7 @@ class SavedStacks {
bool initialized() const { return frames.initialized(); }
bool saveCurrentStack(JSContext *cx, MutableHandleSavedFrame frame);
void sweep(JSRuntime *rt);
void trace(JSTracer *trc);
uint32_t count();
void clear();
@ -139,9 +140,47 @@ class SavedStacks {
column(column)
{ }
ReadBarrieredAtom source;
size_t line;
size_t column;
PreBarrieredAtom source;
size_t line;
size_t column;
};
class MOZ_STACK_CLASS AutoLocationValueRooter : public JS::CustomAutoRooter
{
public:
AutoLocationValueRooter(JSContext *cx)
: JS::CustomAutoRooter(cx),
value() {}
void set(LocationValue &loc) {
value = loc;
}
LocationValue &get() {
return value;
}
private:
virtual void trace(JSTracer *trc) {
if (value.source)
gc::MarkString(trc, &value.source, "SavedStacks::LocationValue::source");
}
SavedStacks::LocationValue value;
};
class MOZ_STACK_CLASS MutableHandleLocationValue
{
public:
inline MOZ_IMPLICIT MutableHandleLocationValue(AutoLocationValueRooter *location)
: location(location) {}
void set(LocationValue &loc) {
location->set(loc);
}
private:
AutoLocationValueRooter *location;
};
struct PCLocationHasher : public DefaultHasher<PCKey> {
@ -163,7 +202,8 @@ class SavedStacks {
PCLocationMap pcLocationMap;
void sweepPCLocationMap();
bool getLocation(JSContext *cx, JSScript *script, jsbytecode *pc, LocationValue *locationp);
bool getLocation(JSContext *cx, JSScript *script, jsbytecode *pc,
MutableHandleLocationValue locationp);
};
bool SavedStacksMetadataCallback(JSContext *cx, JSObject **pmetadata);