Skip to content

Commit

Permalink
Bug 1713010 - Spew information about shape allocation site. r=caroline
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhl committed Sep 30, 2021
1 parent fcc1979 commit 9a45882
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
44 changes: 38 additions & 6 deletions js/src/jit/CacheIRHealth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# include "gc/Zone.h"
# include "jit/CacheIRCompiler.h"
# include "jit/JitScript.h"
# include "vm/JSObject-inl.h"

using namespace js;
using namespace js::jit;
Expand Down Expand Up @@ -69,8 +70,28 @@ CacheIRHealth::Happiness CacheIRHealth::spewStubHealth(
return stubHappiness;
}

BaseScript* CacheIRHealth::maybeExtractBaseScript(JSContext* cx, Shape* shape) {
TaggedProto taggedProto = shape->base()->proto();
if (!taggedProto.isObject()) {
return nullptr;
}
Value cval;
if (!GetPropertyPure(cx, taggedProto.toObject(),
NameToId(cx->names().constructor), &cval)) {
return nullptr;
}
if (!IsFunctionObject(cval)) {
return nullptr;
}
JSFunction& jsfun = cval.toObject().as<JSFunction>();
if (!jsfun.hasBaseScript()) {
return nullptr;
}
return jsfun.baseScript();
}

void CacheIRHealth::spewShapeInformation(AutoStructuredSpewer& spew,
ICStub* stub) {
JSContext* cx, ICStub* stub) {
bool shapesStarted = false;
const CacheIRStubInfo* stubInfo = stub->toCacheIRStub()->stubInfo();
size_t offset = 0;
Expand Down Expand Up @@ -109,6 +130,16 @@ void CacheIRHealth::spewShapeInformation(AutoStructuredSpewer& spew,
}
}
spew->property("totalKeys", propMap->approximateEntryCount());
BaseScript* baseScript = maybeExtractBaseScript(cx, shape);
if (baseScript) {
spew->beginObjectProperty("shapeAllocSite");
{
spew->property("filename", baseScript->filename());
spew->property("line", baseScript->lineno());
spew->property("column", baseScript->column());
}
spew->endObject();
}
}
}
spew->endObject();
Expand All @@ -124,6 +155,7 @@ void CacheIRHealth::spewShapeInformation(AutoStructuredSpewer& spew,
}

bool CacheIRHealth::spewNonFallbackICInformation(AutoStructuredSpewer& spew,
JSContext* cx,
ICStub* firstStub,
Happiness* entryHappiness) {
const CacheIRStubInfo* stubInfo = firstStub->toCacheIRStub()->stubInfo();
Expand All @@ -142,7 +174,7 @@ bool CacheIRHealth::spewNonFallbackICInformation(AutoStructuredSpewer& spew,
*entryHappiness = stubHappiness;
}

spewShapeInformation(spew, stub);
spewShapeInformation(spew, cx, stub);

ICStub* nextStub = stub->toCacheIRStub()->next();
if (!nextStub->isFallback()) {
Expand Down Expand Up @@ -225,7 +257,7 @@ bool CacheIRHealth::spewNonFallbackICInformation(AutoStructuredSpewer& spew,
return true;
}

bool CacheIRHealth::spewICEntryHealth(AutoStructuredSpewer& spew,
bool CacheIRHealth::spewICEntryHealth(AutoStructuredSpewer& spew, JSContext* cx,
HandleScript script, ICEntry* entry,
ICFallbackStub* fallback, jsbytecode* pc,
JSOp op, Happiness* entryHappiness) {
Expand All @@ -239,7 +271,7 @@ bool CacheIRHealth::spewICEntryHealth(AutoStructuredSpewer& spew,

ICStub* firstStub = entry->firstStub();
if (!firstStub->isFallback()) {
if (!spewNonFallbackICInformation(spew, firstStub, entryHappiness)) {
if (!spewNonFallbackICInformation(spew, cx, firstStub, entryHappiness)) {
return false;
}
}
Expand Down Expand Up @@ -321,7 +353,7 @@ void CacheIRHealth::healthReportForIC(JSContext* cx, ICEntry* entry,
JSOp jsOp = JSOp(*op);

Happiness entryHappiness = Happy;
if (!spewICEntryHealth(spew, script, entry, fallback, op, jsOp,
if (!spewICEntryHealth(spew, cx, script, entry, fallback, op, jsOp,
&entryHappiness)) {
cx->recoverFromOutOfMemory();
return;
Expand Down Expand Up @@ -360,7 +392,7 @@ void CacheIRHealth::healthReportForScript(JSContext* cx, HandleScript script,

spew->beginObject();
Happiness entryHappiness = Happy;
if (!spewICEntryHealth(spew, script, &entry, fallback, pc, op,
if (!spewICEntryHealth(spew, cx, script, &entry, fallback, pc, op,
&entryHappiness)) {
cx->recoverFromOutOfMemory();
return;
Expand Down
17 changes: 11 additions & 6 deletions js/src/jit/CacheIRHealth.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ class CacheIRHealth {
Happiness spewStubHealth(AutoStructuredSpewer& spew, ICCacheIRStub* stub);
// If there is more than just a fallback stub in an IC Entry, then additional
// information about the IC entry.
bool spewNonFallbackICInformation(AutoStructuredSpewer& spew,
bool spewNonFallbackICInformation(AutoStructuredSpewer& spew, JSContext* cx,
ICStub* firstStub,
Happiness* entryHappiness);
// Health of all the stubs in an individual CacheIR Entry.
bool spewICEntryHealth(AutoStructuredSpewer& spew, HandleScript script,
ICEntry* entry, ICFallbackStub* fallback,
jsbytecode* pc, JSOp op, Happiness* entryHappiness);
// Spews information about shapes in an ICStub.
void spewShapeInformation(AutoStructuredSpewer& spew, ICStub* stub);
bool spewICEntryHealth(AutoStructuredSpewer& spew, JSContext* cx,
HandleScript script, ICEntry* entry,
ICFallbackStub* fallback, jsbytecode* pc, JSOp op,
Happiness* entryHappiness);
// Spews first and last property name for each shape checked by
// GuardShape in the stub.
void spewShapeInformation(AutoStructuredSpewer& spew, JSContext* cx,
ICStub* stub);
// Returns the BaseScript of a Shape if available.
BaseScript* maybeExtractBaseScript(JSContext* cx, Shape* shape);

public:
// Spews the final hit count for scripts where we care about its final hit
Expand Down

0 comments on commit 9a45882

Please sign in to comment.