1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 17 #define ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 18 19 #include "ecmascript/base/config.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 #include "ecmascript/frames.h" 22 #include "ecmascript/method.h" 23 #include "ecmascript/js_tagged_value.h" 24 #include "ecmascript/js_function.h" 25 #include "ecmascript/js_handle.h" 26 #include "ecmascript/js_thread.h" 27 28 namespace panda::ecmascript { 29 using DispatchEntryPoint = 30 void (*)(JSThread *, const uint8_t *, JSTaggedType *, JSTaggedValue, JSTaggedValue, JSTaggedValue, int16_t); 31 class ConstantPool; 32 class ECMAObject; 33 class GeneratorContext; 34 struct CallParams; 35 36 class InterpreterAssembly { 37 public: 38 enum ActualNumArgsOfCall : uint8_t { CALLARG0 = 0, CALLARG1, CALLARGS2, CALLARGS3 }; 39 static void InitStackFrame(JSThread *thread); 40 static void InitStackFrame(EcmaContext *context); 41 static JSTaggedValue Execute(EcmaRuntimeCallInfo *info); 42 static JSTaggedValue GeneratorReEnterInterpreter(JSThread *thread, JSHandle<GeneratorContext> context); 43 static inline size_t GetJumpSizeAfterCall(const uint8_t *prevPc); 44 static inline void MethodEntry(JSThread *thread, Method *method, JSTaggedValue env); 45 46 static inline JSTaggedValue UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp); 47 static inline void InterpreterFrameCopyArgs(JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs, 48 uint32_t numDeclaredArgs, bool haveExtraArgs = true); 49 static JSTaggedValue GetFunction(JSTaggedType *sp); 50 static JSTaggedValue GetNewTarget(JSTaggedType *sp); 51 static JSTaggedValue GetThis(JSTaggedType *sp); 52 static JSTaggedValue GetConstantPool(JSTaggedType *sp); 53 static JSTaggedValue GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp); 54 static JSTaggedValue GetModule(JSTaggedType *sp); 55 static JSTaggedValue GetProfileTypeInfo(JSTaggedType *sp); 56 static uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); 57 static JSTaggedType *GetAsmInterpreterFramePointer(AsmInterpretedFrame *state); 58 59 static bool AssemblyIsFastNewFrameEnter(JSFunction *ctor, JSHandle<Method> method); 60 61 #ifndef EXCLUDE_C_INTERPRETER 62 #define DEF_HANDLER(name) \ 63 static void name(JSThread *thread, const uint8_t *pc, JSTaggedType *sp, \ 64 JSTaggedValue constpool, JSTaggedValue profileTypeInfo, \ 65 JSTaggedValue acc, int16_t hotnessCounter); 66 ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 67 ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_HANDLER) 68 #undef DEF_HANDLER 69 #endif 70 private: 71 static void InitStackFrameForSP(JSTaggedType *prevSp); 72 }; 73 74 #ifndef EXCLUDE_C_INTERPRETER 75 #define DEF_HANDLER(name) InterpreterAssembly::name, 76 static std::array<DispatchEntryPoint, BCStubEntries::BC_HANDLER_COUNT> asmDispatchTable { 77 ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 78 }; 79 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_DEPRECATED_STUBS> deprecatedDispatchTable { 80 ASM_INTERPRETER_DEPRECATED_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 81 }; 82 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_WIDE_STUBS> wideDispatchTable { 83 ASM_INTERPRETER_WIDE_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 84 }; 85 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_THROW_STUBS> throwDispatchTable { 86 ASM_INTERPRETER_THROW_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 87 }; 88 #undef DEF_HANDLER 89 #endif 90 91 } // namespace panda::ecmascript 92 #endif // ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 93