diff --git a/ecmascript/frames.h b/ecmascript/frames.h index 02acf67b43caf8fcbd390a5532d63a6b018758ee..4aa9dacda9b31c1892aba922c7edbb4101d0d915 100644 --- a/ecmascript/frames.h +++ b/ecmascript/frames.h @@ -215,6 +215,8 @@ #ifndef ECMASCRIPT_FRAMES_H #define ECMASCRIPT_FRAMES_H +#include "ecmascript/js_tagged_value.h" + #ifdef PANDA_TARGET_AMD64 #define GET_CURRETN_FP(fp) asm("mov %%rbp, %0" : "=rm" (fp)) #define POINTER_CAST(fp, type) static_cast(static_cast(fp) @@ -233,17 +235,10 @@ enum class FrameType: uintptr_t { INTERPRETER_FRAME = 2, }; -template -auto as_integer(Enumeration const value) --> typename std::underlying_type::type -{ - return static_cast::type>(value); -} - class OptimizedFrameStateBase { public: - FrameType frameType; - uint64_t *prev; // for llvm :c-fp ; for interrupt: thread-fp for gc + uintptr_t frameType; + JSTaggedType *prev; // for llvm :c-fp ; for interrupt: thread-fp for gc static size_t GetFrameStateOffsetFromSp() { return MEMBER_OFFSET(OptimizedFrameStateBase, prev); @@ -252,13 +247,13 @@ public: class InterpretedFrameStateBase { public: - uint64_t *prev; // for llvm :c-fp ; for interrupt: thread-fp for gc - FrameType frameType; + JSTaggedType *prev; // for llvm :c-fp ; for interrupt: thread-fp for gc + uintptr_t frameType; }; class OptimizedEntryFrameState { public: - uint64_t *threadFp; // for gc + JSTaggedType *threadFp; // for gc OptimizedFrameStateBase base; static size_t GetFrameStateOffsetFromSp() { @@ -268,7 +263,7 @@ public: class FrameConst { public: - static constexpr size_t FRAME_TYPE_OFFSET = -sizeof(FrameType); + static constexpr size_t FRAME_TYPE_OFFSET = -sizeof(uintptr_t); }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_FRAMES_H \ No newline at end of file +#endif // ECMASCRIPT_FRAMES_H diff --git a/ecmascript/interpreter/frame_handler.cpp b/ecmascript/interpreter/frame_handler.cpp index 7ae466a6145382e6aed7841114cc524523fae16f..e66eb78fa2436dfcbded516ddbb2229fd508df2e 100644 --- a/ecmascript/interpreter/frame_handler.cpp +++ b/ecmascript/interpreter/frame_handler.cpp @@ -271,8 +271,7 @@ void FrameIterator::Iterate(const RootVisitor &v0, const RootRangeVisitor &v1) c { JSTaggedType *current = fp_; while (current) { - FrameType type = *(reinterpret_cast( - reinterpret_cast(current) + FrameConst::FRAME_TYPE_OFFSET)); + FrameType type = FrameHandler(current).GetFrameType(); if (type == FrameType::INTERPRETER_FRAME) { FrameState *state = reinterpret_cast(current) - 1; InterpretedFrameHandler(current).Iterate(v0, v1); diff --git a/ecmascript/interpreter/frame_handler.h b/ecmascript/interpreter/frame_handler.h index ed009166dbce895005b30cbc8b4c19c521d156f5..9e4298e755e6f86ba933ad14ecce6b3223560a1d 100644 --- a/ecmascript/interpreter/frame_handler.h +++ b/ecmascript/interpreter/frame_handler.h @@ -59,7 +59,7 @@ private: friend class InterpretedFrameHandler; friend class OptimizedFrameHandler; friend class OptimizedEntryFrameHandler; - JSTaggedType *sp_{nullptr}; + JSTaggedType *sp_ {nullptr}; }; class InterpretedFrameHandler : public FrameHandler { diff --git a/ecmascript/interpreter/interpreter-inl.h b/ecmascript/interpreter/interpreter-inl.h index 0bdc9bb29da9d1a225d39e51a85910a3e36a78e7..5664e6e2534283740e7b4068f8412a6f895bf5f1 100644 --- a/ecmascript/interpreter/interpreter-inl.h +++ b/ecmascript/interpreter/interpreter-inl.h @@ -245,7 +245,7 @@ JSTaggedValue EcmaInterpreter::ExecuteNative(JSThread *thread, const CallParams& FrameState *state = GET_FRAME(newSp); state->base.prev = sp; - state->base.frameType = FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); state->pc = nullptr; state->sp = newSp; state->method = methodToCall; @@ -279,7 +279,7 @@ JSTaggedValue EcmaInterpreter::Execute(JSThread *thread, const CallParams& param breakState->pc = nullptr; breakState->sp = nullptr; breakState->base.prev = originalPrevSp; - breakState->base.frameType = FrameType::INTERPRETER_FRAME; + breakState->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); breakState->numActualArgs = 0; JSTaggedType *prevSp = newSp; @@ -319,7 +319,7 @@ JSTaggedValue EcmaInterpreter::Execute(JSThread *thread, const CallParams& param state->constpool = constpool; state->profileTypeInfo = thisFunc->GetProfileTypeInfo(); state->base.prev = prevSp; - state->base.frameType = FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); state->numActualArgs = numActualArgs; JSTaggedValue env = thisFunc->GetLexicalEnv(); @@ -358,7 +358,7 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH breakState->pc = nullptr; breakState->sp = nullptr; breakState->base.prev = currentSp; - breakState->base.frameType = FrameType::INTERPRETER_FRAME; + breakState->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); breakState->numActualArgs = 0; // create new frame and resume sp and pc @@ -389,7 +389,7 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH state->acc = context->GetAcc(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) state->base.prev = breakSp; - state->base.frameType = FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); JSTaggedValue env = context->GetLexicalEnv(); state->env = env; // execute interpreter @@ -421,7 +421,7 @@ void EcmaInterpreter::ChangeGenContext(JSThread *thread, JSHandlepc = nullptr; breakState->sp = nullptr; breakState->base.prev = currentSp; - breakState->base.frameType = FrameType::INTERPRETER_FRAME; + breakState->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); // create new frame and resume sp and pc uint32_t nregs = context->GetNRegs().GetInt(); @@ -451,7 +451,7 @@ void EcmaInterpreter::ChangeGenContext(JSThread *thread, JSHandleacc = context->GetAcc(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) state->base.prev = breakSp; - state->base.frameType = FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); state->env = context->GetLexicalEnv(); thread->SetCurrentSPFrame(newSp); @@ -795,7 +795,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool FrameState *state = GET_FRAME(newSp); state->base.prev = sp; - state->base.frameType = FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); state->pc = nullptr; state->sp = newSp; state->method = methodToCall; @@ -879,7 +879,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool FrameState *state = GET_FRAME(newSp); state->base.prev = sp; - state->base.frameType = FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); state->pc = pc = JSMethod::Cast(methodToCall)->GetBytecodeArray(); state->sp = sp = newSp; state->method = methodToCall; @@ -3271,7 +3271,7 @@ void EcmaInterpreter::InitStackFrame(JSThread *thread) state->acc = JSTaggedValue::Hole(); state->constpool = nullptr; state->profileTypeInfo = JSTaggedValue::Undefined(); - state->base.frameType = FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(FrameType::INTERPRETER_FRAME); state->base.prev = nullptr; state->numActualArgs = 0; } diff --git a/ecmascript/interpreter/interpreter.h b/ecmascript/interpreter/interpreter.h index fcea0ac62cd1c7660387bb78be36e6b3f4c9249a..9de98319dca16a8b1ee6f517a4076e333d631647 100644 --- a/ecmascript/interpreter/interpreter.h +++ b/ecmascript/interpreter/interpreter.h @@ -23,10 +23,10 @@ #include "ecmascript/frames.h" namespace panda::ecmascript { +using TaggedType = coretypes::TaggedType; class ConstantPool; class ECMAObject; class GeneratorContext; -using TaggedType = coretypes::TaggedType; // align with 8 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) diff --git a/ecmascript/runtime_trampolines.cpp b/ecmascript/runtime_trampolines.cpp index ccd3c38a4d91883e1765c14c10176cb3873d2beb..2d3aef7dcba8b8c797f7a897516633caff690172 100644 --- a/ecmascript/runtime_trampolines.cpp +++ b/ecmascript/runtime_trampolines.cpp @@ -16,13 +16,13 @@ #include "runtime_trampolines.h" #include "ecmascript/accessor_data.h" #include "ecmascript/ecma_macros.h" +#include "ecmascript/frames.h" +#include "ecmascript/interpreter/interpreter-inl.h" #include "ecmascript/js_object.h" #include "ecmascript/js_proxy.h" -#include "ecmascript/frames.h" #include "ecmascript/layout_info.h" #include "ecmascript/message_string.h" #include "ecmascript/object_factory.h" -#include "ecmascript/interpreter/interpreter-inl.h" namespace panda::ecmascript { bool RuntimeTrampolines::AddElementInternal(uint64_t argThread, uint64_t argReceiver, uint32_t argIndex, diff --git a/ecmascript/runtime_trampolines.h b/ecmascript/runtime_trampolines.h index 8870a57a89c5061d660afb29c2e4ccb31317cc78..b68d4c00ece6230bc486ed8244513db41619a766 100644 --- a/ecmascript/runtime_trampolines.h +++ b/ecmascript/runtime_trampolines.h @@ -16,7 +16,9 @@ #ifndef ECMASCRIPT_RUNTIME_TRAMPOLINES_H #define ECMASCRIPT_RUNTIME_TRAMPOLINES_H #include "ecmascript/compiler/fast_stub_define.h" +#include "ecmascript/ecma_macros.h" #include "ecmascript/js_thread.h" +#include "ecmascript/interpreter/frame_handler.h" namespace panda::ecmascript { class RuntimeTrampolines { @@ -66,11 +68,15 @@ public: thread->SetLastIFrameSp(cursp); JSTaggedType *newSp = static_cast(static_cast(newFp)); thread_->SetCurrentSPFrame(newSp); + LOG_ECMA(INFO) << "Sp: " << newSp << " type:" << + static_cast(FrameHandler(newSp).GetFrameType()); } ~CallRuntimeTrampolinesScope() { JSTaggedType *oldSp = static_cast(static_cast(lastFp_)); thread_->SetCurrentSPFrame(oldSp); + LOG_ECMA(INFO) << "Sp: " << oldSp << " type:" << + static_cast(FrameHandler(oldSp).GetFrameType()); thread_->SetLastOptCallRuntimePc(lastOptCallRuntimePc_); } private: @@ -79,4 +85,4 @@ private: uintptr_t *lastOptCallRuntimePc_; }; } // namespace panda::ecmascript -#endif \ No newline at end of file +#endif diff --git a/ecmascript/tests/test_helper.h b/ecmascript/tests/test_helper.h index f65d77ef9a146d960cd20373e6ba00583783391f..645a40c6863e275a356be174766c9b52c73c4a52 100644 --- a/ecmascript/tests/test_helper.h +++ b/ecmascript/tests/test_helper.h @@ -65,7 +65,7 @@ public: JSTaggedType *newSp = sp - frameSize; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) FrameState *state = reinterpret_cast(newSp) - 1; - state->base.frameType = ecmascript::FrameType::INTERPRETER_FRAME; + state->base.frameType = static_cast(ecmascript::FrameType::INTERPRETER_FRAME); state->base.prev = sp; state->pc = nullptr; state->sp = newSp;