From b0d8a813f94cc298b9b484fa4438e7599b09e090 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 20 Dec 2018 04:50:45 +0100 Subject: [PATCH] - fix missing line number for the function throwing the exception and remove the duplicate call stack line --- src/scripting/vm/jit.cpp | 18 ++++++++++----- src/scripting/vm/jit_flow.cpp | 41 +++++++++++++++++++++-------------- src/scripting/vm/jitintern.h | 4 ++-- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/scripting/vm/jit.cpp b/src/scripting/vm/jit.cpp index 1e94e3adaf..1813d19caa 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/scripting/vm/jit.cpp @@ -156,6 +156,8 @@ asmjit::CCFunc *JitCompiler::Codegen() LineInfo[j] = info; } + std::stable_sort(LineInfo.begin(), LineInfo.end(), [](const JitLineInfo &a, const JitLineInfo &b) { return a.InstructionIndex < b.InstructionIndex; }); + return func; } @@ -444,17 +446,15 @@ void JitCompiler::EmitNullPointerThrow(int index, EVMAbortException reason) cc.je(label); } -void JitCompiler::ThrowException(VMScriptFunction *func, VMOP *line, int reason) +void JitCompiler::ThrowException(int reason) { - ThrowAbortException(func, line, (EVMAbortException)reason, nullptr); + ThrowAbortException((EVMAbortException)reason, nullptr); } void JitCompiler::EmitThrowException(EVMAbortException reason) { - auto call = CreateCall(&JitCompiler::ThrowException); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, asmjit::imm(reason)); + auto call = CreateCall(&JitCompiler::ThrowException); + call->setArg(0, asmjit::imm(reason)); } asmjit::Label JitCompiler::EmitThrowExceptionLabel(EVMAbortException reason) @@ -464,6 +464,12 @@ asmjit::Label JitCompiler::EmitThrowExceptionLabel(EVMAbortException reason) cc.bind(label); EmitThrowException(reason); cc.setCursor(cursor); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); + return label; } diff --git a/src/scripting/vm/jit_flow.cpp b/src/scripting/vm/jit_flow.cpp index 0ca8bf4372..96b7bcec0b 100644 --- a/src/scripting/vm/jit_flow.cpp +++ b/src/scripting/vm/jit_flow.cpp @@ -330,15 +330,18 @@ void JitCompiler::EmitBOUND() auto cursor = cc.getCursor(); auto label = cc.newLabel(); cc.bind(label); - auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, regD[A]); - call->setArg(3, asmjit::imm(BC)); + auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); + call->setArg(0, regD[A]); + call->setArg(1, asmjit::imm(BC)); cc.setCursor(cursor); cc.cmp(regD[A], (int)BC); cc.jae(label); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); } void JitCompiler::EmitBOUND_K() @@ -346,15 +349,18 @@ void JitCompiler::EmitBOUND_K() auto cursor = cc.getCursor(); auto label = cc.newLabel(); cc.bind(label); - auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, regD[A]); - call->setArg(3, asmjit::imm(konstd[BC])); + auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); + call->setArg(0, regD[A]); + call->setArg(1, asmjit::imm(konstd[BC])); cc.setCursor(cursor); cc.cmp(regD[A], (int)konstd[BC]); cc.jae(label); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); } void JitCompiler::EmitBOUND_R() @@ -362,18 +368,21 @@ void JitCompiler::EmitBOUND_R() auto cursor = cc.getCursor(); auto label = cc.newLabel(); cc.bind(label); - auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, regD[A]); - call->setArg(3, regD[B]); + auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); + call->setArg(0, regD[A]); + call->setArg(1, regD[B]); cc.setCursor(cursor); cc.cmp(regD[A], regD[B]); cc.jae(label); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); } -void JitCompiler::ThrowArrayOutOfBounds(VMScriptFunction *func, VMOP *line, int index, int size) +void JitCompiler::ThrowArrayOutOfBounds(int index, int size) { if (index >= size) { diff --git a/src/scripting/vm/jitintern.h b/src/scripting/vm/jitintern.h index deb0378f06..67659e6e07 100644 --- a/src/scripting/vm/jitintern.h +++ b/src/scripting/vm/jitintern.h @@ -219,8 +219,8 @@ private: void EmitThrowException(EVMAbortException reason); asmjit::Label EmitThrowExceptionLabel(EVMAbortException reason); - static void ThrowArrayOutOfBounds(VMScriptFunction *func, VMOP *line, int index, int size); - static void ThrowException(VMScriptFunction *func, VMOP *line, int reason); + static void ThrowArrayOutOfBounds(int index, int size); + static void ThrowException(int reason); asmjit::X86Gp CheckRegD(int r0, int r1); asmjit::X86Xmm CheckRegF(int r0, int r1);