1 /* 2 * Copyright (c) 2021 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_handle.h" 25 #include "ecmascript/js_thread.h" 26 27 namespace panda::ecmascript { 28 using DispatchEntryPoint = 29 void (*)(JSThread *, const uint8_t *, JSTaggedType *, JSTaggedValue, JSTaggedValue, JSTaggedValue, int16_t); 30 class ConstantPool; 31 class ECMAObject; 32 class GeneratorContext; 33 struct CallParams; 34 35 class InterpreterAssembly { 36 public: 37 enum ActualNumArgsOfCall : uint8_t { CALLARG0 = 0, CALLARG1, CALLARGS2, CALLARGS3 }; 38 static void InitStackFrame(JSThread *thread); 39 static void InitStackFrame(EcmaContext *context); 40 static JSTaggedValue Execute(EcmaRuntimeCallInfo *info); 41 static JSTaggedValue GeneratorReEnterInterpreter(JSThread *thread, JSHandle<GeneratorContext> context); 42 static inline size_t GetJumpSizeAfterCall(const uint8_t *prevPc); 43 44 static inline JSTaggedValue UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp); 45 static inline void InterpreterFrameCopyArgs(JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs, 46 uint32_t numDeclaredArgs, bool haveExtraArgs = true); 47 static JSTaggedValue GetFunction(JSTaggedType *sp); 48 static JSTaggedValue GetNewTarget(JSTaggedType *sp); 49 static JSTaggedValue GetThis(JSTaggedType *sp); 50 static JSTaggedValue GetConstantPool(JSTaggedType *sp); 51 static JSTaggedValue GetProfileTypeInfo(JSTaggedType *sp); 52 static uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); 53 static JSTaggedType *GetAsmInterpreterFramePointer(AsmInterpretedFrame *state); 54 55 static bool AssemblyIsFastNewFrameEnter(JSFunction *ctor, JSHandle<Method> method); 56 57 #ifndef EXCLUDE_C_INTERPRETER 58 #define DEF_HANDLER(name) \ 59 static void name(JSThread *thread, const uint8_t *pc, JSTaggedType *sp, \ 60 JSTaggedValue constpool, JSTaggedValue profileTypeInfo, \ 61 JSTaggedValue acc, int16_t hotnessCounter); 62 ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 63 ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_HANDLER) 64 #undef DEF_HANDLER 65 #endif 66 private: 67 static void InitStackFrameForSP(JSTaggedType *prevSp); 68 }; 69 70 #ifndef EXCLUDE_C_INTERPRETER 71 #define DEF_HANDLER(name) InterpreterAssembly::name, 72 static std::array<DispatchEntryPoint, BCStubEntries::BC_HANDLER_COUNT> asmDispatchTable { 73 ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 74 }; 75 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_DEPRECATED_STUBS> deprecatedDispatchTable { 76 ASM_INTERPRETER_DEPRECATED_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 77 }; 78 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_WIDE_STUBS> wideDispatchTable { 79 ASM_INTERPRETER_WIDE_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 80 }; 81 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_THROW_STUBS> throwDispatchTable { 82 ASM_INTERPRETER_THROW_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 83 }; 84 #undef DEF_HANDLER 85 #endif 86 87 } // namespace panda::ecmascript 88 #endif // ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 89