• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 JSTaggedValue Execute(EcmaRuntimeCallInfo *info);
41     static JSTaggedValue GeneratorReEnterInterpreter(JSThread *thread, JSHandle<GeneratorContext> context);
42     static inline size_t GetJumpSizeAfterCall(const uint8_t *prevPc);
43     static inline void MethodEntry(JSThread *thread, Method *method, JSTaggedValue env);
44 
45     static inline JSTaggedValue UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp);
46     static inline void InterpreterFrameCopyArgs(JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs,
47                                                 uint32_t numDeclaredArgs, bool haveExtraArgs = true);
48     static JSTaggedValue GetFunction(JSTaggedType *sp);
49     static JSTaggedValue GetNewTarget(JSTaggedType *sp);
50     static JSTaggedValue GetThis(JSTaggedType *sp);
51     static JSTaggedValue GetConstantPool(JSTaggedType *sp);
52     static JSTaggedValue GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp);
53     static JSTaggedValue GetModule(JSTaggedType *sp);
54     static JSTaggedValue GetProfileTypeInfo(JSTaggedType *sp);
55     static uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx);
56     static JSTaggedType *GetAsmInterpreterFramePointer(AsmInterpretedFrame *state);
57 
58     static bool AssemblyIsFastNewFrameEnter(JSFunction *ctor, JSHandle<Method> method);
59 
60 #ifndef EXCLUDE_C_INTERPRETER
61 #define DEF_HANDLER(name)                                                    \
62     static void name(JSThread *thread, const uint8_t *pc, JSTaggedType *sp,  \
63                      JSTaggedValue constpool, JSTaggedValue profileTypeInfo, \
64                      JSTaggedValue acc, int16_t hotnessCounter);
65     ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER)
66     ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_HANDLER)
67 #undef DEF_HANDLER
68 #endif
69 private:
70     static void InitStackFrameForSP(JSTaggedType *prevSp);
71 };
72 
73 #ifndef EXCLUDE_C_INTERPRETER
74 #define DEF_HANDLER(name) InterpreterAssembly::name,
75 static std::array<DispatchEntryPoint, BCStubEntries::BC_HANDLER_COUNT> asmDispatchTable {
76     ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER)
77 };
78 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_DEPRECATED_STUBS> deprecatedDispatchTable {
79     ASM_INTERPRETER_DEPRECATED_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER)
80 };
81 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_WIDE_STUBS> wideDispatchTable {
82     ASM_INTERPRETER_WIDE_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER)
83 };
84 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_THROW_STUBS> throwDispatchTable {
85     ASM_INTERPRETER_THROW_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER)
86 };
87 #undef DEF_HANDLER
88 #endif
89 
90 }  // namespace panda::ecmascript
91 #endif  // ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H
92