• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     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 GetModule(JSTaggedType *sp);
53     static JSTaggedValue GetProfileTypeInfo(JSTaggedType *sp);
54     static uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx);
55     static JSTaggedType *GetAsmInterpreterFramePointer(AsmInterpretedFrame *state);
56 
57     static bool AssemblyIsFastNewFrameEnter(JSFunction *ctor, JSHandle<Method> method);
58 
59 #ifndef EXCLUDE_C_INTERPRETER
60 #define DEF_HANDLER(name)                                                    \
61     static void name(JSThread *thread, const uint8_t *pc, JSTaggedType *sp,  \
62                      JSTaggedValue constpool, JSTaggedValue profileTypeInfo, \
63                      JSTaggedValue acc, int16_t hotnessCounter);
64     ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER)
65     ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_HANDLER)
66 #undef DEF_HANDLER
67 #endif
68 private:
69     static void InitStackFrameForSP(JSTaggedType *prevSp);
70 };
71 
72 #ifndef EXCLUDE_C_INTERPRETER
73 #define DEF_HANDLER(name) InterpreterAssembly::name,
74 static std::array<DispatchEntryPoint, BCStubEntries::BC_HANDLER_COUNT> asmDispatchTable {
75     ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER)
76 };
77 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_DEPRECATED_STUBS> deprecatedDispatchTable {
78     ASM_INTERPRETER_DEPRECATED_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER)
79 };
80 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_WIDE_STUBS> wideDispatchTable {
81     ASM_INTERPRETER_WIDE_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER)
82 };
83 static std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_THROW_STUBS> throwDispatchTable {
84     ASM_INTERPRETER_THROW_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER)
85 };
86 #undef DEF_HANDLER
87 #endif
88 
89 }  // namespace panda::ecmascript
90 #endif  // ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H
91