From b69db6d9d3dab1a478c903819bd5de9b8cdb2e7a Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Wed, 14 Jan 2015 20:13:02 +0100 Subject: [PATCH] Bug 1118826 part 2 - Remove more pc-mapping related code and workarounds we no longer need. r=shu --- js/src/jit/BaselineCompiler.cpp | 21 +------------ js/src/jit/BaselineJIT.cpp | 56 ++++++--------------------------- js/src/jit/BaselineJIT.h | 13 +++----- js/src/jit/JitcodeMap.cpp | 3 +- 4 files changed, 16 insertions(+), 77 deletions(-) diff --git a/js/src/jit/BaselineCompiler.cpp b/js/src/jit/BaselineCompiler.cpp index e011641716c4..db7e52b5281c 100644 --- a/js/src/jit/BaselineCompiler.cpp +++ b/js/src/jit/BaselineCompiler.cpp @@ -415,10 +415,6 @@ BaselineCompiler::emitPrologue() if (!emitSPSPush()) return false; - // Pad a nop so that the last non-op ICEntry we pushed does not get - // confused with the start address of the first op for PC mapping. - masm.nop(); - return true; } @@ -3003,17 +2999,6 @@ static const VMFunction PopBlockScopeInfo = FunctionInfo(jit::P bool BaselineCompiler::emit_JSOP_POPBLOCKSCOPE() { -#ifdef DEBUG - // The static block scope ends right before this op. Assert we generated - // JIT code for the previous op, so that pcForNativeOffset does not - // incorrectly return this pc instead of the previous one and confuse - // ScopeIter::settle. TODO: remove this when bug 1118826 lands. - PCMappingEntry &prevEntry = pcMappingEntries_[pcMappingEntries_.length() - 2]; - PCMappingEntry &curEntry = pcMappingEntries_[pcMappingEntries_.length() - 1]; - MOZ_ASSERT(curEntry.pcOffset == script->pcToOffset(pc)); - MOZ_ASSERT(curEntry.nativeOffset > prevEntry.nativeOffset); -#endif - // Call a stub to pop the block from the block chain. prepareVMCall(); @@ -3029,12 +3014,8 @@ static const VMFunction DebugLeaveBlockInfo = FunctionInfo(ji bool BaselineCompiler::emit_JSOP_DEBUGLEAVEBLOCK() { - if (!compileDebugInstrumentation_) { - // See the comment in emit_JSOP_POPBLOCKSCOPE. - if (*GetNextPc(pc) == JSOP_POPBLOCKSCOPE) - masm.nop(); + if (!compileDebugInstrumentation_) return true; - } prepareVMCall(); masm.loadBaselineFramePtr(BaselineFrameReg, R0.scratchReg()); diff --git a/js/src/jit/BaselineJIT.cpp b/js/src/jit/BaselineJIT.cpp index 9d1e00026fd7..bf52d8926a64 100644 --- a/js/src/jit/BaselineJIT.cpp +++ b/js/src/jit/BaselineJIT.cpp @@ -747,30 +747,13 @@ BaselineScript::nativeCodeForPC(JSScript *script, jsbytecode *pc, PCMappingSlotI } jsbytecode * -BaselineScript::pcForReturnOffset(JSScript *script, uint32_t nativeOffset) -{ - return pcForNativeOffset(script, nativeOffset, true); -} - -jsbytecode * -BaselineScript::pcForReturnAddress(JSScript *script, uint8_t *nativeAddress) +BaselineScript::approximatePcForNativeAddress(JSScript *script, uint8_t *nativeAddress) { MOZ_ASSERT(script->baselineScript() == this); MOZ_ASSERT(nativeAddress >= method_->raw()); MOZ_ASSERT(nativeAddress < method_->raw() + method_->instructionsSize()); - return pcForReturnOffset(script, uint32_t(nativeAddress - method_->raw())); -} -jsbytecode * -BaselineScript::pcForNativeOffset(JSScript *script, uint32_t nativeOffset) -{ - return pcForNativeOffset(script, nativeOffset, false); -} - -jsbytecode * -BaselineScript::pcForNativeOffset(JSScript *script, uint32_t nativeOffset, bool isReturn) -{ - MOZ_ASSERT(script->baselineScript() == this); + uint32_t nativeOffset = nativeAddress - method_->raw(); MOZ_ASSERT(nativeOffset < method_->instructionsSize()); // Look for the first PCMappingIndexEntry with native offset > the native offset we are @@ -786,21 +769,18 @@ BaselineScript::pcForNativeOffset(JSScript *script, uint32_t nativeOffset, bool i--; PCMappingIndexEntry &entry = pcMappingIndexEntry(i); - MOZ_ASSERT_IF(isReturn, nativeOffset >= entry.nativeOffset); CompactBufferReader reader(pcMappingReader(i)); jsbytecode *curPC = script->offsetToPC(entry.pcOffset); uint32_t curNativeOffset = entry.nativeOffset; MOZ_ASSERT(script->containsPC(curPC)); - MOZ_ASSERT_IF(isReturn, nativeOffset >= curNativeOffset); - // In the raw native-lookup case, the native code address can occur - // before the start of ops. Associate those with bytecode offset 0. - if (!isReturn && (curNativeOffset > nativeOffset)) + // The native code address can occur before the start of ops. + // Associate those with bytecode offset 0. + if (curNativeOffset > nativeOffset) return script->code(); - mozilla::DebugOnly lastNativeOffset = curNativeOffset; jsbytecode *lastPC = curPC; while (true) { // If the high bit is set, the native offset relative to the @@ -812,38 +792,20 @@ BaselineScript::pcForNativeOffset(JSScript *script, uint32_t nativeOffset, bool // Return the last PC that matched nativeOffset. Some bytecode // generate no native code (e.g., constant-pushing bytecode like // JSOP_INT8), and so their entries share the same nativeOffset as the - // next op that does generate code. Trying to find an entry for a - // return address is impossible for bytecodes that generate no code - // since calling this method requires VM reentry, so assert an exact - // match. - if (curNativeOffset > nativeOffset) { - MOZ_ASSERT_IF(isReturn, lastNativeOffset == nativeOffset); + // next op that does generate code. + if (curNativeOffset > nativeOffset) return lastPC; - } - // If this is a raw native lookup (not jsop return addresses), then - // the native address may lie in-between the last delta-entry in + // The native address may lie in-between the last delta-entry in // a pcMappingIndexEntry, and the next pcMappingIndexEntry. - if (!reader.more()) { - MOZ_ASSERT_IF(isReturn, curNativeOffset == nativeOffset); + if (!reader.more()) return curPC; - } - lastNativeOffset = curNativeOffset; lastPC = curPC; curPC += GetBytecodeLength(curPC); } } -jsbytecode * -BaselineScript::pcForNativeAddress(JSScript *script, uint8_t *nativeAddress) -{ - MOZ_ASSERT(script->baselineScript() == this); - MOZ_ASSERT(nativeAddress >= method_->raw()); - MOZ_ASSERT(nativeAddress < method_->raw() + method_->instructionsSize()); - return pcForNativeOffset(script, uint32_t(nativeAddress - method_->raw())); -} - void BaselineScript::toggleDebugTraps(JSScript *script, jsbytecode *pc) { diff --git a/js/src/jit/BaselineJIT.h b/js/src/jit/BaselineJIT.h index 101eb3d44080..714efa59d46f 100644 --- a/js/src/jit/BaselineJIT.h +++ b/js/src/jit/BaselineJIT.h @@ -371,20 +371,15 @@ struct BaselineScript uint8_t *nativeCodeForPC(JSScript *script, jsbytecode *pc, PCMappingSlotInfo *slotInfo = nullptr); - jsbytecode *pcForReturnOffset(JSScript *script, uint32_t nativeOffset); - jsbytecode *pcForReturnAddress(JSScript *script, uint8_t *nativeAddress); - - jsbytecode *pcForNativeAddress(JSScript *script, uint8_t *nativeAddress); - jsbytecode *pcForNativeOffset(JSScript *script, uint32_t nativeOffset); + // Return the bytecode offset for a given native code address. Be careful + // when using this method: we don't emit code for some bytecode ops, so + // the result may not be accurate. + jsbytecode *approximatePcForNativeAddress(JSScript *script, uint8_t *nativeAddress); bool addDependentAsmJSModule(JSContext *cx, DependentAsmJSModuleExit exit); void unlinkDependentAsmJSModules(FreeOp *fop); void removeDependentAsmJSModule(DependentAsmJSModuleExit exit); - private: - jsbytecode *pcForNativeOffset(JSScript *script, uint32_t nativeOffset, bool isReturn); - - public: // Toggle debug traps (used for breakpoints and step mode) in the script. // If |pc| is nullptr, toggle traps for all ops in the script. Else, only // toggle traps at |pc|. diff --git a/js/src/jit/JitcodeMap.cpp b/js/src/jit/JitcodeMap.cpp index 3f014631974f..5a5e0494d4c3 100644 --- a/js/src/jit/JitcodeMap.cpp +++ b/js/src/jit/JitcodeMap.cpp @@ -78,7 +78,8 @@ JitcodeGlobalEntry::BaselineEntry::callStackAtAddr(JSRuntime *rt, void *ptr, MOZ_ASSERT(containsPointer(ptr)); MOZ_ASSERT(script_->hasBaselineScript()); - jsbytecode *pc = script_->baselineScript()->pcForNativeAddress(script_, (uint8_t*) ptr); + uint8_t *addr = reinterpret_cast(ptr); + jsbytecode *pc = script_->baselineScript()->approximatePcForNativeAddress(script_, addr); if (!results.append(BytecodeLocation(script_, pc))) return false;