Bug 1847469 - Part 13: Use column number types in PCToLineNumber. r=iain

Differential Revision: https://phabricator.services.mozilla.com/D185751
This commit is contained in:
Tooru Fujisawa 2023-08-16 17:31:39 +00:00
parent 81b7cf1fc7
commit feda566217
15 changed files with 81 additions and 58 deletions

View File

@ -13,6 +13,7 @@
# include "jit/BaselineIC.h"
# include "jit/CacheIRCompiler.h"
# include "jit/JitScript.h"
# include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
# include "vm/JSScript.h"
# include "vm/JSObject-inl.h"
@ -271,9 +272,9 @@ bool CacheIRHealth::spewICEntryHealth(AutoStructuredSpewer& spew, JSContext* cx,
// TODO: If a perf issue arises, look into improving the SrcNotes
// API call below.
unsigned column;
JS::LimitedColumnNumberZeroOrigin column;
spew->property("lineno", PCToLineNumber(script, pc, &column));
spew->property("column", column);
spew->property("column", column.zeroOriginValue());
ICStub* firstStub = entry->firstStub();
if (!firstStub->isFallback()) {

View File

@ -16,7 +16,8 @@
# include "jsapi.h"
# include "jsmath.h"
# include "js/ScalarType.h" // js::Scalar::Type
# include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
# include "js/ScalarType.h" // js::Scalar::Type
# include "util/GetPidProvider.h"
# include "util/Text.h"
# include "vm/JSFunction.h"
@ -340,9 +341,9 @@ void CacheIRSpewer::beginCache(const IRGenerator& gen) {
j.property("file", filename ? filename : "null");
j.property("mode", int(gen.mode_));
if (jsbytecode* pc = gen.pc_) {
unsigned column;
JS::LimitedColumnNumberZeroOrigin column;
j.property("line", PCToLineNumber(gen.script_, pc, &column));
j.property("column", column);
j.property("column", column.zeroOriginValue());
j.formatProperty("pc", "%p", pc);
}
}

View File

@ -52,6 +52,7 @@
#include "jit/SharedICRegisters.h"
#include "jit/VMFunctions.h"
#include "jit/WarpSnapshot.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/experimental/JitInfo.h" // JSJit{Getter,Setter}CallArgs, JSJitMethodCallArgsTraits, JSJitInfo
#include "js/friend/DOMProxy.h" // JS::ExpandoAndGeneration
#include "js/RegExpFlags.h" // JS::RegExpFlag
@ -7272,7 +7273,7 @@ bool CodeGenerator::generateBody() {
#ifdef JS_JITSPEW
const char* filename = nullptr;
size_t lineNumber = 0;
unsigned columnNumber = 0;
JS::LimitedColumnNumberZeroOrigin columnNumber;
if (current->mir()->info().script()) {
filename = current->mir()->info().script()->filename();
if (current->mir()->pc()) {
@ -7282,12 +7283,14 @@ bool CodeGenerator::generateBody() {
} else {
# ifdef DEBUG
lineNumber = current->mir()->lineno();
columnNumber = current->mir()->columnIndex();
columnNumber =
JS::LimitedColumnNumberZeroOrigin(current->mir()->columnIndex());
# endif
}
JitSpew(JitSpew_Codegen, "--------------------------------");
JitSpew(JitSpew_Codegen, "# block%zu %s:%zu:%u%s:", i,
filename ? filename : "?", lineNumber, columnNumber,
filename ? filename : "?", lineNumber,
columnNumber.zeroOriginValue(),
current->mir()->isLoopHeader() ? " (loop header)" : "");
#endif

View File

@ -19,6 +19,7 @@
#include "jit/JitSpewer.h"
#include "jit/ScriptFromCalleeToken.h"
#include "jit/TrialInlining.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "vm/BytecodeUtil.h"
#include "vm/Compartment.h"
#include "vm/FrameIter.h" // js::OnlyJSJitFrameIter
@ -596,14 +597,14 @@ void jit::JitSpewBaselineICStats(JSScript* script, const char* dumpReason) {
uint32_t pcOffset = fallback->pcOffset();
jsbytecode* pc = script->offsetToPC(pcOffset);
unsigned column;
JS::LimitedColumnNumberZeroOrigin column;
unsigned int line = PCToLineNumber(script, pc, &column);
spew->beginObject();
spew->property("op", CodeName(JSOp(*pc)));
spew->property("pc", pcOffset);
spew->property("line", line);
spew->property("column", column);
spew->property("column", column.zeroOriginValue());
spew->beginListProperty("counts");
ICStub* stub = entry.firstStub();

View File

@ -940,7 +940,7 @@ void IonPerfSpewer::saveJitCodeSourceInfo(JSScript* script, JitCode* code,
}
#endif
uint32_t lineno = 0;
uint32_t colno = 0;
JS::LimitedColumnNumberZeroOrigin colno;
for (OpcodeEntry& entry : opcodes_) {
jsbytecode* pc = entry.bytecodepc;
@ -955,15 +955,14 @@ void IonPerfSpewer::saveJitCodeSourceInfo(JSScript* script, JitCode* code,
CreateProfilerSourceEntry(profilerRecord, lock)) {
srcInfo->offset = entry.offset;
srcInfo->lineno = lineno;
srcInfo->colno = JS::LimitedColumnNumberZeroOrigin(colno);
srcInfo->colno = colno;
srcInfo->filename = JS_smprintf("%s", filename);
}
#ifdef JS_ION_PERF
if (perfProfiling) {
WriteJitDumpDebugEntry(uint64_t(code->raw()) + entry.offset, filename,
lineno, JS::LimitedColumnNumberZeroOrigin(colno),
lock);
lineno, colno, lock);
}
#endif
}

View File

@ -22,6 +22,7 @@
#include "jit/TrialInlining.h"
#include "jit/TypeData.h"
#include "jit/WarpBuilder.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "util/DifferentialTesting.h"
#include "vm/BuiltinObjectKind.h"
#include "vm/BytecodeIterator.h"
@ -730,12 +731,13 @@ AbortReasonOr<WarpScriptSnapshot*> WarpScriptOracle::createScriptSnapshot() {
}
static void LineNumberAndColumn(HandleScript script, BytecodeLocation loc,
unsigned* line, unsigned* column) {
unsigned* line,
JS::LimitedColumnNumberZeroOrigin* column) {
#ifdef DEBUG
*line = PCToLineNumber(script, loc.toRawBytecode(), column);
#else
*line = script->lineno();
*column = script->column().zeroOriginValue();
*column = script->column();
#endif
}
@ -773,7 +775,8 @@ AbortReasonOr<Ok> WarpScriptOracle::maybeInlineIC(WarpOpSnapshotList& snapshots,
fallbackStub->clearUsedByTranspiler();
if (firstStub == fallbackStub) {
[[maybe_unused]] unsigned line, column;
[[maybe_unused]] unsigned line;
[[maybe_unused]] JS::LimitedColumnNumberZeroOrigin column;
LineNumberAndColumn(script_, loc, &line, &column);
// No optimized stubs.
@ -781,7 +784,7 @@ AbortReasonOr<Ok> WarpScriptOracle::maybeInlineIC(WarpOpSnapshotList& snapshots,
"fallback stub (entered-count: %" PRIu32
") for JSOp::%s @ %s:%u:%u",
fallbackStub->enteredCount(), CodeName(loc.getOp()),
script_->filename(), line, column);
script_->filename(), line, column.zeroOriginValue());
// If the fallback stub was used but there's no optimized stub, use an IC.
if (fallbackStub->enteredCount() != 0) {
@ -800,11 +803,13 @@ AbortReasonOr<Ok> WarpScriptOracle::maybeInlineIC(WarpOpSnapshotList& snapshots,
// Don't transpile if this IC ever encountered a case where it had
// no stub to attach.
if (fallbackStub->state().hasFailures()) {
[[maybe_unused]] unsigned line, column;
[[maybe_unused]] unsigned line;
[[maybe_unused]] JS::LimitedColumnNumberZeroOrigin column;
LineNumberAndColumn(script_, loc, &line, &column);
JitSpew(JitSpew_WarpTranspiler, "Failed to attach for JSOp::%s @ %s:%u:%u",
CodeName(loc.getOp()), script_->filename(), line, column);
CodeName(loc.getOp()), script_->filename(), line,
column.zeroOriginValue());
return Ok();
}
@ -835,12 +840,14 @@ AbortReasonOr<Ok> WarpScriptOracle::maybeInlineIC(WarpOpSnapshotList& snapshots,
}
}
[[maybe_unused]] unsigned line, column;
[[maybe_unused]] unsigned line;
[[maybe_unused]] JS::LimitedColumnNumberZeroOrigin column;
LineNumberAndColumn(script_, loc, &line, &column);
JitSpew(JitSpew_WarpTranspiler,
"multiple active stubs for JSOp::%s @ %s:%u:%u",
CodeName(loc.getOp()), script_->filename(), line, column);
CodeName(loc.getOp()), script_->filename(), line,
column.zeroOriginValue());
return Ok();
}
@ -855,7 +862,8 @@ AbortReasonOr<Ok> WarpScriptOracle::maybeInlineIC(WarpOpSnapshotList& snapshots,
reader.skip(opInfo.argLength);
if (!opInfo.transpile) {
[[maybe_unused]] unsigned line, column;
[[maybe_unused]] unsigned line;
[[maybe_unused]] JS::LimitedColumnNumberZeroOrigin column;
LineNumberAndColumn(script_, loc, &line, &column);
MOZ_ASSERT(
@ -866,7 +874,7 @@ AbortReasonOr<Ok> WarpScriptOracle::maybeInlineIC(WarpOpSnapshotList& snapshots,
JitSpew(JitSpew_WarpTranspiler,
"unsupported CacheIR opcode %s for JSOp::%s @ %s:%u:%u",
CacheIROpNames[size_t(op)], CodeName(loc.getOp()),
script_->filename(), line, column);
script_->filename(), line, column.zeroOriginValue());
return Ok();
}

View File

@ -18,6 +18,7 @@
#include "frontend/FrontendContext.h" // FrontendContext
#include "gc/PublicIterators.h"
#include "gc/WeakMap.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/experimental/CodeCoverage.h"
#include "js/experimental/CTypes.h" // JS::AutoCTypesActivityCallback, JS::SetCTypesActivityCallback
#include "js/experimental/Intl.h" // JS::AddMoz{DateTimeFormat,DisplayNames}Constructor
@ -478,8 +479,9 @@ void js::SetPreserveWrapperCallbacks(
cx->runtime()->hasReleasedWrapperCallback = hasReleasedWrapper;
}
JS_PUBLIC_API unsigned JS_PCToLineNumber(JSScript* script, jsbytecode* pc,
unsigned* columnp) {
JS_PUBLIC_API unsigned JS_PCToLineNumber(
JSScript* script, jsbytecode* pc,
JS::LimitedColumnNumberZeroOrigin* columnp) {
return PCToLineNumber(script, pc, columnp);
}

View File

@ -11,6 +11,7 @@
#include "js/CallArgs.h"
#include "js/Class.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/GCAPI.h"
#include "js/HeapAPI.h"
#include "js/Object.h" // JS::GetClass
@ -55,9 +56,9 @@ extern JS_PUBLIC_API bool JS_NondeterministicGetWeakSetKeys(
JSContext* cx, JS::HandleObject obj, JS::MutableHandleObject ret);
// Raw JSScript* because this needs to be callable from a signal handler.
extern JS_PUBLIC_API unsigned JS_PCToLineNumber(JSScript* script,
jsbytecode* pc,
unsigned* columnp = nullptr);
extern JS_PUBLIC_API unsigned JS_PCToLineNumber(
JSScript* script, jsbytecode* pc,
JS::LimitedColumnNumberZeroOrigin* columnp = nullptr);
/**
* Determine whether the given object is backed by a DeadObjectProxy.

View File

@ -22,6 +22,7 @@
#include "gc/Tracer.h" // js::TraceChildren
#include "gc/WeakMap.h" // js::IterateHeapUnbarriered, js::WeakMapBase
#include "js/CallAndConstruct.h" // JS::IsCallable
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/GCAPI.h" // JS::GCReason
#include "js/GCVector.h" // JS::RootedVector
#include "js/HeapAPI.h" // JS::GCCellPtr, js::gc::IsInsideNursery
@ -262,7 +263,7 @@ static bool FormatFrame(JSContext* cx, const FrameIter& iter, Sprinter& sp,
JSAutoRealm ar(cx, envChain);
const char* filename = script->filename();
unsigned column = 0;
JS::LimitedColumnNumberZeroOrigin column;
unsigned lineno = PCToLineNumber(script, pc, &column);
Rooted<JSFunction*> fun(cx, iter.maybeCallee(cx));
Rooted<JSString*> funname(cx);
@ -363,7 +364,8 @@ static bool FormatFrame(JSContext* cx, const FrameIter& iter, Sprinter& sp,
// print filename, line number and column
if (!sp.printf("%s [\"%s\":%u:%u]\n", fun ? ")" : "",
filename ? filename : "<unknown>", lineno, column)) {
filename ? filename : "<unknown>", lineno,
column.zeroOriginValue())) {
return false;
}

View File

@ -27,6 +27,7 @@
#include "gc/PublicIterators.h"
#include "jit/IonScript.h" // IonBlockCounts
#include "js/CharacterEncoding.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/experimental/CodeCoverage.h"
#include "js/experimental/PCCountProfiling.h" // JS::{Start,Stop}PCCountProfiling, JS::PurgePCCounts, JS::GetPCCountScript{Count,Summary,Contents}
#include "js/friend/DumpFunctions.h" // js::DumpPC, js::DumpScript
@ -110,11 +111,13 @@ static bool DecompileArgumentFromStack(JSContext* cx, int formalIndex,
for (size_t i = 0; i < ionCounts->numBlocks(); i++) {
const jit::IonBlockCounts& block = ionCounts->block(i);
unsigned lineNumber = 0, columnNumber = 0;
unsigned lineNumber = 0;
JS::LimitedColumnNumberZeroOrigin columnNumber;
lineNumber = PCToLineNumber(script, script->offsetToPC(block.offset()),
&columnNumber);
if (!sp->jsprintf("BB #%" PRIu32 " [%05u,%u,%u]", block.id(),
block.offset(), lineNumber, columnNumber)) {
block.offset(), lineNumber,
columnNumber.zeroOriginValue())) {
return false;
}
if (block.description()) {

View File

@ -629,11 +629,10 @@ unsigned FrameIter::computeLine(
if (isWasm()) {
return wasmFrame().computeLine(column);
}
unsigned columnNumber;
JS::LimitedColumnNumberZeroOrigin columnNumber;
unsigned lineNumber = PCToLineNumber(script(), pc(), &columnNumber);
if (column) {
*column = JS::TaggedColumnNumberZeroOrigin(
JS::LimitedColumnNumberZeroOrigin(columnNumber));
*column = JS::TaggedColumnNumberZeroOrigin(columnNumber);
}
return lineNumber;
}

View File

@ -2689,11 +2689,12 @@ const js::SrcNote* js::GetSrcNote(JSContext* cx, JSScript* script,
return GetSrcNote(cx->caches().gsnCache, script, pc);
}
unsigned js::PCToLineNumber(unsigned startLine, unsigned startCol,
unsigned js::PCToLineNumber(unsigned startLine,
JS::LimitedColumnNumberZeroOrigin startCol,
SrcNote* notes, jsbytecode* code, jsbytecode* pc,
unsigned* columnp) {
JS::LimitedColumnNumberZeroOrigin* columnp) {
unsigned lineno = startLine;
unsigned column = startCol;
JS::LimitedColumnNumberZeroOrigin column = startCol;
/*
* Walk through source notes accumulating their deltas, keeping track of
@ -2712,14 +2713,14 @@ unsigned js::PCToLineNumber(unsigned startLine, unsigned startCol,
SrcNoteType type = sn->type();
if (type == SrcNoteType::SetLine) {
lineno = SrcNote::SetLine::getLine(sn, startLine);
column = 0;
column = JS::LimitedColumnNumberZeroOrigin::zero();
} else if (type == SrcNoteType::NewLine) {
lineno++;
column = 0;
column = JS::LimitedColumnNumberZeroOrigin::zero();
} else if (type == SrcNoteType::ColSpan) {
ptrdiff_t colspan = SrcNote::ColSpan::getSpan(sn);
MOZ_ASSERT(ptrdiff_t(column) + colspan >= 0);
column += colspan;
MOZ_ASSERT(ptrdiff_t(column.zeroOriginValue()) + colspan >= 0);
column += JS::ColumnNumberOffset(colspan);
}
}
@ -2731,14 +2732,14 @@ unsigned js::PCToLineNumber(unsigned startLine, unsigned startCol,
}
unsigned js::PCToLineNumber(JSScript* script, jsbytecode* pc,
unsigned* columnp) {
JS::LimitedColumnNumberZeroOrigin* columnp) {
/* Cope with InterpreterFrame.pc value prior to entering Interpret. */
if (!pc) {
return 0;
}
return PCToLineNumber(script->lineno(), script->column().zeroOriginValue(),
script->notes(), script->code(), pc, columnp);
return PCToLineNumber(script->lineno(), script->column(), script->notes(),
script->code(), pc, columnp);
}
jsbytecode* js::LineNumberToPC(JSScript* script, unsigned target) {

View File

@ -2233,12 +2233,14 @@ void maybeSpewScriptFinalWarmUpCount(JSScript* script);
namespace js {
extern unsigned PCToLineNumber(JSScript* script, jsbytecode* pc,
unsigned* columnp = nullptr);
extern unsigned PCToLineNumber(
JSScript* script, jsbytecode* pc,
JS::LimitedColumnNumberZeroOrigin* columnp = nullptr);
extern unsigned PCToLineNumber(unsigned startLine, unsigned startCol,
SrcNote* notes, jsbytecode* code, jsbytecode* pc,
unsigned* columnp = nullptr);
extern unsigned PCToLineNumber(
unsigned startLine, JS::LimitedColumnNumberZeroOrigin startCol,
SrcNote* notes, jsbytecode* code, jsbytecode* pc,
JS::LimitedColumnNumberZeroOrigin* columnp = nullptr);
/*
* This function returns the file and line number of the script currently

View File

@ -1875,14 +1875,13 @@ bool SavedStacks::getLocation(JSContext* cx, const FrameIter& iter,
}
uint32_t sourceId = script->scriptSource()->id();
uint32_t column;
JS::LimitedColumnNumberZeroOrigin column;
uint32_t line = PCToLineNumber(script, pc, &column);
PCKey key(script, pc);
LocationValue value(
source, sourceId, line,
JS::TaggedColumnNumberOneOrigin(JS::LimitedColumnNumberOneOrigin(
JS::LimitedColumnNumberZeroOrigin(column))));
LocationValue value(source, sourceId, line,
JS::TaggedColumnNumberOneOrigin(
JS::LimitedColumnNumberOneOrigin(column)));
if (!pcLocationMap.add(p, key, value)) {
ReportOutOfMemory(cx);
return false;

View File

@ -7,6 +7,7 @@
#include "ProfileBuffer.h"
#include "BaseProfiler.h"
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberZeroOrigin
#include "js/GCAPI.h"
#include "jsfriendapi.h"
#include "mozilla/MathAlgorithms.h"
@ -224,9 +225,9 @@ void ProfileBufferCollector::CollectProfilingStackFrame(
// a local variable in order -- to avoid rooting hazards.
if (aFrame.script()) {
if (aFrame.pc()) {
unsigned col = 0;
JS::LimitedColumnNumberZeroOrigin col;
line = Some(JS_PCToLineNumber(aFrame.script(), aFrame.pc(), &col));
column = Some(col);
column = Some(col.zeroOriginValue());
}
}