зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1322560 - Refactor js::jit::JSONPrinter -> js::JSONPrinter, r=jonco
--HG-- rename : js/src/jit/JSONPrinter.cpp => js/src/vm/JSONPrinter.cpp rename : js/src/jit/JSONPrinter.h => js/src/vm/JSONPrinter.h extra : rebase_source : ecb1a949065cfb0cbb9f2cc058f762e4df71e09f extra : source : 9c91d92a0215701ed9388f149c8ac7c879510060
This commit is contained in:
Родитель
784adc799a
Коммит
27778f3982
|
@ -81,14 +81,14 @@ CacheIRSpewer::beginCache(LockGuard<Mutex>&, const IRGenerator& gen)
|
|||
JSONPrinter& j = json.ref();
|
||||
|
||||
j.beginObject();
|
||||
j.stringProperty("name", "%s", CacheKindNames[uint8_t(gen.cacheKind_)]);
|
||||
j.stringProperty("file", "%s", gen.script_->filename());
|
||||
j.integerProperty("mode", int(gen.mode_));
|
||||
j.property("name", "%s", CacheKindNames[uint8_t(gen.cacheKind_)]);
|
||||
j.property("file", "%s", gen.script_->filename());
|
||||
j.property("mode", int(gen.mode_));
|
||||
if (jsbytecode* pc = gen.pc_) {
|
||||
unsigned column;
|
||||
j.integerProperty("line", PCToLineNumber(gen.script_, pc, &column));
|
||||
j.integerProperty("column", column);
|
||||
j.stringProperty("pc", "%p", pc);
|
||||
j.property("line", PCToLineNumber(gen.script_, pc, &column));
|
||||
j.property("column", column);
|
||||
j.property("pc", "%p", pc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,12 +133,12 @@ CacheIRSpewer::valueProperty(LockGuard<Mutex>&, const char* name, const Value& v
|
|||
const char* type = InformalValueTypeName(v);
|
||||
if (v.isInt32())
|
||||
type = "int32";
|
||||
j.stringProperty("type", "%s", type);
|
||||
j.property("type", "%s", type);
|
||||
|
||||
if (v.isInt32()) {
|
||||
j.integerProperty("value", v.toInt32());
|
||||
j.property("value", v.toInt32());
|
||||
} else if (v.isDouble()) {
|
||||
j.doubleProperty("value", v.toDouble());
|
||||
j.property("value", v.toDouble());
|
||||
} else if (v.isString() || v.isSymbol()) {
|
||||
JSString* str = v.isString() ? v.toString() : v.toSymbol()->description();
|
||||
if (str && str->isLinear()) {
|
||||
|
@ -147,7 +147,7 @@ CacheIRSpewer::valueProperty(LockGuard<Mutex>&, const char* name, const Value& v
|
|||
j.endStringProperty();
|
||||
}
|
||||
} else if (v.isObject()) {
|
||||
j.stringProperty("value", "%p (shape: %p)", &v.toObject(),
|
||||
j.property("value", "%p (shape: %p)", &v.toObject(),
|
||||
v.toObject().maybeShape());
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ void
|
|||
CacheIRSpewer::attached(LockGuard<Mutex>&, const char* name)
|
||||
{
|
||||
MOZ_ASSERT(enabled());
|
||||
json.ref().stringProperty("attached", "%s", name);
|
||||
json.ref().property("attached", "%s", name);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
#include "mozilla/Maybe.h"
|
||||
|
||||
#include "jit/CacheIR.h"
|
||||
#include "jit/JSONPrinter.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "threading/LockGuard.h"
|
||||
#include "vm/JSONPrinter.h"
|
||||
#include "vm/MutexIDs.h"
|
||||
|
||||
namespace js {
|
||||
|
|
|
@ -26,9 +26,9 @@ JSONSpewer::beginFunction(JSScript* script)
|
|||
{
|
||||
beginObject();
|
||||
if (script)
|
||||
stringProperty("name", "%s:%" PRIuSIZE, script->filename(), script->lineno());
|
||||
property("name", "%s:%" PRIuSIZE, script->filename(), script->lineno());
|
||||
else
|
||||
stringProperty("name", "wasm compilation");
|
||||
property("name", "wasm compilation");
|
||||
beginListProperty("passes");
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ void
|
|||
JSONSpewer::beginPass(const char* pass)
|
||||
{
|
||||
beginObject();
|
||||
stringProperty("name", "%s", pass);
|
||||
property("name", "%s", pass);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -48,26 +48,26 @@ JSONSpewer::spewMResumePoint(MResumePoint* rp)
|
|||
beginObjectProperty("resumePoint");
|
||||
|
||||
if (rp->caller())
|
||||
integerProperty("caller", rp->caller()->block()->id());
|
||||
property("caller", rp->caller()->block()->id());
|
||||
|
||||
switch (rp->mode()) {
|
||||
case MResumePoint::ResumeAt:
|
||||
stringProperty("mode", "%s", "At");
|
||||
property("mode", "%s", "At");
|
||||
break;
|
||||
case MResumePoint::ResumeAfter:
|
||||
stringProperty("mode", "%s", "After");
|
||||
property("mode", "%s", "After");
|
||||
break;
|
||||
case MResumePoint::Outer:
|
||||
stringProperty("mode", "%s", "Outer");
|
||||
property("mode", "%s", "Outer");
|
||||
break;
|
||||
}
|
||||
|
||||
beginListProperty("operands");
|
||||
for (MResumePoint* iter = rp; iter; iter = iter->caller()) {
|
||||
for (int i = iter->numOperands() - 1; i >= 0; i--)
|
||||
integerValue(iter->getOperand(i)->id());
|
||||
value(iter->getOperand(i)->id());
|
||||
if (iter->caller())
|
||||
stringValue("|");
|
||||
value("|");
|
||||
}
|
||||
endList();
|
||||
|
||||
|
@ -79,33 +79,33 @@ JSONSpewer::spewMDef(MDefinition* def)
|
|||
{
|
||||
beginObject();
|
||||
|
||||
integerProperty("id", def->id());
|
||||
property("id", def->id());
|
||||
|
||||
property("opcode");
|
||||
propertyName("opcode");
|
||||
out_.printf("\"");
|
||||
def->printOpcode(out_);
|
||||
out_.printf("\"");
|
||||
|
||||
beginListProperty("attributes");
|
||||
#define OUTPUT_ATTRIBUTE(X) do{ if(def->is##X()) stringValue(#X); } while(0);
|
||||
#define OUTPUT_ATTRIBUTE(X) do{ if(def->is##X()) value(#X); } while(0);
|
||||
MIR_FLAG_LIST(OUTPUT_ATTRIBUTE);
|
||||
#undef OUTPUT_ATTRIBUTE
|
||||
endList();
|
||||
|
||||
beginListProperty("inputs");
|
||||
for (size_t i = 0, e = def->numOperands(); i < e; i++)
|
||||
integerValue(def->getOperand(i)->id());
|
||||
value(def->getOperand(i)->id());
|
||||
endList();
|
||||
|
||||
beginListProperty("uses");
|
||||
for (MUseDefIterator use(def); use; use++)
|
||||
integerValue(use.def()->id());
|
||||
value(use.def()->id());
|
||||
endList();
|
||||
|
||||
if (!def->isLowered()) {
|
||||
beginListProperty("memInputs");
|
||||
if (def->dependency())
|
||||
integerValue(def->dependency()->id());
|
||||
value(def->dependency()->id());
|
||||
endList();
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ JSONSpewer::spewMDef(MDefinition* def)
|
|||
out_.printf(" : %s%s", StringFromMIRType(def->type()), (isTruncated ? " (t)" : ""));
|
||||
endStringProperty();
|
||||
} else {
|
||||
stringProperty("type", "%s%s", StringFromMIRType(def->type()), (isTruncated ? " (t)" : ""));
|
||||
property("type", "%s%s", StringFromMIRType(def->type()), (isTruncated ? " (t)" : ""));
|
||||
}
|
||||
|
||||
if (def->isInstruction()) {
|
||||
|
@ -139,30 +139,30 @@ JSONSpewer::spewMIR(MIRGraph* mir)
|
|||
for (MBasicBlockIterator block(mir->begin()); block != mir->end(); block++) {
|
||||
beginObject();
|
||||
|
||||
integerProperty("number", block->id());
|
||||
property("number", block->id());
|
||||
if (block->getHitState() == MBasicBlock::HitState::Count)
|
||||
integerProperty("count", block->getHitCount());
|
||||
property("count", block->getHitCount());
|
||||
|
||||
beginListProperty("attributes");
|
||||
if (block->hasLastIns()) {
|
||||
if (block->isLoopBackedge())
|
||||
stringValue("backedge");
|
||||
value("backedge");
|
||||
if (block->isLoopHeader())
|
||||
stringValue("loopheader");
|
||||
value("loopheader");
|
||||
if (block->isSplitEdge())
|
||||
stringValue("splitedge");
|
||||
value("splitedge");
|
||||
}
|
||||
endList();
|
||||
|
||||
beginListProperty("predecessors");
|
||||
for (size_t i = 0; i < block->numPredecessors(); i++)
|
||||
integerValue(block->getPredecessor(i)->id());
|
||||
value(block->getPredecessor(i)->id());
|
||||
endList();
|
||||
|
||||
beginListProperty("successors");
|
||||
if (block->hasLastIns()) {
|
||||
for (size_t i = 0; i < block->numSuccessors(); i++)
|
||||
integerValue(block->getSuccessor(i)->id());
|
||||
value(block->getSuccessor(i)->id());
|
||||
}
|
||||
endList();
|
||||
|
||||
|
@ -187,16 +187,16 @@ JSONSpewer::spewLIns(LNode* ins)
|
|||
{
|
||||
beginObject();
|
||||
|
||||
integerProperty("id", ins->id());
|
||||
property("id", ins->id());
|
||||
|
||||
property("opcode");
|
||||
propertyName("opcode");
|
||||
out_.printf("\"");
|
||||
ins->dump(out_);
|
||||
out_.printf("\"");
|
||||
|
||||
beginListProperty("defs");
|
||||
for (size_t i = 0; i < ins->numDefs(); i++)
|
||||
integerValue(ins->getDef(i)->virtualRegister());
|
||||
value(ins->getDef(i)->virtualRegister());
|
||||
endList();
|
||||
|
||||
endObject();
|
||||
|
@ -214,7 +214,7 @@ JSONSpewer::spewLIR(MIRGraph* mir)
|
|||
continue;
|
||||
|
||||
beginObject();
|
||||
integerProperty("number", i->id());
|
||||
property("number", i->id());
|
||||
|
||||
beginListProperty("instructions");
|
||||
for (size_t p = 0; p < block->numPhis(); p++)
|
||||
|
@ -238,7 +238,7 @@ JSONSpewer::spewRanges(BacktrackingAllocator* regalloc)
|
|||
|
||||
for (size_t bno = 0; bno < regalloc->graph.numBlocks(); bno++) {
|
||||
beginObject();
|
||||
integerProperty("number", bno);
|
||||
property("number", bno);
|
||||
beginListProperty("vregs");
|
||||
|
||||
LBlock* lir = regalloc->graph.getBlock(bno);
|
||||
|
@ -248,16 +248,16 @@ JSONSpewer::spewRanges(BacktrackingAllocator* regalloc)
|
|||
VirtualRegister* vreg = ®alloc->vregs[id];
|
||||
|
||||
beginObject();
|
||||
integerProperty("vreg", id);
|
||||
property("vreg", id);
|
||||
beginListProperty("ranges");
|
||||
|
||||
for (LiveRange::RegisterLinkIterator iter = vreg->rangesBegin(); iter; iter++) {
|
||||
LiveRange* range = LiveRange::get(*iter);
|
||||
|
||||
beginObject();
|
||||
stringProperty("allocation", "%s", range->bundle()->allocation().toString().get());
|
||||
integerProperty("start", range->from().bits());
|
||||
integerProperty("end", range->to().bits());
|
||||
property("allocation", "%s", range->bundle()->allocation().toString().get());
|
||||
property("start", range->from().bits());
|
||||
property("end", range->to().bits());
|
||||
endObject();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jit/JSONPrinter.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "vm/JSONPrinter.h"
|
||||
|
||||
namespace js {
|
||||
namespace jit {
|
||||
|
|
|
@ -237,7 +237,6 @@ UNIFIED_SOURCES += [
|
|||
'jit/JitFrames.cpp',
|
||||
'jit/JitOptions.cpp',
|
||||
'jit/JitSpewer.cpp',
|
||||
'jit/JSONPrinter.cpp',
|
||||
'jit/JSONSpewer.cpp',
|
||||
'jit/LICM.cpp',
|
||||
'jit/Linker.cpp',
|
||||
|
@ -325,6 +324,7 @@ UNIFIED_SOURCES += [
|
|||
'vm/HelperThreads.cpp',
|
||||
'vm/Id.cpp',
|
||||
'vm/JSONParser.cpp',
|
||||
'vm/JSONPrinter.cpp',
|
||||
'vm/MemoryMetrics.cpp',
|
||||
'vm/NativeObject.cpp',
|
||||
'vm/ObjectGroup.cpp',
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "jit/JSONPrinter.h"
|
||||
#include "vm/JSONPrinter.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/FloatingPoint.h"
|
||||
|
@ -13,7 +13,6 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
using namespace js;
|
||||
using namespace js::jit;
|
||||
|
||||
void
|
||||
JSONPrinter::indent()
|
||||
|
@ -25,7 +24,7 @@ JSONPrinter::indent()
|
|||
}
|
||||
|
||||
void
|
||||
JSONPrinter::property(const char* name)
|
||||
JSONPrinter::propertyName(const char* name)
|
||||
{
|
||||
if (!first_)
|
||||
out_.printf(",");
|
||||
|
@ -49,7 +48,7 @@ JSONPrinter::beginObject()
|
|||
void
|
||||
JSONPrinter::beginObjectProperty(const char* name)
|
||||
{
|
||||
property(name);
|
||||
propertyName(name);
|
||||
out_.printf("{");
|
||||
indentLevel_++;
|
||||
first_ = true;
|
||||
|
@ -58,7 +57,7 @@ JSONPrinter::beginObjectProperty(const char* name)
|
|||
void
|
||||
JSONPrinter::beginListProperty(const char* name)
|
||||
{
|
||||
property(name);
|
||||
propertyName(name);
|
||||
out_.printf("[");
|
||||
first_ = true;
|
||||
}
|
||||
|
@ -66,7 +65,7 @@ JSONPrinter::beginListProperty(const char* name)
|
|||
void
|
||||
JSONPrinter::beginStringProperty(const char* name)
|
||||
{
|
||||
property(name);
|
||||
propertyName(name);
|
||||
out_.printf("\"");
|
||||
}
|
||||
|
||||
|
@ -77,7 +76,7 @@ JSONPrinter::endStringProperty()
|
|||
}
|
||||
|
||||
void
|
||||
JSONPrinter::stringProperty(const char* name, const char* format, ...)
|
||||
JSONPrinter::property(const char* name, const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
@ -90,7 +89,7 @@ JSONPrinter::stringProperty(const char* name, const char* format, ...)
|
|||
}
|
||||
|
||||
void
|
||||
JSONPrinter::stringValue(const char* format, ...)
|
||||
JSONPrinter::value(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
@ -106,25 +105,55 @@ JSONPrinter::stringValue(const char* format, ...)
|
|||
}
|
||||
|
||||
void
|
||||
JSONPrinter::integerProperty(const char* name, int value)
|
||||
JSONPrinter::property(const char* name, int32_t value)
|
||||
{
|
||||
property(name);
|
||||
out_.printf("%d", value);
|
||||
propertyName(name);
|
||||
out_.printf("%" PRId32, value);
|
||||
}
|
||||
|
||||
void
|
||||
JSONPrinter::integerValue(int value)
|
||||
JSONPrinter::value(int val)
|
||||
{
|
||||
if (!first_)
|
||||
out_.printf(",");
|
||||
out_.printf("%d", value);
|
||||
out_.printf("%d", val);
|
||||
first_ = false;
|
||||
}
|
||||
|
||||
void
|
||||
JSONPrinter::doubleProperty(const char* name, double value)
|
||||
JSONPrinter::property(const char* name, uint32_t value)
|
||||
{
|
||||
property(name);
|
||||
propertyName(name);
|
||||
out_.printf("%u", value);
|
||||
}
|
||||
|
||||
void
|
||||
JSONPrinter::property(const char* name, int64_t value)
|
||||
{
|
||||
propertyName(name);
|
||||
out_.printf("%" PRId64, value);
|
||||
}
|
||||
|
||||
void
|
||||
JSONPrinter::property(const char* name, uint64_t value)
|
||||
{
|
||||
propertyName(name);
|
||||
out_.printf("%" PRIu64, value);
|
||||
}
|
||||
|
||||
#ifdef XP_DARWIN
|
||||
void
|
||||
JSONPrinter::property(const char* name, size_t value)
|
||||
{
|
||||
propertyName(name);
|
||||
out_.printf("%" PRIuSIZE, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
JSONPrinter::property(const char* name, double value)
|
||||
{
|
||||
propertyName(name);
|
||||
if (mozilla::IsFinite(value))
|
||||
out_.printf("%f", value);
|
||||
else
|
|
@ -4,8 +4,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef jit_JSONPrinter_h
|
||||
#define jit_JSONPrinter_h
|
||||
#ifndef vm_JSONPrinter_h
|
||||
#define vm_JSONPrinter_h
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
|||
#include "vm/Printer.h"
|
||||
|
||||
namespace js {
|
||||
namespace jit {
|
||||
|
||||
class JSONPrinter
|
||||
{
|
||||
|
@ -31,22 +30,36 @@ class JSONPrinter
|
|||
out_(out)
|
||||
{ }
|
||||
|
||||
void property(const char* name);
|
||||
void beginObject();
|
||||
void beginObjectProperty(const char* name);
|
||||
void beginListProperty(const char* name);
|
||||
void stringValue(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3);
|
||||
void stringProperty(const char* name, const char* format, ...) MOZ_FORMAT_PRINTF(3, 4);
|
||||
|
||||
void value(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3);
|
||||
void value(int value);
|
||||
|
||||
void property(const char* name, const char* format, ...) MOZ_FORMAT_PRINTF(3, 4);
|
||||
void property(const char* name, int32_t value);
|
||||
void property(const char* name, uint32_t value);
|
||||
void property(const char* name, int64_t value);
|
||||
void property(const char* name, uint64_t value);
|
||||
#ifdef XP_DARWIN
|
||||
// On OSX, size_t is long unsigned, uint32_t is unsigned, and uint64_t is
|
||||
// long long unsigned. Everywhere else, size_t matches either uint32_t or
|
||||
// uint64_t.
|
||||
void property(const char* name, size_t value);
|
||||
#endif
|
||||
void property(const char* name, double value);
|
||||
|
||||
void beginStringProperty(const char* name);
|
||||
void endStringProperty();
|
||||
void integerValue(int value);
|
||||
void integerProperty(const char* name, int value);
|
||||
void doubleProperty(const char* name, double value);
|
||||
|
||||
void endObject();
|
||||
void endList();
|
||||
|
||||
protected:
|
||||
void propertyName(const char* name);
|
||||
};
|
||||
|
||||
} // namespace jit
|
||||
} // namespace js
|
||||
|
||||
#endif /* jit_JSONPrinter_h */
|
||||
#endif /* vm_JSONPrinter_h */
|
|
@ -549,18 +549,4 @@ LSprinter::put(const char* s, size_t len)
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
LSprinter::reportOutOfMemory()
|
||||
{
|
||||
if (hadOOM_)
|
||||
return;
|
||||
hadOOM_ = true;
|
||||
}
|
||||
|
||||
bool
|
||||
LSprinter::hadOutOfMemory() const
|
||||
{
|
||||
return hadOOM_;
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
|
|
@ -47,9 +47,7 @@ class GenericPrinter
|
|||
bool printf(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
|
||||
bool vprintf(const char* fmt, va_list ap);
|
||||
|
||||
// Report that a string operation failed to get the memory it requested. The
|
||||
// first call to this function calls JS_ReportOutOfMemory, and sets this
|
||||
// Sprinter's outOfMemory flag; subsequent calls do nothing.
|
||||
// Report that a string operation failed to get the memory it requested.
|
||||
virtual void reportOutOfMemory();
|
||||
|
||||
// Return true if this Sprinter ran out of memory.
|
||||
|
@ -195,14 +193,6 @@ class LSprinter final : public GenericPrinter
|
|||
// return true on success, false on failure.
|
||||
virtual bool put(const char* s, size_t len) override;
|
||||
using GenericPrinter::put; // pick up |inline bool put(const char* s);|
|
||||
|
||||
// Report that a string operation failed to get the memory it requested. The
|
||||
// first call to this function calls JS_ReportOutOfMemory, and sets this
|
||||
// Sprinter's outOfMemory flag; subsequent calls do nothing.
|
||||
virtual void reportOutOfMemory() override;
|
||||
|
||||
// Return true if this Sprinter ran out of memory.
|
||||
virtual bool hadOutOfMemory() const override;
|
||||
};
|
||||
|
||||
// Map escaped code to the letter/symbol escaped with a backslash.
|
||||
|
|
Загрузка…
Ссылка в новой задаче