• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_RUNTIME_STUBS_H
17 #define ECMASCRIPT_RUNTIME_STUBS_H
18 
19 #include "common_components/heap/allocator/region_desc.h"
20 #include "ecmascript/frames.h"
21 #include "ecmascript/ecma_macros.h"
22 #include "ecmascript/js_tagged_value.h"
23 #include "ecmascript/jspandafile/class_info_extractor.h"
24 #include "ecmascript/jspandafile/class_literal.h"
25 #include "ecmascript/method.h"
26 #include "ecmascript/mem/c_containers.h"
27 #include "ecmascript/mem/region.h"
28 #include "ecmascript/stubs/runtime_stub_list.h"
29 
30 namespace panda::ecmascript {
31 class EcmaVM;
32 class GlobalEnv;
33 class JSThread;
34 class JSFunction;
35 class ObjectFactory;
36 class JSBoundFunction;
37 class JSProxy;
38 class JSTypedArray;
39 class AOTLiteralInfo;
40 class GeneratorContext;
41 struct EcmaRuntimeCallInfo;
42 
43 using JSFunctionEntryType = JSTaggedValue (*)(uintptr_t glue, uint32_t argc, const JSTaggedType argV[],
44                                               uintptr_t prevFp, bool needPushArgv);
45 using FastCallAotEntryType = JSTaggedValue (*)(uintptr_t glue, uint32_t argc, const JSTaggedType argV[],
46                                               uintptr_t prevFp);
47 
48 PUBLIC_API extern "C" JSTaggedType LazyDeoptEntry();
49 class RuntimeStubs {
50 public:
51     static constexpr uint32_t TRACE_NUMBER = 100;
52     static constexpr uint32_t RT_STUB_FUNC_SIZE = 8;
53 
54     static void Initialize(JSThread *thread);
55 
56 #define DECLARE_RUNTIME_STUBS(name) \
57     static JSTaggedType name(uintptr_t argGlue, uint32_t argc, uintptr_t argv);
58     RUNTIME_STUB_WITH_GC_LIST(DECLARE_RUNTIME_STUBS)
RUNTIME_STUB_WITH_DFX(DECLARE_RUNTIME_STUBS)59     RUNTIME_STUB_WITH_DFX(DECLARE_RUNTIME_STUBS)
60     TEST_RUNTIME_STUB_GC_LIST(DECLARE_RUNTIME_STUBS)
61 #undef DECLARE_RUNTIME_STUBS
62 
63     inline static JSTaggedType GetTArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index)
64     {
65         ASSERT(index < argc);
66         return *(reinterpret_cast<JSTaggedType *>(argv) + (index));
67     }
68 
GetArg(uintptr_t argv,uint32_t argc,uint32_t index)69     inline static JSTaggedValue GetArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index)
70     {
71         ASSERT(index < argc);
72         return JSTaggedValue(*(reinterpret_cast<JSTaggedType *>(argv) + (index)));
73     }
74 
75     template<typename T>
GetHArg(uintptr_t argv,uint32_t argc,uint32_t index)76     inline static JSHandle<T> GetHArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index)
77     {
78         ASSERT(index < argc);
79         return JSHandle<T>(&(reinterpret_cast<JSTaggedType *>(argv)[index]));
80     }
81 
82     template<typename T>
GetPtrArg(uintptr_t argv,uint32_t argc,uint32_t index)83     inline static T *GetPtrArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index)
84     {
85         ASSERT(index < argc);
86         return reinterpret_cast<T*>(*(reinterpret_cast<JSTaggedType *>(argv) + (index)));
87     }
88 
89     static void Dump(JSTaggedType value);
90     static void DebugDump(JSTaggedType value);
91     static void DumpWithHint(uintptr_t hintStrAddress, JSTaggedType value);
92     static void DebugDumpWithHint(uintptr_t hintStrAddress, JSTaggedType value);
93     static void DebugPrint(int fmtMessageId, ...);
94     static void DebugPrintCustom(uintptr_t fmt, ...);
95     static void DebugPrintInstruction([[maybe_unused]] uintptr_t argGlue, const uint8_t *pc);
96     static void CollectingOpcodes([[maybe_unused]] uintptr_t argGlue, const uint8_t *pc);
97     static void DebugOsrEntry([[maybe_unused]] uintptr_t argGlue, const uint8_t *codeEntry);
98     static void Comment(uintptr_t argStr);
99     static void FatalPrint(int fmtMessageId, ...);
100     static void FatalPrintCustom(uintptr_t fmt, ...);
101     static void MarkingBarrier([[maybe_unused]] uintptr_t argGlue,
102         uintptr_t object, size_t offset, TaggedObject *value);
103     static void SharedGCMarkingBarrier(uintptr_t argGlue, uintptr_t object, size_t offset, TaggedObject *value);
104     static void CMCGCMarkingBarrier(uintptr_t argGlue, uintptr_t object, size_t offset, TaggedObject *value);
105     static JSTaggedType ReadBarrier(uintptr_t argGlue, uintptr_t addr);
106     static void CopyCallTarget(uintptr_t argGlue, uintptr_t callTarget);
107     static void CopyArgvArray(uintptr_t argGlue, uintptr_t argv, uint64_t argc);
108     static JSTaggedType GetActualArgvNoGC(uintptr_t argGlue);
109     static void InsertOldToNewRSet([[maybe_unused]] uintptr_t argGlue, uintptr_t object, size_t offset);
110     static void InsertLocalToShareRSet([[maybe_unused]] uintptr_t argGlue, uintptr_t object, size_t offset);
111     static void SetBitAtomic(GCBitset::GCBitsetWord *word, GCBitset::GCBitsetWord mask,
112                              GCBitset::GCBitsetWord oldValue);
113     static int32_t DoubleToInt(double x, size_t bits);
114     static int32_t SaturateTruncDoubleToInt32(double x);
115     static uint8_t LrInt(double x);
116     static double FloatMod(double x, double y);
117     static double FloatAcos(double x);
118     static double FloatAcosh(double x);
119     static double FloatAsin(double x);
120     static double FloatAsinh(double x);
121     static double FloatAtan(double x);
122     static double FloatAtan2(double y, double x);
123     static double FloatAtanh(double x);
124     static double FloatCos(double x);
125     static double FloatCosh(double x);
126     static double FloatSin(double x);
127     static double FloatSinh(double x);
128     static double FloatTan(double x);
129     static double FloatTanh(double x);
130     static double FloatTrunc(double x);
131     static double FloatFloor(double x);
132     static double FloatLog(double x);
133     static double FloatLog2(double x);
134     static double FloatLog10(double x);
135     static double FloatLog1p(double x);
136     static double FloatExp(double x);
137     static double FloatExpm1(double x);
138     static double FloatPow(double base, double exp);
139     static double FloatCbrt(double x);
140     static double FloatCeil(double x);
141     static double CallDateNow();
142     static void UpdateFieldType(uintptr_t argGlue, JSTaggedType hclass, uint64_t value);
143     static bool BigIntEquals(JSTaggedType left, JSTaggedType right);
144     static bool BigIntSameValueZero(JSTaggedType key, JSTaggedType other);
145     static JSTaggedValue JSHClassFindProtoTransitions(uintptr_t argGlue, JSHClass *cls, JSTaggedValue key,
146                                                       JSTaggedValue proto);
147     static void FinishObjSizeTracking(uintptr_t argGlue, JSHClass *cls);
148     static JSTaggedValue NumberHelperStringToDouble(uintptr_t argGlue, EcmaString *str);
149     static int IntLexicographicCompare(JSTaggedType x, JSTaggedType y);
150     static int DoubleLexicographicCompare(JSTaggedType x, JSTaggedType y);
151     static int FastArraySortString(uintptr_t argGlue, JSTaggedValue x, JSTaggedValue y);
152     static JSTaggedValue StringToNumber(uintptr_t argGlue, JSTaggedType numberString, int32_t radix);
153     static void ArrayTrim(uintptr_t argGlue, TaggedArray *array, int64_t newLength);
154     static double TimeClip(double time);
155     static double SetDateValues(double year, double month, double day);
156     static void StartCallTimer(uintptr_t argGlue, JSTaggedType func, bool isAot);
157     static void EndCallTimer(uintptr_t argGlue, JSTaggedType func);
158     static JSTaggedValue RuntimeArraySort(JSThread *thread, JSHandle<JSTaggedValue> thisHandle);
159 
160     static JSTaggedValue CallBoundFunction(EcmaRuntimeCallInfo *info);
161 
162     static int32_t StringGetStart(bool isUtf8, EcmaString *srcString, int32_t length, int32_t startIndex);
163     static int32_t StringGetEnd(bool isUtf8, EcmaString *srcString, int32_t start, int32_t length, int32_t startIndex);
164     static void CopyTypedArrayBuffer(uintptr_t argGlue, JSTypedArray *srcArray, JSTypedArray *targetArray,
165                                      int32_t srcStartPos, int32_t tarStartPos, int32_t count);
166     static inline uint32_t RuntimeGetBytecodePcOfstForBaseline(JSThread *thread, const JSHandle<JSFunction> &func,
167                                                                uintptr_t nativePc);
168     static void ReverseTypedArray(uintptr_t argGlue, JSTypedArray *typedArray);
169     static void SortTypedArray(uintptr_t argGlue, JSTypedArray *typedArray);
170     static inline uintptr_t RuntimeGetNativePcOfstForBaseline(JSThread *thread, const JSHandle<JSFunction> &func,
171                                                               uint64_t bytecodePos);
172     static void ObjectCopy(uintptr_t argGlue, JSTaggedType *dstObj,
173                             JSTaggedType *dst, JSTaggedType *src, uint32_t count);
174     static void CopyObjectPrimitive(uintptr_t argGlue, JSTaggedType *dstObj,
175                                     JSTaggedType *dst, JSTaggedType *src, uint32_t count);
176     static void FillObject(JSTaggedType *dst, JSTaggedType value, uint32_t count);
177     static void ReverseArray(uintptr_t argGlue, JSTaggedType *dst, uint32_t length);
178 
179     static JSTaggedValue FindPatchModule(uintptr_t argGlue, JSTaggedValue resolvedModule);
180     static JSTaggedValue UpdateSharedModule(uintptr_t argGlue, JSTaggedValue resolvedModule);
181     static void FatalPrintMisstakenResolvedBinding(int32_t index, JSTaggedValue curModule);
182     static void LoadNativeModuleFailed(JSTaggedValue curModule);
183     static void TraceLazyDeoptCommitSuccess(uintptr_t argGlue, JSHandle<JSTaggedValue> func);
184     static JSTaggedValue GetExternalModuleVar(uintptr_t argGlue, JSFunction *jsFunc, int32_t index);
185     static bool MarkRSetCardTable(BaseObject* obj);
186     static void MarkInBuffer(BaseObject* ref);
187     static void BatchMarkInBuffer(void* src, size_t count);
188 
189 private:
190     static void DumpToStreamWithHint(std::ostream &out, std::string_view prompt, JSTaggedValue value);
191     static inline void DumpInfoForMoreLdInfo(JSThread *thread, JSHandle<JSTaggedValue> &receiver, CString &msg);
192     static inline void DumpInfoForLdObjByValue(JSThread *thread, JSHandle<JSTaggedValue> &profile, JSTaggedValue slotId,
193                                                JSTaggedValue key, CString &msg);
194     static inline JSTaggedValue RuntimeInc(JSThread *thread, const JSHandle<JSTaggedValue> &value);
195     static inline JSTaggedValue RuntimeDec(JSThread *thread, const JSHandle<JSTaggedValue> &value);
196     static inline JSTaggedValue RuntimeExp(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent);
197     static inline JSTaggedValue RuntimeIsIn(JSThread *thread, const JSHandle<JSTaggedValue> &prop,
198                                             const JSHandle<JSTaggedValue> &obj);
199     static inline JSTaggedValue RuntimeInstanceof(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
200                                                   const JSHandle<JSTaggedValue> &target);
201     static inline JSTaggedValue RuntimeInstanceofByHandler(JSThread *thread, JSHandle<JSTaggedValue> target,
202                                                            JSHandle<JSTaggedValue> object,
203                                                            JSHandle<JSTaggedValue> instOfHandler);
204     static inline JSTaggedValue RuntimeCreateGeneratorObj(JSThread *thread, const JSHandle<JSTaggedValue> &genFunc);
205 
206     static inline JSTaggedValue RuntimeCreateAsyncGeneratorObj(JSThread *thread,
207                                                                const JSHandle<JSTaggedValue> &genFunc);
208 
209     static inline JSTaggedValue RuntimeAsyncGeneratorResolve(JSThread *thread, JSHandle<JSTaggedValue> asyncFuncObj,
210                                                              JSHandle<JSTaggedValue> value, JSTaggedValue flag);
211     static inline JSTaggedValue RuntimeAsyncGeneratorReject(JSThread *thread, JSHandle<JSTaggedValue> asyncFuncObj,
212                                                             JSHandle<JSTaggedValue> value);
213     static inline JSTaggedValue RuntimeGetTemplateObject(JSThread *thread, const JSHandle<JSTaggedValue> &literal);
214     static inline JSTaggedValue RuntimeGetNextPropName(JSThread *thread, const JSHandle<JSTaggedValue> &iter);
215     static inline JSTaggedValue RuntimeIterNext(JSThread *thread, const JSHandle<JSTaggedValue> &iter);
216     static inline JSTaggedValue RuntimeCloseIterator(JSThread *thread, const JSHandle<JSTaggedValue> &iter);
217     static inline JSTaggedValue RuntimeSuperCallSpread(JSThread *thread, const JSHandle<JSTaggedValue> &func,
218                                                        const JSHandle<JSTaggedValue> &newTarget,
219                                                        const JSHandle<JSTaggedValue> &array);
220     static inline JSTaggedValue RuntimeOptSuperCallSpread(JSThread *thread, const JSHandle<JSTaggedValue> &func,
221                                                           const JSHandle<JSTaggedValue> &newTarget,
222                                                           const JSHandle<JSTaggedValue> &taggedArray);
223     static inline JSTaggedValue RuntimeSuperCallForwardAllArgs(JSThread *thread, JSTaggedType *sp,
224                                                                const JSHandle<JSTaggedValue> &superFunc,
225                                                                const JSHandle<JSTaggedValue> &newTarget,
226                                                                uint32_t restNumArgs, uint32_t startIdx);
227     static inline JSTaggedValue RuntimeDelObjProp(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
228                                                   const JSHandle<JSTaggedValue> &prop);
229     static inline JSTaggedValue RuntimeNewObjApply(JSThread *thread, const JSHandle<JSTaggedValue> &func,
230                                                    const JSHandle<JSTaggedValue> &array);
231     static inline JSTaggedValue RuntimeCreateIterResultObj(JSThread *thread, const JSHandle<JSTaggedValue> &value,
232                                                            JSTaggedValue flag);
233     static inline JSTaggedValue RuntimeAsyncFunctionAwaitUncaught(JSThread *thread,
234                                                                   const JSHandle<JSTaggedValue> &asyncFuncObj,
235                                                                   const JSHandle<JSTaggedValue> &value);
236     static inline JSTaggedValue RuntimeAsyncFunctionResolveOrReject(JSThread *thread,
237                                                                     const JSHandle<JSTaggedValue> &asyncFuncObj,
238                                                                     const JSHandle<JSTaggedValue> &value,
239                                                                     bool is_resolve);
240     static inline JSTaggedValue RuntimeCopyDataProperties(JSThread *thread, const JSHandle<JSTaggedValue> &dst,
241                                                           const JSHandle<JSTaggedValue> &src);
242     static inline JSTaggedValue RuntimeStArraySpread(JSThread *thread, const JSHandle<JSTaggedValue> &dst,
243                                                      JSTaggedValue index, const JSHandle<JSTaggedValue> &src);
244     static inline JSTaggedValue RuntimeSetObjectWithProto(JSThread *thread, const JSHandle<JSTaggedValue> &proto,
245                                                           const JSHandle<JSObject> &obj);
246     static inline JSTaggedValue RuntimeGetIteratorNext(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
247                                                        const JSHandle<JSTaggedValue> &method);
248     static inline JSTaggedValue RuntimeLdObjByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
249                                                     const JSHandle<JSTaggedValue> &prop, bool callGetter,
250                                                     JSTaggedValue receiver);
251     static inline JSTaggedValue RuntimeStObjByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
252                                                     const JSHandle<JSTaggedValue> &prop,
253                                                     const JSHandle<JSTaggedValue> &value);
254     static inline JSTaggedValue RuntimeStOwnByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
255                                                     const JSHandle<JSTaggedValue> &key,
256                                                     const JSHandle<JSTaggedValue> &value);
257     static inline JSTaggedValue RuntimeLdSuperByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
258                                                       const JSHandle<JSTaggedValue> &key, JSTaggedValue thisFunc);
259     static inline JSTaggedValue RuntimeStSuperByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
260                                                       const JSHandle<JSTaggedValue> &key,
261                                                       const JSHandle<JSTaggedValue> &value, JSTaggedValue thisFunc);
262     static inline JSTaggedValue RuntimeLdObjByIndex(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t idx,
263                                                     bool callGetter, JSTaggedValue receiver);
264     static inline JSTaggedValue RuntimeStObjByIndex(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t idx,
265                                                     const JSHandle<JSTaggedValue> &value);
266     static inline JSTaggedValue RuntimeStOwnByIndex(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
267                                                     const JSHandle<JSTaggedValue> &idx,
268                                                     const JSHandle<JSTaggedValue> &value);
269     static inline JSTaggedValue RuntimeStGlobalRecord(JSThread *thread, const JSHandle<JSTaggedValue> &prop,
270                                                       const JSHandle<JSTaggedValue> &value, bool isConst);
271     static inline JSTaggedValue RuntimeNeg(JSThread *thread, const JSHandle<JSTaggedValue> &value);
272     static inline JSTaggedValue RuntimeNot(JSThread *thread, const JSHandle<JSTaggedValue> &value);
273     static inline JSTaggedValue RuntimeResolveClass(JSThread *thread, const JSHandle<JSFunction> &ctor,
274                                                     const JSHandle<TaggedArray> &literal,
275                                                     const JSHandle<JSTaggedValue> &base,
276                                                     const JSHandle<JSTaggedValue> &lexenv);
277     static inline JSTaggedValue RuntimeCloneClassFromTemplate(JSThread *thread, const JSHandle<JSFunction> &ctor,
278                                                               const JSHandle<JSTaggedValue> &base,
279                                                               const JSHandle<JSTaggedValue> &lexenv);
280     static inline JSTaggedValue RuntimeCreateClassWithBuffer(JSThread *thread,
281                                                              const JSHandle<JSTaggedValue> &base,
282                                                              const JSHandle<JSTaggedValue> &lexenv,
283                                                              const JSHandle<JSTaggedValue> &constpool,
284                                                              uint16_t methodId, uint16_t literalId,
285                                                              const JSHandle<JSTaggedValue> &module,
286                                                              const JSHandle<JSTaggedValue> &length);
287     static inline void SetProfileTypeInfoCellToFunction(JSThread *thread, const JSHandle<JSFunction> &jsFunc,
288                                                         const JSHandle<JSFunction> &definedFunc, uint16_t slotId);
289     static inline JSTaggedValue RuntimeCreateSharedClass(JSThread *thread,
290                                                          const JSHandle<JSTaggedValue> &base,
291                                                          const JSHandle<JSTaggedValue> &constpool,
292                                                          uint16_t methodId, uint16_t literalId, uint16_t length,
293                                                          const JSHandle<JSTaggedValue> &module);
294     static inline JSTaggedValue RuntimeLdSendableClass(JSThread *thread, const JSHandle<JSTaggedValue> &env,
295                                                        uint16_t level);
296     static inline JSTaggedValue RuntimeSetClassInheritanceRelationship(JSThread *thread,
297                                                                        const JSHandle<JSTaggedValue> &ctor,
298                                                                        const JSHandle<JSTaggedValue> &base,
299                                                                        ClassKind kind = ClassKind::NON_SENDABLE);
300     static inline JSTaggedValue RuntimeSetClassConstructorLength(JSThread *thread, JSTaggedValue ctor,
301                                                                  JSTaggedValue length);
302     static inline JSTaggedValue RuntimeNotifyInlineCache(JSThread *thread, const JSHandle<JSFunction> &function,
303                                                          uint32_t icSlotSize);
304     static inline JSTaggedValue RuntimeStOwnByValueWithNameSet(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
305                                                                const JSHandle<JSTaggedValue> &key,
306                                                                const JSHandle<JSTaggedValue> &value);
307     static inline JSTaggedValue RuntimeStOwnByName(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
308                                                    const JSHandle<JSTaggedValue> &prop,
309                                                    const JSHandle<JSTaggedValue> &value);
310     static inline JSTaggedValue RuntimeSuspendGenerator(JSThread *thread, const JSHandle<JSTaggedValue> &genObj,
311                                                         const JSHandle<JSTaggedValue> &value);
312     static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, int32_t index);
313     static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, int32_t index,
314                                                           JSTaggedValue jsFunc);
315     static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, JSTaggedValue localName);
316     static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, JSTaggedValue localName,
317                                                           JSTaggedValue jsFunc);
318     static inline void RuntimeStModuleVar(JSThread *thread, int32_t index, JSTaggedValue value);
319     static inline void RuntimeStModuleVar(JSThread *thread, int32_t index, JSTaggedValue value,
320                                           JSTaggedValue jsFunc);
321     static inline void RuntimeStModuleVar(JSThread *thread, JSTaggedValue key, JSTaggedValue value);
322     static inline void RuntimeStModuleVar(JSThread *thread, JSTaggedValue key, JSTaggedValue value,
323                                           JSTaggedValue jsFunc);
324     static inline JSTaggedValue RuntimeLdLocalModuleVar(JSThread *thread, int32_t index);
325     static inline JSTaggedValue RuntimeLdLocalModuleVarWithModule(JSThread *thread, int32_t index,
326         JSHandle<JSTaggedValue> moduleHdl);
327     static inline JSTaggedValue RuntimeLdLocalModuleVar(JSThread *thread, int32_t index,
328                                                         JSTaggedValue jsFunc);
329     static inline JSTaggedValue RuntimeLdExternalModuleVar(JSThread *thread, int32_t index);
330     static inline JSTaggedValue RuntimeLdExternalModuleVarWithModule(JSThread *thread, int32_t index,
331         JSHandle<JSTaggedValue> moduleHdl);
332     static inline JSTaggedValue RuntimeLdSendableExternalModuleVar(JSThread *thread, int32_t index,
333                                                                    JSTaggedValue jsFunc);
334     static inline JSTaggedValue RuntimeLdSendableLocalModuleVar(JSThread *thread, int32_t index, JSTaggedValue jsFunc);
335     static inline JSTaggedValue RuntimeLdExternalModuleVar(JSThread *thread, int32_t index,
336                                                            JSTaggedValue jsFunc);
337     static inline JSTaggedValue RuntimeLdLazySendableExternalModuleVar(JSThread *thread, int32_t index,
338                                                                        JSTaggedValue jsFunc);
339     static inline JSTaggedValue RuntimeLdLazyExternalModuleVar(JSThread *thread, int32_t index,
340                                                                JSTaggedValue jsFunc);
341     static inline JSTaggedValue RuntimeLdModuleVar(JSThread *thread, JSTaggedValue key, bool inner);
342     static inline JSTaggedValue RuntimeLdModuleVar(JSThread *thread, JSTaggedValue key, bool inner,
343                                                    JSTaggedValue jsFunc);
344     static inline JSTaggedValue RuntimeGetPropIterator(JSThread *thread, const JSHandle<JSTaggedValue> &value);
345     static inline JSTaggedValue RuntimeAsyncFunctionEnter(JSThread *thread);
346     static inline JSTaggedValue RuntimeGetIterator(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
347     static inline JSTaggedValue RuntimeGetAsyncIterator(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
348     static inline void RuntimeSetGeneratorState(JSThread *thread, const JSHandle<JSTaggedValue> &genObj,
349                                                         const int32_t index);
350     static inline void RuntimeThrow(JSThread *thread, JSTaggedValue value);
351     static inline void RuntimeThrowThrowNotExists(JSThread *thread);
352     static inline void RuntimeThrowPatternNonCoercible(JSThread *thread);
353     static inline void RuntimeThrowDeleteSuperProperty(JSThread *thread);
354     static inline void RuntimeThrowUndefinedIfHole(JSThread *thread, const JSHandle<EcmaString> &obj);
355     static inline void RuntimeThrowIfNotObject(JSThread *thread);
356     static inline void RuntimeThrowConstAssignment(JSThread *thread, const JSHandle<EcmaString> &value);
357     static inline JSTaggedValue RuntimeLdGlobalRecord(JSThread *thread, JSTaggedValue key);
358     static inline JSTaggedValue RuntimeTryLdGlobalByName(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
359                                                          const JSHandle<JSTaggedValue> &prop);
360     static inline JSTaggedValue RuntimeTryUpdateGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value);
361     static inline JSTaggedValue RuntimeThrowReferenceError(JSThread *thread, const JSHandle<JSTaggedValue> &prop,
362                                                            const char *desc);
363     static inline JSTaggedValue RuntimeLdGlobalVarFromProto(JSThread *thread, const JSHandle<JSTaggedValue> &globalObj,
364                                                             const JSHandle<JSTaggedValue> &prop);
365     static inline JSTaggedValue RuntimeStGlobalVar(JSThread *thread, const JSHandle<JSTaggedValue> &prop,
366                                                    const JSHandle<JSTaggedValue> &value);
367     static inline JSTaggedValue RuntimeToNumber(JSThread *thread, const JSHandle<JSTaggedValue> &value);
368     static inline JSTaggedValue RuntimeDynamicImport(JSThread *thread, const JSHandle<JSTaggedValue> &specifier,
369                                                      const JSHandle<JSTaggedValue> &func);
370     static inline JSTaggedValue RuntimeToNumeric(JSThread *thread, const JSHandle<JSTaggedValue> &value);
371     static inline JSTaggedValue RuntimeEq(JSThread *thread, const JSHandle<JSTaggedValue> &left,
372                                           const JSHandle<JSTaggedValue> &right);
373     static inline JSTaggedValue RuntimeLdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop,
374                                                    bool callGetter, JSTaggedValue receiver);
375     static inline JSTaggedValue RuntimeNotEq(JSThread *thread, const JSHandle<JSTaggedValue> &left,
376                                              const JSHandle<JSTaggedValue> &right);
377     static inline JSTaggedValue RuntimeLess(JSThread *thread, const JSHandle<JSTaggedValue> &left,
378                                             const JSHandle<JSTaggedValue> &right);
379     static inline JSTaggedValue RuntimeLessEq(JSThread *thread, const JSHandle<JSTaggedValue> &left,
380                                               const JSHandle<JSTaggedValue> &right);
381     static inline JSTaggedValue RuntimeGreater(JSThread *thread, const JSHandle<JSTaggedValue> &left,
382                                                const JSHandle<JSTaggedValue> &right);
383     static inline JSTaggedValue RuntimeGreaterEq(JSThread *thread, const JSHandle<JSTaggedValue> &left,
384                                                  const JSHandle<JSTaggedValue> &right);
385     static inline JSTaggedValue RuntimeAdd2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
386                                             const JSHandle<JSTaggedValue> &right);
387     static inline JSTaggedValue RuntimeShl2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
388                                             const JSHandle<JSTaggedValue> &right);
389     static inline JSTaggedValue RuntimeShr2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
390                                             const JSHandle<JSTaggedValue> &right);
391     static inline JSTaggedValue RuntimeSub2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
392                                             const JSHandle<JSTaggedValue> &right);
393     static inline JSTaggedValue RuntimeMul2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
394                                             const JSHandle<JSTaggedValue> &right);
395     static inline JSTaggedValue RuntimeDiv2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
396                                             const JSHandle<JSTaggedValue> &right);
397     static inline JSTaggedValue RuntimeMod2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
398                                             const JSHandle<JSTaggedValue> &right);
399     static inline JSTaggedValue RuntimeAshr2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
400                                              const JSHandle<JSTaggedValue> &right);
401     static inline JSTaggedValue RuntimeAnd2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
402                                             const JSHandle<JSTaggedValue> &right);
403     static inline JSTaggedValue RuntimeOr2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
404                                            const JSHandle<JSTaggedValue> &right);
405     static inline JSTaggedValue RuntimeXor2(JSThread *thread, const JSHandle<JSTaggedValue> &left,
406                                             const JSHandle<JSTaggedValue> &right);
407     static inline JSTaggedValue RuntimeStOwnByNameWithNameSet(JSThread *thread,
408                                                               const JSHandle<JSTaggedValue> &obj,
409                                                               const JSHandle<JSTaggedValue> &prop,
410                                                               const JSHandle<JSTaggedValue> &value);
411     static inline JSTaggedValue RuntimeStObjByName(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
412                                                    const JSHandle<JSTaggedValue> &prop,
413                                                    const JSHandle<JSTaggedValue> &value);
414     static inline JSTaggedValue RuntimeToJSTaggedValueWithInt32(JSThread *thread,
415                                                                 const JSHandle<JSTaggedValue> &value);
416     static inline JSTaggedValue RuntimeToJSTaggedValueWithUint32(JSThread *thread,
417                                                                  const JSHandle<JSTaggedValue> &value);
418     static inline JSTaggedValue RuntimeCreateEmptyObject(JSThread *thread, ObjectFactory *factory,
419                                                          JSHandle<GlobalEnv> globalEnv);
420     static inline JSTaggedValue RuntimeCreateEmptyArray(JSThread *thread, ObjectFactory *factory,
421                                                         JSHandle<GlobalEnv> globalEnv);
422     static inline JSTaggedValue RuntimeGetUnmapedArgs(JSThread *thread, JSTaggedType *sp, uint32_t actualNumArgs,
423                                                       uint32_t startIdx);
424     static inline JSTaggedValue RuntimeCopyRestArgs(JSThread *thread, JSTaggedType *sp, uint32_t restNumArgs,
425                                                     uint32_t startIdx);
426     static inline JSTaggedValue RuntimeCreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory,
427                                                              const JSHandle<JSTaggedValue> &literal);
428     static inline JSTaggedValue RuntimeCreateObjectWithBuffer(JSThread *thread, ObjectFactory *factory,
429                                                               const JSHandle<JSObject> &literal);
430     static inline JSTaggedValue RuntimeNewLexicalEnv(JSThread *thread, uint16_t numVars);
431     static inline JSTaggedValue RuntimeNewSendableEnv(JSThread *thread, uint16_t numVars);
432     static inline JSTaggedValue RuntimeNewObjRange(JSThread *thread, const JSHandle<JSTaggedValue> &func,
433                                                    const JSHandle<JSTaggedValue> &newTarget, uint16_t firstArgIdx,
434                                                    uint16_t length);
435     static inline JSTaggedValue RuntimeDefinefunc(JSThread *thread, const JSHandle<JSTaggedValue> &constpool,
436                                                   uint16_t methodId, const JSHandle<JSTaggedValue> &module,
437                                                   uint16_t length, const JSHandle<JSTaggedValue> &envHandle,
438                                                   const JSHandle<JSTaggedValue> &homeObject);
439     static inline void DefineFuncTryUseAOTHClass(JSThread* thread,
440                                                  const JSHandle<JSFunction>& func,
441                                                  const JSHandle<JSTaggedValue>& ihc,
442                                                  const JSHandle<AOTLiteralInfo>& aotLiteralInfo);
443     static inline JSTaggedValue RuntimeCreateRegExpWithLiteral(JSThread *thread, const JSHandle<JSTaggedValue> &pattern,
444                                                                uint8_t flags);
445     static inline JSTaggedValue RuntimeThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index,
446                                                                   JSTaggedValue thisValue);
447     static inline JSTaggedValue RuntimeCreateObjectHavingMethod(JSThread *thread, ObjectFactory *factory,
448                                                                 const JSHandle<JSObject> &literal,
449                                                                 const JSHandle<JSTaggedValue> &env);
450     static inline JSTaggedValue RuntimeCreateObjectWithExcludedKeys(JSThread *thread, uint16_t numKeys,
451                                                                     const JSHandle<JSTaggedValue> &objVal,
452                                                                     uint16_t firstArgRegIdx);
453     static inline JSTaggedValue RuntimeDefineMethod(JSThread *thread, const JSHandle<Method> &methodHandle,
454                                                     const JSHandle<JSTaggedValue> &homeObject, uint16_t length,
455                                                     const JSHandle<JSTaggedValue> &env,
456                                                     const JSHandle<JSTaggedValue> &module);
457     static inline JSTaggedValue RuntimeCallSpread(JSThread *thread, const JSHandle<JSTaggedValue> &func,
458                                                      const JSHandle<JSTaggedValue> &obj,
459                                                      const JSHandle<JSTaggedValue> &array);
460     static inline JSTaggedValue RuntimeDefineGetterSetterByValue(JSThread *thread, const JSHandle<JSObject> &obj,
461                                                                  const JSHandle<JSTaggedValue> &prop,
462                                                                  const JSHandle<JSTaggedValue> &getter,
463                                                                  const JSHandle<JSTaggedValue> &setter, bool flag,
464                                                                  const JSHandle<JSTaggedValue> &func,
465                                                                  int32_t pcOffset);
466     static inline JSTaggedValue RuntimeSuperCall(JSThread *thread, const JSHandle<JSTaggedValue> &func,
467                                                  const JSHandle<JSTaggedValue> &newTarget, uint16_t firstVRegIdx,
468                                                  uint16_t length);
469     static inline JSTaggedValue RuntimeOptSuperCall(JSThread *thread, const JSHandle<JSTaggedValue> &func,
470                                                     const JSHandle<JSTaggedValue> &newTarget,
471                                                     const JSHandle<TaggedArray> &argv,
472                                                     uint16_t length);
473     static inline JSTaggedValue RuntimeThrowTypeError(JSThread *thread, const char *message);
474     static inline JSTaggedValue RuntimeGetCallSpreadArgs(JSThread *thread, const JSHandle<JSTaggedValue> &array);
475     static inline JSTaggedValue RuntimeThrowReferenceError(JSThread *thread, JSTaggedValue prop, const char *desc);
476     static inline JSTaggedValue RuntimeThrowSyntaxError(JSThread *thread, const char *message);
477     static inline JSTaggedValue RuntimeLdBigInt(JSThread *thread, const JSHandle<JSTaggedValue> &numberBigInt);
478     static inline JSTaggedValue RuntimeCallBigIntAsIntN(JSThread *thread, JSTaggedValue bits, JSTaggedValue bigint);
479     static inline JSTaggedValue RuntimeCallBigIntAsUintN(JSThread *thread, JSTaggedValue bits, JSTaggedValue bigint);
480     static inline JSTaggedValue RuntimeNewLexicalEnvWithName(JSThread *thread, uint16_t numVars, uint16_t scopeId);
481     static inline JSTaggedValue RuntimeOptGetUnmapedArgs(JSThread *thread, uint32_t actualNumArgs);
482     static inline JSTaggedValue RuntimeGetUnmapedJSArgumentObj(JSThread *thread,
483                                                                const JSHandle<TaggedArray> &argumentsList);
484     static inline JSTaggedValue RuntimeOptNewLexicalEnvWithName(JSThread *thread, uint16_t numVars, uint16_t scopeId,
485                                                                 JSHandle<JSTaggedValue> &currentEnv,
486                                                                 JSHandle<JSTaggedValue> &func);
487     static inline JSTaggedValue RuntimeOptCopyRestArgs(JSThread *thread, uint32_t actualArgc, uint32_t restIndex);
488     static inline JSTaggedValue RuntimeOptSuspendGenerator(JSThread *thread, const JSHandle<JSTaggedValue> &genObj,
489                                                            const JSHandle<JSTaggedValue> &value);
490     static inline JSTaggedValue RuntimeOptAsyncGeneratorResolve(JSThread *thread, JSHandle<JSTaggedValue> asyncFuncObj,
491                                                                 JSHandle<JSTaggedValue> value, JSTaggedValue flag);
492     static inline JSTaggedValue CommonCreateObjectWithExcludedKeys(JSThread *thread,
493                                                                    const JSHandle<JSTaggedValue> &objVal,
494                                                                    uint32_t numExcludedKeys,
495                                                                    JSHandle<TaggedArray> excludedKeys);
496     static inline JSTaggedValue RuntimeOptCreateObjectWithExcludedKeys(JSThread *thread, uintptr_t argv, uint32_t argc);
497     static inline JSTaggedValue RuntimeOptNewObjRange(JSThread *thread, uintptr_t argv, uint32_t argc);
498     static inline JSTaggedValue RuntimeOptConstruct(JSThread *thread, JSHandle<JSTaggedValue> ctor,
499                                                     JSHandle<JSTaggedValue> newTarget, JSHandle<JSTaggedValue> preArgs,
500                                                     JSHandle<TaggedArray> args);
501     static inline JSTaggedValue RuntimeOptConstructProxy(JSThread *thread, JSHandle<JSProxy> ctor,
502                                                          JSHandle<JSTaggedValue> newTgt,
503                                                          JSHandle<JSTaggedValue> preArgs, JSHandle<TaggedArray> args);
504     static inline JSTaggedValue RuntimeOptConstructBoundFunction(JSThread *thread, JSHandle<JSBoundFunction> ctor,
505                                                                  JSHandle<JSTaggedValue> newTgt,
506                                                                  JSHandle<JSTaggedValue> preArgs,
507                                                                  JSHandle<TaggedArray> args);
508     static inline JSTaggedValue RuntimeOptConstructGeneric(JSThread *thread, JSHandle<JSFunction> ctor,
509                                                            JSHandle<JSTaggedValue> newTgt,
510                                                            JSHandle<JSTaggedValue> preArgs, JSHandle<TaggedArray> args);
511     static inline JSTaggedValue GetResultValue(JSThread *thread, bool isAotMethod, JSHandle<JSFunction> ctor,
512         CVector<JSTaggedType> &values, JSHandle<JSTaggedValue> newTgt, uint32_t &size, JSHandle<JSTaggedValue> obj);
513     static inline JSTaggedValue RuntimeOptGenerateScopeInfo(JSThread *thread, uint16_t scopeId, JSTaggedValue func);
514     static inline JSTaggedType *GetActualArgv(JSThread *thread);
515     static inline JSTaggedType *GetActualArgvFromStub(JSThread *thread);
516     static inline OptimizedJSFunctionFrame *GetOptimizedJSFunctionFrame(JSThread *thread);
517     static inline OptimizedJSFunctionFrame *GetOptimizedJSFunctionFrameNoGC(JSThread *thread);
518 
519     static JSTaggedValue NewObject(EcmaRuntimeCallInfo *info);
520     static void SaveFrameToContext(JSThread *thread, JSHandle<GeneratorContext> context);
521 
522     static inline JSTaggedValue RuntimeLdPatchVar(JSThread *thread, uint32_t index);
523     static inline JSTaggedValue RuntimeStPatchVar(JSThread *thread, uint32_t index,
524                                                   const JSHandle<JSTaggedValue> &value);
525     static inline JSTaggedValue RuntimeNotifyConcurrentResult(JSThread *thread, JSTaggedValue result,
526         JSTaggedValue hint);
527     static inline JSTaggedValue RuntimeDefineField(JSThread *thread, JSTaggedValue obj,
528                                                    JSTaggedValue propKey, JSTaggedValue value);
529     static inline JSTaggedValue RuntimeCreatePrivateProperty(JSThread *thread, JSTaggedValue constpool,
530         uint32_t count, JSTaggedValue lexicalEnv, uint32_t literalId, JSTaggedValue module);
531     static inline JSTaggedValue RuntimeDefinePrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
532         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value);
533     static inline JSTaggedValue RuntimeLdPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
534         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj);
535     static inline JSTaggedValue RuntimeStPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
536         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value);
537     static inline JSTaggedValue RuntimeTestIn(JSThread *thread, JSTaggedValue lexicalEnv,
538         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj);
539     static inline JSTaggedValue RuntimeUpdateAOTHClass(JSThread *thread, const JSHandle<JSHClass> &oldhclass,
540         const JSHandle<JSHClass> &newhclass, JSTaggedValue key);
541     static inline JSTaggedValue RuntimeNotifyDebuggerStatement(JSThread *thread);
542     static inline bool CheckElementsNumber(const JSThread *thread, JSHandle<TaggedArray> elements, uint32_t len);
543     static inline JSHandle<JSTaggedValue> GetOrCreateNumberString(JSThread *thread,
544         JSHandle<JSTaggedValue> presentValue, std::map<uint64_t, JSHandle<JSTaggedValue>> &cachedString);
545     static inline JSTaggedValue TryCopyCOWArray(JSThread *thread, JSHandle<JSArray> holderHandler, bool &isCOWArray);
546     static inline JSTaggedValue ArrayNumberSort(JSThread *thread, JSHandle<JSObject> thisObj, uint32_t len);
547     static inline bool ShouldUseAOTHClass(const JSHandle<JSTaggedValue> &ihc,
548                                           const JSHandle<JSTaggedValue> &chc,
549                                           const JSHandle<ClassLiteral> &classLiteral);
550     static inline JSTaggedType RuntimeTryGetInternString(uintptr_t argGlue, const JSHandle<EcmaString> &string);
551     static inline void RuntimeSetPatchModule(JSThread *thread, const JSHandle<JSFunction> &func);
552     template <typename T>
553     static inline JSTaggedValue RuntimeDecodeURIComponent(JSThread *thread, const JSHandle<EcmaString> &str,
554                                                           const T *data);
555     template <typename T>
556     static inline uint16_t GetCodeUnit(Span<T> &sp, int32_t index, int32_t length);
557     template <typename T>
558     static inline JSTaggedValue DecodePercentEncoding(JSThread *thread, const JSHandle<EcmaString> &str, int32_t &k,
559                                                       int32_t strLen, std::u16string &resStr, Span<T> &sp);
560     template <typename T>
561     static inline JSTaggedValue DecodePercentEncoding(JSThread *thread, int32_t &n, int32_t &k,
562                                                       const JSHandle<EcmaString> &str, uint8_t &bb,
563                                                       std::vector<uint8_t> &oct, Span<T> &sp,
564                                                       int32_t strLen);
565     static inline JSTaggedValue UTF16EncodeCodePoint(JSThread *thread, const std::vector<uint8_t> &oct,
566                                                      const JSHandle<EcmaString> &str, std::u16string &resStr);
567     static inline bool IsFastRegExp(uintptr_t argGlue, JSTaggedValue thisValue);
568 
569     static inline RememberedSet* CreateLocalToShare(Region *region);
570     static inline RememberedSet* CreateOldToNew(Region *region);
571     static inline uint8_t GetValueFromTwoHex(uint8_t front, uint8_t behind);
572     static inline bool IsTargetBundleName(uintptr_t argGlue);
573     static inline bool MaybeHasInterfacesType(JSThread *thread, const JSHandle<TaggedArray> &arrayHandle);
574     static inline JSHandle<JSFunction> EntranceForDefineClass(JSThread *thread,
575                                                               const JSHandle<JSTaggedValue> &base,
576                                                               const JSHandle<JSTaggedValue> &lexenv,
577                                                               JSHandle<ClassInfoExtractor> &extractor,
578                                                               const JSHandle<JSTaggedValue> &ihc,
579                                                               const JSHandle<JSTaggedValue> &chc,
580                                                               const JSHandle<ClassLiteral> &classLiteral);
581     static inline void DefineInterfaceTypeOwnProperty(JSThread *thread, JSHandle<JSFunction> &cls,
582                                                       const JSHandle<JSTaggedValue> &base,
583                                                       const JSHandle<JSTaggedValue> &lexenv,
584                                                       JSHandle<ClassInfoExtractor> &extractor,
585                                                       const JSHandle<JSTaggedValue> &ihc,
586                                                       const JSHandle<JSTaggedValue> &chc,
587                                                       const JSHandle<TaggedArray> &arrayHandle,
588                                                       const JSHandle<ClassLiteral> &classLiteral);
589     friend class SlowRuntimeStub;
590 };
591 }  // namespace panda::ecmascript
592 #endif
593