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 using EcmaOpcode = BytecodeInstruction::Opcode; 32 class ConstantPool; 33 class ECMAObject; 34 class GeneratorContext; 35 struct CallParams; 36 37 class InterpreterAssembly { 38 public: 39 enum ActualNumArgsOfCall : uint8_t { CALLARG0 = 0, CALLARG1, CALLARGS2, CALLARGS3 }; 40 static void InitStackFrame(JSThread *thread); 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(JSThread *thread, JSTaggedType *sp); 51 static JSTaggedValue GetThis(JSTaggedType *sp); 52 static JSTaggedValue GetConstantPool(JSThread *thread, JSTaggedType *sp); 53 static JSTaggedValue GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp); 54 static JSTaggedValue GetModule(JSThread *thread, JSTaggedType *sp); 55 static JSTaggedValue GetProfileTypeInfo(JSThread *thread, JSTaggedType *sp); 56 static uint32_t GetNumArgs(JSThread *thread, JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); 57 static JSTaggedType *GetAsmInterpreterFramePointer(AsmInterpretedFrame *state); 58 59 static bool AssemblyIsFastNewFrameEnter(JSThread *thread, JSFunction *ctor, JSHandle<Method> method); 60 static PUBLIC_API int64_t GetCallSize(EcmaOpcode opcode); 61 62 #ifndef EXCLUDE_C_INTERPRETER 63 #define DEF_HANDLER(name) \ 64 static void name(JSThread *thread, const uint8_t *pc, JSTaggedType *sp, \ 65 JSTaggedValue constpool, JSTaggedValue profileTypeInfo, \ 66 JSTaggedValue acc, int16_t hotnessCounter); 67 ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 68 ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_HANDLER) 69 #undef DEF_HANDLER 70 #endif 71 private: 72 static void InitStackFrameForSP(JSTaggedType *prevSp); 73 }; 74 75 #ifndef EXCLUDE_C_INTERPRETER 76 #define DEF_HANDLER(name) InterpreterAssembly::name, 77 static std::array<DispatchEntryPoint, BCStubEntries::BC_HANDLER_COUNT> asmDispatchTable { 78 ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 79 }; 80 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_DEPRECATED_STUBS> deprecatedDispatchTable { 81 ASM_INTERPRETER_DEPRECATED_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 82 }; 83 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_WIDE_STUBS> wideDispatchTable { 84 ASM_INTERPRETER_WIDE_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 85 }; 86 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_THROW_STUBS> throwDispatchTable { 87 ASM_INTERPRETER_THROW_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 88 }; 89 #undef DEF_HANDLER 90 #endif 91 92 } // namespace panda::ecmascript 93 #endif // ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 94