Bug 1614622 part 2 - Remove trackedOpts shell function. r=djvj

Differential Revision: https://phabricator.services.mozilla.com/D62426

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan de Mooij 2020-02-12 10:54:51 +00:00
Родитель 867af8f744
Коммит 79d45d6fcb
1 изменённых файлов: 0 добавлений и 274 удалений

Просмотреть файл

@ -7490,274 +7490,6 @@ static void ShutdownBufferStreams() {
state->jobs.clearAndFree();
}
class SprintOptimizationTypeInfoOp
: public JS::ForEachTrackedOptimizationTypeInfoOp {
Sprinter* sp;
bool startedTypes_;
bool hadError_;
public:
explicit SprintOptimizationTypeInfoOp(Sprinter* sp)
: sp(sp), startedTypes_(false), hadError_(false) {}
void readType(const char* keyedBy, const char* name, const char* location,
const Maybe<unsigned>& lineno) override {
if (hadError_) {
return;
}
do {
if (!startedTypes_) {
startedTypes_ = true;
if (!sp->put("{\"typeset\": [")) {
break;
}
}
if (!sp->jsprintf("{\"keyedBy\":\"%s\"", keyedBy)) {
break;
}
if (name) {
if (!sp->jsprintf(",\"name\":\"%s\"", name)) {
break;
}
}
if (location) {
char buf[512];
PutEscapedString(buf, mozilla::ArrayLength(buf), location,
strlen(location), '"');
if (!sp->jsprintf(",\"location\":%s", buf)) {
break;
}
}
if (lineno.isSome()) {
if (!sp->jsprintf(",\"line\":%u", *lineno)) {
break;
}
}
if (!sp->put("},")) {
break;
}
return;
} while (false);
hadError_ = true;
}
void operator()(JS::TrackedTypeSite site, const char* mirType) override {
if (hadError_) {
return;
}
do {
if (startedTypes_) {
// Clear trailing ,
if ((*sp)[sp->getOffset() - 1] == ',') {
(*sp)[sp->getOffset() - 1] = ' ';
}
if (!sp->put("],")) {
break;
}
startedTypes_ = false;
} else {
if (!sp->put("{")) {
break;
}
}
if (!sp->jsprintf("\"site\":\"%s\",\"mirType\":\"%s\"},",
TrackedTypeSiteString(site), mirType)) {
break;
}
return;
} while (false);
hadError_ = true;
}
bool hadError() const { return hadError_; }
};
class SprintOptimizationAttemptsOp
: public JS::ForEachTrackedOptimizationAttemptOp {
Sprinter* sp;
bool hadError_;
public:
explicit SprintOptimizationAttemptsOp(Sprinter* sp)
: sp(sp), hadError_(false) {}
void operator()(JS::TrackedStrategy strategy,
JS::TrackedOutcome outcome) override {
if (hadError_) {
return;
}
hadError_ = !sp->jsprintf("{\"strategy\":\"%s\",\"outcome\":\"%s\"},",
TrackedStrategyString(strategy),
TrackedOutcomeString(outcome));
}
bool hadError() const { return hadError_; }
};
static bool ReflectTrackedOptimizations(JSContext* cx, unsigned argc,
Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
RootedObject callee(cx, &args.callee());
JSRuntime* rt = cx->runtime();
if (!rt->hasJitRuntime() ||
!rt->jitRuntime()->isOptimizationTrackingEnabled(cx->runtime())) {
JS_ReportErrorASCII(cx, "Optimization tracking is off.");
return false;
}
if (args.length() != 1) {
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
if (!args[0].isObject() || !args[0].toObject().is<JSFunction>()) {
ReportUsageErrorASCII(cx, callee, "Argument must be a function");
return false;
}
RootedFunction fun(cx, &args[0].toObject().as<JSFunction>());
if (!fun->hasScript() || !fun->nonLazyScript()->hasIonScript()) {
args.rval().setNull();
return true;
}
// Suppress GC for the unrooted JitcodeGlobalEntry below.
gc::AutoSuppressGC suppress(cx);
jit::JitcodeGlobalTable* table = rt->jitRuntime()->getJitcodeGlobalTable();
jit::IonScript* ion = fun->nonLazyScript()->ionScript();
jit::JitcodeGlobalEntry* entry = table->lookup(ion->method()->raw());
if (!entry) {
return false;
}
if (!entry->hasTrackedOptimizations()) {
JSObject* obj = JS_NewPlainObject(cx);
if (!obj) {
return false;
}
args.rval().setObject(*obj);
return true;
}
Sprinter sp(cx);
if (!sp.init()) {
return false;
}
const jit::IonTrackedOptimizationsRegionTable* regions =
entry->ionEntry().trackedOptimizationsRegionTable();
if (!sp.put("{\"regions\": [")) {
return false;
}
for (uint32_t i = 0; i < regions->numEntries(); i++) {
jit::IonTrackedOptimizationsRegion region = regions->entry(i);
jit::IonTrackedOptimizationsRegion::RangeIterator iter = region.ranges();
while (iter.more()) {
uint32_t startOffset, endOffset;
uint8_t index;
iter.readNext(&startOffset, &endOffset, &index);
JSScript* script;
jsbytecode* pc;
// Use endOffset, as startOffset may be associated with a
// previous, adjacent region ending exactly at startOffset. That
// is, suppose we have two regions [0, startOffset], [startOffset,
// endOffset]. Since we are not querying a return address, we want
// the second region and not the first.
uint8_t* addr = ion->method()->raw() + endOffset;
entry->youngestFrameLocationAtAddr(rt, addr, &script, &pc);
if (!sp.jsprintf("{\"location\":\"%s:%u\",\"offset\":%zu,\"index\":%u}%s",
script->filename(), script->lineno(),
script->pcToOffset(pc), index, iter.more() ? "," : "")) {
return false;
}
}
}
if (!sp.put("],")) {
return false;
}
if (!sp.put("\"opts\": [")) {
return false;
}
for (uint8_t i = 0; i < entry->ionEntry().numOptimizationAttempts(); i++) {
if (!sp.jsprintf("%s{\"typeinfo\":[", i == 0 ? "" : ",")) {
return false;
}
SprintOptimizationTypeInfoOp top(&sp);
jit::IonTrackedOptimizationsTypeInfo::ForEachOpAdapter adapter(top);
entry->trackedOptimizationTypeInfo(i).forEach(adapter,
entry->allTrackedTypes());
if (top.hadError()) {
return false;
}
// Clear the trailing ,
if (sp[sp.getOffset() - 1] == ',') {
sp[sp.getOffset() - 1] = ' ';
}
if (!sp.put("],\"attempts\":[")) {
return false;
}
SprintOptimizationAttemptsOp aop(&sp);
entry->trackedOptimizationAttempts(i).forEach(aop);
if (aop.hadError()) {
return false;
}
// Clear the trailing ,
if (sp[sp.getOffset() - 1] == ',') {
sp[sp.getOffset() - 1] = ' ';
}
if (!sp.put("]}")) {
return false;
}
}
if (!sp.put("]}")) {
return false;
}
if (sp.hadOutOfMemory()) {
return false;
}
RootedString str(cx, JS_NewStringCopyZ(cx, sp.string()));
if (!str) {
return false;
}
RootedValue jsonVal(cx);
if (!JS_ParseJSON(cx, str, &jsonVal)) {
return false;
}
args.rval().set(jsonVal);
return true;
}
static bool DumpScopeChain(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
RootedObject callee(cx, &args.callee());
@ -9282,12 +9014,6 @@ TestAssertRecoveredOnBailout,
" might be asked for the source code of compilations that |fun|\n"
" performed, and which, presumably, only |hook| knows how to find.\n"),
JS_FN_HELP("trackedOpts", ReflectTrackedOptimizations, 1, 0,
"trackedOpts(fun)",
" Returns an object describing the tracked optimizations of |fun|, if\n"
" any. If |fun| is not a scripted function or has not been compiled by\n"
" Ion, null is returned."),
JS_FN_HELP("crash", Crash, 0, 0,
"crash([message, [{disable_minidump:true}]])",
" Crashes the process with a MOZ_CRASH, optionally providing a message.\n"