• 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 #include "ecmascript/interpreter/interpreter_assembly.h"
17 
18 #include "ecmascript/ic/ic_runtime_stub-inl.h"
19 #include "ecmascript/interpreter/slow_runtime_stub.h"
20 #include "ecmascript/js_async_generator_object.h"
21 #include "ecmascript/base/gc_helper.h"
22 
23 #if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
24 #include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
25 #endif
26 
27 namespace panda::ecmascript {
28 using panda::ecmascript::kungfu::CommonStubCSigns;
29 #if defined(__clang__)
30 #pragma clang diagnostic push
31 #pragma clang diagnostic ignored "-Wvoid-ptr-dereference"
32 #pragma clang diagnostic ignored "-Wgnu-label-as-value"
33 #pragma clang diagnostic ignored "-Wunused-parameter"
34 #elif defined(__GNUC__)
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wpedantic"
37 #pragma GCC diagnostic ignored "-Wunused-parameter"
38 #endif
39 
40 #if ECMASCRIPT_ENABLE_INTERPRETER_LOG
41 #define LOG_INST() LOG_INTERPRETER(DEBUG)
42 #else
43 #define LOG_INST() false && LOG_INTERPRETER(DEBUG)
44 #endif
45 
46 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
47 #define ADVANCE_PC(offset) \
48     pc += (offset);  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-macro-usage)
49 
50 #define GOTO_NEXT()  // NOLINT(clang-diagnostic-gnu-label-as-value, cppcoreguidelines-macro-usage)
51 
52 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
53 #define DISPATCH_OFFSET(offset)                                                                               \
54     do {                                                                                                      \
55         ADVANCE_PC(offset)                                                                                    \
56         SAVE_PC();                                                                                            \
57         SAVE_ACC();                                                                                           \
58         AsmInterpretedFrame *frame = GET_ASM_FRAME(sp);                                                       \
59         auto currentMethod = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(thread);      \
60         currentMethod->SetHotnessCounter(static_cast<int16_t>(hotnessCounter));                               \
61         return;                                                                                               \
62     } while (false)
63 
64 #define DISPATCH(opcode)  DISPATCH_OFFSET(BytecodeInstruction::Size(BytecodeInstruction::Opcode::opcode))
65 
66 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
67 #define GET_ASM_FRAME(CurrentSp) \
68     (reinterpret_cast<AsmInterpretedFrame *>(CurrentSp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
69 #define GET_ENTRY_FRAME(sp) \
70     (reinterpret_cast<InterpretedEntryFrame *>(sp) - 1)  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
71 #define GET_BUILTIN_FRAME(sp) \
72     (reinterpret_cast<InterpretedBuiltinFrame *>(sp) - 1)  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
73 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
74 #define SAVE_PC() (GET_ASM_FRAME(sp)->pc = pc)  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
75 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
76 #define SAVE_ACC() (GET_ASM_FRAME(sp)->acc = acc)  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
77 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
78 #define RESTORE_ACC() (acc = GET_ASM_FRAME(sp)->acc)  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
79 
80 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
81 #define INTERPRETER_GOTO_EXCEPTION_HANDLER()                                                                        \
82     do {                                                                                                            \
83         SAVE_PC();                                                                                                  \
84         GET_ASM_FRAME(sp)->acc = JSTaggedValue::Exception();                                                        \
85         return;                                                                                                     \
86     } while (false)
87 
88 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
89 #define INTERPRETER_HANDLE_RETURN()                                                     \
90     do {                                                                                \
91         JSFunction* prevFunc = JSFunction::Cast(prevState->function.GetTaggedObject()); \
92         method = prevFunc->GetCallTarget(thread);                                       \
93         hotnessCounter = static_cast<int32_t>(method->GetHotnessCounter());             \
94         ASSERT(prevState->callSize == GetJumpSizeAfterCall(pc));                        \
95         DISPATCH_OFFSET(prevState->callSize);                                           \
96     } while (false)
97 
98 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
99 #define INTERPRETER_RETURN_IF_ABRUPT(result)      \
100     do {                                          \
101         if ((result).IsException()) {             \
102             INTERPRETER_GOTO_EXCEPTION_HANDLER(); \
103         }                                         \
104     } while (false)
105 
106 #if ECMASCRIPT_ENABLE_IC
107 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
108 #define UPDATE_HOTNESS_COUNTER(offset)                                      \
109     do {                                                                    \
110         hotnessCounter += offset;                                           \
111         if (UNLIKELY(hotnessCounter <= 0)) {                                \
112             SAVE_ACC();                                                     \
113             profileTypeInfo = UpdateHotnessCounter(thread, sp);             \
114             RESTORE_ACC();                                                  \
115             hotnessCounter = EcmaInterpreter::METHOD_HOTNESS_THRESHOLD;     \
116         }                                                                   \
117     } while (false)
118 #else
119 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
120 #define UPDATE_HOTNESS_COUNTER(offset) static_cast<void>(0)
121 #endif
122 
123 #define READ_INST_OP() READ_INST_8(0)               // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
124 #define READ_INST_4_0() (READ_INST_8(1) & 0xf)      // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
125 #define READ_INST_4_1() (READ_INST_8(1) >> 4 & 0xf) // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
126 #define READ_INST_4_2() (READ_INST_8(2) & 0xf)      // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
127 #define READ_INST_4_3() (READ_INST_8(2) >> 4 & 0xf) // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
128 #define READ_INST_8_0() READ_INST_8(1)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
129 #define READ_INST_8_1() READ_INST_8(2)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
130 #define READ_INST_8_2() READ_INST_8(3)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
131 #define READ_INST_8_3() READ_INST_8(4)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
132 #define READ_INST_8_4() READ_INST_8(5)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
133 #define READ_INST_8_5() READ_INST_8(6)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
134 #define READ_INST_8_6() READ_INST_8(7)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
135 #define READ_INST_8_7() READ_INST_8(8)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
136 #define READ_INST_8_8() READ_INST_8(9)              // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
137 #define READ_INST_8_9() READ_INST_8(10)             // NOLINT(hicpp-signed-bitwise, cppcoreguidelines-macro-usage)
138 #define READ_INST_8(offset) (*(pc + (offset)))
139 #define MOVE_AND_READ_INST_8(currentInst, offset) \
140     (currentInst) <<= 8;                          \
141     (currentInst) += READ_INST_8(offset);         \
142 
143 #define READ_INST_16_0() READ_INST_16(2)
144 #define READ_INST_16_1() READ_INST_16(3)
145 #define READ_INST_16_2() READ_INST_16(4)
146 #define READ_INST_16_3() READ_INST_16(5)
147 #define READ_INST_16_5() READ_INST_16(7)
148 #define READ_INST_16_7() READ_INST_16(9)
149 #define READ_INST_16(offset)                            \
150     ({                                                  \
151         uint16_t currentInst = READ_INST_8(offset);     \
152         MOVE_AND_READ_INST_8(currentInst, (offset) - 1) \
153     })
154 
155 #define READ_INST_32_0() READ_INST_32(4)
156 #define READ_INST_32_1() READ_INST_32(5)
157 #define READ_INST_32_2() READ_INST_32(6)
158 #define READ_INST_32(offset)                            \
159     ({                                                  \
160         uint32_t currentInst = READ_INST_8(offset);     \
161         MOVE_AND_READ_INST_8(currentInst, (offset) - 1) \
162         MOVE_AND_READ_INST_8(currentInst, (offset) - 2) \
163         MOVE_AND_READ_INST_8(currentInst, (offset) - 3) \
164     })
165 
166 #define READ_INST_64_0()                       \
167     ({                                         \
168         uint64_t currentInst = READ_INST_8(8); \
169         MOVE_AND_READ_INST_8(currentInst, 7)   \
170         MOVE_AND_READ_INST_8(currentInst, 6)   \
171         MOVE_AND_READ_INST_8(currentInst, 5)   \
172         MOVE_AND_READ_INST_8(currentInst, 4)   \
173         MOVE_AND_READ_INST_8(currentInst, 3)   \
174         MOVE_AND_READ_INST_8(currentInst, 2)   \
175         MOVE_AND_READ_INST_8(currentInst, 1)   \
176     })
177 
178 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
179 #define GET_VREG(idx) (sp[idx])  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
180 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
181 #define GET_VREG_VALUE(idx) (JSTaggedValue(sp[idx]))  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
182 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
183 #define SET_VREG(idx, val) (sp[idx] = (val));  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
184 #define GET_ACC() (acc)                        // NOLINT(cppcoreguidelines-macro-usage)
185 #define SET_ACC(val) (acc = val)               // NOLINT(cppcoreguidelines-macro-usage)
186 
187 using InterpreterEntry = JSTaggedType (*)(uintptr_t glue, ECMAObject *callTarget,
188     Method *method, uint64_t callField, size_t argc, uintptr_t argv);
189 using GeneratorReEnterInterpEntry = JSTaggedType (*)(uintptr_t glue, JSTaggedType context);
190 
InitStackFrame(JSThread * thread)191 void InterpreterAssembly::InitStackFrame(JSThread *thread)
192 {
193     InitStackFrameForSP(const_cast<JSTaggedType *>(thread->GetCurrentSPFrame()));
194 }
195 
InitStackFrameForSP(JSTaggedType * prevSp)196 void InterpreterAssembly::InitStackFrameForSP(JSTaggedType *prevSp)
197 {
198     InterpretedEntryFrame *entryState = InterpretedEntryFrame::GetFrameFromSp(prevSp);
199     entryState->base.type = FrameType::INTERPRETER_ENTRY_FRAME;
200     entryState->base.prev = nullptr;
201     entryState->pc = nullptr;
202 }
203 
Execute(EcmaRuntimeCallInfo * info)204 JSTaggedValue InterpreterAssembly::Execute(EcmaRuntimeCallInfo *info)
205 {
206     ASSERT(info);
207     JSThread *thread = info->GetThread();
208     INTERPRETER_TRACE(thread, AsmExecute);
209 #if ECMASCRIPT_ENABLE_INTERPRETER_ARKUINAITVE_TRACE
210     ECMA_BYTRACE_NAME(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "ArkCompiler::InterpreterAssembly::Execute", "");
211 #endif
212     // When the  function is jit-compiled, the Method object is reinstalled.
213     // In this case, the AotWithCall field may be updated.
214     // This causes a Construct that is not a ClassConstructor to call jit code.
215     ECMAObject *callTarget = reinterpret_cast<ECMAObject*>(info->GetFunctionValue().GetTaggedObject());
216     Method *method = callTarget->GetCallTarget(thread);
217     bool isCompiledCode = JSFunctionBase::IsCompiledCodeFromCallTarget(thread, info->GetFunctionValue());
218 
219     // check is or not debugger
220     thread->CheckSwitchDebuggerBCStub();
221     thread->CheckSafepoint();
222     uint32_t argc = info->GetArgsNumber();
223     uintptr_t argv = reinterpret_cast<uintptr_t>(info->GetArgs());
224 
225     callTarget = reinterpret_cast<ECMAObject*>(info->GetFunctionValue().GetTaggedObject());
226     method = callTarget->GetCallTarget(thread);
227     if (isCompiledCode) {
228         JSHandle<JSFunction> func(thread, info->GetFunctionValue());
229         if (func->IsClassConstructor()) {
230             {
231                 EcmaVM *ecmaVm = thread->GetEcmaVM();
232                 ObjectFactory *factory = ecmaVm->GetFactory();
233                 JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
234                     "class constructor cannot called without 'new'", StackCheck::NO);
235                 thread->SetException(error.GetTaggedValue());
236             }
237             return thread->GetException();
238         }
239         JSTaggedValue res = JSFunction::InvokeOptimizedEntrypoint(thread, func, info);
240         const JSTaggedType *curSp = thread->GetCurrentSPFrame();
241         InterpretedEntryFrame *entryState = InterpretedEntryFrame::GetFrameFromSp(curSp);
242         JSTaggedType *prevSp = entryState->base.prev;
243         thread->SetCurrentSPFrame(prevSp);
244         if (thread->HasPendingException()) {
245             return thread->GetException();
246         }
247 #if ECMASCRIPT_ENABLE_STUB_RESULT_CHECK
248         thread->CheckJSTaggedType(JSTaggedValue(res).GetRawData());
249 #endif
250         return JSTaggedValue(res);
251     }
252 #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
253     RuntimeStubs::StartCallTimer(thread->GetGlueAddr(), info->GetFunctionValue().GetRawData(), false);
254 #endif
255     if (thread->IsDebugMode() && !method->IsNativeWithCallField()) {
256         JSHandle<JSFunction> func(thread, info->GetFunctionValue());
257         JSTaggedValue env = func->GetLexicalEnv(thread);
258         MethodEntry(thread, method, env);
259     }
260     if (thread->NeedReadBarrier()) {
261         base::GCHelper::CopyCallTarget(thread, callTarget); // callTarget should be ToSpace Reference
262         method = callTarget->GetCallTarget(thread);
263     }
264     // When C++ enters ASM, save the current globalenv and restore to glue after call
265     SaveEnv envScope(thread);
266     auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_AsmInterpreterEntry);
267     auto acc = reinterpret_cast<InterpreterEntry>(entry)(thread->GetGlueAddr(),
268         callTarget, method, method->GetCallField(), argc, argv);
269 
270     if (thread->IsEntryFrameDroppedTrue()) {
271         thread->PendingEntryFrameDroppedState();
272         return JSTaggedValue::Hole();
273     }
274 
275     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentSPFrame());
276     ASSERT(FrameHandler::GetFrameType(sp) == FrameType::INTERPRETER_ENTRY_FRAME);
277     auto prevEntry = InterpretedEntryFrame::GetFrameFromSp(sp)->GetPrevFrameFp();
278     thread->SetCurrentSPFrame(prevEntry);
279 
280 #if ECMASCRIPT_ENABLE_STUB_RESULT_CHECK
281     thread->CheckJSTaggedType(JSTaggedValue(acc).GetRawData());
282 #endif
283     return JSTaggedValue(acc);
284 }
285 
MethodEntry(JSThread * thread,Method * method,JSTaggedValue env)286 void InterpreterAssembly::MethodEntry(JSThread *thread, Method *method, JSTaggedValue env)
287 {
288     auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
289     FrameHandler frameHandler(thread);
290     // No frame before the first method is executed
291     if (!frameHandler.HasFrame()) {
292         debuggerMgr->GetNotificationManager()->MethodEntryEvent(thread, method, env);
293         return;
294     }
295 
296     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
297         if (frameHandler.IsEntryFrame()) {
298             continue;
299         }
300         debuggerMgr->GetNotificationManager()->MethodEntryEvent(thread, method, env);
301         return;
302     }
303 }
304 
GetCallSize(EcmaOpcode opcode)305 int64_t InterpreterAssembly::GetCallSize(EcmaOpcode opcode)
306 {
307     int64_t callSize = static_cast<int64_t>(BytecodeInstruction::Size(opcode));
308     switch (opcode) {
309         case EcmaOpcode::SUPERCALLSPREAD_IMM8_V8:
310         case EcmaOpcode::SUPERCALLTHISRANGE_IMM8_IMM8_V8:
311         case EcmaOpcode::NEWOBJRANGE_IMM8_IMM8_V8:
312         case EcmaOpcode::WIDE_NEWOBJRANGE_PREF_IMM16_V8:
313             return -callSize;
314         default:
315             return callSize;
316     }
317     return callSize;
318 }
319 
GeneratorReEnterInterpreter(JSThread * thread,JSHandle<GeneratorContext> context)320 JSTaggedValue InterpreterAssembly::GeneratorReEnterInterpreter(JSThread *thread, JSHandle<GeneratorContext> context)
321 {
322     // check is or not debugger
323     thread->CheckSwitchDebuggerBCStub();
324     // When C++ enters ASM, save the current globalenv and restore to glue after call
325     SaveEnv envScope(thread);
326     auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_GeneratorReEnterAsmInterp);
327     JSTaggedValue func = context->GetMethod(thread);
328     Method *method = ECMAObject::Cast(func.GetTaggedObject())->GetCallTarget(thread);
329     JSTaggedValue env = context->GetLexicalEnv(thread);
330     if (thread->IsDebugMode() && !method->IsNativeWithCallField()) {
331         MethodEntry(thread, method, env);
332     }
333     if (thread->NeedReadBarrier()) {
334         // func should be ToSpace Reference
335         base::GCHelper::CopyCallTarget(thread, func.GetTaggedObject());
336         // context should be ToSpace Reference
337         base::GCHelper::CopyGeneratorContext(thread, context.GetObject<GeneratorContext>());
338     }
339     auto acc = reinterpret_cast<GeneratorReEnterInterpEntry>(entry)(thread->GetGlueAddr(), context.GetTaggedType());
340     return JSTaggedValue(acc);
341 }
342 #ifndef EXCLUDE_C_INTERPRETER
HandleMovV4V4(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)343 void InterpreterAssembly::HandleMovV4V4(
344     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
345     JSTaggedValue acc, int16_t hotnessCounter)
346 {
347     uint16_t vdst = READ_INST_4_0();
348     uint16_t vsrc = READ_INST_4_1();
349     LOG_INST() << "mov v" << vdst << ", v" << vsrc;
350     uint64_t value = GET_VREG(vsrc);
351     SET_VREG(vdst, value)
352     DISPATCH(MOV_V4_V4);
353 }
354 
HandleMovV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)355 void InterpreterAssembly::HandleMovV8V8(
356     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
357     JSTaggedValue acc, int16_t hotnessCounter)
358 {
359     uint16_t vdst = READ_INST_8_0();
360     uint16_t vsrc = READ_INST_8_1();
361     LOG_INST() << "mov v" << vdst << ", v" << vsrc;
362     uint64_t value = GET_VREG(vsrc);
363     SET_VREG(vdst, value)
364     DISPATCH(MOV_V8_V8);
365 }
366 
HandleMovV16V16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)367 void InterpreterAssembly::HandleMovV16V16(
368     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
369     JSTaggedValue acc, int16_t hotnessCounter)
370 {
371     uint16_t vdst = READ_INST_16_0();
372     uint16_t vsrc = READ_INST_16_2();
373     LOG_INST() << "mov v" << vdst << ", v" << vsrc;
374     uint64_t value = GET_VREG(vsrc);
375     SET_VREG(vdst, value)
376     DISPATCH(MOV_V16_V16);
377 }
378 
HandleLdaStrId16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)379 void InterpreterAssembly::HandleLdaStrId16(
380     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
381     JSTaggedValue acc, int16_t hotnessCounter)
382 {
383     uint16_t stringId = READ_INST_16_0();
384     LOG_INST() << "lda.str " << std::hex << stringId;
385     constpool = GetConstantPool(thread, sp);
386     SET_ACC(ConstantPool::GetStringFromCache(thread, constpool, stringId));
387     DISPATCH(LDA_STR_ID16);
388 }
389 
HandleJmpImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)390 void InterpreterAssembly::HandleJmpImm8(
391     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
392     JSTaggedValue acc, int16_t hotnessCounter)
393 {
394     int8_t offset = READ_INST_8_0();
395     UPDATE_HOTNESS_COUNTER(offset);
396     LOG_INST() << "jmp " << std::hex << static_cast<int32_t>(offset);
397     DISPATCH_OFFSET(offset);
398 }
399 
HandleJmpImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)400 void InterpreterAssembly::HandleJmpImm16(
401     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
402     JSTaggedValue acc, int16_t hotnessCounter)
403 {
404     int16_t offset = static_cast<int16_t>(READ_INST_16_0());
405     UPDATE_HOTNESS_COUNTER(offset);
406     LOG_INST() << "jmp " << std::hex << static_cast<int32_t>(offset);
407     DISPATCH_OFFSET(offset);
408 }
409 
HandleJmpImm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)410 void InterpreterAssembly::HandleJmpImm32(
411     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
412     JSTaggedValue acc, int16_t hotnessCounter)
413 {
414     int32_t offset = static_cast<int32_t>(READ_INST_32_0());
415     UPDATE_HOTNESS_COUNTER(offset);
416     LOG_INST() << "jmp " << std::hex << offset;
417     DISPATCH_OFFSET(offset);
418 }
419 
HandleJeqzImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)420 void InterpreterAssembly::HandleJeqzImm8(
421     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
422     JSTaggedValue acc, int16_t hotnessCounter)
423 {
424     int8_t offset = READ_INST_8_0();
425     LOG_INST() << "jeqz ->\t"
426                 << "cond jmpz " << std::hex << static_cast<int32_t>(offset);
427     if (GET_ACC().IsFalse() || (GET_ACC().IsInt() && GET_ACC().GetInt() == 0) ||
428         (GET_ACC().IsDouble() && GET_ACC().GetDouble() == 0)) {
429         UPDATE_HOTNESS_COUNTER(offset);
430         DISPATCH_OFFSET(offset);
431     } else {
432         DISPATCH(JEQZ_IMM8);
433     }
434 }
435 
HandleJeqzImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)436 void InterpreterAssembly::HandleJeqzImm16(
437     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
438     JSTaggedValue acc, int16_t hotnessCounter)
439 {
440     int16_t offset = static_cast<int16_t>(READ_INST_16_0());
441     LOG_INST() << "jeqz ->\t"
442                 << "cond jmpz " << std::hex << static_cast<int32_t>(offset);
443     if (GET_ACC().IsFalse() || (GET_ACC().IsInt() && GET_ACC().GetInt() == 0) ||
444         (GET_ACC().IsDouble() && GET_ACC().GetDouble() == 0)) {
445         UPDATE_HOTNESS_COUNTER(offset);
446         DISPATCH_OFFSET(offset);
447     } else {
448         DISPATCH(JEQZ_IMM16);
449     }
450 }
451 
HandleJeqzImm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)452 void InterpreterAssembly::HandleJeqzImm32(
453     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
454     JSTaggedValue acc, int16_t hotnessCounter)
455 {
456     int32_t offset = static_cast<int32_t>(READ_INST_32_0());
457     LOG_INST() << "jeqz ->\t"
458                 << "cond jmpz " << std::hex << offset;
459     if (GET_ACC().IsFalse() || (GET_ACC().IsInt() && GET_ACC().GetInt() == 0) ||
460         (GET_ACC().IsDouble() && GET_ACC().GetDouble() == 0)) {
461         UPDATE_HOTNESS_COUNTER(offset);
462         DISPATCH_OFFSET(offset);
463     } else {
464         DISPATCH(JEQZ_IMM16);
465     }
466 }
467 
HandleJnezImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)468 void InterpreterAssembly::HandleJnezImm8(
469     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
470     JSTaggedValue acc, int16_t hotnessCounter)
471 {
472     int8_t offset = READ_INST_8_0();
473     LOG_INST() << "jnez ->\t"
474                 << "cond jmpz " << std::hex << static_cast<int32_t>(offset);
475     if (GET_ACC().IsTrue() || (GET_ACC().IsInt() && GET_ACC().GetInt() != 0) ||
476         (GET_ACC().IsDouble() && GET_ACC().GetDouble() != 0)) {
477         UPDATE_HOTNESS_COUNTER(offset);
478         DISPATCH_OFFSET(offset);
479     } else {
480         DISPATCH(JNEZ_IMM8);
481     }
482 }
483 
HandleJnezImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)484 void InterpreterAssembly::HandleJnezImm16(
485     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
486     JSTaggedValue acc, int16_t hotnessCounter)
487 {
488     int16_t offset = static_cast<int16_t>(READ_INST_16_0());
489     LOG_INST() << "jnez ->\t"
490                 << "cond jmpz " << std::hex << static_cast<int32_t>(offset);
491     if (GET_ACC().IsTrue() || (GET_ACC().IsInt() && GET_ACC().GetInt() != 0) ||
492         (GET_ACC().IsDouble() && GET_ACC().GetDouble() != 0)) {
493         UPDATE_HOTNESS_COUNTER(offset);
494         DISPATCH_OFFSET(offset);
495     } else {
496         DISPATCH(JNEZ_IMM16);
497     }
498 }
499 
HandleJnezImm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)500 void InterpreterAssembly::HandleJnezImm32(
501     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
502     JSTaggedValue acc, int16_t hotnessCounter)
503 {
504     int32_t offset = static_cast<int32_t>(READ_INST_32_0());
505     LOG_INST() << "jnez ->\t"
506                 << "cond jmpz " << std::hex << offset;
507     if (GET_ACC().IsTrue() || (GET_ACC().IsInt() && GET_ACC().GetInt() != 0) ||
508         (GET_ACC().IsDouble() && GET_ACC().GetDouble() != 0)) {
509         UPDATE_HOTNESS_COUNTER(offset);
510         DISPATCH_OFFSET(offset);
511     } else {
512         DISPATCH(JNEZ_IMM32);
513     }
514 }
515 
HandleLdaV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)516 void InterpreterAssembly::HandleLdaV8(
517     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
518     JSTaggedValue acc, int16_t hotnessCounter)
519 {
520     uint16_t vsrc = READ_INST_8_0();
521     LOG_INST() << "lda v" << vsrc;
522     uint64_t value = GET_VREG(vsrc);
523     SET_ACC(JSTaggedValue(value));
524     DISPATCH(LDA_V8);
525 }
526 
HandleStaV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)527 void InterpreterAssembly::HandleStaV8(
528     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
529     JSTaggedValue acc, int16_t hotnessCounter)
530 {
531     uint16_t vdst = READ_INST_8_0();
532     LOG_INST() << "sta v" << vdst;
533     SET_VREG(vdst, GET_ACC().GetRawData())
534     DISPATCH(STA_V8);
535 }
536 
HandleLdaiImm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)537 void InterpreterAssembly::HandleLdaiImm32(
538     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
539     JSTaggedValue acc, int16_t hotnessCounter)
540 {
541     int32_t imm = static_cast<int32_t>(READ_INST_32_0());
542     LOG_INST() << "ldai " << std::hex << imm;
543     SET_ACC(JSTaggedValue(imm));
544     DISPATCH(LDAI_IMM32);
545 }
546 
HandleFldaiImm64(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)547 void InterpreterAssembly::HandleFldaiImm64(
548     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
549     JSTaggedValue acc, int16_t hotnessCounter)
550 {
551     auto imm = base::bit_cast<double>(READ_INST_64_0());
552     LOG_INST() << "fldai " << imm;
553     SET_ACC(JSTaggedValue(imm));
554     DISPATCH(FLDAI_IMM64);
555 }
556 
HandleReturn(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)557 void InterpreterAssembly::HandleReturn(
558     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
559     JSTaggedValue acc, int16_t hotnessCounter)
560 {
561     LOG_INST() << "returnla ";
562     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
563     LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
564                             << std::hex << reinterpret_cast<uintptr_t>(state->pc);
565     Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
566     [[maybe_unused]] auto fistPC = method->GetBytecodeArray();
567     UPDATE_HOTNESS_COUNTER(-(pc - fistPC));
568     method->SetHotnessCounter(static_cast<int16_t>(hotnessCounter));
569     sp = state->base.prev;
570     ASSERT(sp != nullptr);
571 
572     AsmInterpretedFrame *prevState = GET_ASM_FRAME(sp);
573     pc = prevState->pc;
574     thread->SetCurrentFrame(sp);
575     // entry frame
576     if (pc == nullptr) {
577         state->acc = acc;
578         return;
579     }
580 
581     // new stackless not supported
582     INTERPRETER_HANDLE_RETURN();
583 }
584 
HandleReturnundefined(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)585 void InterpreterAssembly::HandleReturnundefined(
586     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
587     JSTaggedValue acc, int16_t hotnessCounter)
588 {
589     LOG_INST() << "return.undefined";
590     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
591     LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
592                             << std::hex << reinterpret_cast<uintptr_t>(state->pc);
593     Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
594     [[maybe_unused]] auto fistPC = method->GetBytecodeArray();
595     UPDATE_HOTNESS_COUNTER(-(pc - fistPC));
596     method->SetHotnessCounter(static_cast<int16_t>(hotnessCounter));
597     sp = state->base.prev;
598     ASSERT(sp != nullptr);
599 
600     AsmInterpretedFrame *prevState = GET_ASM_FRAME(sp);
601     pc = prevState->pc;
602     thread->SetCurrentFrame(sp);
603     // entry frame
604     if (pc == nullptr) {
605         state->acc = JSTaggedValue::Undefined();
606         return;
607     }
608 
609     // new stackless not supported
610     SET_ACC(JSTaggedValue::Undefined());
611     INTERPRETER_HANDLE_RETURN();
612 }
613 
HandleLdnan(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)614 void InterpreterAssembly::HandleLdnan(
615     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
616     JSTaggedValue acc, int16_t hotnessCounter)
617 {
618     LOG_INST() << "intrinsics::ldnan";
619     SET_ACC(JSTaggedValue(base::NAN_VALUE));
620     DISPATCH(LDNAN);
621 }
622 
HandleLdinfinity(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)623 void InterpreterAssembly::HandleLdinfinity(
624     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
625     JSTaggedValue acc, int16_t hotnessCounter)
626 {
627     LOG_INST() << "intrinsics::ldinfinity";
628     SET_ACC(JSTaggedValue(base::POSITIVE_INFINITY));
629     DISPATCH(LDINFINITY);
630 }
631 
HandleLdundefined(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)632 void InterpreterAssembly::HandleLdundefined(
633     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
634     JSTaggedValue acc, int16_t hotnessCounter)
635 {
636     LOG_INST() << "intrinsics::ldundefined";
637     SET_ACC(JSTaggedValue::Undefined());
638     DISPATCH(LDUNDEFINED);
639 }
640 
HandleLdnull(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)641 void InterpreterAssembly::HandleLdnull(
642     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
643     JSTaggedValue acc, int16_t hotnessCounter)
644 {
645     LOG_INST() << "intrinsics::ldnull";
646     SET_ACC(JSTaggedValue::Null());
647     DISPATCH(LDNULL);
648 }
649 
HandleLdsymbol(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)650 void InterpreterAssembly::HandleLdsymbol(
651     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
652     JSTaggedValue acc, int16_t hotnessCounter)
653 {
654     LOG_INST() << "intrinsics::ldsymbol";
655     EcmaVM *ecmaVm = thread->GetEcmaVM();
656     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
657     SET_ACC(globalEnv->GetSymbolFunction().GetTaggedValue());
658     DISPATCH(LDSYMBOL);
659 }
660 
HandleLdglobal(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)661 void InterpreterAssembly::HandleLdglobal(
662     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
663     JSTaggedValue acc, int16_t hotnessCounter)
664 {
665     LOG_INST() << "intrinsics::ldglobal";
666     EcmaVM *ecmaVm = thread->GetEcmaVM();
667     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
668     JSTaggedValue globalObj = globalEnv->GetGlobalObject();
669     SET_ACC(globalObj);
670     DISPATCH(LDGLOBAL);
671 }
672 
HandleLdtrue(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)673 void InterpreterAssembly::HandleLdtrue(
674     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
675     JSTaggedValue acc, int16_t hotnessCounter)
676 {
677     LOG_INST() << "intrinsics::ldtrue";
678     SET_ACC(JSTaggedValue::True());
679     DISPATCH(LDTRUE);
680 }
681 
HandleLdfalse(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)682 void InterpreterAssembly::HandleLdfalse(
683     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
684     JSTaggedValue acc, int16_t hotnessCounter)
685 {
686     LOG_INST() << "intrinsics::ldfalse";
687     SET_ACC(JSTaggedValue::False());
688     DISPATCH(LDFALSE);
689 }
690 
HandleGetunmappedargs(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)691 void InterpreterAssembly::HandleGetunmappedargs(
692     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
693     JSTaggedValue acc, int16_t hotnessCounter)
694 {
695     LOG_INST() << "intrinsics::getunmappedargs";
696 
697     uint32_t startIdx = 0;
698     uint32_t actualNumArgs = GetNumArgs(thread, sp, 0, startIdx);
699 
700     SAVE_PC();
701     JSTaggedValue res = SlowRuntimeStub::GetUnmapedArgs(thread, sp, actualNumArgs, startIdx);
702     INTERPRETER_RETURN_IF_ABRUPT(res);
703     SET_ACC(res);
704     DISPATCH(GETUNMAPPEDARGS);
705 }
706 
HandleAsyncfunctionenter(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)707 void InterpreterAssembly::HandleAsyncfunctionenter(
708     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
709     JSTaggedValue acc, int16_t hotnessCounter)
710 {
711     LOG_INST() << "intrinsics::asyncfunctionenter";
712     SAVE_PC();
713     JSTaggedValue res = SlowRuntimeStub::AsyncFunctionEnter(thread);
714     INTERPRETER_RETURN_IF_ABRUPT(res);
715     SET_ACC(res);
716     DISPATCH(ASYNCFUNCTIONENTER);
717 }
718 
HandleTonumberImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)719 void InterpreterAssembly::HandleTonumberImm8(
720     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
721     JSTaggedValue acc, int16_t hotnessCounter)
722 {
723     LOG_INST() << "intrinsics::tonumber";
724     JSTaggedValue value = GET_ACC();
725     if (value.IsNumber()) {
726         // fast path
727         SET_ACC(value);
728     } else {
729         // slow path
730         SAVE_PC();
731         JSTaggedValue res = SlowRuntimeStub::ToNumber(thread, value);
732         INTERPRETER_RETURN_IF_ABRUPT(res);
733         SET_ACC(res);
734     }
735     DISPATCH(TONUMBER_IMM8);
736 }
737 
HandleNegImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)738 void InterpreterAssembly::HandleNegImm8(
739     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
740     JSTaggedValue acc, int16_t hotnessCounter)
741 {
742     LOG_INST() << "intrinsics::neg";
743     JSTaggedValue value = GET_ACC();
744     // fast path
745     if (value.IsInt()) {
746         if (value.GetInt() == 0) {
747             SET_ACC(JSTaggedValue(-0.0));
748         } else {
749             SET_ACC(JSTaggedValue(-value.GetInt()));
750         }
751     } else if (value.IsDouble()) {
752         SET_ACC(JSTaggedValue(-value.GetDouble()));
753     } else {  // slow path
754         SAVE_PC();
755         JSTaggedValue res = SlowRuntimeStub::Neg(thread, value);
756         INTERPRETER_RETURN_IF_ABRUPT(res);
757         SET_ACC(res);
758     }
759     DISPATCH(NEG_IMM8);
760 }
761 
HandleNotImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)762 void InterpreterAssembly::HandleNotImm8(
763     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
764     JSTaggedValue acc, int16_t hotnessCounter)
765 {
766     LOG_INST() << "intrinsics::not";
767     JSTaggedValue value = GET_ACC();
768     int32_t number;
769     // number, fast path
770     if (value.IsInt()) {
771         number = static_cast<int32_t>(value.GetInt());
772         SET_ACC(JSTaggedValue(~number));  // NOLINT(hicpp-signed-bitwise);
773     } else if (value.IsDouble()) {
774         number = base::NumberHelper::DoubleToInt(value.GetDouble(), base::INT32_BITS);
775         SET_ACC(JSTaggedValue(~number));  // NOLINT(hicpp-signed-bitwise);
776     } else {
777         // slow path
778         SAVE_PC();
779         JSTaggedValue res = SlowRuntimeStub::Not(thread, value);
780         INTERPRETER_RETURN_IF_ABRUPT(res);
781         SET_ACC(res);
782     }
783     DISPATCH(NOT_IMM8);
784 }
785 
HandleIncImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)786 void InterpreterAssembly::HandleIncImm8(
787     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
788     JSTaggedValue acc, int16_t hotnessCounter)
789 {
790     LOG_INST() << "intrinsics::inc";
791     JSTaggedValue value = GET_ACC();
792     // number fast path
793     if (value.IsInt()) {
794         int32_t a0 = value.GetInt();
795         if (UNLIKELY(a0 == INT32_MAX)) {
796             auto ret = static_cast<double>(a0) + 1.0;
797             SET_ACC(JSTaggedValue(ret));
798         } else {
799             SET_ACC(JSTaggedValue(a0 + 1));
800         }
801     } else if (value.IsDouble()) {
802         SET_ACC(JSTaggedValue(value.GetDouble() + 1.0));
803     } else {
804         // slow path
805         SAVE_PC();
806         JSTaggedValue res = SlowRuntimeStub::Inc(thread, value);
807         INTERPRETER_RETURN_IF_ABRUPT(res);
808         SET_ACC(res);
809     }
810     DISPATCH(INC_IMM8);
811 }
812 
HandleDecImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)813 void InterpreterAssembly::HandleDecImm8(
814     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
815     JSTaggedValue acc, int16_t hotnessCounter)
816 {
817     LOG_INST() << "intrinsics::dec";
818     JSTaggedValue value = GET_ACC();
819     // number, fast path
820     if (value.IsInt()) {
821         int32_t a0 = value.GetInt();
822         if (UNLIKELY(a0 == INT32_MIN)) {
823             auto ret = static_cast<double>(a0) - 1.0;
824             SET_ACC(JSTaggedValue(ret));
825         } else {
826             SET_ACC(JSTaggedValue(a0 - 1));
827         }
828     } else if (value.IsDouble()) {
829         SET_ACC(JSTaggedValue(value.GetDouble() - 1.0));
830     } else {
831         // slow path
832         SAVE_PC();
833         JSTaggedValue res = SlowRuntimeStub::Dec(thread, value);
834         INTERPRETER_RETURN_IF_ABRUPT(res);
835         SET_ACC(res);
836     }
837     DISPATCH(DEC_IMM8);
838 }
839 
HandleThrow(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)840 void InterpreterAssembly::HandleThrow(
841     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
842     JSTaggedValue acc, int16_t hotnessCounter)
843 {
844     LOG_INST() << "intrinsics::throw";
845     SAVE_PC();
846     SlowRuntimeStub::Throw(thread, GET_ACC());
847     INTERPRETER_GOTO_EXCEPTION_HANDLER();
848 }
849 
HandleTypeofImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)850 void InterpreterAssembly::HandleTypeofImm8(
851     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
852     JSTaggedValue acc, int16_t hotnessCounter)
853 {
854     LOG_INST() << "intrinsics::typeof";
855     JSTaggedValue res = FastRuntimeStub::FastTypeOf(thread, GET_ACC());
856     SET_ACC(res);
857     DISPATCH(TYPEOF_IMM8);
858 }
859 
HandleGetpropiterator(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)860 void InterpreterAssembly::HandleGetpropiterator(
861     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
862     JSTaggedValue acc, int16_t hotnessCounter)
863 {
864     LOG_INST() << "intrinsics::getpropiterator";
865     SAVE_PC();
866     JSTaggedValue res = SlowRuntimeStub::GetPropIterator(thread, GET_ACC());
867     INTERPRETER_RETURN_IF_ABRUPT(res);
868     SET_ACC(res);
869     DISPATCH(GETPROPITERATOR);
870 }
871 
HandleResumegenerator(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)872 void InterpreterAssembly::HandleResumegenerator(
873     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
874     JSTaggedValue acc, int16_t hotnessCounter)
875 {
876     LOG_INST() << "intrinsics::resumegenerator";
877     JSTaggedValue objVal = GET_ACC();
878     if (objVal.IsAsyncGeneratorObject()) {
879         JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject());
880         SET_ACC(obj->GetResumeResult(thread));
881     } else {
882         JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject());
883         SET_ACC(obj->GetResumeResult(thread));
884     }
885     DISPATCH(RESUMEGENERATOR);
886 }
887 
HandleGetresumemode(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)888 void InterpreterAssembly::HandleGetresumemode(
889     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
890     JSTaggedValue acc, int16_t hotnessCounter)
891 {
892     LOG_INST() << "intrinsics::getresumemode";
893     JSTaggedValue objVal = GET_ACC();
894     if (objVal.IsAsyncGeneratorObject()) {
895         JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject());
896         SET_ACC(JSTaggedValue(static_cast<int>(obj->GetResumeMode())));
897     } else {
898         JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject());
899         SET_ACC(JSTaggedValue(static_cast<int>(obj->GetResumeMode())));
900     }
901     DISPATCH(GETRESUMEMODE);
902 }
903 
HandleGetiteratorImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)904 void InterpreterAssembly::HandleGetiteratorImm8(
905     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
906     JSTaggedValue acc, int16_t hotnessCounter)
907 {
908     LOG_INST() << "intrinsics::getiterator";
909     JSTaggedValue obj = GET_ACC();
910     // slow path
911     SAVE_PC();
912     JSTaggedValue res = SlowRuntimeStub::GetIterator(thread, obj);
913     INTERPRETER_RETURN_IF_ABRUPT(res);
914     SET_ACC(res);
915     DISPATCH(GETITERATOR_IMM8);
916 }
917 
HandleGetasynciteratorImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)918 void InterpreterAssembly::HandleGetasynciteratorImm8(
919     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
920     JSTaggedValue acc, int16_t hotnessCounter)
921 {
922     LOG_INST() << "intrinsics::getasynciterator";
923     JSTaggedValue obj = GET_ACC();
924     // slow path
925     SAVE_PC();
926     JSTaggedValue res = SlowRuntimeStub::GetAsyncIterator(thread, obj);
927     INTERPRETER_RETURN_IF_ABRUPT(res);
928     SET_ACC(res);
929     DISPATCH(GETASYNCITERATOR_IMM8);
930 }
931 
HandleThrowConstassignmentPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)932 void InterpreterAssembly::HandleThrowConstassignmentPrefV8(
933     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
934     JSTaggedValue acc, int16_t hotnessCounter)
935 {
936     uint16_t v0 = READ_INST_8_1();
937     LOG_INST() << "throwconstassignment"
938                 << " v" << v0;
939     SAVE_PC();
940     SlowRuntimeStub::ThrowConstAssignment(thread, GET_VREG_VALUE(v0));
941     INTERPRETER_GOTO_EXCEPTION_HANDLER();
942 }
943 
HandleThrowPatternnoncoerciblePrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)944 void InterpreterAssembly::HandleThrowPatternnoncoerciblePrefNone(
945     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
946     JSTaggedValue acc, int16_t hotnessCounter)
947 {
948     LOG_INST() << "throwpatternnoncoercible";
949 
950     SAVE_PC();
951     SlowRuntimeStub::ThrowPatternNonCoercible(thread);
952     INTERPRETER_GOTO_EXCEPTION_HANDLER();
953 }
954 
HandleThrowIfnotobjectPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)955 void InterpreterAssembly::HandleThrowIfnotobjectPrefV8(
956     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
957     JSTaggedValue acc, int16_t hotnessCounter)
958 {
959     LOG_INST() << "throwifnotobject";
960     uint16_t v0 = READ_INST_8_1();
961 
962     JSTaggedValue value = GET_VREG_VALUE(v0);
963     // fast path
964     if (value.IsECMAObject()) {
965         DISPATCH(THROW_IFNOTOBJECT_PREF_V8);
966     }
967 
968     // slow path
969     SAVE_PC();
970     SlowRuntimeStub::ThrowIfNotObject(thread);
971     INTERPRETER_GOTO_EXCEPTION_HANDLER();
972 }
973 
HandleCloseiteratorImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)974 void InterpreterAssembly::HandleCloseiteratorImm8V8(
975     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
976     JSTaggedValue acc, int16_t hotnessCounter)
977 {
978     uint16_t v0 = READ_INST_8_1();
979     LOG_INST() << "intrinsics::closeiterator"
980                << " v" << v0;
981     SAVE_PC();
982     JSTaggedValue iter = GET_VREG_VALUE(v0);
983     JSTaggedValue res = SlowRuntimeStub::CloseIterator(thread, iter);
984     INTERPRETER_RETURN_IF_ABRUPT(res);
985     SET_ACC(res);
986     DISPATCH(CLOSEITERATOR_IMM8_V8);
987 }
988 
HandleAdd2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)989 void InterpreterAssembly::HandleAdd2Imm8V8(
990     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
991     JSTaggedValue acc, int16_t hotnessCounter)
992 {
993     uint16_t v0 = READ_INST_8_1();
994     LOG_INST() << "intrinsics::add2"
995                << " v" << v0;
996     int32_t a0;
997     int32_t a1;
998     JSTaggedValue left = GET_VREG_VALUE(v0);
999     JSTaggedValue right = GET_ACC();
1000     // number, fast path
1001     if (left.IsInt() && right.IsInt()) {
1002         a0 = left.GetInt();
1003         a1 = right.GetInt();
1004         if ((a0 > 0 && a1 > INT32_MAX - a0) || (a0 < 0 && a1 < INT32_MIN - a0)) {
1005             auto ret = static_cast<double>(a0) + static_cast<double>(a1);
1006             SET_ACC(JSTaggedValue(ret));
1007         } else {
1008             SET_ACC(JSTaggedValue(a0 + a1));
1009         }
1010     } else if (left.IsNumber() && right.IsNumber()) {
1011         double a0Double = left.IsInt() ? left.GetInt() : left.GetDouble();
1012         double a1Double = right.IsInt() ? right.GetInt() : right.GetDouble();
1013         double ret = a0Double + a1Double;
1014         SET_ACC(JSTaggedValue(ret));
1015     } else {
1016         // one or both are not number, slow path
1017         SAVE_PC();
1018         JSTaggedValue res = SlowRuntimeStub::Add2(thread, left, right);
1019         INTERPRETER_RETURN_IF_ABRUPT(res);
1020         SET_ACC(res);
1021     }
1022     DISPATCH(ADD2_IMM8_V8);
1023 }
1024 
HandleSub2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1025 void InterpreterAssembly::HandleSub2Imm8V8(
1026     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1027     JSTaggedValue acc, int16_t hotnessCounter)
1028 {
1029     uint16_t v0 = READ_INST_8_1();
1030     LOG_INST() << "intrinsics::sub2"
1031                << " v" << v0;
1032     int32_t a0;
1033     int32_t a1;
1034     JSTaggedValue left = GET_VREG_VALUE(v0);
1035     JSTaggedValue right = GET_ACC();
1036     if (left.IsInt() && right.IsInt()) {
1037         a0 = left.GetInt();
1038         a1 = -right.GetInt();
1039         if ((a0 > 0 && a1 > INT32_MAX - a0) || (a0 < 0 && a1 < INT32_MIN - a0)) {
1040             auto ret = static_cast<double>(a0) + static_cast<double>(a1);
1041             SET_ACC(JSTaggedValue(ret));
1042         } else {
1043             SET_ACC(JSTaggedValue(a0 + a1));
1044         }
1045     } else if (left.IsNumber() && right.IsNumber()) {
1046         double a0Double = left.IsInt() ? left.GetInt() : left.GetDouble();
1047         double a1Double = right.IsInt() ? right.GetInt() : right.GetDouble();
1048         double ret = a0Double - a1Double;
1049         SET_ACC(JSTaggedValue(ret));
1050     } else {
1051         // one or both are not number, slow path
1052         SAVE_PC();
1053         JSTaggedValue res = SlowRuntimeStub::Sub2(thread, left, right);
1054         INTERPRETER_RETURN_IF_ABRUPT(res);
1055         SET_ACC(res);
1056     }
1057     DISPATCH(SUB2_IMM8_V8);
1058 }
HandleMul2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1059 void InterpreterAssembly::HandleMul2Imm8V8(
1060     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1061     JSTaggedValue acc, int16_t hotnessCounter)
1062 {
1063     uint16_t v0 = READ_INST_8_1();
1064     LOG_INST() << "intrinsics::mul2"
1065                 << " v" << v0;
1066     JSTaggedValue left = GET_VREG_VALUE(v0);
1067     JSTaggedValue right = acc;
1068     JSTaggedValue value = FastRuntimeStub::FastMul(left, right);
1069     if (!value.IsHole()) {
1070         SET_ACC(value);
1071     } else {
1072         // slow path
1073         SAVE_PC();
1074         JSTaggedValue res = SlowRuntimeStub::Mul2(thread, left, right);
1075         INTERPRETER_RETURN_IF_ABRUPT(res);
1076         SET_ACC(res);
1077     }
1078     DISPATCH(MUL2_IMM8_V8);
1079 }
1080 
HandleDiv2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1081 void InterpreterAssembly::HandleDiv2Imm8V8(
1082     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1083     JSTaggedValue acc, int16_t hotnessCounter)
1084 {
1085     uint16_t v0 = READ_INST_8_1();
1086     LOG_INST() << "intrinsics::div2"
1087                << " v" << v0;
1088     JSTaggedValue left = GET_VREG_VALUE(v0);
1089     JSTaggedValue right = acc;
1090     // fast path
1091     JSTaggedValue res = FastRuntimeStub::FastDiv(left, right);
1092     if (!res.IsHole()) {
1093         SET_ACC(res);
1094     } else {
1095         // slow path
1096         SAVE_PC();
1097         JSTaggedValue slowRes = SlowRuntimeStub::Div2(thread, left, right);
1098         INTERPRETER_RETURN_IF_ABRUPT(slowRes);
1099         SET_ACC(slowRes);
1100     }
1101     DISPATCH(DIV2_IMM8_V8);
1102 }
1103 
HandleMod2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1104 void InterpreterAssembly::HandleMod2Imm8V8(
1105     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1106     JSTaggedValue acc, int16_t hotnessCounter)
1107 {
1108     uint16_t vs = READ_INST_8_1();
1109     LOG_INST() << "intrinsics::mod2"
1110                 << " v" << vs;
1111     JSTaggedValue left = GET_VREG_VALUE(vs);
1112     JSTaggedValue right = GET_ACC();
1113 
1114     JSTaggedValue res = FastRuntimeStub::FastMod(left, right);
1115     if (!res.IsHole()) {
1116         SET_ACC(res);
1117     } else {
1118         // slow path
1119         SAVE_PC();
1120         JSTaggedValue slowRes = SlowRuntimeStub::Mod2(thread, left, right);
1121         INTERPRETER_RETURN_IF_ABRUPT(slowRes);
1122         SET_ACC(slowRes);
1123     }
1124     DISPATCH(MOD2_IMM8_V8);
1125 }
1126 
HandleEqImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1127 void InterpreterAssembly::HandleEqImm8V8(
1128     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1129     JSTaggedValue acc, int16_t hotnessCounter)
1130 {
1131     uint16_t v0 = READ_INST_8_1();
1132 
1133     LOG_INST() << "intrinsics::eq"
1134                 << " v" << v0;
1135     JSTaggedValue left = GET_VREG_VALUE(v0);
1136     JSTaggedValue right = acc;
1137     JSTaggedValue res = FastRuntimeStub::FastEqual(left, right);
1138     if (!res.IsHole()) {
1139         SET_ACC(res);
1140     } else {
1141         // slow path
1142         SAVE_PC();
1143         res = SlowRuntimeStub::Eq(thread, left, right);
1144         INTERPRETER_RETURN_IF_ABRUPT(res);
1145         SET_ACC(res);
1146     }
1147 
1148     DISPATCH(EQ_IMM8_V8);
1149 }
1150 
HandleNoteqImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1151 void InterpreterAssembly::HandleNoteqImm8V8(
1152     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1153     JSTaggedValue acc, int16_t hotnessCounter)
1154 {
1155     uint16_t v0 = READ_INST_8_1();
1156 
1157     LOG_INST() << "intrinsics::noteq"
1158                << " v" << v0;
1159     JSTaggedValue left = GET_VREG_VALUE(v0);
1160     JSTaggedValue right = acc;
1161 
1162     JSTaggedValue res = FastRuntimeStub::FastEqual(left, right);
1163     if (!res.IsHole()) {
1164         res = res.IsTrue() ? JSTaggedValue::False() : JSTaggedValue::True();
1165         SET_ACC(res);
1166     } else {
1167         // slow path
1168         SAVE_PC();
1169         res = SlowRuntimeStub::NotEq(thread, left, right);
1170         INTERPRETER_RETURN_IF_ABRUPT(res);
1171         SET_ACC(res);
1172     }
1173     DISPATCH(NOTEQ_IMM8_V8);
1174 }
1175 
HandleLessImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1176 void InterpreterAssembly::HandleLessImm8V8(
1177     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1178     JSTaggedValue acc, int16_t hotnessCounter)
1179 {
1180     uint16_t v0 = READ_INST_8_1();
1181 
1182     LOG_INST() << "intrinsics::less"
1183                << " v" << v0;
1184     JSTaggedValue left = GET_VREG_VALUE(v0);
1185     JSTaggedValue right = GET_ACC();
1186     if (left.IsInt() && right.IsInt()) {
1187         // fast path
1188         bool ret = left.GetInt() < right.GetInt();
1189         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1190     } else if (left.IsNumber() && right.IsNumber()) {
1191         // fast path
1192         double valueA = left.IsInt() ? static_cast<double>(left.GetInt()) : left.GetDouble();
1193         double valueB = right.IsInt() ? static_cast<double>(right.GetInt()) : right.GetDouble();
1194         bool ret = JSTaggedValue::StrictNumberCompare(valueA, valueB) == ComparisonResult::LESS;
1195         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1196     } else if (left.IsBigInt() && right.IsBigInt()) {
1197         bool result = BigInt::LessThan(left, right);
1198         SET_ACC(JSTaggedValue(result));
1199     } else {
1200         // slow path
1201         SAVE_PC();
1202         JSTaggedValue res = SlowRuntimeStub::Less(thread, left, right);
1203         INTERPRETER_RETURN_IF_ABRUPT(res);
1204         SET_ACC(res);
1205     }
1206     DISPATCH(LESS_IMM8_V8);
1207 }
1208 
HandleLesseqImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1209 void InterpreterAssembly::HandleLesseqImm8V8(
1210     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1211     JSTaggedValue acc, int16_t hotnessCounter)
1212 {
1213     uint16_t vs = READ_INST_8_1();
1214     LOG_INST() << "intrinsics::lesseq "
1215                << " v" << vs;
1216     JSTaggedValue left = GET_VREG_VALUE(vs);
1217     JSTaggedValue right = GET_ACC();
1218     if (left.IsInt() && right.IsInt()) {
1219         // fast path
1220         bool ret = ((left.GetInt() < right.GetInt()) || (left.GetInt() == right.GetInt()));
1221         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1222     } else if (left.IsNumber() && right.IsNumber()) {
1223         // fast path
1224         double valueA = left.IsInt() ? static_cast<double>(left.GetInt()) : left.GetDouble();
1225         double valueB = right.IsInt() ? static_cast<double>(right.GetInt()) : right.GetDouble();
1226         bool ret = JSTaggedValue::StrictNumberCompare(valueA, valueB) <= ComparisonResult::EQUAL;
1227         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1228     } else if (left.IsBigInt() && right.IsBigInt()) {
1229         bool result = BigInt::LessThan(left, right) || BigInt::Equal(left, right);
1230         SET_ACC(JSTaggedValue(result));
1231     } else {
1232         // slow path
1233         SAVE_PC();
1234         JSTaggedValue res = SlowRuntimeStub::LessEq(thread, left, right);
1235         INTERPRETER_RETURN_IF_ABRUPT(res);
1236         SET_ACC(res);
1237     }
1238     DISPATCH(LESSEQ_IMM8_V8);
1239 }
1240 
HandleGreaterImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1241 void InterpreterAssembly::HandleGreaterImm8V8(
1242     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1243     JSTaggedValue acc, int16_t hotnessCounter)
1244 {
1245     uint16_t v0 = READ_INST_8_1();
1246 
1247     LOG_INST() << "intrinsics::greater"
1248                << " v" << v0;
1249     JSTaggedValue left = GET_VREG_VALUE(v0);
1250     JSTaggedValue right = acc;
1251     if (left.IsInt() && right.IsInt()) {
1252         // fast path
1253         bool ret = left.GetInt() > right.GetInt();
1254         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1255     } else if (left.IsNumber() && right.IsNumber()) {
1256         // fast path
1257         double valueA = left.IsInt() ? static_cast<double>(left.GetInt()) : left.GetDouble();
1258         double valueB = right.IsInt() ? static_cast<double>(right.GetInt()) : right.GetDouble();
1259         bool ret = JSTaggedValue::StrictNumberCompare(valueA, valueB) == ComparisonResult::GREAT;
1260         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1261     } else if (left.IsBigInt() && right.IsBigInt()) {
1262         bool result = BigInt::LessThan(right, left);
1263         SET_ACC(JSTaggedValue(result));
1264     } else {
1265         // slow path
1266         SAVE_PC();
1267         JSTaggedValue res = SlowRuntimeStub::Greater(thread, left, right);
1268         INTERPRETER_RETURN_IF_ABRUPT(res);
1269         SET_ACC(res);
1270     }
1271     DISPATCH(GREATER_IMM8_V8);
1272 }
1273 
HandleGreatereqImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1274 void InterpreterAssembly::HandleGreatereqImm8V8(
1275     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1276     JSTaggedValue acc, int16_t hotnessCounter)
1277 {
1278     uint16_t vs = READ_INST_8_1();
1279     LOG_INST() << "intrinsics::greateq "
1280                << " v" << vs;
1281     JSTaggedValue left = GET_VREG_VALUE(vs);
1282     JSTaggedValue right = GET_ACC();
1283     if (left.IsInt() && right.IsInt()) {
1284         // fast path
1285         bool ret = ((left.GetInt() > right.GetInt()) || (left.GetInt() == right.GetInt()));
1286         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1287     } else if (left.IsNumber() && right.IsNumber()) {
1288         // fast path
1289         double valueA = left.IsInt() ? static_cast<double>(left.GetInt()) : left.GetDouble();
1290         double valueB = right.IsInt() ? static_cast<double>(right.GetInt()) : right.GetDouble();
1291         ComparisonResult comparison = JSTaggedValue::StrictNumberCompare(valueA, valueB);
1292         bool ret = (comparison == ComparisonResult::GREAT) || (comparison == ComparisonResult::EQUAL);
1293         SET_ACC(ret ? JSTaggedValue::True() : JSTaggedValue::False());
1294     } else if (left.IsBigInt() && right.IsBigInt()) {
1295         bool result = BigInt::LessThan(right, left) || BigInt::Equal(right, left);
1296         SET_ACC(JSTaggedValue(result));
1297     }  else {
1298         // slow path
1299         SAVE_PC();
1300         JSTaggedValue res = SlowRuntimeStub::GreaterEq(thread, left, right);
1301         INTERPRETER_RETURN_IF_ABRUPT(res);
1302         SET_ACC(res);
1303     }
1304     DISPATCH(GREATEREQ_IMM8_V8);
1305 }
1306 
HandleShl2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1307 void InterpreterAssembly::HandleShl2Imm8V8(
1308     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1309     JSTaggedValue acc, int16_t hotnessCounter)
1310 {
1311     uint16_t v0 = READ_INST_8_1();
1312 
1313     LOG_INST() << "intrinsics::shl2"
1314                << " v" << v0;
1315     JSTaggedValue left = GET_VREG_VALUE(v0);
1316     JSTaggedValue right = GET_ACC();
1317     // both number, fast path
1318     if (left.IsInt() && right.IsInt()) {
1319         int32_t opNumber0 = left.GetInt();
1320         int32_t opNumber1 = right.GetInt();
1321         uint32_t shift =
1322             static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
1323         using unsigned_type = std::make_unsigned_t<int32_t>;
1324         auto ret =
1325             static_cast<int32_t>(static_cast<unsigned_type>(opNumber0) << shift); // NOLINT(hicpp-signed-bitwise)
1326         SET_ACC(JSTaggedValue(ret));
1327     } else if (left.IsNumber() && right.IsNumber()) {
1328         int32_t opNumber0 =
1329             left.IsInt() ? left.GetInt() : base::NumberHelper::DoubleToInt(left.GetDouble(), base::INT32_BITS);
1330         int32_t opNumber1 =
1331             right.IsInt() ? right.GetInt() : base::NumberHelper::DoubleToInt(right.GetDouble(), base::INT32_BITS);
1332         uint32_t shift =
1333             static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
1334         using unsigned_type = std::make_unsigned_t<int32_t>;
1335         auto ret =
1336             static_cast<int32_t>(static_cast<unsigned_type>(opNumber0) << shift); // NOLINT(hicpp-signed-bitwise)
1337         SET_ACC(JSTaggedValue(ret));
1338     } else {
1339         // slow path
1340         SAVE_PC();
1341         JSTaggedValue res = SlowRuntimeStub::Shl2(thread, left, right);
1342         INTERPRETER_RETURN_IF_ABRUPT(res);
1343         SET_ACC(res);
1344     }
1345     DISPATCH(SHL2_IMM8_V8);
1346 }
1347 
HandleShr2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1348 void InterpreterAssembly::HandleShr2Imm8V8(
1349     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1350     JSTaggedValue acc, int16_t hotnessCounter)
1351 {
1352     uint16_t v0 = READ_INST_8_1();
1353     LOG_INST() << "intrinsics::shr2"
1354                << " v" << v0;
1355     JSTaggedValue left = GET_VREG_VALUE(v0);
1356     JSTaggedValue right = GET_ACC();
1357     // both number, fast path
1358     if (left.IsInt() && right.IsInt()) {
1359         int32_t opNumber0 = left.GetInt();
1360         int32_t opNumber1 = right.GetInt();
1361         uint32_t shift =
1362             static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
1363         using unsigned_type = std::make_unsigned_t<uint32_t>;
1364         auto ret =
1365             static_cast<uint32_t>(static_cast<unsigned_type>(opNumber0) >> shift); // NOLINT(hicpp-signed-bitwise)
1366         SET_ACC(JSTaggedValue(ret));
1367     } else if (left.IsNumber() && right.IsNumber()) {
1368         int32_t opNumber0 =
1369             left.IsInt() ? left.GetInt() : base::NumberHelper::DoubleToInt(left.GetDouble(), base::INT32_BITS);
1370         int32_t opNumber1 =
1371             right.IsInt() ? right.GetInt() : base::NumberHelper::DoubleToInt(right.GetDouble(), base::INT32_BITS);
1372         uint32_t shift =
1373             static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
1374         using unsigned_type = std::make_unsigned_t<uint32_t>;
1375         auto ret =
1376             static_cast<uint32_t>(static_cast<unsigned_type>(opNumber0) >> shift); // NOLINT(hicpp-signed-bitwise)
1377         SET_ACC(JSTaggedValue(ret));
1378     } else {
1379         // slow path
1380         SAVE_PC();
1381         JSTaggedValue res = SlowRuntimeStub::Shr2(thread, left, right);
1382         INTERPRETER_RETURN_IF_ABRUPT(res);
1383         SET_ACC(res);
1384     }
1385     DISPATCH(SHR2_IMM8_V8);
1386 }
1387 
HandleAshr2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1388 void InterpreterAssembly::HandleAshr2Imm8V8(
1389     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1390     JSTaggedValue acc, int16_t hotnessCounter)
1391 {
1392     uint16_t v0 = READ_INST_8_1();
1393     LOG_INST() << "intrinsics::ashr2"
1394                << " v" << v0;
1395     JSTaggedValue left = GET_VREG_VALUE(v0);
1396     JSTaggedValue right = GET_ACC();
1397     // both number, fast path
1398     if (left.IsInt() && right.IsInt()) {
1399         int32_t opNumber0 = left.GetInt();
1400         int32_t opNumber1 = right.GetInt();
1401         uint32_t shift =
1402             static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
1403         auto ret = static_cast<int32_t>(opNumber0 >> shift); // NOLINT(hicpp-signed-bitwise)
1404         SET_ACC(JSTaggedValue(ret));
1405     } else if (left.IsNumber() && right.IsNumber()) {
1406         int32_t opNumber0 =
1407             left.IsInt() ? left.GetInt() : base::NumberHelper::DoubleToInt(left.GetDouble(), base::INT32_BITS);
1408         int32_t opNumber1 =
1409             right.IsInt() ? right.GetInt() : base::NumberHelper::DoubleToInt(right.GetDouble(), base::INT32_BITS);
1410         uint32_t shift =
1411             static_cast<uint32_t>(opNumber1) & 0x1f; // NOLINT(hicpp-signed-bitwise, readability-magic-numbers)
1412         auto ret = static_cast<int32_t>(opNumber0 >> shift); // NOLINT(hicpp-signed-bitwise)
1413         SET_ACC(JSTaggedValue(ret));
1414     } else {
1415         // slow path
1416         SAVE_PC();
1417         JSTaggedValue res = SlowRuntimeStub::Ashr2(thread, left, right);
1418         INTERPRETER_RETURN_IF_ABRUPT(res);
1419         SET_ACC(res);
1420     }
1421     DISPATCH(ASHR2_IMM8_V8);
1422 }
1423 
HandleAnd2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1424 void InterpreterAssembly::HandleAnd2Imm8V8(
1425     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1426     JSTaggedValue acc, int16_t hotnessCounter)
1427 {
1428     uint16_t v0 = READ_INST_8_1();
1429 
1430     LOG_INST() << "intrinsics::and2"
1431                << " v" << v0;
1432     JSTaggedValue left = GET_VREG_VALUE(v0);
1433     JSTaggedValue right = GET_ACC();
1434     // both number, fast path
1435     if (left.IsInt() && right.IsInt()) {
1436         int32_t opNumber0 = left.GetInt();
1437         int32_t opNumber1 = right.GetInt();
1438         // NOLINT(hicpp-signed-bitwise)
1439         auto ret = static_cast<uint32_t>(opNumber0) & static_cast<uint32_t>(opNumber1);
1440         SET_ACC(JSTaggedValue(static_cast<int32_t>(ret)));
1441     } else if (left.IsNumber() && right.IsNumber()) {
1442         int32_t opNumber0 =
1443             left.IsInt() ? left.GetInt() : base::NumberHelper::DoubleToInt(left.GetDouble(), base::INT32_BITS);
1444         int32_t opNumber1 =
1445             right.IsInt() ? right.GetInt() : base::NumberHelper::DoubleToInt(right.GetDouble(), base::INT32_BITS);
1446         // NOLINT(hicpp-signed-bitwise)
1447         auto ret = static_cast<uint32_t>(opNumber0) & static_cast<uint32_t>(opNumber1);
1448         SET_ACC(JSTaggedValue(static_cast<int32_t>(ret)));
1449     } else {
1450         // slow path
1451         SAVE_PC();
1452         JSTaggedValue res = SlowRuntimeStub::And2(thread, left, right);
1453         INTERPRETER_RETURN_IF_ABRUPT(res);
1454         SET_ACC(res);
1455     }
1456     DISPATCH(AND2_IMM8_V8);
1457 }
1458 
HandleOr2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1459 void InterpreterAssembly::HandleOr2Imm8V8(
1460     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1461     JSTaggedValue acc, int16_t hotnessCounter)
1462 {
1463     uint16_t v0 = READ_INST_8_1();
1464 
1465     LOG_INST() << "intrinsics::or2"
1466                << " v" << v0;
1467     JSTaggedValue left = GET_VREG_VALUE(v0);
1468     JSTaggedValue right = GET_ACC();
1469     // both number, fast path
1470     if (left.IsInt() && right.IsInt()) {
1471         int32_t opNumber0 = left.GetInt();
1472         int32_t opNumber1 = right.GetInt();
1473         // NOLINT(hicpp-signed-bitwise)
1474         auto ret = static_cast<uint32_t>(opNumber0) | static_cast<uint32_t>(opNumber1);
1475         SET_ACC(JSTaggedValue(static_cast<int32_t>(ret)));
1476     } else if (left.IsNumber() && right.IsNumber()) {
1477         int32_t opNumber0 =
1478             left.IsInt() ? left.GetInt() : base::NumberHelper::DoubleToInt(left.GetDouble(), base::INT32_BITS);
1479         int32_t opNumber1 =
1480             right.IsInt() ? right.GetInt() : base::NumberHelper::DoubleToInt(right.GetDouble(), base::INT32_BITS);
1481         // NOLINT(hicpp-signed-bitwise)
1482         auto ret = static_cast<uint32_t>(opNumber0) | static_cast<uint32_t>(opNumber1);
1483         SET_ACC(JSTaggedValue(static_cast<int32_t>(ret)));
1484     } else {
1485         // slow path
1486         SAVE_PC();
1487         JSTaggedValue res = SlowRuntimeStub::Or2(thread, left, right);
1488         INTERPRETER_RETURN_IF_ABRUPT(res);
1489         SET_ACC(res);
1490     }
1491     DISPATCH(OR2_IMM8_V8);
1492 }
1493 
HandleXor2Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1494 void InterpreterAssembly::HandleXor2Imm8V8(
1495     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1496     JSTaggedValue acc, int16_t hotnessCounter)
1497 {
1498     uint16_t v0 = READ_INST_8_1();
1499 
1500     LOG_INST() << "intrinsics::xor2"
1501                << " v" << v0;
1502     JSTaggedValue left = GET_VREG_VALUE(v0);
1503     JSTaggedValue right = GET_ACC();
1504     // both number, fast path
1505     if (left.IsInt() && right.IsInt()) {
1506         int32_t opNumber0 = left.GetInt();
1507         int32_t opNumber1 = right.GetInt();
1508         // NOLINT(hicpp-signed-bitwise)
1509         auto ret = static_cast<uint32_t>(opNumber0) ^ static_cast<uint32_t>(opNumber1);
1510         SET_ACC(JSTaggedValue(static_cast<int32_t>(ret)));
1511     } else if (left.IsNumber() && right.IsNumber()) {
1512         int32_t opNumber0 =
1513             left.IsInt() ? left.GetInt() : base::NumberHelper::DoubleToInt(left.GetDouble(), base::INT32_BITS);
1514         int32_t opNumber1 =
1515             right.IsInt() ? right.GetInt() : base::NumberHelper::DoubleToInt(right.GetDouble(), base::INT32_BITS);
1516         // NOLINT(hicpp-signed-bitwise)
1517         auto ret = static_cast<uint32_t>(opNumber0) ^ static_cast<uint32_t>(opNumber1);
1518         SET_ACC(JSTaggedValue(static_cast<int32_t>(ret)));
1519     } else {
1520         // slow path
1521         SAVE_PC();
1522         JSTaggedValue res = SlowRuntimeStub::Xor2(thread, left, right);
1523         INTERPRETER_RETURN_IF_ABRUPT(res);
1524         SET_ACC(res);
1525     }
1526     DISPATCH(XOR2_IMM8_V8);
1527 }
1528 
HandleDelobjpropV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1529 void InterpreterAssembly::HandleDelobjpropV8(
1530     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1531     JSTaggedValue acc, int16_t hotnessCounter)
1532 {
1533     uint16_t v0 = READ_INST_8_0();
1534     LOG_INST() << "intrinsics::delobjprop"
1535                << " v0" << v0;
1536 
1537     JSTaggedValue obj = GET_VREG_VALUE(v0);
1538     JSTaggedValue prop = GET_ACC();
1539     SAVE_PC();
1540     JSTaggedValue res = SlowRuntimeStub::DelObjProp(thread, obj, prop);
1541     INTERPRETER_RETURN_IF_ABRUPT(res);
1542     SET_ACC(res);
1543 
1544     DISPATCH(DELOBJPROP_V8);
1545 }
1546 
HandleExpImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1547 void InterpreterAssembly::HandleExpImm8V8(
1548     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1549     JSTaggedValue acc, int16_t hotnessCounter)
1550 {
1551     uint16_t v0 = READ_INST_8_1();
1552     LOG_INST() << "intrinsics::exp"
1553                << " v" << v0;
1554     JSTaggedValue base = GET_VREG_VALUE(v0);
1555     JSTaggedValue exponent = GET_ACC();
1556     if (base.IsNumber() && exponent.IsNumber()) {
1557         // fast path
1558         double doubleBase = base.IsInt() ? base.GetInt() : base.GetDouble();
1559         double doubleExponent = exponent.IsInt() ? exponent.GetInt() : exponent.GetDouble();
1560         if ((std::abs(doubleBase) == 1 && std::isinf(doubleExponent)) || std::isnan(doubleExponent)) {
1561             SET_ACC(JSTaggedValue(base::NAN_VALUE));
1562         }
1563         bool baseZero = doubleBase == 0 &&
1564             (base::bit_cast<uint64_t>(doubleBase) & base::DOUBLE_SIGN_MASK) == base::DOUBLE_SIGN_MASK;
1565         bool isFinite = std::isfinite(doubleExponent);
1566         bool truncEqual = base::NumberHelper::TruncateDouble(doubleExponent) == doubleExponent;
1567         bool halfTruncEqual = (base::NumberHelper::TruncateDouble(doubleExponent / 2) + base::HALF) ==
1568                                 (doubleExponent / 2);
1569         if (baseZero && isFinite && truncEqual && halfTruncEqual) {
1570             if (doubleExponent > 0) {
1571                 SET_ACC(JSTaggedValue(-0.0));
1572             }
1573             if (doubleExponent < 0) {
1574                 SET_ACC(JSTaggedValue(-base::POSITIVE_INFINITY));
1575             }
1576         }
1577         SET_ACC(JSTaggedValue(std::pow(doubleBase, doubleExponent)));
1578     } else {
1579         // slow path
1580         SAVE_PC();
1581         JSTaggedValue res = SlowRuntimeStub::Exp(thread, base, exponent);
1582         INTERPRETER_RETURN_IF_ABRUPT(res);
1583         SET_ACC(res);
1584     }
1585     DISPATCH(EXP_IMM8_V8);
1586 }
1587 
HandleIsinImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1588 void InterpreterAssembly::HandleIsinImm8V8(
1589     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1590     JSTaggedValue acc, int16_t hotnessCounter)
1591 {
1592     uint16_t v0 = READ_INST_8_1();
1593     LOG_INST() << "intrinsics::isin"
1594                << " v" << v0;
1595     JSTaggedValue prop = GET_VREG_VALUE(v0);
1596     JSTaggedValue obj = GET_ACC();
1597     SAVE_PC();
1598     JSTaggedValue res = SlowRuntimeStub::IsIn(thread, prop, obj);
1599     INTERPRETER_RETURN_IF_ABRUPT(res);
1600     SET_ACC(res);
1601     DISPATCH(ISIN_IMM8_V8);
1602 }
1603 
HandleInstanceofImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1604 void InterpreterAssembly::HandleInstanceofImm8V8(
1605     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1606     JSTaggedValue acc, int16_t hotnessCounter)
1607 {
1608     uint16_t v0 = READ_INST_8_1();
1609     LOG_INST() << "intrinsics::instanceof"
1610                << " v" << v0;
1611     JSTaggedValue obj = GET_VREG_VALUE(v0);
1612     JSTaggedValue target = GET_ACC();
1613     SAVE_PC();
1614     JSTaggedValue res = SlowRuntimeStub::Instanceof(thread, obj, target);
1615     INTERPRETER_RETURN_IF_ABRUPT(res);
1616     SET_ACC(res);
1617     DISPATCH(INSTANCEOF_IMM8_V8);
1618 }
1619 
HandleStrictnoteqImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1620 void InterpreterAssembly::HandleStrictnoteqImm8V8(
1621     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1622     JSTaggedValue acc, int16_t hotnessCounter)
1623 {
1624     uint16_t v0 = READ_INST_8_1();
1625     LOG_INST() << "intrinsics::strictnoteq"
1626                << " v" << v0;
1627     JSTaggedValue left = GET_VREG_VALUE(v0);
1628     JSTaggedValue right = GET_ACC();
1629     JSTaggedValue res = FastRuntimeStub::FastStrictEqual(thread, left, right);
1630     if (!res.IsHole()) {
1631         res = res.IsTrue() ? JSTaggedValue::False() : JSTaggedValue::True();
1632         SET_ACC(res);
1633     } else {
1634         // slow path
1635         res = SlowRuntimeStub::NotEq(thread, left, right);
1636         INTERPRETER_RETURN_IF_ABRUPT(res);
1637         SET_ACC(res);
1638     }
1639     DISPATCH(STRICTNOTEQ_IMM8_V8);
1640 }
1641 
HandleStricteqImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1642 void InterpreterAssembly::HandleStricteqImm8V8(
1643     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1644     JSTaggedValue acc, int16_t hotnessCounter)
1645 {
1646     uint16_t v0 = READ_INST_8_1();
1647     LOG_INST() << "intrinsics::stricteq"
1648                << " v" << v0;
1649     JSTaggedValue left = GET_VREG_VALUE(v0);
1650     JSTaggedValue right = GET_ACC();
1651     JSTaggedValue res = FastRuntimeStub::FastStrictEqual(thread, left, right);
1652     if (!res.IsHole()) {
1653         SET_ACC(res);
1654     } else {
1655         // slow path
1656         res = SlowRuntimeStub::Eq(thread, left, right);
1657         INTERPRETER_RETURN_IF_ABRUPT(res);
1658         SET_ACC(res);
1659     }
1660     DISPATCH(STRICTEQ_IMM8_V8);
1661 }
1662 
HandleLdlexvarImm8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1663 void InterpreterAssembly::HandleLdlexvarImm8Imm8(
1664     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1665     JSTaggedValue acc, int16_t hotnessCounter)
1666 {
1667     uint16_t level = READ_INST_8_0();
1668     uint16_t slot = READ_INST_8_1();
1669 
1670     LOG_INST() << "intrinsics::ldlexvar"
1671                << " level:" << level << " slot:" << slot;
1672     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
1673     JSTaggedValue currentLexenv = state->env;
1674     JSTaggedValue env(currentLexenv);
1675     for (uint32_t i = 0; i < level; i++) {
1676         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
1677         ASSERT(!taggedParentEnv.IsUndefined());
1678         env = taggedParentEnv;
1679     }
1680     SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot));
1681     DISPATCH(LDLEXVAR_IMM8_IMM8);
1682 }
1683 
HandleLdlexvarImm4Imm4(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1684 void InterpreterAssembly::HandleLdlexvarImm4Imm4(
1685     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1686     JSTaggedValue acc, int16_t hotnessCounter)
1687 {
1688     uint16_t level = READ_INST_4_0();
1689     uint16_t slot = READ_INST_4_1();
1690 
1691     LOG_INST() << "intrinsics::ldlexvar"
1692                << " level:" << level << " slot:" << slot;
1693     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
1694     JSTaggedValue currentLexenv = state->env;
1695     JSTaggedValue env(currentLexenv);
1696     for (uint32_t i = 0; i < level; i++) {
1697         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
1698         ASSERT(!taggedParentEnv.IsUndefined());
1699         env = taggedParentEnv;
1700     }
1701     SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot));
1702     DISPATCH(LDLEXVAR_IMM4_IMM4);
1703 }
1704 
HandleWideStlexvarPrefImm16Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1705 void InterpreterAssembly::HandleWideStlexvarPrefImm16Imm16(
1706     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1707     JSTaggedValue acc, int16_t hotnessCounter)
1708 {
1709     uint16_t level = READ_INST_16_1();
1710     uint16_t slot = READ_INST_16_3();
1711     LOG_INST() << "intrinsics::stlexvar"
1712                << " level:" << level << " slot:" << slot;
1713 
1714     JSTaggedValue value = GET_ACC();
1715     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
1716     JSTaggedValue env = state->env;
1717     for (uint32_t i = 0; i < level; i++) {
1718         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
1719         ASSERT(!taggedParentEnv.IsUndefined());
1720         env = taggedParentEnv;
1721     }
1722     LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
1723 
1724     DISPATCH(WIDE_STLEXVAR_PREF_IMM16_IMM16);
1725 }
1726 
HandleStlexvarImm8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1727 void InterpreterAssembly::HandleStlexvarImm8Imm8(
1728     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1729     JSTaggedValue acc, int16_t hotnessCounter)
1730 {
1731     uint16_t level = READ_INST_8_0();
1732     uint16_t slot = READ_INST_8_1();
1733     LOG_INST() << "intrinsics::stlexvar"
1734                << " level:" << level << " slot:" << slot;
1735 
1736     JSTaggedValue value = GET_ACC();
1737     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
1738     JSTaggedValue env = state->env;
1739     for (uint32_t i = 0; i < level; i++) {
1740         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
1741         ASSERT(!taggedParentEnv.IsUndefined());
1742         env = taggedParentEnv;
1743     }
1744     LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
1745 
1746     DISPATCH(STLEXVAR_IMM8_IMM8);
1747 }
1748 
HandleStlexvarImm4Imm4(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1749 void InterpreterAssembly::HandleStlexvarImm4Imm4(
1750     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1751     JSTaggedValue acc, int16_t hotnessCounter)
1752 {
1753     uint16_t level = READ_INST_4_0();
1754     uint16_t slot = READ_INST_4_1();
1755     LOG_INST() << "intrinsics::stlexvar"
1756                << " level:" << level << " slot:" << slot;
1757 
1758     JSTaggedValue value = GET_ACC();
1759     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
1760     JSTaggedValue env = state->env;
1761     for (uint32_t i = 0; i < level; i++) {
1762         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
1763         ASSERT(!taggedParentEnv.IsUndefined());
1764         env = taggedParentEnv;
1765     }
1766     LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
1767 
1768     DISPATCH(STLEXVAR_IMM4_IMM4);
1769 }
1770 
HandleNewlexenvImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1771 void InterpreterAssembly::HandleNewlexenvImm8(
1772     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1773     JSTaggedValue acc, int16_t hotnessCounter)
1774 {
1775     uint8_t numVars = READ_INST_8_0();
1776     LOG_INST() << "intrinsics::newlexenv"
1777                << " imm " << numVars;
1778     EcmaVM *ecmaVm = thread->GetEcmaVM();
1779     ObjectFactory *factory = ecmaVm->GetFactory();
1780     JSTaggedValue res = FastRuntimeStub::NewLexicalEnv(thread, factory, numVars);
1781     if (res.IsHole()) {
1782         res = SlowRuntimeStub::NewLexicalEnv(thread, numVars);
1783         INTERPRETER_RETURN_IF_ABRUPT(res);
1784     }
1785     SET_ACC(res);
1786     GET_ASM_FRAME(sp)->env = res;
1787     DISPATCH(NEWLEXENV_IMM8);
1788 }
1789 
HandlePoplexenv(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1790 void InterpreterAssembly::HandlePoplexenv(
1791     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1792     JSTaggedValue acc, int16_t hotnessCounter)
1793 {
1794     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
1795     JSTaggedValue currentLexenv = state->env;
1796     JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(thread);
1797     GET_ASM_FRAME(sp)->env = parentLexenv;
1798     DISPATCH(POPLEXENV);
1799 }
1800 
HandleCreateiterresultobjV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1801 void InterpreterAssembly::HandleCreateiterresultobjV8V8(
1802     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1803     JSTaggedValue acc, int16_t hotnessCounter)
1804 {
1805     uint16_t v0 = READ_INST_8_0();
1806     uint16_t v1 = READ_INST_8_1();
1807     LOG_INST() << "intrinsics::createiterresultobj"
1808                << " v" << v0 << " v" << v1;
1809     JSTaggedValue value = GET_VREG_VALUE(v0);
1810     JSTaggedValue flag = GET_VREG_VALUE(v1);
1811     SAVE_PC();
1812     JSTaggedValue res = SlowRuntimeStub::CreateIterResultObj(thread, value, flag);
1813     INTERPRETER_RETURN_IF_ABRUPT(res);
1814     SET_ACC(res);
1815     DISPATCH(CREATEITERRESULTOBJ_V8_V8);
1816 }
1817 
HandleSuspendgeneratorV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1818 void InterpreterAssembly::HandleSuspendgeneratorV8(
1819     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1820     JSTaggedValue acc, int16_t hotnessCounter)
1821 {
1822     uint16_t v0 = READ_INST_8_0();
1823     LOG_INST() << "intrinsics::suspendgenerator"
1824                 << " v" << v0;
1825     JSTaggedValue genObj = GET_VREG_VALUE(v0);
1826     JSTaggedValue value = GET_ACC();
1827     // suspend will record bytecode offset
1828     SAVE_PC();
1829     SAVE_ACC();
1830     JSTaggedValue res = SlowRuntimeStub::SuspendGenerator(thread, genObj, value);
1831     INTERPRETER_RETURN_IF_ABRUPT(res);
1832     SET_ACC(res);
1833 
1834     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
1835     Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
1836     [[maybe_unused]] auto fistPC = method->GetBytecodeArray();
1837     UPDATE_HOTNESS_COUNTER(-(pc - fistPC));
1838     LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
1839                             << std::hex << reinterpret_cast<uintptr_t>(state->pc);
1840     sp = state->base.prev;
1841     ASSERT(sp != nullptr);
1842 
1843     AsmInterpretedFrame *prevState = GET_ASM_FRAME(sp);
1844     pc = prevState->pc;
1845     thread->SetCurrentSPFrame(sp);
1846     // entry frame
1847     if (pc == nullptr) {
1848         state->acc = acc;
1849         return;
1850     }
1851 
1852     ASSERT(prevState->callSize == GetJumpSizeAfterCall(pc));
1853     DISPATCH_OFFSET(prevState->callSize);
1854 }
1855 
HandleAsyncfunctionawaituncaughtV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1856 void InterpreterAssembly::HandleAsyncfunctionawaituncaughtV8(
1857     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1858     JSTaggedValue acc, int16_t hotnessCounter)
1859 {
1860     uint16_t v0 = READ_INST_8_0();
1861     LOG_INST() << "intrinsics::asyncfunctionawaituncaught"
1862                << " v" << v0;
1863     JSTaggedValue asyncFuncObj = GET_VREG_VALUE(v0);
1864     JSTaggedValue value = GET_ACC();
1865     SAVE_PC();
1866     JSTaggedValue res = SlowRuntimeStub::AsyncFunctionAwaitUncaught(thread, asyncFuncObj, value);
1867     INTERPRETER_RETURN_IF_ABRUPT(res);
1868     SET_ACC(res);
1869     DISPATCH(ASYNCFUNCTIONAWAITUNCAUGHT_V8);
1870 }
1871 
HandleAsyncfunctionresolveV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1872 void InterpreterAssembly::HandleAsyncfunctionresolveV8(
1873     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1874     JSTaggedValue acc, int16_t hotnessCounter)
1875 {
1876     uint16_t v0 = READ_INST_8_0();
1877     LOG_INST() << "intrinsics::asyncfunctionresolve"
1878                 << " v" << v0;
1879 
1880     JSTaggedValue asyncFuncObj = GET_VREG_VALUE(v0);
1881     JSTaggedValue value = GET_ACC();
1882     SAVE_PC();
1883     JSTaggedValue res = SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, asyncFuncObj, value, true);
1884     INTERPRETER_RETURN_IF_ABRUPT(res);
1885     SET_ACC(res);
1886     DISPATCH(ASYNCFUNCTIONRESOLVE_V8);
1887 }
1888 
HandleAsyncfunctionrejectV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1889 void InterpreterAssembly::HandleAsyncfunctionrejectV8(
1890     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1891     JSTaggedValue acc, int16_t hotnessCounter)
1892 {
1893         uint16_t v0 = READ_INST_8_0();
1894         LOG_INST() << "intrinsics::asyncfunctionreject"
1895                    << " v" << v0;
1896 
1897         JSTaggedValue asyncFuncObj = GET_VREG_VALUE(v0);
1898         JSTaggedValue value = GET_ACC();
1899         SAVE_PC();
1900         JSTaggedValue res = SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, asyncFuncObj, value, false);
1901         INTERPRETER_RETURN_IF_ABRUPT(res);
1902         SET_ACC(res);
1903         DISPATCH(ASYNCFUNCTIONREJECT_V8);
1904 }
1905 
HandleNewobjapplyImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1906 void InterpreterAssembly::HandleNewobjapplyImm8V8(
1907     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1908     JSTaggedValue acc, int16_t hotnessCounter)
1909 {
1910     uint16_t v0 = READ_INST_8_1();
1911     LOG_INST() << "intrinsic::newobjspeard"
1912                << " v" << v0;
1913     JSTaggedValue func = GET_VREG_VALUE(v0);
1914     JSTaggedValue array = GET_ACC();
1915     SAVE_PC();
1916     JSTaggedValue res = SlowRuntimeStub::NewObjApply(thread, func, array);
1917     INTERPRETER_RETURN_IF_ABRUPT(res);
1918     SET_ACC(res);
1919     DISPATCH(NEWOBJAPPLY_IMM8_V8);
1920 }
1921 
HandleThrowUndefinedifholePrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1922 void InterpreterAssembly::HandleThrowUndefinedifholePrefV8V8(
1923     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1924     JSTaggedValue acc, int16_t hotnessCounter)
1925 {
1926     uint16_t v0 = READ_INST_8_1();
1927     uint16_t v1 = READ_INST_8_2();
1928     LOG_INST() << "intrinsic::throwundefinedifhole"
1929                << " v" << v0 << " v" << v1;
1930     JSTaggedValue hole = GET_VREG_VALUE(v0);
1931     if (!hole.IsHole()) {
1932         DISPATCH(THROW_UNDEFINEDIFHOLE_PREF_V8_V8);
1933     }
1934     JSTaggedValue obj = GET_VREG_VALUE(v1);
1935     ASSERT(obj.IsString());
1936     SAVE_PC();
1937     SlowRuntimeStub::ThrowUndefinedIfHole(thread, obj);
1938     INTERPRETER_GOTO_EXCEPTION_HANDLER();
1939 }
1940 
HandleThrowUndefinedifholewithnamePrefId16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1941 void InterpreterAssembly::HandleThrowUndefinedifholewithnamePrefId16(
1942     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1943     JSTaggedValue acc, int16_t hotnessCounter)
1944 {
1945     JSTaggedValue hole = acc;
1946     if (!hole.IsHole()) {
1947         DISPATCH(THROW_UNDEFINEDIFHOLEWITHNAME_PREF_ID16);
1948     }
1949 
1950     uint16_t stringId = READ_INST_16_1();
1951     LOG_INST() << "intrinsic::throwundefinedifholewithname" << std::hex << stringId;
1952     constpool = GetConstantPool(thread, sp);
1953     JSTaggedValue obj = ConstantPool::GetStringFromCache(thread, constpool, stringId);
1954     ASSERT(obj.IsString());
1955     SAVE_PC();
1956     SlowRuntimeStub::ThrowUndefinedIfHole(thread, obj);
1957     INTERPRETER_GOTO_EXCEPTION_HANDLER();
1958 }
1959 
HandleStownbynameImm8Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)1960 void InterpreterAssembly::HandleStownbynameImm8Id16V8(
1961     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
1962     JSTaggedValue acc, int16_t hotnessCounter)
1963 {
1964     uint16_t stringId = READ_INST_16_1();
1965     uint32_t v0 = READ_INST_8_3();
1966     LOG_INST() << "intrinsics::stownbyname "
1967                << "v" << v0 << " stringId:" << stringId;
1968 
1969     JSTaggedValue receiver = GET_VREG_VALUE(v0);
1970     if (receiver.IsJSObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
1971         SAVE_ACC();
1972         constpool = GetConstantPool(thread, sp);
1973         JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
1974         RESTORE_ACC();
1975         JSTaggedValue value = GET_ACC();
1976         // fast path
1977         SAVE_ACC();
1978         receiver = GET_VREG_VALUE(v0);
1979         JSTaggedValue res = FastRuntimeStub::SetPropertyByName<ObjectFastOperator::Status::UseOwn>
1980                             (thread, receiver, propKey, value);
1981         if (!res.IsHole()) {
1982             INTERPRETER_RETURN_IF_ABRUPT(res);
1983             RESTORE_ACC();
1984             DISPATCH(STOWNBYNAME_IMM8_ID16_V8);
1985         }
1986         RESTORE_ACC();
1987     }
1988 
1989     SAVE_ACC();
1990     constpool = GetConstantPool(thread, sp);
1991     auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);  // Maybe moved by GC
1992     RESTORE_ACC();
1993     auto value = GET_ACC();                                  // Maybe moved by GC
1994     receiver = GET_VREG_VALUE(v0);                           // Maybe moved by GC
1995     JSTaggedValue res = SlowRuntimeStub::StOwnByName(thread, receiver, propKey, value);
1996     RESTORE_ACC();
1997     INTERPRETER_RETURN_IF_ABRUPT(res);
1998     DISPATCH(STOWNBYNAME_IMM8_ID16_V8);
1999 }
2000 
HandleCreateemptyarrayImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2001 void InterpreterAssembly::HandleCreateemptyarrayImm8(
2002     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2003     JSTaggedValue acc, int16_t hotnessCounter)
2004 {
2005     LOG_INST() << "intrinsics::createemptyarray";
2006     SAVE_PC();
2007     EcmaVM *ecmaVm = thread->GetEcmaVM();
2008     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
2009     ObjectFactory *factory = ecmaVm->GetFactory();
2010     JSTaggedValue res = SlowRuntimeStub::CreateEmptyArray(thread, factory, globalEnv);
2011     SET_ACC(res);
2012     DISPATCH(CREATEEMPTYARRAY_IMM8);
2013 }
2014 
HandleCreateemptyobject(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2015 void InterpreterAssembly::HandleCreateemptyobject(
2016     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2017     JSTaggedValue acc, int16_t hotnessCounter)
2018 {
2019     LOG_INST() << "intrinsics::createemptyobject";
2020     SAVE_PC();
2021     EcmaVM *ecmaVm = thread->GetEcmaVM();
2022     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
2023     ObjectFactory *factory = ecmaVm->GetFactory();
2024     JSTaggedValue res = SlowRuntimeStub::CreateEmptyObject(thread, factory, globalEnv);
2025     SET_ACC(res);
2026     DISPATCH(CREATEEMPTYOBJECT);
2027 }
2028 
HandleSetobjectwithprotoImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2029 void InterpreterAssembly::HandleSetobjectwithprotoImm8V8(
2030     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2031     JSTaggedValue acc, int16_t hotnessCounter)
2032 {
2033     uint16_t v0 = READ_INST_8_1();
2034     LOG_INST() << "intrinsics::setobjectwithproto"
2035                << " v" << v0;
2036     JSTaggedValue proto = GET_VREG_VALUE(v0);
2037     JSTaggedValue obj = GET_ACC();
2038     SAVE_ACC();
2039     SAVE_PC();
2040     JSTaggedValue res = SlowRuntimeStub::SetObjectWithProto(thread, proto, obj);
2041     INTERPRETER_RETURN_IF_ABRUPT(res);
2042     RESTORE_ACC();
2043     DISPATCH(SETOBJECTWITHPROTO_IMM8_V8);
2044 }
2045 
HandleCreateregexpwithliteralImm8Id16Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2046 void InterpreterAssembly::HandleCreateregexpwithliteralImm8Id16Imm8(
2047     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2048     JSTaggedValue acc, int16_t hotnessCounter)
2049 {
2050     uint16_t stringId = READ_INST_16_1();
2051     SAVE_ACC();
2052     constpool = GetConstantPool(thread, sp);
2053     JSTaggedValue pattern = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2054     uint8_t flags = READ_INST_8_3();
2055     LOG_INST() << "intrinsics::createregexpwithliteral "
2056                << "stringId:" << stringId << ", "
2057                << ConvertToString(thread, EcmaString::Cast(pattern.GetTaggedObject()))
2058                << ", flags:" << flags;
2059     JSTaggedValue res = SlowRuntimeStub::CreateRegExpWithLiteral(thread, pattern, flags);
2060     INTERPRETER_RETURN_IF_ABRUPT(res);
2061     SET_ACC(res);
2062     DISPATCH(CREATEREGEXPWITHLITERAL_IMM8_ID16_IMM8);
2063 }
2064 
HandleGettemplateobjectImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2065 void InterpreterAssembly::HandleGettemplateobjectImm8(
2066     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2067     JSTaggedValue acc, int16_t hotnessCounter)
2068 {
2069     LOG_INST() << "intrinsic::gettemplateobject";
2070 
2071     JSTaggedValue literal = GET_ACC();
2072     SAVE_PC();
2073     JSTaggedValue res = SlowRuntimeStub::GetTemplateObject(thread, literal);
2074     INTERPRETER_RETURN_IF_ABRUPT(res);
2075     SET_ACC(res);
2076     DISPATCH(GETTEMPLATEOBJECT_IMM8);
2077 }
2078 
HandleGetnextpropnameV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2079 void InterpreterAssembly::HandleGetnextpropnameV8(
2080     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2081     JSTaggedValue acc, int16_t hotnessCounter)
2082 {
2083     uint16_t v0 = READ_INST_8_0();
2084     LOG_INST() << "intrinsic::getnextpropname"
2085                 << " v" << v0;
2086     JSTaggedValue iter = GET_VREG_VALUE(v0);
2087     SAVE_PC();
2088     JSTaggedValue res = SlowRuntimeStub::GetNextPropName(thread, iter);
2089     INTERPRETER_RETURN_IF_ABRUPT(res);
2090     SET_ACC(res);
2091     DISPATCH(GETNEXTPROPNAME_V8);
2092 }
2093 
HandleCopydatapropertiesV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2094 void InterpreterAssembly::HandleCopydatapropertiesV8(
2095     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2096     JSTaggedValue acc, int16_t hotnessCounter)
2097 {
2098     uint16_t v0 = READ_INST_8_0();
2099     LOG_INST() << "intrinsic::copydataproperties"
2100                << " v" << v0;
2101     JSTaggedValue dst = GET_VREG_VALUE(v0);
2102     JSTaggedValue src = GET_ACC();
2103     SAVE_PC();
2104     JSTaggedValue res = SlowRuntimeStub::CopyDataProperties(thread, dst, src);
2105     INTERPRETER_RETURN_IF_ABRUPT(res);
2106     SET_ACC(res);
2107     DISPATCH(COPYDATAPROPERTIES_V8);
2108 }
2109 
HandleStownbyindexImm8V8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2110 void InterpreterAssembly::HandleStownbyindexImm8V8Imm16(
2111     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2112     JSTaggedValue acc, int16_t hotnessCounter)
2113 {
2114     uint32_t v0 = READ_INST_8_1();
2115     uint16_t index = READ_INST_16_2();
2116     LOG_INST() << "intrinsics::stownbyindex"
2117                << " v" << v0 << " imm" << index;
2118     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2119     // fast path
2120     if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
2121         SAVE_ACC();
2122         JSTaggedValue value = GET_ACC();
2123         // fast path
2124         JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex<ObjectFastOperator::Status::UseOwn>
2125                             (thread, receiver, index, value);
2126         if (!res.IsHole()) {
2127             INTERPRETER_RETURN_IF_ABRUPT(res);
2128             RESTORE_ACC();
2129             DISPATCH(STOWNBYINDEX_IMM8_V8_IMM16);
2130         }
2131         RESTORE_ACC();
2132     }
2133     SAVE_ACC();
2134     receiver = GET_VREG_VALUE(v0);  // Maybe moved by GC
2135     auto value = GET_ACC();         // Maybe moved by GC
2136     SAVE_PC();
2137     JSTaggedValue res = SlowRuntimeStub::StOwnByIndex(thread, receiver, index, value);
2138     INTERPRETER_RETURN_IF_ABRUPT(res);
2139     RESTORE_ACC();
2140     DISPATCH(STOWNBYINDEX_IMM8_V8_IMM16);
2141 }
2142 
HandleStownbyvalueImm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2143 void InterpreterAssembly::HandleStownbyvalueImm8V8V8(
2144     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2145     JSTaggedValue acc, int16_t hotnessCounter)
2146 {
2147     uint32_t v0 = READ_INST_8_1();
2148     uint32_t v1 = READ_INST_8_2();
2149     LOG_INST() << "intrinsics::stownbyvalue"
2150                << " v" << v0 << " v" << v1;
2151 
2152     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2153     if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
2154         SAVE_ACC();
2155         JSTaggedValue propKey = GET_VREG_VALUE(v1);
2156         JSTaggedValue value = GET_ACC();
2157         // fast path
2158         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue<ObjectFastOperator::Status::UseOwn>
2159                             (thread, receiver, propKey, value);
2160 
2161         // SetPropertyByValue maybe gc need update the value
2162         RESTORE_ACC();
2163         propKey = GET_VREG_VALUE(v1);
2164         value = GET_ACC();
2165         if (!res.IsHole()) {
2166             INTERPRETER_RETURN_IF_ABRUPT(res);
2167             RESTORE_ACC();
2168             DISPATCH(STOWNBYVALUE_IMM8_V8_V8);
2169         }
2170     }
2171 
2172     // slow path
2173     SAVE_ACC();
2174     receiver = GET_VREG_VALUE(v0);      // Maybe moved by GC
2175     auto propKey = GET_VREG_VALUE(v1);  // Maybe moved by GC
2176     auto value = GET_ACC();             // Maybe moved by GC
2177     SAVE_PC();
2178     JSTaggedValue res = SlowRuntimeStub::StOwnByValue(thread, receiver, propKey, value);
2179     RESTORE_ACC();
2180     INTERPRETER_RETURN_IF_ABRUPT(res);
2181     DISPATCH(STOWNBYVALUE_IMM8_V8_V8);
2182 }
2183 
HandleCreateobjectwithexcludedkeysImm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2184 void InterpreterAssembly::HandleCreateobjectwithexcludedkeysImm8V8V8(
2185     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2186     JSTaggedValue acc, int16_t hotnessCounter)
2187 {
2188     uint8_t numKeys = READ_INST_8_0();
2189     uint16_t v0 = READ_INST_8_1();
2190     uint16_t firstArgRegIdx = READ_INST_8_2();
2191     LOG_INST() << "intrinsics::createobjectwithexcludedkeys " << numKeys << " v" << firstArgRegIdx;
2192 
2193     JSTaggedValue obj = GET_VREG_VALUE(v0);
2194 
2195     SAVE_PC();
2196     JSTaggedValue res = SlowRuntimeStub::CreateObjectWithExcludedKeys(thread, numKeys, obj, firstArgRegIdx);
2197     INTERPRETER_RETURN_IF_ABRUPT(res);
2198     SET_ACC(res);
2199     DISPATCH(CREATEOBJECTWITHEXCLUDEDKEYS_IMM8_V8_V8);
2200 }
2201 
HandleLdhole(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2202 void InterpreterAssembly::HandleLdhole(
2203     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2204     JSTaggedValue acc, int16_t hotnessCounter)
2205 {
2206     LOG_INST() << "intrinsic::ldhole";
2207     SET_ACC(JSTaggedValue::Hole());
2208     DISPATCH(LDHOLE);
2209 }
2210 
HandleCopyrestargsImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2211 void InterpreterAssembly::HandleCopyrestargsImm8(
2212     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2213     JSTaggedValue acc, int16_t hotnessCounter)
2214 {
2215     uint16_t restIdx = READ_INST_8_0();
2216     LOG_INST() << "intrinsics::copyrestargs"
2217                << " index: " << restIdx;
2218 
2219     uint32_t startIdx = 0;
2220     uint32_t restNumArgs = GetNumArgs(thread, sp, restIdx, startIdx);
2221 
2222     JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, sp, restNumArgs, startIdx);
2223     INTERPRETER_RETURN_IF_ABRUPT(res);
2224     SET_ACC(res);
2225     DISPATCH(COPYRESTARGS_IMM8);
2226 }
2227 
HandleDefinegettersetterbyvalueV8V8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2228 void InterpreterAssembly::HandleDefinegettersetterbyvalueV8V8V8V8(
2229     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2230     JSTaggedValue acc, int16_t hotnessCounter)
2231 {
2232     uint16_t v0 = READ_INST_8_0();
2233     uint16_t v1 = READ_INST_8_1();
2234     uint16_t v2 = READ_INST_8_2();
2235     uint16_t v3 = READ_INST_8_3();
2236     LOG_INST() << "intrinsics::definegettersetterbyvalue"
2237                << " v" << v0 << " v" << v1 << " v" << v2 << " v" << v3;
2238 
2239     JSTaggedValue obj = GET_VREG_VALUE(v0);
2240     JSTaggedValue prop = GET_VREG_VALUE(v1);
2241     JSTaggedValue getter = GET_VREG_VALUE(v2);
2242     JSTaggedValue setter = GET_VREG_VALUE(v3);
2243     JSTaggedValue flag = GET_ACC();
2244     SAVE_PC();
2245     JSTaggedValue res =
2246         SlowRuntimeStub::DefineGetterSetterByValue(thread, obj, prop, getter, setter, flag.ToBoolean());
2247     INTERPRETER_RETURN_IF_ABRUPT(res);
2248     SET_ACC(res);
2249     DISPATCH(DEFINEGETTERSETTERBYVALUE_V8_V8_V8_V8);
2250 }
2251 
HandleStobjbyindexImm8V8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2252 void InterpreterAssembly::HandleStobjbyindexImm8V8Imm16(
2253     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2254     JSTaggedValue acc, int16_t hotnessCounter)
2255 {
2256     uint16_t v0 = READ_INST_8_1();
2257     uint32_t index = READ_INST_16_2();
2258     LOG_INST() << "intrinsics::stobjbyindex"
2259                 << " v" << v0 << " imm" << index;
2260 
2261     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2262     if (receiver.IsHeapObject()) {
2263         SAVE_ACC();
2264         JSTaggedValue value = GET_ACC();
2265         // fast path
2266         JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex(thread, receiver, index, value);
2267         if (!res.IsHole()) {
2268             INTERPRETER_RETURN_IF_ABRUPT(res);
2269             RESTORE_ACC();
2270             DISPATCH(STOBJBYINDEX_IMM8_V8_IMM16);
2271         }
2272         RESTORE_ACC();
2273     }
2274     // slow path
2275     SAVE_ACC();
2276     SAVE_PC();
2277     receiver = GET_VREG_VALUE(v0);    // Maybe moved by GC
2278     JSTaggedValue value = GET_ACC();  // Maybe moved by GC
2279     JSTaggedValue res = SlowRuntimeStub::StObjByIndex(thread, receiver, index, value);
2280     INTERPRETER_RETURN_IF_ABRUPT(res);
2281     RESTORE_ACC();
2282     DISPATCH(STOBJBYINDEX_IMM8_V8_IMM16);
2283 }
2284 
HandleStobjbyvalueImm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2285 void InterpreterAssembly::HandleStobjbyvalueImm8V8V8(
2286     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2287     JSTaggedValue acc, int16_t hotnessCounter)
2288 {
2289     uint32_t v0 = READ_INST_8_1();
2290     uint32_t v1 = READ_INST_8_2();
2291 
2292     LOG_INST() << "intrinsics::stobjbyvalue"
2293                << " v" << v0 << " v" << v1;
2294 
2295     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2296 #if ECMASCRIPT_ENABLE_IC
2297     if (!profileTypeInfo.IsUndefined()) {
2298         uint16_t slotId = READ_INST_8_0();
2299         auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject());
2300         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
2301         JSTaggedValue propKey = GET_VREG_VALUE(v1);
2302         JSTaggedValue value = GET_ACC();
2303         JSTaggedValue res = JSTaggedValue::Hole();
2304         SAVE_ACC();
2305 
2306         if (LIKELY(firstValue.IsHeapObject())) {
2307             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
2308             res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value);
2309         }
2310         // IC miss and not enter the megamorphic state, store as polymorphic
2311         if (res.IsHole() && !firstValue.IsHole()) {
2312             res = ICRuntimeStub::StoreICByValue(thread,
2313                                                 profileTypeArray,
2314                                                 receiver, propKey, value, slotId);
2315         }
2316 
2317         if (LIKELY(!res.IsHole())) {
2318             INTERPRETER_RETURN_IF_ABRUPT(res);
2319             RESTORE_ACC();
2320             DISPATCH(STOBJBYVALUE_IMM8_V8_V8);
2321         }
2322     }
2323 #endif
2324     if (receiver.IsHeapObject()) {
2325         SAVE_ACC();
2326         JSTaggedValue propKey = GET_VREG_VALUE(v1);
2327         JSTaggedValue value = GET_ACC();
2328         // fast path
2329         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue(thread, receiver, propKey, value);
2330         if (!res.IsHole()) {
2331             INTERPRETER_RETURN_IF_ABRUPT(res);
2332             RESTORE_ACC();
2333             DISPATCH(STOBJBYVALUE_IMM8_V8_V8);
2334         }
2335         RESTORE_ACC();
2336     }
2337     {
2338         // slow path
2339         SAVE_ACC();
2340         SAVE_PC();
2341         receiver = GET_VREG_VALUE(v0);  // Maybe moved by GC
2342         JSTaggedValue propKey = GET_VREG_VALUE(v1);   // Maybe moved by GC
2343         JSTaggedValue value = GET_ACC();              // Maybe moved by GC
2344         JSTaggedValue res = SlowRuntimeStub::StObjByValue(thread, receiver, propKey, value);
2345         INTERPRETER_RETURN_IF_ABRUPT(res);
2346         RESTORE_ACC();
2347     }
2348     DISPATCH(STOBJBYVALUE_IMM8_V8_V8);
2349 }
2350 
HandleStsuperbyvalueImm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2351 void InterpreterAssembly::HandleStsuperbyvalueImm8V8V8(
2352     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2353     JSTaggedValue acc, int16_t hotnessCounter)
2354 {
2355     uint32_t v0 = READ_INST_8_1();
2356     uint32_t v1 = READ_INST_8_2();
2357 
2358     LOG_INST() << "intrinsics::stsuperbyvalue"
2359                << " v" << v0 << " v" << v1;
2360     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2361     JSTaggedValue propKey = GET_VREG_VALUE(v1);
2362     JSTaggedValue value = GET_ACC();
2363 
2364     // slow path
2365     SAVE_ACC();
2366     SAVE_PC();
2367     JSTaggedValue thisFunc = GetFunction(sp);
2368     JSTaggedValue res = SlowRuntimeStub::StSuperByValue(thread, receiver, propKey, value, thisFunc);
2369     INTERPRETER_RETURN_IF_ABRUPT(res);
2370     RESTORE_ACC();
2371     DISPATCH(STSUPERBYVALUE_IMM8_V8_V8);
2372 }
2373 
HandleTryldglobalbynameImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2374 void InterpreterAssembly::HandleTryldglobalbynameImm8Id16(
2375     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2376     JSTaggedValue acc, int16_t hotnessCounter)
2377 {
2378     uint16_t stringId = READ_INST_16_1();
2379     constpool = GetConstantPool(thread, sp);
2380     auto prop = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2381 
2382     EcmaVM *ecmaVm = thread->GetEcmaVM();
2383     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
2384     JSTaggedValue globalObj = globalEnv->GetGlobalObject();
2385 
2386     LOG_INST() << "intrinsics::tryldglobalbyname "
2387                << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject()));
2388 
2389 #if ECMSCRIPT_ENABLE_IC
2390     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
2391     auto tmpProfileTypeInfo = state->profileTypeInfo;
2392     if (!tmpProfileTypeInfo.IsUndefined()) {
2393         uint16_t slotId = READ_INST_8_0();
2394         JSTaggedValue res = ICRuntimeStub::LoadGlobalICByName(thread,
2395                                                               ProfileTypeInfo::Cast(
2396                                                                   tmpProfileTypeInfo.GetTaggedObject()),
2397                                                               globalObj, prop, slotId, true);
2398         INTERPRETER_RETURN_IF_ABRUPT(res);
2399         SET_ACC(res);
2400         DISPATCH(TRYLDGLOBALBYNAME_IMM8_ID16);
2401     }
2402 #endif
2403 
2404     // order: 1. global record 2. global object
2405     JSTaggedValue result = SlowRuntimeStub::LdGlobalRecord(thread, prop);
2406     if (!result.IsUndefined()) {
2407         SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread));
2408     } else {
2409         JSTaggedValue globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, prop);
2410         if (!globalResult.IsHole()) {
2411             SET_ACC(globalResult);
2412         } else {
2413             // slow path
2414             SAVE_PC();
2415             JSTaggedValue res = SlowRuntimeStub::TryLdGlobalByNameFromGlobalProto(thread, globalObj, prop);
2416             INTERPRETER_RETURN_IF_ABRUPT(res);
2417             SET_ACC(res);
2418         }
2419     }
2420 
2421     DISPATCH(TRYLDGLOBALBYNAME_IMM8_ID16);
2422 }
2423 
HandleTrystglobalbynameImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2424 void InterpreterAssembly::HandleTrystglobalbynameImm8Id16(
2425     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2426     JSTaggedValue acc, int16_t hotnessCounter)
2427 {
2428     uint16_t stringId = READ_INST_16_1();
2429     SAVE_ACC();
2430     constpool = GetConstantPool(thread, sp);
2431     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2432 
2433     EcmaVM *ecmaVm = thread->GetEcmaVM();
2434     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
2435     JSTaggedValue globalObj = globalEnv->GetGlobalObject();
2436 
2437     RESTORE_ACC();
2438     LOG_INST() << "intrinsics::trystglobalbyname"
2439                << " stringId:" << stringId << ", "
2440                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()));
2441 
2442 #if ECMSCRIPT_ENABLE_IC
2443     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
2444     auto tmpProfileTypeInfo = state->profileTypeInfo;
2445     if (!tmpProfileTypeInfo.IsUndefined()) {
2446         uint16_t slotId = READ_INST_8_0();
2447         JSTaggedValue value = GET_ACC();
2448         SAVE_ACC();
2449         JSTaggedValue res = ICRuntimeStub::StoreGlobalICByName(thread,
2450                                                                ProfileTypeInfo::Cast(
2451                                                                    tmpProfileTypeInfo.GetTaggedObject()),
2452                                                                globalObj, propKey, value, slotId, true);
2453         INTERPRETER_RETURN_IF_ABRUPT(res);
2454         RESTORE_ACC();
2455         DISPATCH(TRYSTGLOBALBYNAME_IMM8_ID16);
2456     }
2457 #endif
2458 
2459     auto recordResult = SlowRuntimeStub::LdGlobalRecord(thread, propKey);
2460     SAVE_PC();
2461     // 1. find from global record
2462     if (!recordResult.IsUndefined()) {
2463         JSTaggedValue value = GET_ACC();
2464         SAVE_ACC();
2465         JSTaggedValue res = SlowRuntimeStub::TryUpdateGlobalRecord(thread, propKey, value);
2466         INTERPRETER_RETURN_IF_ABRUPT(res);
2467         RESTORE_ACC();
2468     } else {
2469         // 2. find from global object
2470         auto globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, propKey);
2471         if (globalResult.IsHole()) {
2472             auto result = SlowRuntimeStub::ThrowReferenceError(thread, propKey, " is not defined");
2473             INTERPRETER_RETURN_IF_ABRUPT(result);
2474         }
2475         JSTaggedValue value = GET_ACC();
2476         SAVE_ACC();
2477         JSTaggedValue res = SlowRuntimeStub::StGlobalVar(thread, propKey, value);
2478         INTERPRETER_RETURN_IF_ABRUPT(res);
2479         RESTORE_ACC();
2480     }
2481     DISPATCH(TRYSTGLOBALBYNAME_IMM8_ID16);
2482 }
2483 
HandleStownbyvaluewithnamesetImm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2484 void InterpreterAssembly::HandleStownbyvaluewithnamesetImm8V8V8(
2485     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2486     JSTaggedValue acc, int16_t hotnessCounter)
2487 {
2488     uint32_t v0 = READ_INST_8_1();
2489     uint32_t v1 = READ_INST_8_2();
2490     LOG_INST() << "intrinsics::stownbyvaluewithnameset"
2491                << " v" << v0 << " v" << v1;
2492     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2493     if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
2494         SAVE_ACC();
2495         JSTaggedValue propKey = GET_VREG_VALUE(v1);
2496         JSTaggedValue value = GET_ACC();
2497         // fast path
2498         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue<ObjectFastOperator::Status::UseOwn>
2499                             (thread, receiver, propKey, value);
2500 
2501         // SetPropertyByValue maybe gc need update the value
2502         RESTORE_ACC();
2503         propKey = GET_VREG_VALUE(v1);
2504         value = GET_ACC();
2505         if (!res.IsHole()) {
2506             INTERPRETER_RETURN_IF_ABRUPT(res);
2507             JSFunction::SetFunctionNameNoPrefix(thread, JSFunction::Cast(value.GetTaggedObject()), propKey);
2508             RESTORE_ACC();
2509             DISPATCH(STOWNBYVALUEWITHNAMESET_IMM8_V8_V8);
2510         }
2511     }
2512 
2513     // slow path
2514     SAVE_ACC();
2515     SAVE_PC();
2516     receiver = GET_VREG_VALUE(v0);      // Maybe moved by GC
2517     auto propKey = GET_VREG_VALUE(v1);  // Maybe moved by GC
2518     auto value = GET_ACC();             // Maybe moved by GC
2519     JSTaggedValue res = SlowRuntimeStub::StOwnByValueWithNameSet(thread, receiver, propKey, value);
2520     RESTORE_ACC();
2521     INTERPRETER_RETURN_IF_ABRUPT(res);
2522     DISPATCH(STOWNBYVALUEWITHNAMESET_IMM8_V8_V8);
2523 }
2524 
HandleStownbynamewithnamesetImm8Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2525 void InterpreterAssembly::HandleStownbynamewithnamesetImm8Id16V8(
2526     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2527     JSTaggedValue acc, int16_t hotnessCounter)
2528 {
2529     uint16_t stringId = READ_INST_16_1();
2530     uint32_t v0 = READ_INST_8_3();
2531     LOG_INST() << "intrinsics::stownbynamewithnameset "
2532                 << "v" << v0 << " stringId:" << stringId;
2533 
2534     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2535     if (receiver.IsJSObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
2536         SAVE_ACC();
2537         constpool = GetConstantPool(thread, sp);
2538         JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
2539         RESTORE_ACC();
2540         JSTaggedValue value = GET_ACC();
2541         // fast path
2542         SAVE_ACC();
2543         JSTaggedValue res = FastRuntimeStub::SetPropertyByName<ObjectFastOperator::Status::UseOwn>
2544                             (thread, receiver, propKey, value);
2545         if (!res.IsHole()) {
2546             INTERPRETER_RETURN_IF_ABRUPT(res);
2547             JSFunction::SetFunctionNameNoPrefix(thread, JSFunction::Cast(value.GetTaggedObject()), propKey);
2548             RESTORE_ACC();
2549             DISPATCH(STOWNBYNAMEWITHNAMESET_IMM8_ID16_V8);
2550         }
2551         RESTORE_ACC();
2552     }
2553 
2554     SAVE_ACC();
2555     SAVE_PC();
2556     receiver = GET_VREG_VALUE(v0);
2557     constpool = GetConstantPool(thread, sp);                           // Maybe moved by GC
2558     auto propKey =
2559         ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);  // Maybe moved by GC
2560     RESTORE_ACC();
2561     auto value = GET_ACC();                                  // Maybe moved by GC
2562     JSTaggedValue res = SlowRuntimeStub::StOwnByNameWithNameSet(thread, receiver, propKey, value);
2563     RESTORE_ACC();
2564     INTERPRETER_RETURN_IF_ABRUPT(res);
2565     DISPATCH(STOWNBYNAMEWITHNAMESET_IMM8_ID16_V8);
2566 }
2567 
HandleLdglobalvarImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2568 void InterpreterAssembly::HandleLdglobalvarImm16Id16(
2569     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2570     JSTaggedValue acc, int16_t hotnessCounter)
2571 {
2572     uint16_t stringId = READ_INST_16_2();
2573     LOG_INST() << "intrinsics::ldglobalvar stringId:" << stringId;
2574     SAVE_ACC();
2575     constpool = GetConstantPool(thread, sp);
2576     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2577 
2578     EcmaVM *ecmaVm = thread->GetEcmaVM();
2579     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
2580     JSTaggedValue globalObj = globalEnv->GetGlobalObject();
2581 
2582 #if ECMSCRIPT_ENABLE_IC
2583     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
2584     auto tmpProfileTypeInfo = state->profileTypeInfo;
2585     if (!tmpProfileTypeInfo.IsUndefined()) {
2586         uint16_t slotId = READ_INST_16_0();
2587         JSTaggedValue res = ICRuntimeStub::LoadGlobalICByName(thread,
2588                                                               ProfileTypeInfo::Cast(
2589                                                                   tmpProfileTypeInfo.GetTaggedObject()),
2590                                                               globalObj, propKey, slotId, false);
2591         INTERPRETER_RETURN_IF_ABRUPT(res);
2592         SET_ACC(res);
2593         DISPATCH(LDGLOBALVAR_IMM16_ID16);
2594     }
2595 #endif
2596 
2597     JSTaggedValue result = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, propKey);
2598     if (!result.IsHole()) {
2599         SET_ACC(result);
2600     } else {
2601         // slow path
2602         SAVE_PC();
2603         JSTaggedValue res = SlowRuntimeStub::LdGlobalVarFromGlobalProto(thread, globalObj, propKey);
2604         INTERPRETER_RETURN_IF_ABRUPT(res);
2605         SET_ACC(res);
2606     }
2607     DISPATCH(LDGLOBALVAR_IMM16_ID16);
2608 }
2609 
HandleStobjbynameImm8Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2610 void InterpreterAssembly::HandleStobjbynameImm8Id16V8(
2611     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2612     JSTaggedValue acc, int16_t hotnessCounter)
2613 {
2614     uint32_t v0 = READ_INST_8_3();
2615 #if ECMASCRIPT_ENABLE_IC
2616     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
2617     auto tmpProfileTypeInfo = state->profileTypeInfo;
2618     if (!tmpProfileTypeInfo.IsUndefined()) {
2619         uint16_t slotId = READ_INST_8_0();
2620         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
2621         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
2622         JSTaggedValue res = JSTaggedValue::Hole();
2623         SAVE_ACC();
2624 
2625         JSTaggedValue receiver = GET_VREG_VALUE(v0);
2626         JSTaggedValue value = GET_ACC();
2627         if (LIKELY(firstValue.IsHeapObject())) {
2628             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
2629             res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value);
2630         }
2631         if (LIKELY(!res.IsHole())) {
2632             INTERPRETER_RETURN_IF_ABRUPT(res);
2633             RESTORE_ACC();
2634             DISPATCH(STOBJBYNAME_IMM8_ID16_V8);
2635         } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic
2636             uint16_t stringId = READ_INST_16_1();
2637             SAVE_ACC();
2638             constpool = GetConstantPool(thread, sp);
2639             JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2640             RESTORE_ACC();
2641             value = GET_ACC();
2642             receiver = GET_VREG_VALUE(v0);
2643             profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
2644             res = ICRuntimeStub::StoreICByName(thread,
2645                                                profileTypeArray,
2646                                                receiver, propKey, value, slotId);
2647             INTERPRETER_RETURN_IF_ABRUPT(res);
2648             RESTORE_ACC();
2649             DISPATCH(STOBJBYNAME_IMM8_ID16_V8);
2650         }
2651     }
2652 #endif
2653     uint16_t stringId = READ_INST_16_1();
2654     LOG_INST() << "intrinsics::stobjbyname "
2655                << "v" << v0 << " stringId:" << stringId;
2656     JSTaggedValue receiver = GET_VREG_VALUE(v0);
2657     if (receiver.IsHeapObject()) {
2658         SAVE_ACC();
2659         constpool = GetConstantPool(thread, sp);
2660         JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2661         RESTORE_ACC();
2662         JSTaggedValue value = GET_ACC();
2663         receiver = GET_VREG_VALUE(v0);
2664         // fast path
2665         JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, receiver, propKey, value);
2666         if (!res.IsHole()) {
2667             INTERPRETER_RETURN_IF_ABRUPT(res);
2668             RESTORE_ACC();
2669             DISPATCH(STOBJBYNAME_IMM8_ID16_V8);
2670         }
2671         RESTORE_ACC();
2672     }
2673     // slow path
2674     SAVE_ACC();
2675     SAVE_PC();
2676     constpool = GetConstantPool(thread, sp);                    // Maybe moved by GC
2677     auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);  // Maybe moved by GC
2678     RESTORE_ACC();
2679     JSTaggedValue value = GET_ACC();                                  // Maybe moved by GC
2680     receiver = GET_VREG_VALUE(v0);
2681     JSTaggedValue res = SlowRuntimeStub::StObjByName(thread, receiver, propKey, value);
2682     INTERPRETER_RETURN_IF_ABRUPT(res);
2683     RESTORE_ACC();
2684     DISPATCH(STOBJBYNAME_IMM8_ID16_V8);
2685 }
2686 
HandleStsuperbynameImm8Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2687 void InterpreterAssembly::HandleStsuperbynameImm8Id16V8(
2688     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2689     JSTaggedValue acc, int16_t hotnessCounter)
2690 {
2691     uint16_t stringId = READ_INST_16_1();
2692     uint32_t v0 = READ_INST_8_3();
2693 
2694     JSTaggedValue obj = GET_VREG_VALUE(v0);
2695     SAVE_ACC();
2696     constpool = GetConstantPool(thread, sp);
2697     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2698     RESTORE_ACC();
2699     JSTaggedValue value = GET_ACC();
2700 
2701     LOG_INST() << "intrinsics::stsuperbyname"
2702                << "v" << v0 << " stringId:" << stringId << ", "
2703                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData()
2704                << ", value:" << value.GetRawData();
2705 
2706     // slow path
2707     SAVE_ACC();
2708     SAVE_PC();
2709     JSTaggedValue thisFunc = GetFunction(sp);
2710     JSTaggedValue res = SlowRuntimeStub::StSuperByValue(thread, obj, propKey, value, thisFunc);
2711     INTERPRETER_RETURN_IF_ABRUPT(res);
2712     RESTORE_ACC();
2713     DISPATCH(STSUPERBYNAME_IMM8_ID16_V8);
2714 }
2715 
HandleStglobalvarImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2716 void InterpreterAssembly::HandleStglobalvarImm16Id16(
2717     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2718     JSTaggedValue acc, int16_t hotnessCounter)
2719 {
2720     uint16_t stringId = READ_INST_16_2();
2721     SAVE_ACC();
2722     constpool = GetConstantPool(thread, sp);
2723     JSTaggedValue prop = ConstantPool::GetStringFromCache(thread, constpool, stringId);
2724     RESTORE_ACC();
2725     JSTaggedValue value = GET_ACC();
2726 
2727     LOG_INST() << "intrinsics::stglobalvar "
2728                << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject()))
2729                << ", value:" << value.GetRawData();
2730 #if ECMSCRIPT_ENABLE_IC
2731     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
2732     auto tmpProfileTypeInfo = state->profileTypeInfo;
2733     if (!tmpProfileTypeInfo.IsUndefined()) {
2734         uint16_t slotId = READ_INST_16_0();
2735         SAVE_ACC();
2736         JSTaggedValue res = ICRuntimeStub::StoreGlobalICByName(thread,
2737                                                                ProfileTypeInfo::Cast(
2738                                                                    tmpProfileTypeInfo.GetTaggedObject()),
2739                                                                globalObj, prop, value, slotId, false);
2740         INTERPRETER_RETURN_IF_ABRUPT(res);
2741         RESTORE_ACC();
2742         DISPATCH(STGLOBALVAR_IMM16_ID16);
2743     }
2744 #endif
2745     SAVE_ACC();
2746     SAVE_PC();
2747     JSTaggedValue res = SlowRuntimeStub::StGlobalVar(thread, prop, value);
2748     INTERPRETER_RETURN_IF_ABRUPT(res);
2749     RESTORE_ACC();
2750     DISPATCH(STGLOBALVAR_IMM16_ID16);
2751 }
2752 
HandleCreategeneratorobjV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2753 void InterpreterAssembly::HandleCreategeneratorobjV8(
2754     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2755     JSTaggedValue acc, int16_t hotnessCounter)
2756 {
2757     uint16_t v0 = READ_INST_8_0();
2758     LOG_INST() << "intrinsics::creategeneratorobj"
2759                << " v" << v0;
2760     SAVE_PC();
2761     JSTaggedValue genFunc = GET_VREG_VALUE(v0);
2762     JSTaggedValue res = SlowRuntimeStub::CreateGeneratorObj(thread, genFunc);
2763     INTERPRETER_RETURN_IF_ABRUPT(res);
2764     SET_ACC(res);
2765     DISPATCH(CREATEGENERATOROBJ_V8);
2766 }
2767 
HandleCreateasyncgeneratorobjV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2768 void InterpreterAssembly::HandleCreateasyncgeneratorobjV8(
2769     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2770     JSTaggedValue acc, int16_t hotnessCounter)
2771 {
2772     uint16_t v0 = READ_INST_8_0();
2773     LOG_INST() << "intrinsics::createasyncgeneratorobj"
2774                << " v" << v0;
2775     SAVE_PC();
2776     JSTaggedValue genFunc = GET_VREG_VALUE(v0);
2777     JSTaggedValue res = SlowRuntimeStub::CreateAsyncGeneratorObj(thread, genFunc);
2778     INTERPRETER_RETURN_IF_ABRUPT(res);
2779     SET_ACC(res);
2780     DISPATCH(CREATEASYNCGENERATOROBJ_V8);
2781 }
2782 
HandleAsyncgeneratorresolveV8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2783 void InterpreterAssembly::HandleAsyncgeneratorresolveV8V8V8(
2784     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2785     JSTaggedValue acc, int16_t hotnessCounter)
2786 {
2787     uint16_t v0 = READ_INST_8_0();
2788     uint16_t v1 = READ_INST_8_1();
2789     uint16_t v2 = READ_INST_8_2();
2790     LOG_INST() << "intrinsics::asyncgeneratorresolve"
2791                    << " v" << v0 << " v" << v1 << " v" << v2;
2792     JSTaggedValue asyncGenerator = GET_VREG_VALUE(v0);
2793     JSTaggedValue value = GET_VREG_VALUE(v1);
2794     JSTaggedValue flag = GET_VREG_VALUE(v2);
2795     SAVE_PC();
2796     JSTaggedValue res = SlowRuntimeStub::AsyncGeneratorResolve(thread, asyncGenerator, value, flag);
2797     INTERPRETER_RETURN_IF_ABRUPT(res);
2798     SET_ACC(res);
2799 
2800     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
2801     Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
2802     [[maybe_unused]] auto fistPC = method->GetBytecodeArray();
2803     UPDATE_HOTNESS_COUNTER(-(pc - fistPC));
2804     LOG_INST() << "Exit: AsyncGeneratorresolve " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
2805                             << std::hex << reinterpret_cast<uintptr_t>(state->pc);
2806     sp = state->base.prev;
2807     ASSERT(sp != nullptr);
2808     InterpretedFrame *prevState = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
2809     pc = prevState->pc;
2810     // entry frame
2811     if (FrameHandler::IsEntryFrame(pc)) {
2812         state->acc = acc;
2813         return;
2814     }
2815 
2816     thread->SetCurrentSPFrame(sp);
2817 
2818     size_t jumpSize = GetJumpSizeAfterCall(pc);
2819     DISPATCH_OFFSET(jumpSize);
2820 }
2821 
HandleAsyncgeneratorrejectV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2822 void InterpreterAssembly::HandleAsyncgeneratorrejectV8(
2823     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2824     JSTaggedValue acc, int16_t hotnessCounter)
2825 {
2826     uint16_t v0 = READ_INST_8_0();
2827     LOG_INST() << "intrinsics::asyncgeneratorreject"
2828                << " v" << v0;
2829     JSTaggedValue asyncGenerator = GET_VREG_VALUE(v0);
2830     JSTaggedValue value = GET_ACC();
2831     SAVE_PC();
2832     JSTaggedValue res = SlowRuntimeStub::AsyncGeneratorReject(thread, asyncGenerator, value);
2833     INTERPRETER_RETURN_IF_ABRUPT(res);
2834     SET_ACC(res);
2835     DISPATCH(ASYNCGENERATORREJECT_V8);
2836 }
2837 
HandleSetgeneratorstateImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2838 void InterpreterAssembly::HandleSetgeneratorstateImm8(
2839     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2840     JSTaggedValue acc, int16_t hotnessCounter)
2841 {
2842     uint32_t index = READ_INST_8_0();
2843     LOG_INST() << "intrinsics::setgeneratorstate index" << index;
2844     JSTaggedValue objVal = GET_ACC();
2845 
2846     SAVE_PC();
2847     SAVE_ACC();
2848     SlowRuntimeStub::SetGeneratorState(thread, objVal, index);
2849     RESTORE_ACC();
2850     DISPATCH(SETGENERATORSTATE_IMM8);
2851 }
2852 
HandleDeprecatedAsyncgeneratorrejectPrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2853 void InterpreterAssembly::HandleDeprecatedAsyncgeneratorrejectPrefV8V8(
2854     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2855     JSTaggedValue acc, int16_t hotnessCounter)
2856 {
2857     uint16_t v0 = READ_INST_8_1();
2858     uint16_t v1 = READ_INST_8_2();
2859     LOG_INST() << "intrinsics::asyncgeneratorreject"
2860                    << " v" << v0 << " v" << v1;
2861     JSTaggedValue asyncGenerator = GET_VREG_VALUE(v0);
2862     JSTaggedValue value = GET_VREG_VALUE(v1);
2863     SAVE_PC();
2864     JSTaggedValue res = SlowRuntimeStub::AsyncGeneratorReject(thread, asyncGenerator, value);
2865     INTERPRETER_RETURN_IF_ABRUPT(res);
2866     SET_ACC(res);
2867     DISPATCH(DEPRECATED_ASYNCGENERATORREJECT_PREF_V8_V8);
2868 }
2869 
HandleStarrayspreadV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2870 void InterpreterAssembly::HandleStarrayspreadV8V8(
2871     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2872     JSTaggedValue acc, int16_t hotnessCounter)
2873 {
2874     uint16_t v0 = READ_INST_8_0();
2875     uint16_t v1 = READ_INST_8_1();
2876     LOG_INST() << "ecmascript::intrinsics::starrayspread"
2877                << " v" << v0 << " v" << v1 << "acc";
2878     JSTaggedValue dst = GET_VREG_VALUE(v0);
2879     JSTaggedValue index = GET_VREG_VALUE(v1);
2880     JSTaggedValue src = GET_ACC();
2881     SAVE_PC();
2882     JSTaggedValue res = SlowRuntimeStub::StArraySpread(thread, dst, index, src);
2883     INTERPRETER_RETURN_IF_ABRUPT(res);
2884     SET_ACC(res);
2885     DISPATCH(STARRAYSPREAD_V8_V8);
2886 }
2887 
HandleLdfunction(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2888 void InterpreterAssembly::HandleLdfunction(
2889     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2890     JSTaggedValue acc, int16_t hotnessCounter)
2891 {
2892     LOG_INST() << "intrinsic::ldfunction";
2893     SET_ACC(GetFunction(sp));
2894     DISPATCH(LDFUNCTION);
2895 }
2896 
HandleLdbigintId16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2897 void InterpreterAssembly::HandleLdbigintId16(
2898     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2899     JSTaggedValue acc, int16_t hotnessCounter)
2900 {
2901     uint16_t stringId = READ_INST_16_0();
2902     LOG_INST() << "intrinsic::ldbigint";
2903     SAVE_ACC();
2904     constpool = GetConstantPool(thread, sp);
2905     JSTaggedValue numberBigInt = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
2906     SAVE_PC();
2907     JSTaggedValue res = SlowRuntimeStub::LdBigInt(thread, numberBigInt);
2908     INTERPRETER_RETURN_IF_ABRUPT(res);
2909     SET_ACC(res);
2910     DISPATCH(LDBIGINT_ID16);
2911 }
2912 
HandleTonumericImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2913 void InterpreterAssembly::HandleTonumericImm8(
2914     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2915     JSTaggedValue acc, int16_t hotnessCounter)
2916 {
2917     LOG_INST() << "intrinsics::tonumeric";
2918     JSTaggedValue value = GET_ACC();
2919     if (value.IsNumber() || value.IsBigInt()) {
2920         // fast path
2921         SET_ACC(value);
2922     } else {
2923         // slow path
2924         SAVE_PC();
2925         JSTaggedValue res = SlowRuntimeStub::ToNumeric(thread, value);
2926         INTERPRETER_RETURN_IF_ABRUPT(res);
2927         SET_ACC(res);
2928     }
2929     DISPATCH(TONUMERIC_IMM8);
2930 }
2931 
HandleSupercallspreadImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2932 void InterpreterAssembly::HandleSupercallspreadImm8V8(
2933     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2934     JSTaggedValue acc, int16_t hotnessCounter)
2935 {
2936     uint16_t v0 = READ_INST_8_1();
2937     LOG_INST() << "intrinsic::supercallspread"
2938                << " array: v" << v0;
2939 
2940     JSTaggedValue thisFunc = GET_ACC();
2941     JSTaggedValue newTarget = GetNewTarget(thread, sp);
2942     JSTaggedValue array = GET_VREG_VALUE(v0);
2943 
2944     SAVE_PC();
2945     JSTaggedValue res = SlowRuntimeStub::SuperCallSpread(thread, thisFunc, newTarget, array);
2946     INTERPRETER_RETURN_IF_ABRUPT(res);
2947     SET_ACC(res);
2948     DISPATCH(SUPERCALLSPREAD_IMM8_V8);
2949 }
2950 
HandleThrowIfsupernotcorrectcallPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2951 void InterpreterAssembly::HandleThrowIfsupernotcorrectcallPrefImm16(
2952     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2953     JSTaggedValue acc, int16_t hotnessCounter)
2954 {
2955     uint16_t imm = READ_INST_16_1();
2956     JSTaggedValue thisValue = GET_ACC();
2957     LOG_INST() << "intrinsic::throwifsupernotcorrectcall"
2958                << " imm:" << imm;
2959     SAVE_PC();
2960     JSTaggedValue res = SlowRuntimeStub::ThrowIfSuperNotCorrectCall(thread, imm, thisValue);
2961     INTERPRETER_RETURN_IF_ABRUPT(res);
2962     DISPATCH(THROW_IFSUPERNOTCORRECTCALL_PREF_IMM16);
2963 }
2964 
HandleThrowDeletesuperpropertyPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2965 void InterpreterAssembly::HandleThrowDeletesuperpropertyPrefNone(
2966     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2967     JSTaggedValue acc, int16_t hotnessCounter)
2968 {
2969     LOG_INST() << "throwdeletesuperproperty";
2970 
2971     SAVE_PC();
2972     SlowRuntimeStub::ThrowDeleteSuperProperty(thread);
2973     INTERPRETER_GOTO_EXCEPTION_HANDLER();
2974 }
2975 
HandleDebugger(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2976 void InterpreterAssembly::HandleDebugger(
2977     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2978     JSTaggedValue acc, int16_t hotnessCounter)
2979 {
2980     LOG_INST() << "intrinsics::debugger";
2981     DISPATCH(DEBUGGER);
2982 }
2983 
HandleIstrue(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2984 void InterpreterAssembly::HandleIstrue(
2985     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2986     JSTaggedValue acc, int16_t hotnessCounter)
2987 {
2988     LOG_INST() << "intrinsics::istrue";
2989     if (GET_ACC().ToBoolean()) {
2990         SET_ACC(JSTaggedValue::True());
2991     } else {
2992         SET_ACC(JSTaggedValue::False());
2993     }
2994     DISPATCH(ISTRUE);
2995 }
2996 
HandleCallRuntimeIstruePrefImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)2997 void InterpreterAssembly::HandleCallRuntimeIstruePrefImm8(
2998     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
2999     JSTaggedValue acc, int16_t hotnessCounter)
3000 {
3001     LOG_INST() << "intrinsics::callruntimeistrueprefimm8";
3002     if (GET_ACC().ToBoolean()) {
3003         SET_ACC(JSTaggedValue::True());
3004     } else {
3005         SET_ACC(JSTaggedValue::False());
3006     }
3007     DISPATCH(CALLRUNTIME_ISTRUE_PREF_IMM8);
3008 }
3009 
HandleIsfalse(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3010 void InterpreterAssembly::HandleIsfalse(
3011     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3012     JSTaggedValue acc, int16_t hotnessCounter)
3013 {
3014     LOG_INST() << "intrinsics::isfalse";
3015     if (GET_ACC().ToBoolean()) {
3016         SET_ACC(JSTaggedValue::False());
3017     } else {
3018         SET_ACC(JSTaggedValue::True());
3019     }
3020     DISPATCH(ISFALSE);
3021 }
3022 
HandleCallRuntimeIsfalsePrefImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3023 void InterpreterAssembly::HandleCallRuntimeIsfalsePrefImm8(
3024     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3025     JSTaggedValue acc, int16_t hotnessCounter)
3026 {
3027     LOG_INST() << "intrinsics::callruntimeisfalseprefimm8";
3028     if (GET_ACC().ToBoolean()) {
3029         SET_ACC(JSTaggedValue::False());
3030     } else {
3031         SET_ACC(JSTaggedValue::True());
3032     }
3033     DISPATCH(CALLRUNTIME_ISFALSE_PREF_IMM8);
3034 }
3035 
HandleTypeofImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3036 void InterpreterAssembly::HandleTypeofImm16(
3037     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3038     JSTaggedValue acc, int16_t hotnessCounter)
3039 {
3040     LOG_INST() << "intrinsics::typeof";
3041     JSTaggedValue res = FastRuntimeStub::FastTypeOf(thread, GET_ACC());
3042     SET_ACC(res);
3043     DISPATCH(TYPEOF_IMM16);
3044 }
3045 
HandleCreateemptyarrayImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3046 void InterpreterAssembly::HandleCreateemptyarrayImm16(
3047     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3048     JSTaggedValue acc, int16_t hotnessCounter)
3049 {
3050     LOG_INST() << "intrinsics::createemptyarray";
3051     SAVE_PC();
3052     EcmaVM *ecmaVm = thread->GetEcmaVM();
3053     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
3054     ObjectFactory *factory = ecmaVm->GetFactory();
3055     JSTaggedValue res = SlowRuntimeStub::CreateEmptyArray(thread, factory, globalEnv);
3056     SET_ACC(res);
3057     DISPATCH(CREATEEMPTYARRAY_IMM16);
3058 }
3059 
HandleGetiteratorImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3060 void InterpreterAssembly::HandleGetiteratorImm16(
3061     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3062     JSTaggedValue acc, int16_t hotnessCounter)
3063 {
3064     LOG_INST() << "intrinsics::getiterator";
3065     JSTaggedValue obj = GET_ACC();
3066     // slow path
3067     SAVE_PC();
3068     JSTaggedValue res = SlowRuntimeStub::GetIterator(thread, obj);
3069     INTERPRETER_RETURN_IF_ABRUPT(res);
3070     SET_ACC(res);
3071     DISPATCH(GETITERATOR_IMM16);
3072 }
3073 
HandleGettemplateobjectImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3074 void InterpreterAssembly::HandleGettemplateobjectImm16(
3075     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3076     JSTaggedValue acc, int16_t hotnessCounter)
3077 {
3078     LOG_INST() << "intrinsics::gettemplateobject";
3079     JSTaggedValue obj = GET_ACC();
3080     // slow path
3081     SAVE_PC();
3082     JSTaggedValue res = SlowRuntimeStub::GetTemplateObject(thread, obj);
3083     INTERPRETER_RETURN_IF_ABRUPT(res);
3084     SET_ACC(res);
3085     DISPATCH(GETTEMPLATEOBJECT_IMM16);
3086 }
3087 
HandleCloseiteratorImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3088 void InterpreterAssembly::HandleCloseiteratorImm16V8(
3089     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3090     JSTaggedValue acc, int16_t hotnessCounter)
3091 {
3092     uint16_t v0 = READ_INST_8_2();
3093     LOG_INST() << "intrinsics::closeiterator"
3094                << " v" << v0;
3095     SAVE_PC();
3096     JSTaggedValue iter = GET_VREG_VALUE(v0);
3097     JSTaggedValue res = SlowRuntimeStub::CloseIterator(thread, iter);
3098     INTERPRETER_RETURN_IF_ABRUPT(res);
3099     SET_ACC(res);
3100     DISPATCH(CLOSEITERATOR_IMM16_V8);
3101 }
3102 
HandleSetobjectwithprotoImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3103 void InterpreterAssembly::HandleSetobjectwithprotoImm16V8(
3104     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3105     JSTaggedValue acc, int16_t hotnessCounter)
3106 {
3107     uint16_t v0 = READ_INST_8_2();
3108     LOG_INST() << "intrinsics::setobjectwithproto"
3109                << " v" << v0;
3110     JSTaggedValue proto = GET_VREG_VALUE(v0);
3111     JSTaggedValue obj = GET_ACC();
3112     SAVE_ACC();
3113     SAVE_PC();
3114     JSTaggedValue res = SlowRuntimeStub::SetObjectWithProto(thread, proto, obj);
3115     INTERPRETER_RETURN_IF_ABRUPT(res);
3116     RESTORE_ACC();
3117     DISPATCH(SETOBJECTWITHPROTO_IMM16_V8);
3118 }
3119 
HandleStobjbyvalueImm16V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3120 void InterpreterAssembly::HandleStobjbyvalueImm16V8V8(
3121     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3122     JSTaggedValue acc, int16_t hotnessCounter)
3123 {
3124     uint32_t v0 = READ_INST_8_2();
3125     uint32_t v1 = READ_INST_8_3();
3126 
3127     LOG_INST() << "intrinsics::stobjbyvalue"
3128                << " v" << v0 << " v" << v1;
3129 
3130     JSTaggedValue receiver = GET_VREG_VALUE(v0);
3131 #if ECMSCRIPT_ENABLE_IC
3132     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
3133     auto tmpProfileTypeInfo = state->profileTypeInfo;
3134     if (!tmpProfileTypeInfo.IsUndefined()) {
3135         uint16_t slotId = READ_INST_16_0();
3136         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
3137         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
3138         JSTaggedValue propKey = GET_VREG_VALUE(v1);
3139         JSTaggedValue value = GET_ACC();
3140         JSTaggedValue res = JSTaggedValue::Hole();
3141         SAVE_ACC();
3142 
3143         if (LIKELY(firstValue.IsHeapObject())) {
3144             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
3145             res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value);
3146         }
3147         // IC miss and not enter the megamorphic state, store as polymorphic
3148         if (res.IsHole() && !firstValue.IsHole()) {
3149             res = ICRuntimeStub::StoreICByValue(thread,
3150                                                 profileTypeArray,
3151                                                 receiver, propKey, value, slotId);
3152         }
3153 
3154         if (LIKELY(!res.IsHole())) {
3155             INTERPRETER_RETURN_IF_ABRUPT(res);
3156             RESTORE_ACC();
3157             DISPATCH(STOBJBYVALUE_IMM16_V8_V8);
3158         }
3159     }
3160 #endif
3161     if (receiver.IsHeapObject()) {
3162         SAVE_ACC();
3163         JSTaggedValue propKey = GET_VREG_VALUE(v1);
3164         JSTaggedValue value = GET_ACC();
3165         // fast path
3166         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue(thread, receiver, propKey, value);
3167         if (!res.IsHole()) {
3168             INTERPRETER_RETURN_IF_ABRUPT(res);
3169             RESTORE_ACC();
3170             DISPATCH(STOBJBYVALUE_IMM16_V8_V8);
3171         }
3172         RESTORE_ACC();
3173     }
3174     {
3175         // slow path
3176         SAVE_ACC();
3177         SAVE_PC();
3178         receiver = GET_VREG_VALUE(v0);  // Maybe moved by GC
3179         JSTaggedValue propKey = GET_VREG_VALUE(v1);   // Maybe moved by GC
3180         JSTaggedValue value = GET_ACC();              // Maybe moved by GC
3181         JSTaggedValue res = SlowRuntimeStub::StObjByValue(thread, receiver, propKey, value);
3182         INTERPRETER_RETURN_IF_ABRUPT(res);
3183         RESTORE_ACC();
3184     }
3185     DISPATCH(STOBJBYVALUE_IMM16_V8_V8);
3186 }
3187 
HandleStownbyvalueImm16V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3188 void InterpreterAssembly::HandleStownbyvalueImm16V8V8(
3189     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3190     JSTaggedValue acc, int16_t hotnessCounter)
3191 {
3192     uint32_t v0 = READ_INST_8_2();
3193     uint32_t v1 = READ_INST_8_3();
3194     LOG_INST() << "intrinsics::stownbyvalue"
3195                << " v" << v0 << " v" << v1;
3196 
3197     JSTaggedValue receiver = GET_VREG_VALUE(v0);
3198     if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
3199         SAVE_ACC();
3200         JSTaggedValue propKey = GET_VREG_VALUE(v1);
3201         JSTaggedValue value = GET_ACC();
3202         // fast path
3203         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue<ObjectFastOperator::Status::UseOwn>
3204                             (thread, receiver, propKey, value);
3205 
3206         // SetPropertyByValue maybe gc need update the value
3207         RESTORE_ACC();
3208         propKey = GET_VREG_VALUE(v1);
3209         value = GET_ACC();
3210         if (!res.IsHole()) {
3211             INTERPRETER_RETURN_IF_ABRUPT(res);
3212             RESTORE_ACC();
3213             DISPATCH(STOWNBYVALUE_IMM16_V8_V8);
3214         }
3215     }
3216 
3217     // slow path
3218     SAVE_ACC();
3219     receiver = GET_VREG_VALUE(v0);      // Maybe moved by GC
3220     auto propKey = GET_VREG_VALUE(v1);  // Maybe moved by GC
3221     auto value = GET_ACC();             // Maybe moved by GC
3222     SAVE_PC();
3223     JSTaggedValue res = SlowRuntimeStub::StOwnByValue(thread, receiver, propKey, value);
3224     RESTORE_ACC();
3225     INTERPRETER_RETURN_IF_ABRUPT(res);
3226     DISPATCH(STOWNBYVALUE_IMM16_V8_V8);
3227 }
3228 
HandleStobjbyindexImm16V8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3229 void InterpreterAssembly::HandleStobjbyindexImm16V8Imm16(
3230     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3231     JSTaggedValue acc, int16_t hotnessCounter)
3232 {
3233     uint8_t v0 = READ_INST_8_2();
3234     uint16_t index = READ_INST_16_3();
3235     LOG_INST() << "intrinsics::stobjbyindex"
3236                << " v" << v0 << " imm" << index;
3237 
3238     JSTaggedValue receiver = GET_VREG_VALUE(v0);
3239     if (receiver.IsHeapObject()) {
3240         SAVE_ACC();
3241         JSTaggedValue value = GET_ACC();
3242         // fast path
3243         JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex(thread, receiver, index, value);
3244         if (!res.IsHole()) {
3245             INTERPRETER_RETURN_IF_ABRUPT(res);
3246             RESTORE_ACC();
3247             DISPATCH(STOBJBYINDEX_IMM16_V8_IMM16);
3248         }
3249         RESTORE_ACC();
3250     }
3251     // slow path
3252     SAVE_ACC();
3253     SAVE_PC();
3254     receiver = GET_VREG_VALUE(v0);    // Maybe moved by GC
3255     JSTaggedValue value = GET_ACC();  // Maybe moved by GC
3256     JSTaggedValue res = SlowRuntimeStub::StObjByIndex(thread, receiver, index, value);
3257     INTERPRETER_RETURN_IF_ABRUPT(res);
3258     RESTORE_ACC();
3259     DISPATCH(STOBJBYINDEX_IMM16_V8_IMM16);
3260 }
3261 
HandleStownbyindexImm16V8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3262 void InterpreterAssembly::HandleStownbyindexImm16V8Imm16(
3263     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3264     JSTaggedValue acc, int16_t hotnessCounter)
3265 {
3266     uint8_t v0 = READ_INST_8_2();
3267     uint16_t index = READ_INST_16_3();
3268     LOG_INST() << "intrinsics::stownbyindex"
3269                << " v" << v0 << " imm" << index;
3270     JSTaggedValue receiver = GET_VREG_VALUE(v0);
3271     // fast path
3272     if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
3273         SAVE_ACC();
3274         JSTaggedValue value = GET_ACC();
3275         // fast path
3276         JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex<ObjectFastOperator::Status::UseOwn>
3277                             (thread, receiver, index, value);
3278         if (!res.IsHole()) {
3279             INTERPRETER_RETURN_IF_ABRUPT(res);
3280             RESTORE_ACC();
3281             DISPATCH(STOWNBYINDEX_IMM16_V8_IMM16);
3282         }
3283         RESTORE_ACC();
3284     }
3285     SAVE_ACC();
3286     receiver = GET_VREG_VALUE(v0);  // Maybe moved by GC
3287     auto value = GET_ACC();         // Maybe moved by GC
3288     SAVE_PC();
3289     JSTaggedValue res = SlowRuntimeStub::StOwnByIndex(thread, receiver, index, value);
3290     INTERPRETER_RETURN_IF_ABRUPT(res);
3291     RESTORE_ACC();
3292     DISPATCH(STOWNBYINDEX_IMM16_V8_IMM16);
3293 }
3294 
HandleThrowIfsupernotcorrectcallPrefImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3295 void InterpreterAssembly::HandleThrowIfsupernotcorrectcallPrefImm8(
3296     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3297     JSTaggedValue acc, int16_t hotnessCounter)
3298 {
3299     uint8_t imm = READ_INST_8_1();
3300     JSTaggedValue thisValue = GET_ACC();
3301     LOG_INST() << "intrinsic::throwifsupernotcorrectcall"
3302                << " imm:" << imm;
3303     SAVE_PC();
3304     JSTaggedValue res = SlowRuntimeStub::ThrowIfSuperNotCorrectCall(thread, imm, thisValue);
3305     INTERPRETER_RETURN_IF_ABRUPT(res);
3306     DISPATCH(THROW_IFSUPERNOTCORRECTCALL_PREF_IMM8);
3307 }
3308 
HandleThrowNotexistsPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3309 void InterpreterAssembly::HandleThrowNotexistsPrefNone(
3310     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3311     JSTaggedValue acc, int16_t hotnessCounter)
3312 {
3313     LOG_INST() << "throwthrownotexists";
3314 
3315     SAVE_PC();
3316     SlowRuntimeStub::ThrowThrowNotExists(thread);
3317     INTERPRETER_GOTO_EXCEPTION_HANDLER();
3318 }
3319 
HandleThrowPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3320 void InterpreterAssembly::HandleThrowPrefNone(
3321     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3322     JSTaggedValue acc, int16_t hotnessCounter)
3323 {
3324     LOG_INST() << "intrinsics::throw";
3325     SAVE_PC();
3326     SlowRuntimeStub::Throw(thread, GET_ACC());
3327     INTERPRETER_GOTO_EXCEPTION_HANDLER();
3328 }
3329 
HandleWideLdexternalmodulevarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3330 void InterpreterAssembly::HandleWideLdexternalmodulevarPrefImm16(
3331     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3332     JSTaggedValue acc, int16_t hotnessCounter)
3333 {
3334     int32_t index = READ_INST_16_1();
3335 
3336     LOG_INST() << "intrinsics::ldmodulevar index:" << index;
3337 
3338     JSTaggedValue moduleVar = SlowRuntimeStub::LdExternalModuleVar(thread, index);
3339     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
3340     SET_ACC(moduleVar);
3341     DISPATCH(WIDE_LDEXTERNALMODULEVAR_PREF_IMM16);
3342 }
3343 
HandleCallRuntimeWideLdsendableexternalmodulevarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3344 void InterpreterAssembly::HandleCallRuntimeWideLdsendableexternalmodulevarPrefImm16(
3345     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3346     JSTaggedValue acc, int16_t hotnessCounter)
3347 {
3348     int32_t index = READ_INST_16_1();
3349     JSTaggedValue thisFunc = GetFunction(sp);
3350     LOG_INST() << "intrinsics::ldsendableexternalmodulevar index:" << index;
3351 
3352     JSTaggedValue moduleVar = SlowRuntimeStub::LdSendableExternalModuleVar(thread, index, thisFunc);
3353     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
3354     SET_ACC(moduleVar);
3355     DISPATCH(CALLRUNTIME_WIDELDSENDABLEEXTERNALMODULEVAR_PREF_IMM16);
3356 }
3357 
HandleCallRuntimeWideLdsendablelocalmodulevarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3358 void InterpreterAssembly::HandleCallRuntimeWideLdsendablelocalmodulevarPrefImm16(
3359     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3360     JSTaggedValue acc, int16_t hotnessCounter)
3361 {
3362     int32_t index = READ_INST_16_1();
3363     JSTaggedValue thisFunc = GetFunction(sp);
3364     LOG_INST() << "intrinsics::ldsendablelocalmodulevar index:" << index;
3365 
3366     JSTaggedValue moduleVar = SlowRuntimeStub::LdSendableLocalModuleVar(thread, index, thisFunc);
3367     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
3368     SET_ACC(moduleVar);
3369     DISPATCH(CALLRUNTIME_WIDELDSENDABLELOCALMODULEVAR_PREF_IMM16);
3370 }
3371 
HandleWideLdlocalmodulevarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3372 void InterpreterAssembly::HandleWideLdlocalmodulevarPrefImm16(
3373     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3374     JSTaggedValue acc, int16_t hotnessCounter)
3375 {
3376     int32_t index = READ_INST_16_1();
3377     LOG_INST() << "intrinsics::ldmodulevar index:" << index;
3378 
3379     JSTaggedValue moduleVar = SlowRuntimeStub::LdLocalModuleVar(thread, index);
3380     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
3381     SET_ACC(moduleVar);
3382     DISPATCH(WIDE_LDLOCALMODULEVAR_PREF_IMM16);
3383 }
3384 
HandleWideStmodulevarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3385 void InterpreterAssembly::HandleWideStmodulevarPrefImm16(
3386     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3387     JSTaggedValue acc, int16_t hotnessCounter)
3388 {
3389     int32_t index = READ_INST_16_1();
3390 
3391     LOG_INST() << "intrinsics::stmodulevar index:" << index;
3392 
3393     JSTaggedValue value = GET_ACC();
3394 
3395     SlowRuntimeStub::StModuleVar(thread, index, value);
3396     RESTORE_ACC();
3397     DISPATCH(WIDE_STMODULEVAR_PREF_IMM16);
3398 }
3399 
HandleWideGetmodulenamespacePrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3400 void InterpreterAssembly::HandleWideGetmodulenamespacePrefImm16(
3401     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3402     JSTaggedValue acc, int16_t hotnessCounter)
3403 {
3404     int32_t index = READ_INST_16_1();
3405 
3406     LOG_INST() << "intrinsics::getmodulenamespace index:" << index;
3407 
3408     JSTaggedValue moduleNamespace = SlowRuntimeStub::GetModuleNamespace(thread, index);
3409     INTERPRETER_RETURN_IF_ABRUPT(moduleNamespace);
3410     SET_ACC(moduleNamespace);
3411     DISPATCH(WIDE_GETMODULENAMESPACE_PREF_IMM16);
3412 }
3413 
HandleWideLdlexvarPrefImm16Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3414 void InterpreterAssembly::HandleWideLdlexvarPrefImm16Imm16(
3415     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3416     JSTaggedValue acc, int16_t hotnessCounter)
3417 {
3418     uint16_t level = READ_INST_16_1();
3419     uint16_t slot = READ_INST_16_3();
3420 
3421     LOG_INST() << "intrinsics::ldlexvar"
3422                << " level:" << level << " slot:" << slot;
3423     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
3424     JSTaggedValue currentLexenv = state->env;
3425     JSTaggedValue env(currentLexenv);
3426     for (uint32_t i = 0; i < level; i++) {
3427         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
3428         ASSERT(!taggedParentEnv.IsUndefined());
3429         env = taggedParentEnv;
3430     }
3431     SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot));
3432     DISPATCH(WIDE_LDLEXVAR_PREF_IMM16_IMM16);
3433 }
3434 
HandleWideCopyrestargsPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3435 void InterpreterAssembly::HandleWideCopyrestargsPrefImm16(
3436     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3437     JSTaggedValue acc, int16_t hotnessCounter)
3438 {
3439     uint16_t restIdx = READ_INST_16_1();
3440     LOG_INST() << "intrinsics::copyrestargs"
3441                << " index: " << restIdx;
3442 
3443     uint32_t startIdx = 0;
3444     uint32_t restNumArgs = GetNumArgs(thread, sp, restIdx, startIdx);
3445 
3446     SAVE_PC();
3447     JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, sp, restNumArgs, startIdx);
3448     INTERPRETER_RETURN_IF_ABRUPT(res);
3449     SET_ACC(res);
3450     DISPATCH(WIDE_COPYRESTARGS_PREF_IMM16);
3451 }
3452 
HandleWideStownbyindexPrefV8Imm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3453 void InterpreterAssembly::HandleWideStownbyindexPrefV8Imm32(
3454     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3455     JSTaggedValue acc, int16_t hotnessCounter)
3456 {
3457     uint8_t v0 = READ_INST_8_1();
3458     uint32_t index = READ_INST_32_2();
3459     LOG_INST() << "intrinsics::stownbyindex"
3460                << " v" << v0 << " imm" << index;
3461     JSTaggedValue receiver = GET_VREG_VALUE(v0);
3462     // fast path
3463     if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
3464         SAVE_ACC();
3465         JSTaggedValue value = GET_ACC();
3466         // fast path
3467         JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex<ObjectFastOperator::Status::UseOwn>
3468                             (thread, receiver, index, value);
3469         if (!res.IsHole()) {
3470             INTERPRETER_RETURN_IF_ABRUPT(res);
3471             RESTORE_ACC();
3472             DISPATCH(WIDE_STOWNBYINDEX_PREF_V8_IMM32);
3473         }
3474         RESTORE_ACC();
3475     }
3476     SAVE_ACC();
3477     receiver = GET_VREG_VALUE(v0);  // Maybe moved by GC
3478     auto value = GET_ACC();         // Maybe moved by GC
3479     SAVE_PC();
3480     JSTaggedValue res = SlowRuntimeStub::StOwnByIndex(thread, receiver, index, value);
3481     INTERPRETER_RETURN_IF_ABRUPT(res);
3482     RESTORE_ACC();
3483     DISPATCH(WIDE_STOWNBYINDEX_PREF_V8_IMM32);
3484 }
3485 
HandleWideStobjbyindexPrefV8Imm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3486 void InterpreterAssembly::HandleWideStobjbyindexPrefV8Imm32(
3487     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3488     JSTaggedValue acc, int16_t hotnessCounter)
3489 {
3490     uint8_t v0 = READ_INST_8_1();
3491     uint32_t index = READ_INST_32_2();
3492     LOG_INST() << "intrinsics::stobjbyindex"
3493                << " v" << v0 << " imm" << index;
3494 
3495     JSTaggedValue receiver = GET_VREG_VALUE(v0);
3496     if (receiver.IsHeapObject()) {
3497         SAVE_ACC();
3498         JSTaggedValue value = GET_ACC();
3499         // fast path
3500         JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex(thread, receiver, index, value);
3501         if (!res.IsHole()) {
3502             INTERPRETER_RETURN_IF_ABRUPT(res);
3503             RESTORE_ACC();
3504             DISPATCH(WIDE_STOBJBYINDEX_PREF_V8_IMM32);
3505         }
3506         RESTORE_ACC();
3507     }
3508     // slow path
3509     SAVE_ACC();
3510     SAVE_PC();
3511     receiver = GET_VREG_VALUE(v0);    // Maybe moved by GC
3512     JSTaggedValue value = GET_ACC();  // Maybe moved by GC
3513     JSTaggedValue res = SlowRuntimeStub::StObjByIndex(thread, receiver, index, value);
3514     INTERPRETER_RETURN_IF_ABRUPT(res);
3515     RESTORE_ACC();
3516     DISPATCH(WIDE_STOBJBYINDEX_PREF_V8_IMM32);
3517 }
3518 
HandleWideLdobjbyindexPrefImm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3519 void InterpreterAssembly::HandleWideLdobjbyindexPrefImm32(
3520     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3521     JSTaggedValue acc, int16_t hotnessCounter)
3522 {
3523     uint32_t idx = READ_INST_32_1();
3524     LOG_INST() << "intrinsics::ldobjbyindex"
3525                << " imm" << idx;
3526 
3527     JSTaggedValue receiver = GET_ACC();
3528     // fast path
3529     if (LIKELY(receiver.IsHeapObject())) {
3530         JSTaggedValue res = FastRuntimeStub::GetPropertyByIndex(thread, receiver, idx);
3531         if (!res.IsHole()) {
3532             INTERPRETER_RETURN_IF_ABRUPT(res);
3533             SET_ACC(res);
3534             DISPATCH(WIDE_LDOBJBYINDEX_PREF_IMM32);
3535         }
3536     }
3537     // not meet fast condition or fast path return hole, walk slow path
3538     // slow stub not need receiver
3539     SAVE_PC();
3540     JSTaggedValue res = SlowRuntimeStub::LdObjByIndex(thread, receiver, idx, false, JSTaggedValue::Undefined());
3541     INTERPRETER_RETURN_IF_ABRUPT(res);
3542     SET_ACC(res);
3543     DISPATCH(WIDE_LDOBJBYINDEX_PREF_IMM32);
3544 }
3545 
AssemblyIsFastNewFrameEnter(JSThread * thread,JSFunction * ctor,JSHandle<Method> method)3546 bool InterpreterAssembly::AssemblyIsFastNewFrameEnter(JSThread *thread, JSFunction *ctor, JSHandle<Method> method)
3547 {
3548     if (method->IsNativeWithCallField()) {
3549         return false;
3550     }
3551 
3552     if (ctor->IsBase(thread)) {
3553         return method->OnlyHaveThisWithCallField();
3554     }
3555 
3556     if (ctor->IsDerivedConstructor(thread)) {
3557         return method->OnlyHaveNewTagetAndThisWithCallField();
3558     }
3559 
3560     return false;
3561 }
3562 
HandleWideSupercallarrowrangePrefImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3563 void InterpreterAssembly::HandleWideSupercallarrowrangePrefImm16V8(
3564     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3565     JSTaggedValue acc, int16_t hotnessCounter)
3566 {
3567     JSMutableHandle<Method> methodHandle(thread, JSTaggedValue::Undefined());
3568     uint16_t range = READ_INST_16_1();
3569     uint16_t v0 = READ_INST_8_3();
3570     LOG_INST() << "intrinsics::supercall"
3571                << " range: " << range << " v" << v0;
3572 
3573     JSTaggedValue thisFunc = GET_ACC();
3574     JSTaggedValue newTarget = GetNewTarget(thread, sp);
3575 
3576     SAVE_PC();
3577     JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc);
3578     INTERPRETER_RETURN_IF_ABRUPT(superCtor);
3579 
3580     if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) {
3581         JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject());
3582         methodHandle.Update(superCtorFunc->GetMethod(thread));
3583         if (superCtorFunc->IsBuiltinConstructor(thread)) {
3584             ASSERT(methodHandle->GetNumVregsWithCallField() == 0);
3585             size_t frameSize =
3586                 InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs
3587             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3588             JSTaggedType *newSp = sp - frameSize;
3589             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
3590                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3591             }
3592             // copy args
3593             uint32_t index = 0;
3594             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3595             EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo *>(newSp);
3596             newSp[index++] = ToUintPtr(thread);
3597             newSp[index++] = range + NUM_MANDATORY_JSFUNC_ARGS;
3598             // func
3599             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3600             newSp[index++] = superCtor.GetRawData();
3601             // newTarget
3602             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3603             newSp[index++] = newTarget.GetRawData();
3604             // this
3605             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3606             newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3607             for (size_t i = 0; i < range; ++i) {
3608                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3609                 newSp[index++] = GET_VREG(v0 + i);
3610             }
3611 
3612             InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp);
3613             state->base.prev = sp;
3614             state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME;
3615             state->pc = nullptr;
3616             state->function = superCtor;
3617             thread->SetCurrentSPFrame(newSp);
3618             LOG_INST() << "Entry: Runtime SuperCall ";
3619             JSTaggedValue retValue = reinterpret_cast<EcmaEntrypoint>(
3620                 superCtorFunc->GetNativePointer())(ecmaRuntimeCallInfo);
3621             thread->SetCurrentSPFrame(sp);
3622 
3623             if (UNLIKELY(thread->HasPendingException())) {
3624                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3625             }
3626             LOG_INST() << "Exit: Runtime SuperCall ";
3627             SET_ACC(retValue);
3628             DISPATCH(WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8);
3629         }
3630 
3631         if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) {
3632             SAVE_PC();
3633             uint32_t numVregs = methodHandle->GetNumVregsWithCallField();
3634             uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ?
3635                 methodHandle->GetNumArgsWithCallField() + 1 :  // +1 for this
3636                 methodHandle->GetNumArgsWithCallField() + 2;   // +2 for newTarget and this
3637             // +1 for hidden this, explicit this may be overwritten after bc optimizer
3638             size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs + 1;
3639             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3640             JSTaggedType *newSp = sp - frameSize;
3641             InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(newSp) - 1;
3642 
3643             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
3644                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3645             }
3646 
3647             uint32_t index = 0;
3648             // initialize vregs value
3649             for (size_t i = 0; i < numVregs; ++i) {
3650                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3651             }
3652 
3653             // this
3654             JSTaggedValue thisObj;
3655             if (superCtorFunc->IsBase(thread)) {
3656                 thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state);
3657                 INTERPRETER_RETURN_IF_ABRUPT(thisObj);
3658                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3659                 newSp[index++] = thisObj.GetRawData();
3660             } else {
3661                 ASSERT(superCtorFunc->IsDerivedConstructor(thread));
3662                 newSp[index++] = newTarget.GetRawData();
3663                 thisObj = JSTaggedValue::Undefined();
3664                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3665                 newSp[index++] = thisObj.GetRawData();
3666 
3667                 state->function = superCtor;
3668                 state->constpool = methodHandle->GetConstantPool(thread);
3669                 state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread);
3670                 state->env = superCtorFunc->GetLexicalEnv(thread);
3671             }
3672 
3673             // the second condition ensure not push extra args
3674             for (size_t i = 0; i < range && index < numVregs + numDeclaredArgs; ++i) {
3675                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3676                 newSp[index++] = GET_VREG(v0 + i);
3677             }
3678 
3679             // set undefined to the extra prats of declare
3680             for (size_t i = index; i < numVregs + numDeclaredArgs; ++i) {
3681                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3682                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3683             }
3684 
3685             state->base.prev = sp;
3686             state->base.type = FrameType::INTERPRETER_FAST_NEW_FRAME;
3687             state->thisObj = thisObj;
3688             state->pc = pc = methodHandle->GetBytecodeArray();
3689             sp = newSp;
3690             state->acc = JSTaggedValue::Hole();
3691 
3692             thread->SetCurrentSPFrame(newSp);
3693             LOG_INST() << "Entry: Runtime SuperCall " << std::hex << reinterpret_cast<uintptr_t>(sp)
3694                                     << " " << std::hex << reinterpret_cast<uintptr_t>(pc);
3695             DISPATCH_OFFSET(0);
3696         }
3697     }
3698 
3699     SAVE_PC();
3700     JSTaggedValue res = SlowRuntimeStub::SuperCall(thread, thisFunc, newTarget, v0, range);
3701     INTERPRETER_RETURN_IF_ABRUPT(res);
3702     SET_ACC(res);
3703     DISPATCH(WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8);
3704 }
3705 
HandleWideSupercallthisrangePrefImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3706 void InterpreterAssembly::HandleWideSupercallthisrangePrefImm16V8(
3707     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3708     JSTaggedValue acc, int16_t hotnessCounter)
3709 {
3710     JSMutableHandle<Method> methodHandle(thread, JSTaggedValue::Undefined());
3711     uint16_t range = READ_INST_16_1();
3712     uint16_t v0 = READ_INST_8_3();
3713     LOG_INST() << "intrinsics::supercall"
3714                << " range: " << range << " v" << v0;
3715 
3716     JSTaggedValue thisFunc = GetFunction(sp);
3717     JSTaggedValue newTarget = GetNewTarget(thread, sp);
3718 
3719     SAVE_PC();
3720     JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc);
3721     INTERPRETER_RETURN_IF_ABRUPT(superCtor);
3722 
3723     if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) {
3724         JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject());
3725         methodHandle.Update(superCtorFunc->GetMethod(thread));
3726         if (superCtorFunc->IsBuiltinConstructor(thread)) {
3727             ASSERT(methodHandle->GetNumVregsWithCallField() == 0);
3728             size_t frameSize =
3729                 InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs
3730             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3731             JSTaggedType *newSp = sp - frameSize;
3732             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
3733                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3734             }
3735             // copy args
3736             uint32_t index = 0;
3737             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3738             EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo *>(newSp);
3739             newSp[index++] = ToUintPtr(thread);
3740             newSp[index++] = range + NUM_MANDATORY_JSFUNC_ARGS;
3741             // func
3742             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3743             newSp[index++] = superCtor.GetRawData();
3744             // newTarget
3745             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3746             newSp[index++] = newTarget.GetRawData();
3747             // this
3748             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3749             newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3750             for (size_t i = 0; i < range; ++i) {
3751                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3752                 newSp[index++] = GET_VREG(v0 + i);
3753             }
3754 
3755             InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp);
3756             state->base.prev = sp;
3757             state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME;
3758             state->pc = nullptr;
3759             state->function = superCtor;
3760             thread->SetCurrentSPFrame(newSp);
3761             LOG_INST() << "Entry: Runtime SuperCall ";
3762             JSTaggedValue retValue = reinterpret_cast<EcmaEntrypoint>(
3763                 superCtorFunc->GetNativePointer())(ecmaRuntimeCallInfo);
3764             thread->SetCurrentSPFrame(sp);
3765 
3766             if (UNLIKELY(thread->HasPendingException())) {
3767                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3768             }
3769             LOG_INST() << "Exit: Runtime SuperCall ";
3770             SET_ACC(retValue);
3771             DISPATCH(WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8);
3772         }
3773 
3774         if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) {
3775             SAVE_PC();
3776             uint32_t numVregs = methodHandle->GetNumVregsWithCallField();
3777             uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ?
3778                 methodHandle->GetNumArgsWithCallField() + 1 :  // +1 for this
3779                 methodHandle->GetNumArgsWithCallField() + 2;   // +2 for newTarget and this
3780             // +1 for hidden this, explicit this may be overwritten after bc optimizer
3781             size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs + 1;
3782             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3783             JSTaggedType *newSp = sp - frameSize;
3784             InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(newSp) - 1;
3785 
3786             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
3787                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3788             }
3789 
3790             uint32_t index = 0;
3791             // initialize vregs value
3792             for (size_t i = 0; i < numVregs; ++i) {
3793                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3794             }
3795 
3796             // this
3797             JSTaggedValue thisObj;
3798             if (superCtorFunc->IsBase(thread)) {
3799                 thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state);
3800                 INTERPRETER_RETURN_IF_ABRUPT(thisObj);
3801                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3802                 newSp[index++] = thisObj.GetRawData();
3803             } else {
3804                 ASSERT(superCtorFunc->IsDerivedConstructor(thread));
3805                 newSp[index++] = newTarget.GetRawData();
3806                 thisObj = JSTaggedValue::Undefined();
3807                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3808                 newSp[index++] = thisObj.GetRawData();
3809 
3810                 state->function = superCtor;
3811                 state->constpool = methodHandle->GetConstantPool(thread);
3812                 state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread);
3813                 state->env = superCtorFunc->GetLexicalEnv(thread);
3814             }
3815 
3816             // the second condition ensure not push extra args
3817             for (size_t i = 0; i < range && index < numVregs + numDeclaredArgs; ++i) {
3818                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3819                 newSp[index++] = GET_VREG(v0 + i);
3820             }
3821 
3822             // set undefined to the extra prats of declare
3823             for (size_t i = index; i < numVregs + numDeclaredArgs; ++i) {
3824                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3825                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3826             }
3827 
3828             state->base.prev = sp;
3829             state->base.type = FrameType::INTERPRETER_FAST_NEW_FRAME;
3830             state->thisObj = thisObj;
3831             state->pc = pc = methodHandle->GetBytecodeArray();
3832             sp = newSp;
3833             state->acc = JSTaggedValue::Hole();
3834 
3835             thread->SetCurrentSPFrame(newSp);
3836             LOG_INST() << "Entry: Runtime SuperCall " << std::hex << reinterpret_cast<uintptr_t>(sp)
3837                                     << " " << std::hex << reinterpret_cast<uintptr_t>(pc);
3838             DISPATCH_OFFSET(0);
3839         }
3840     }
3841 
3842     SAVE_PC();
3843     JSTaggedValue res = SlowRuntimeStub::SuperCall(thread, thisFunc, newTarget, v0, range);
3844     INTERPRETER_RETURN_IF_ABRUPT(res);
3845     SET_ACC(res);
3846     DISPATCH(WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8);
3847 }
3848 
HandleWideCallthisrangePrefImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3849 void InterpreterAssembly::HandleWideCallthisrangePrefImm16V8(
3850     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3851     JSTaggedValue acc, int16_t hotnessCounter)
3852 {
3853     DISPATCH(WIDE_CALLTHISRANGE_PREF_IMM16_V8);
3854 }
3855 
HandleWideCallrangePrefImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3856 void InterpreterAssembly::HandleWideCallrangePrefImm16V8(
3857     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3858     JSTaggedValue acc, int16_t hotnessCounter)
3859 {
3860     DISPATCH(WIDE_CALLRANGE_PREF_IMM16_V8);
3861 }
3862 
HandleWideNewlexenvwithnamePrefImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3863 void InterpreterAssembly::HandleWideNewlexenvwithnamePrefImm16Id16(
3864     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3865     JSTaggedValue acc, int16_t hotnessCounter)
3866 {
3867     uint16_t numVars = READ_INST_16_1();
3868     uint16_t scopeId = READ_INST_16_3();
3869     LOG_INST() << "intrinsics::newlexenvwithname"
3870                << " numVars " << numVars << " scopeId " << scopeId;
3871 
3872     SAVE_PC();
3873     JSTaggedValue res = SlowRuntimeStub::NewLexicalEnvWithName(thread, numVars, scopeId);
3874     INTERPRETER_RETURN_IF_ABRUPT(res);
3875 
3876     SET_ACC(res);
3877     (reinterpret_cast<InterpretedFrame *>(sp) - 1)->env = res;
3878     DISPATCH(WIDE_NEWLEXENVWITHNAME_PREF_IMM16_ID16);
3879 }
3880 
HandleWideNewlexenvPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3881 void InterpreterAssembly::HandleWideNewlexenvPrefImm16(
3882     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3883     JSTaggedValue acc, int16_t hotnessCounter)
3884 {
3885     uint16_t numVars = READ_INST_16_1();
3886     LOG_INST() << "intrinsics::newlexenv"
3887                << " imm " << numVars;
3888 
3889     EcmaVM *ecmaVm = thread->GetEcmaVM();
3890     ObjectFactory *factory = ecmaVm->GetFactory();
3891     JSTaggedValue res = FastRuntimeStub::NewLexicalEnv(thread, factory, numVars);
3892     if (res.IsHole()) {
3893         SAVE_PC();
3894         res = SlowRuntimeStub::NewLexicalEnv(thread, numVars);
3895         INTERPRETER_RETURN_IF_ABRUPT(res);
3896     }
3897     SET_ACC(res);
3898     (reinterpret_cast<InterpretedFrame *>(sp) - 1)->env = res;
3899     DISPATCH(WIDE_NEWLEXENV_PREF_IMM16);
3900 }
3901 
HandleWideNewobjrangePrefImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)3902 void InterpreterAssembly::HandleWideNewobjrangePrefImm16V8(
3903     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
3904     JSTaggedValue acc, int16_t hotnessCounter)
3905 {
3906     JSMutableHandle<Method> methodHandle(thread, JSTaggedValue::Undefined());
3907     uint16_t numArgs = READ_INST_16_1();
3908     uint16_t firstArgRegIdx = READ_INST_8_3();
3909     LOG_INST() << "intrinsics::newobjRange " << numArgs << " v" << firstArgRegIdx;
3910     JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx);
3911     if (ctor.IsJSFunction() && ctor.IsConstructor()) {
3912         JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject());
3913         methodHandle.Update(ctorFunc->GetMethod(thread));
3914         if (ctorFunc->IsBuiltinConstructor(thread)) {
3915             ASSERT(methodHandle->GetNumVregsWithCallField() == 0);
3916             size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4;  // 3: this & numArgs & thread
3917             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3918             JSTaggedType *newSp = sp - frameSize;
3919             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
3920                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3921             }
3922             // copy args
3923             uint32_t index = 0;
3924             // numArgs
3925             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3926             EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo*>(newSp);
3927             newSp[index++] = ToUintPtr(thread);
3928             newSp[index++] = numArgs + 2; // 2 : for newtarget / this
3929             // func
3930             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3931             newSp[index++] = ctor.GetRawData();
3932             // newTarget
3933             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3934             newSp[index++] = ctor.GetRawData();
3935             // this
3936             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3937             newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3938             for (size_t i = 1; i < numArgs; ++i) {
3939                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3940                 newSp[index++] = GET_VREG(firstArgRegIdx + i);
3941             }
3942 
3943             InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp);
3944             state->base.prev = sp;
3945             state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME;
3946             state->pc = nullptr;
3947             state->function = ctor;
3948             thread->SetCurrentSPFrame(newSp);
3949 
3950             LOG_INST() << "Entry: Runtime New.";
3951             SAVE_PC();
3952             JSTaggedValue retValue = reinterpret_cast<EcmaEntrypoint>(
3953                 ctorFunc->GetNativePointer())(ecmaRuntimeCallInfo);
3954             thread->SetCurrentSPFrame(sp);
3955             if (UNLIKELY(thread->HasPendingException())) {
3956                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3957             }
3958             LOG_INST() << "Exit: Runtime New.";
3959             SET_ACC(retValue);
3960             DISPATCH(WIDE_NEWOBJRANGE_PREF_IMM16_V8);
3961         }
3962 
3963         if (AssemblyIsFastNewFrameEnter(thread, ctorFunc, methodHandle)) {
3964             SAVE_PC();
3965             uint32_t numVregs = methodHandle->GetNumVregsWithCallField();
3966             uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ?
3967                                        methodHandle->GetNumArgsWithCallField() + 1 :  // +1 for this
3968                                        methodHandle->GetNumArgsWithCallField() + 2;   // +2 for newTarget and this
3969             size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs;
3970             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3971             JSTaggedType *newSp = sp - frameSize;
3972             InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(newSp) - 1);
3973 
3974             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
3975                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
3976             }
3977 
3978             uint32_t index = 0;
3979             // initialize vregs value
3980             for (size_t i = 0; i < numVregs; ++i) {
3981                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
3982             }
3983 
3984             // this
3985             JSTaggedValue thisObj;
3986             if (ctorFunc->IsBase(thread)) {
3987                 thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state);
3988                 INTERPRETER_RETURN_IF_ABRUPT(thisObj);
3989                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3990                 newSp[index++] = thisObj.GetRawData();
3991             } else {
3992                 ASSERT(ctorFunc->IsDerivedConstructor(thread));
3993                 newSp[index++] = ctor.GetRawData();
3994                 thisObj = JSTaggedValue::Undefined();
3995                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
3996                 newSp[index++] = thisObj.GetRawData();
3997 
3998                 state->function = ctor;
3999                 state->constpool = methodHandle->GetConstantPool(thread);
4000                 state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread);
4001                 state->env = ctorFunc->GetLexicalEnv(thread);
4002             }
4003 
4004             // the second condition ensure not push extra args
4005             for (size_t i = 1; i < numArgs && index < numVregs + numDeclaredArgs; ++i) {
4006                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
4007                 newSp[index++] = GET_VREG(firstArgRegIdx + i);
4008             }
4009 
4010             // set undefined to the extra prats of declare
4011             for (size_t i = index; i < numVregs + numDeclaredArgs; ++i) {
4012                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
4013                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
4014             }
4015 
4016             state->base.prev = sp;
4017             state->base.type = FrameType::INTERPRETER_FAST_NEW_FRAME;
4018             state->thisObj = thisObj;
4019             state->pc = pc = methodHandle->GetBytecodeArray();
4020             sp = newSp;
4021             state->acc = JSTaggedValue::Hole();
4022 
4023             thread->SetCurrentSPFrame(newSp);
4024             LOG_INST() << "Entry: Runtime New " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
4025                                     << std::hex << reinterpret_cast<uintptr_t>(pc);
4026             DISPATCH_OFFSET(0);
4027         }
4028     }
4029 
4030     // bound function, proxy, other call types, enter slow path
4031     constexpr uint16_t firstArgOffset = 1;
4032     // Exclude func and newTarget
4033     uint16_t firstArgIdx = firstArgRegIdx + firstArgOffset;
4034     uint16_t length = numArgs - firstArgOffset;
4035 
4036     SAVE_PC();
4037     JSTaggedValue res = SlowRuntimeStub::NewObjRange(thread, ctor, ctor, firstArgIdx, length);
4038     INTERPRETER_RETURN_IF_ABRUPT(res);
4039     SET_ACC(res);
4040     DISPATCH(WIDE_NEWOBJRANGE_PREF_IMM16_V8);
4041 }
4042 
HandleWideCreateobjectwithexcludedkeysPrefImm16V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4043 void InterpreterAssembly::HandleWideCreateobjectwithexcludedkeysPrefImm16V8V8(
4044     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4045     JSTaggedValue acc, int16_t hotnessCounter)
4046 {
4047     uint16_t numKeys = READ_INST_16_1();
4048     uint16_t v0 = READ_INST_8_3();
4049     uint16_t firstArgRegIdx = READ_INST_8_4();
4050     LOG_INST() << "intrinsics::createobjectwithexcludedkeys " << numKeys << " v" << firstArgRegIdx;
4051 
4052     JSTaggedValue obj = GET_VREG_VALUE(v0);
4053 
4054     SAVE_PC();
4055     JSTaggedValue res = SlowRuntimeStub::CreateObjectWithExcludedKeys(thread, numKeys, obj, firstArgRegIdx);
4056     INTERPRETER_RETURN_IF_ABRUPT(res);
4057     SET_ACC(res);
4058     DISPATCH(WIDE_CREATEOBJECTWITHEXCLUDEDKEYS_PREF_IMM16_V8_V8);
4059 }
4060 
HandleDeprecatedCreateobjecthavingmethodPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4061 void InterpreterAssembly::HandleDeprecatedCreateobjecthavingmethodPrefImm16(
4062     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4063     JSTaggedValue acc, int16_t hotnessCounter)
4064 {
4065     uint16_t imm = READ_INST_16_1();
4066     LOG_INST() << "intrinsics::createobjecthavingmethod"
4067                << " imm:" << imm;
4068     SAVE_ACC();
4069     constpool = GetConstantPool(thread, sp);
4070     JSObject *result =
4071         JSObject::Cast(ConstantPool::GetMethodFromCache(thread, constpool, imm).GetTaggedObject());
4072     RESTORE_ACC();
4073     JSTaggedValue env = GET_ACC();
4074 
4075     SAVE_PC();
4076     EcmaVM *ecmaVm = thread->GetEcmaVM();
4077     ObjectFactory *factory = ecmaVm->GetFactory();
4078     JSTaggedValue res = SlowRuntimeStub::CreateObjectHavingMethod(thread, factory, result, env);
4079     INTERPRETER_RETURN_IF_ABRUPT(res);
4080     SET_ACC(res);
4081     DISPATCH(DEPRECATED_CREATEOBJECTHAVINGMETHOD_PREF_IMM16);
4082 }
4083 
HandleDeprecatedLdhomeobjectPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4084 void InterpreterAssembly::HandleDeprecatedLdhomeobjectPrefNone(
4085     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4086     JSTaggedValue acc, int16_t hotnessCounter)
4087 {
4088     LOG_INST() << "intrinsics::ldhomeobject";
4089 
4090     JSTaggedValue thisFunc = GetFunction(sp);
4091     JSTaggedValue homeObject = JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject(thread);
4092 
4093     SET_ACC(homeObject);
4094     DISPATCH(DEPRECATED_LDHOMEOBJECT_PREF_NONE);
4095 }
4096 
HandleDeprecatedStclasstoglobalrecordPrefId32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4097 void InterpreterAssembly::HandleDeprecatedStclasstoglobalrecordPrefId32(
4098     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4099     JSTaggedValue acc, int16_t hotnessCounter)
4100 {
4101     uint16_t stringId = READ_INST_32_1();
4102     SAVE_ACC();
4103     constpool = GetConstantPool(thread, sp);
4104     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4105     RESTORE_ACC();
4106     LOG_INST() << "intrinsics::stclasstoglobalrecord"
4107                << " stringId:" << stringId << ", "
4108                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()));
4109 
4110     JSTaggedValue value = GET_ACC();
4111     SAVE_PC();
4112     JSTaggedValue res = SlowRuntimeStub::StGlobalRecord(thread, propKey, value, false);
4113     INTERPRETER_RETURN_IF_ABRUPT(res);
4114     RESTORE_ACC();
4115     DISPATCH(DEPRECATED_STCLASSTOGLOBALRECORD_PREF_ID32);
4116 }
4117 
HandleDeprecatedStlettoglobalrecordPrefId32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4118 void InterpreterAssembly::HandleDeprecatedStlettoglobalrecordPrefId32(
4119     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4120     JSTaggedValue acc, int16_t hotnessCounter)
4121 {
4122     uint16_t stringId = READ_INST_32_1();
4123     SAVE_ACC();
4124     constpool = GetConstantPool(thread, sp);
4125     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4126     RESTORE_ACC();
4127     LOG_INST() << "intrinsics::stlettoglobalrecord"
4128                << " stringId:" << stringId << ", "
4129                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()));
4130 
4131     JSTaggedValue value = GET_ACC();
4132     SAVE_PC();
4133     JSTaggedValue res = SlowRuntimeStub::StGlobalRecord(thread, propKey, value, false);
4134     INTERPRETER_RETURN_IF_ABRUPT(res);
4135     RESTORE_ACC();
4136     DISPATCH(DEPRECATED_STLETTOGLOBALRECORD_PREF_ID32);
4137 }
4138 
HandleDeprecatedStconsttoglobalrecordPrefId32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4139 void InterpreterAssembly::HandleDeprecatedStconsttoglobalrecordPrefId32(
4140     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4141     JSTaggedValue acc, int16_t hotnessCounter)
4142 {
4143     uint16_t stringId = READ_INST_32_1();
4144     SAVE_ACC();
4145     constpool = GetConstantPool(thread, sp);
4146     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4147     RESTORE_ACC();
4148     LOG_INST() << "intrinsics::stconsttoglobalrecord"
4149                << " stringId:" << stringId << ", "
4150                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()));
4151 
4152     JSTaggedValue value = GET_ACC();
4153     SAVE_PC();
4154     JSTaggedValue res = SlowRuntimeStub::StGlobalRecord(thread, propKey, value, true);
4155     INTERPRETER_RETURN_IF_ABRUPT(res);
4156     RESTORE_ACC();
4157     DISPATCH(DEPRECATED_STCONSTTOGLOBALRECORD_PREF_ID32);
4158 }
4159 
HandleDeprecatedLdmodulevarPrefId32Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4160 void InterpreterAssembly::HandleDeprecatedLdmodulevarPrefId32Imm8(
4161     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4162     JSTaggedValue acc, int16_t hotnessCounter)
4163 {
4164     uint16_t stringId = READ_INST_16_1();
4165     uint8_t innerFlag = READ_INST_8_5();
4166 
4167     constpool = GetConstantPool(thread, sp);
4168     JSTaggedValue key = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4169     LOG_INST() << "intrinsics::ldmodulevar "
4170                << "string_id:" << stringId << ", "
4171                << "key: " << ConvertToString(thread, EcmaString::Cast(key.GetTaggedObject()));
4172 
4173     JSTaggedValue moduleVar = SlowRuntimeStub::LdModuleVar(thread, key, innerFlag != 0);
4174     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
4175     SET_ACC(moduleVar);
4176     DISPATCH(DEPRECATED_LDMODULEVAR_PREF_ID32_IMM8);
4177 }
HandleDeprecatedLdsuperbynamePrefId32V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4178 void InterpreterAssembly::HandleDeprecatedLdsuperbynamePrefId32V8(
4179     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4180     JSTaggedValue acc, int16_t hotnessCounter)
4181 {
4182     uint32_t stringId = READ_INST_32_1();
4183     uint32_t v0 = READ_INST_8_5();
4184     JSTaggedValue obj = GET_VREG_VALUE(v0);
4185     constpool = GetConstantPool(thread, sp);
4186     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4187 
4188     LOG_INST() << "intrinsics::ldsuperbyname"
4189                << "v" << v0 << " stringId:" << stringId << ", "
4190                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData();
4191 
4192     SAVE_PC();
4193     JSTaggedValue thisFunc = GetFunction(sp);
4194     JSTaggedValue res = SlowRuntimeStub::LdSuperByValue(thread, obj, propKey, thisFunc);
4195 
4196     INTERPRETER_RETURN_IF_ABRUPT(res);
4197     SET_ACC(res);
4198     DISPATCH(DEPRECATED_LDSUPERBYNAME_PREF_ID32_V8);
4199 }
HandleDeprecatedLdobjbynamePrefId32V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4200 void InterpreterAssembly::HandleDeprecatedLdobjbynamePrefId32V8(
4201     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4202     JSTaggedValue acc, int16_t hotnessCounter)
4203 {
4204     uint32_t v0 = READ_INST_8_5();
4205     JSTaggedValue receiver = GET_VREG_VALUE(v0);
4206 
4207     uint16_t stringId = READ_INST_32_1();
4208     constpool = GetConstantPool(thread, sp);
4209     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4210     LOG_INST() << "intrinsics::ldobjbyname "
4211                << "v" << v0 << " stringId:" << stringId << ", "
4212                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()))
4213                << ", obj:" << receiver.GetRawData();
4214 
4215     if (LIKELY(receiver.IsHeapObject())) {
4216         // fast path
4217         JSTaggedValue res = FastRuntimeStub::GetPropertyByName(thread, receiver, propKey);
4218         if (!res.IsHole()) {
4219             ASSERT(!res.IsAccessor());
4220             INTERPRETER_RETURN_IF_ABRUPT(res);
4221             SET_ACC(res);
4222             DISPATCH(DEPRECATED_LDOBJBYNAME_PREF_ID32_V8);
4223         }
4224     }
4225     // not meet fast condition or fast path return hole, walk slow path
4226     // slow stub not need receiver
4227     SAVE_PC();
4228     JSTaggedValue res = SlowRuntimeStub::LdObjByName(thread, receiver, propKey, false, JSTaggedValue::Undefined());
4229     INTERPRETER_RETURN_IF_ABRUPT(res);
4230     SET_ACC(res);
4231     DISPATCH(DEPRECATED_LDOBJBYNAME_PREF_ID32_V8);
4232 }
4233 
HandleDeprecatedStmodulevarPrefId32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4234 void InterpreterAssembly::HandleDeprecatedStmodulevarPrefId32(
4235     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4236     JSTaggedValue acc, int16_t hotnessCounter)
4237 {
4238     uint16_t stringId = READ_INST_32_1();
4239     SAVE_ACC();
4240     constpool = GetConstantPool(thread, sp);
4241     auto key = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4242     RESTORE_ACC();
4243 
4244     LOG_INST() << "intrinsics::stmodulevar "
4245                << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(key.GetTaggedObject()));
4246 
4247     JSTaggedValue value = GET_ACC();
4248 
4249     SlowRuntimeStub::StModuleVar(thread, key, value);
4250     RESTORE_ACC();
4251     DISPATCH(DEPRECATED_STMODULEVAR_PREF_ID32);
4252 }
4253 
HandleDeprecatedGetmodulenamespacePrefId32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4254 void InterpreterAssembly::HandleDeprecatedGetmodulenamespacePrefId32(
4255     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4256     JSTaggedValue acc, int16_t hotnessCounter)
4257 {
4258     uint16_t stringId = READ_INST_32_1();
4259     constpool = GetConstantPool(thread, sp);
4260     auto localName = ConstantPool::GetStringFromCache(thread, constpool, stringId);
4261 
4262     LOG_INST() << "intrinsics::getmodulenamespace "
4263                << "stringId:" << stringId << ", "
4264                << ConvertToString(thread, EcmaString::Cast(localName.GetTaggedObject()));
4265 
4266     JSTaggedValue moduleNamespace = SlowRuntimeStub::GetModuleNamespace(thread, localName);
4267     INTERPRETER_RETURN_IF_ABRUPT(moduleNamespace);
4268     SET_ACC(moduleNamespace);
4269     DISPATCH(DEPRECATED_GETMODULENAMESPACE_PREF_ID32);
4270 }
4271 
HandleDeprecatedStlexvarPrefImm16Imm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4272 void InterpreterAssembly::HandleDeprecatedStlexvarPrefImm16Imm16V8(
4273     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4274     JSTaggedValue acc, int16_t hotnessCounter)
4275 {
4276     uint16_t level = READ_INST_16_1();
4277     uint16_t slot = READ_INST_16_3();
4278     uint16_t v0 = READ_INST_8_5();
4279     LOG_INST() << "intrinsics::stlexvar"
4280                << " level:" << level << " slot:" << slot << " v" << v0;
4281 
4282     JSTaggedValue value = GET_VREG_VALUE(v0);
4283     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
4284     JSTaggedValue env = state->env;
4285     for (uint32_t i = 0; i < level; i++) {
4286         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
4287         ASSERT(!taggedParentEnv.IsUndefined());
4288         env = taggedParentEnv;
4289     }
4290     LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
4291 
4292     DISPATCH(DEPRECATED_STLEXVAR_PREF_IMM16_IMM16_V8);
4293 }
4294 
HandleDeprecatedStlexvarPrefImm8Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4295 void InterpreterAssembly::HandleDeprecatedStlexvarPrefImm8Imm8V8(
4296     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4297     JSTaggedValue acc, int16_t hotnessCounter)
4298 {
4299     uint16_t level = READ_INST_8_1();
4300     uint16_t slot = READ_INST_8_2();
4301     uint16_t v0 = READ_INST_8_3();
4302     LOG_INST() << "intrinsics::stlexvar"
4303                << " level:" << level << " slot:" << slot << " v" << v0;
4304 
4305     JSTaggedValue value = GET_VREG_VALUE(v0);
4306     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
4307     JSTaggedValue env = state->env;
4308     for (uint32_t i = 0; i < level; i++) {
4309         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
4310         ASSERT(!taggedParentEnv.IsUndefined());
4311         env = taggedParentEnv;
4312     }
4313     LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
4314 
4315     DISPATCH(DEPRECATED_STLEXVAR_PREF_IMM8_IMM8_V8);
4316 }
4317 
HandleDeprecatedStlexvarPrefImm4Imm4V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4318 void InterpreterAssembly::HandleDeprecatedStlexvarPrefImm4Imm4V8(
4319     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4320     JSTaggedValue acc, int16_t hotnessCounter)
4321 {
4322     uint16_t level = READ_INST_4_2();
4323     uint16_t slot = READ_INST_4_3();
4324     uint16_t v0 = READ_INST_8_2();
4325     LOG_INST() << "intrinsics::stlexvar"
4326                << " level:" << level << " slot:" << slot << " v" << v0;
4327 
4328     JSTaggedValue value = GET_VREG_VALUE(v0);
4329     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
4330     JSTaggedValue env = state->env;
4331     for (uint32_t i = 0; i < level; i++) {
4332         JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
4333         ASSERT(!taggedParentEnv.IsUndefined());
4334         env = taggedParentEnv;
4335     }
4336     LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
4337 
4338     DISPATCH(DEPRECATED_STLEXVAR_PREF_IMM4_IMM4_V8);
4339 }
4340 
HandleDeprecatedAsyncfunctionrejectPrefV8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4341 void InterpreterAssembly::HandleDeprecatedAsyncfunctionrejectPrefV8V8V8(
4342     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4343     JSTaggedValue acc, int16_t hotnessCounter)
4344 {
4345     uint16_t v0 = READ_INST_8_1();
4346     uint16_t v1 = READ_INST_8_2();
4347     uint16_t v2 = READ_INST_8_3();
4348     LOG_INST() << "intrinsics::asyncfunctionreject"
4349                << " v" << v0 << " v" << v1 << " v" << v2;
4350 
4351     JSTaggedValue asyncFuncObj = GET_VREG_VALUE(v0);
4352     JSTaggedValue value = GET_VREG_VALUE(v2);
4353     SAVE_PC();
4354     JSTaggedValue res = SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, asyncFuncObj, value, false);
4355     INTERPRETER_RETURN_IF_ABRUPT(res);
4356     SET_ACC(res);
4357     DISPATCH(DEPRECATED_ASYNCFUNCTIONREJECT_PREF_V8_V8_V8);
4358 }
4359 
HandleDeprecatedAsyncfunctionresolvePrefV8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4360 void InterpreterAssembly::HandleDeprecatedAsyncfunctionresolvePrefV8V8V8(
4361     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4362     JSTaggedValue acc, int16_t hotnessCounter)
4363 {
4364     uint16_t v0 = READ_INST_8_1();
4365     uint16_t v1 = READ_INST_8_2();
4366     uint16_t v2 = READ_INST_8_3();
4367     LOG_INST() << "intrinsics::asyncfunctionresolve"
4368                << " v" << v0 << " v" << v1 << " v" << v2;
4369 
4370     JSTaggedValue asyncFuncObj = GET_VREG_VALUE(v0);
4371     JSTaggedValue value = GET_VREG_VALUE(v2);
4372     SAVE_PC();
4373     JSTaggedValue res = SlowRuntimeStub::AsyncFunctionResolveOrReject(thread, asyncFuncObj, value, true);
4374     INTERPRETER_RETURN_IF_ABRUPT(res);
4375     SET_ACC(res);
4376     DISPATCH(DEPRECATED_ASYNCFUNCTIONRESOLVE_PREF_V8_V8_V8);
4377 }
4378 
HandleDeprecatedLdobjbyindexPrefV8Imm32(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4379 void InterpreterAssembly::HandleDeprecatedLdobjbyindexPrefV8Imm32(
4380     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4381     JSTaggedValue acc, int16_t hotnessCounter)
4382 {
4383     uint16_t v0 = READ_INST_8_1();
4384     uint32_t idx = READ_INST_32_2();
4385     LOG_INST() << "intrinsics::ldobjbyindex"
4386                << " v" << v0 << " imm" << idx;
4387 
4388     JSTaggedValue receiver = GET_VREG_VALUE(v0);
4389     // fast path
4390     if (LIKELY(receiver.IsHeapObject())) {
4391         JSTaggedValue res = FastRuntimeStub::GetPropertyByIndex(thread, receiver, idx);
4392         if (!res.IsHole()) {
4393             INTERPRETER_RETURN_IF_ABRUPT(res);
4394             SET_ACC(res);
4395             DISPATCH(DEPRECATED_LDOBJBYINDEX_PREF_V8_IMM32);
4396         }
4397     }
4398     // not meet fast condition or fast path return hole, walk slow path
4399     // slow stub not need receiver
4400     SAVE_PC();
4401     JSTaggedValue res = SlowRuntimeStub::LdObjByIndex(thread, receiver, idx, false, JSTaggedValue::Undefined());
4402     INTERPRETER_RETURN_IF_ABRUPT(res);
4403     SET_ACC(res);
4404     DISPATCH(DEPRECATED_LDOBJBYINDEX_PREF_V8_IMM32);
4405 }
4406 
HandleDeprecatedLdsuperbyvaluePrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4407 void InterpreterAssembly::HandleDeprecatedLdsuperbyvaluePrefV8V8(
4408     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4409     JSTaggedValue acc, int16_t hotnessCounter)
4410 {
4411     uint32_t v0 = READ_INST_8_1();
4412     uint32_t v1 = READ_INST_8_2();
4413     LOG_INST() << "intrinsics::Ldsuperbyvalue"
4414                << " v" << v0 << " v" << v1;
4415 
4416     JSTaggedValue receiver = GET_VREG_VALUE(v0);
4417     JSTaggedValue propKey = GET_VREG_VALUE(v1);
4418 
4419     // slow path
4420     SAVE_PC();
4421     JSTaggedValue thisFunc = GetFunction(sp);
4422     JSTaggedValue res = SlowRuntimeStub::LdSuperByValue(thread, receiver, propKey, thisFunc);
4423     INTERPRETER_RETURN_IF_ABRUPT(res);
4424     SET_ACC(res);
4425     DISPATCH(DEPRECATED_LDSUPERBYVALUE_PREF_V8_V8);
4426 }
4427 
HandleDeprecatedLdobjbyvaluePrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4428 void InterpreterAssembly::HandleDeprecatedLdobjbyvaluePrefV8V8(
4429     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4430     JSTaggedValue acc, int16_t hotnessCounter)
4431 {
4432     uint32_t v0 = READ_INST_8_1();
4433     uint32_t v1 = READ_INST_8_2();
4434     LOG_INST() << "intrinsics::Ldobjbyvalue"
4435                << " v" << v0 << " v" << v1;
4436 
4437     JSTaggedValue receiver = GET_VREG_VALUE(v0);
4438     JSTaggedValue propKey = GET_VREG_VALUE(v1);
4439 
4440     // fast path
4441     if (LIKELY(receiver.IsHeapObject())) {
4442         JSTaggedValue res = FastRuntimeStub::GetPropertyByValue(thread, receiver, propKey);
4443         if (!res.IsHole()) {
4444             ASSERT(!res.IsAccessor());
4445             INTERPRETER_RETURN_IF_ABRUPT(res);
4446             SET_ACC(res);
4447             DISPATCH(DEPRECATED_LDOBJBYVALUE_PREF_V8_V8);
4448         }
4449     }
4450     // slow path
4451     SAVE_PC();
4452     JSTaggedValue res = SlowRuntimeStub::LdObjByValue(thread, receiver, propKey, false, JSTaggedValue::Undefined());
4453     INTERPRETER_RETURN_IF_ABRUPT(res);
4454     SET_ACC(res);
4455     DISPATCH(DEPRECATED_LDOBJBYVALUE_PREF_V8_V8);
4456 }
4457 
HandleDeprecatedSetobjectwithprotoPrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4458 void InterpreterAssembly::HandleDeprecatedSetobjectwithprotoPrefV8V8(
4459     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4460     JSTaggedValue acc, int16_t hotnessCounter)
4461 {
4462     uint16_t v0 = READ_INST_8_1();
4463     uint16_t v1 = READ_INST_8_2();
4464     LOG_INST() << "intrinsics::setobjectwithproto"
4465                << " v" << v0 << " v" << v1;
4466     JSTaggedValue proto = GET_VREG_VALUE(v0);
4467     JSTaggedValue obj = GET_VREG_VALUE(v1);
4468     SAVE_ACC();
4469     SAVE_PC();
4470     JSTaggedValue res = SlowRuntimeStub::SetObjectWithProto(thread, proto, obj);
4471     INTERPRETER_RETURN_IF_ABRUPT(res);
4472     RESTORE_ACC();
4473     DISPATCH(DEPRECATED_SETOBJECTWITHPROTO_PREF_V8_V8);
4474 }
4475 
HandleDeprecatedCopydatapropertiesPrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4476 void InterpreterAssembly::HandleDeprecatedCopydatapropertiesPrefV8V8(
4477     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4478     JSTaggedValue acc, int16_t hotnessCounter)
4479 {
4480     uint16_t v0 = READ_INST_8_1();
4481     uint16_t v1 = READ_INST_8_2();
4482     LOG_INST() << "intrinsic::copydataproperties"
4483                << " v" << v0 << " v" << v1;
4484     JSTaggedValue dst = GET_VREG_VALUE(v0);
4485     JSTaggedValue src = GET_VREG_VALUE(v1);
4486     SAVE_PC();
4487     JSTaggedValue res = SlowRuntimeStub::CopyDataProperties(thread, dst, src);
4488     INTERPRETER_RETURN_IF_ABRUPT(res);
4489     SET_ACC(res);
4490     DISPATCH(DEPRECATED_COPYDATAPROPERTIES_PREF_V8_V8);
4491 }
4492 
HandleDeprecatedAsyncfunctionawaituncaughtPrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4493 void InterpreterAssembly::HandleDeprecatedAsyncfunctionawaituncaughtPrefV8V8(
4494     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4495     JSTaggedValue acc, int16_t hotnessCounter)
4496 {
4497     uint16_t v0 = READ_INST_8_1();
4498     uint16_t v1 = READ_INST_8_2();
4499     LOG_INST() << "intrinsics::asyncfunctionawaituncaught"
4500                << " v" << v0 << " v" << v1;
4501     JSTaggedValue asyncFuncObj = GET_VREG_VALUE(v0);
4502     JSTaggedValue value = GET_VREG_VALUE(v1);
4503     SAVE_PC();
4504     JSTaggedValue res = SlowRuntimeStub::AsyncFunctionAwaitUncaught(thread, asyncFuncObj, value);
4505     INTERPRETER_RETURN_IF_ABRUPT(res);
4506     SET_ACC(res);
4507     DISPATCH(DEPRECATED_ASYNCFUNCTIONAWAITUNCAUGHT_PREF_V8_V8);
4508 }
4509 
HandleDeprecatedSuspendgeneratorPrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4510 void InterpreterAssembly::HandleDeprecatedSuspendgeneratorPrefV8V8(
4511     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4512     JSTaggedValue acc, int16_t hotnessCounter)
4513 {
4514     uint16_t v0 = READ_INST_8_1();
4515     uint16_t v1 = READ_INST_8_2();
4516     LOG_INST() << "intrinsics::suspendgenerator"
4517                << " v" << v0 << " v" << v1;
4518     JSTaggedValue genObj = GET_VREG_VALUE(v0);
4519     JSTaggedValue value = GET_VREG_VALUE(v1);
4520     // suspend will record bytecode offset
4521     SAVE_PC();
4522     SAVE_ACC();
4523     JSTaggedValue res = SlowRuntimeStub::SuspendGenerator(thread, genObj, value);
4524     INTERPRETER_RETURN_IF_ABRUPT(res);
4525     SET_ACC(res);
4526 
4527     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
4528     Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
4529     [[maybe_unused]] auto fistPC = method->GetBytecodeArray();
4530     UPDATE_HOTNESS_COUNTER(-(pc - fistPC));
4531     LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
4532                             << std::hex << reinterpret_cast<uintptr_t>(state->pc);
4533     sp = state->base.prev;
4534     ASSERT(sp != nullptr);
4535     InterpretedFrame *prevState = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
4536     pc = prevState->pc;
4537     // entry frame
4538     if (FrameHandler::IsEntryFrame(pc)) {
4539         state->acc = acc;
4540         return;
4541     }
4542 
4543     thread->SetCurrentSPFrame(sp);
4544 
4545     size_t jumpSize = GetJumpSizeAfterCall(pc);
4546     DISPATCH_OFFSET(jumpSize);
4547 }
4548 
HandleDeprecatedDelobjpropPrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4549 void InterpreterAssembly::HandleDeprecatedDelobjpropPrefV8V8(
4550     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4551     JSTaggedValue acc, int16_t hotnessCounter)
4552 {
4553     uint16_t v0 = READ_INST_8_1();
4554     uint16_t v1 = READ_INST_8_2();
4555     LOG_INST() << "intrinsics::delobjprop"
4556                << " v0" << v0 << " v1" << v1;
4557 
4558     JSTaggedValue obj = GET_VREG_VALUE(v0);
4559     JSTaggedValue prop = GET_VREG_VALUE(v1);
4560     SAVE_PC();
4561     JSTaggedValue res = SlowRuntimeStub::DelObjProp(thread, obj, prop);
4562     INTERPRETER_RETURN_IF_ABRUPT(res);
4563     SET_ACC(res);
4564 
4565     DISPATCH(DEPRECATED_DELOBJPROP_PREF_V8_V8);
4566 }
4567 
HandleDeprecatedGettemplateobjectPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4568 void InterpreterAssembly::HandleDeprecatedGettemplateobjectPrefV8(
4569     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4570     JSTaggedValue acc, int16_t hotnessCounter)
4571 {
4572     uint16_t v0 = READ_INST_8_1();
4573     LOG_INST() << "intrinsic::gettemplateobject"
4574                << " v" << v0;
4575 
4576     JSTaggedValue literal = GET_VREG_VALUE(v0);
4577     SAVE_PC();
4578     JSTaggedValue res = SlowRuntimeStub::GetTemplateObject(thread, literal);
4579     INTERPRETER_RETURN_IF_ABRUPT(res);
4580     SET_ACC(res);
4581     DISPATCH(DEPRECATED_GETTEMPLATEOBJECT_PREF_V8);
4582 }
4583 
HandleDeprecatedGetresumemodePrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4584 void InterpreterAssembly::HandleDeprecatedGetresumemodePrefV8(
4585     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4586     JSTaggedValue acc, int16_t hotnessCounter)
4587 {
4588     LOG_INST() << "intrinsics::getresumemode";
4589     uint16_t vs = READ_INST_8_1();
4590     JSTaggedValue objVal = GET_VREG_VALUE(vs);
4591     if (objVal.IsAsyncGeneratorObject()) {
4592         JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject());
4593         SET_ACC(JSTaggedValue(static_cast<int>(obj->GetResumeMode())));
4594     } else {
4595         JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject());
4596         SET_ACC(JSTaggedValue(static_cast<int>(obj->GetResumeMode())));
4597     }
4598     DISPATCH(DEPRECATED_GETRESUMEMODE_PREF_V8);
4599 }
4600 
HandleDeprecatedResumegeneratorPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4601 void InterpreterAssembly::HandleDeprecatedResumegeneratorPrefV8(
4602     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4603     JSTaggedValue acc, int16_t hotnessCounter)
4604 {
4605     LOG_INST() << "intrinsics::resumegenerator";
4606     uint16_t vs = READ_INST_8_1();
4607     JSTaggedValue objVal = GET_VREG_VALUE(vs);
4608     if (objVal.IsAsyncGeneratorObject()) {
4609         JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject());
4610         SET_ACC(obj->GetResumeResult(thread));
4611     } else {
4612         JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject());
4613         SET_ACC(obj->GetResumeResult(thread));
4614     }
4615     DISPATCH(DEPRECATED_RESUMEGENERATOR_PREF_V8);
4616 }
4617 
HandleDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4618 void InterpreterAssembly::HandleDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8(
4619     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4620     JSTaggedValue acc, int16_t hotnessCounter)
4621 {
4622     uint16_t methodId = READ_INST_16_1();
4623     uint16_t length = READ_INST_16_5();
4624     uint16_t v0 = READ_INST_8_7();
4625     uint16_t v1 = READ_INST_8_8();
4626     LOG_INST() << "intrinsics::defineclasswithbuffer"
4627                << " method id:" << methodId << " lexenv: v" << v0 << " parent: v" << v1;
4628 
4629     JSTaggedValue lexenv = GET_VREG_VALUE(v0);
4630     JSTaggedValue proto = GET_VREG_VALUE(v1);
4631 
4632     SAVE_PC();
4633     JSTaggedValue res =
4634         SlowRuntimeStub::CreateClassWithBuffer(thread, proto, lexenv, GetConstantPool(thread, sp),
4635                                                methodId, methodId + 1, GetModule(thread, sp),
4636                                                JSTaggedValue(length));
4637 
4638     INTERPRETER_RETURN_IF_ABRUPT(res);
4639     ASSERT(res.IsClassConstructor());
4640 
4641     SET_ACC(res);
4642     DISPATCH(DEPRECATED_DEFINECLASSWITHBUFFER_PREF_ID16_IMM16_IMM16_V8_V8);
4643 }
4644 
HandleDeprecatedCallspreadPrefV8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4645 void InterpreterAssembly::HandleDeprecatedCallspreadPrefV8V8V8(
4646     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4647     JSTaggedValue acc, int16_t hotnessCounter)
4648 {
4649     uint16_t v0 = READ_INST_8_1();
4650     uint16_t v1 = READ_INST_8_2();
4651     uint16_t v2 = READ_INST_8_3();
4652     LOG_INST() << "intrinsics::callspread"
4653                 << " v" << v0 << " v" << v1 << " v" << v2;
4654     JSTaggedValue func = GET_VREG_VALUE(v0);
4655     JSTaggedValue obj = GET_VREG_VALUE(v1);
4656     JSTaggedValue array = GET_VREG_VALUE(v2);
4657 
4658     SAVE_PC();
4659     JSTaggedValue res = SlowRuntimeStub::CallSpread(thread, func, obj, array);
4660     INTERPRETER_RETURN_IF_ABRUPT(res);
4661     SET_ACC(res);
4662 
4663     DISPATCH(DEPRECATED_CALLSPREAD_PREF_V8_V8_V8);
4664 }
4665 
HandleDeprecatedCallargs3PrefV8V8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4666 void InterpreterAssembly::HandleDeprecatedCallargs3PrefV8V8V8V8(
4667     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4668     JSTaggedValue acc, int16_t hotnessCounter)
4669 {
4670     DISPATCH(DEPRECATED_CALLARGS3_PREF_V8_V8_V8_V8);
4671 }
4672 
HandleDeprecatedCallargs2PrefV8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4673 void InterpreterAssembly::HandleDeprecatedCallargs2PrefV8V8V8(
4674     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4675     JSTaggedValue acc, int16_t hotnessCounter)
4676 {
4677     DISPATCH(DEPRECATED_CALLARGS2_PREF_V8_V8_V8);
4678 }
4679 
HandleDeprecatedCallarg1PrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4680 void InterpreterAssembly::HandleDeprecatedCallarg1PrefV8V8(
4681     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4682     JSTaggedValue acc, int16_t hotnessCounter)
4683 {
4684     DISPATCH(DEPRECATED_CALLARG1_PREF_V8_V8);
4685 }
4686 
HandleDeprecatedCallarg0PrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4687 void InterpreterAssembly::HandleDeprecatedCallarg0PrefV8(
4688     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4689     JSTaggedValue acc, int16_t hotnessCounter)
4690 {
4691     DISPATCH(DEPRECATED_CALLARG0_PREF_V8);
4692 }
4693 
HandleDeprecatedDecPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4694 void InterpreterAssembly::HandleDeprecatedDecPrefV8(
4695     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4696     JSTaggedValue acc, int16_t hotnessCounter)
4697 {
4698     uint16_t v0 = READ_INST_8_1();
4699     LOG_INST() << "intrinsics::dec"
4700                << " v" << v0;
4701 
4702     JSTaggedValue value = GET_VREG_VALUE(v0);
4703     // number, fast path
4704     if (value.IsInt()) {
4705         int32_t a0 = value.GetInt();
4706         if (UNLIKELY(a0 == INT32_MIN)) {
4707             auto ret = static_cast<double>(a0) - 1.0;
4708             SET_ACC(JSTaggedValue(ret));
4709         } else {
4710             SET_ACC(JSTaggedValue(a0 - 1));
4711         }
4712     } else if (value.IsDouble()) {
4713         SET_ACC(JSTaggedValue(value.GetDouble() - 1.0));
4714     } else {
4715         // slow path
4716         SAVE_PC();
4717         JSTaggedValue res = SlowRuntimeStub::Dec(thread, value);
4718         INTERPRETER_RETURN_IF_ABRUPT(res);
4719         SET_ACC(res);
4720     }
4721     DISPATCH(DEPRECATED_DEC_PREF_V8);
4722 }
4723 
HandleDeprecatedIncPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4724 void InterpreterAssembly::HandleDeprecatedIncPrefV8(
4725     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4726     JSTaggedValue acc, int16_t hotnessCounter)
4727 {
4728     uint16_t v0 = READ_INST_8_1();
4729 
4730     LOG_INST() << "intrinsics::inc"
4731                << " v" << v0;
4732 
4733     JSTaggedValue value = GET_VREG_VALUE(v0);
4734     // number fast path
4735     if (value.IsInt()) {
4736         int32_t a0 = value.GetInt();
4737         if (UNLIKELY(a0 == INT32_MAX)) {
4738             auto ret = static_cast<double>(a0) + 1.0;
4739             SET_ACC(JSTaggedValue(ret));
4740         } else {
4741             SET_ACC(JSTaggedValue(a0 + 1));
4742         }
4743     } else if (value.IsDouble()) {
4744         SET_ACC(JSTaggedValue(value.GetDouble() + 1.0));
4745     } else {
4746         // slow path
4747         SAVE_PC();
4748         JSTaggedValue res = SlowRuntimeStub::Inc(thread, value);
4749         INTERPRETER_RETURN_IF_ABRUPT(res);
4750         SET_ACC(res);
4751     }
4752     DISPATCH(DEPRECATED_INC_PREF_V8);
4753 }
4754 
HandleDeprecatedNotPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4755 void InterpreterAssembly::HandleDeprecatedNotPrefV8(
4756     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4757     JSTaggedValue acc, int16_t hotnessCounter)
4758 {
4759     uint16_t v0 = READ_INST_8_1();
4760 
4761     LOG_INST() << "intrinsics::not"
4762                << " v" << v0;
4763     JSTaggedValue value = GET_VREG_VALUE(v0);
4764     int32_t number;
4765     // number, fast path
4766     if (value.IsInt()) {
4767         number = static_cast<int32_t>(value.GetInt());
4768         SET_ACC(JSTaggedValue(~number));  // NOLINT(hicpp-signed-bitwise);
4769     } else if (value.IsDouble()) {
4770         number = base::NumberHelper::DoubleToInt(value.GetDouble(), base::INT32_BITS);
4771         SET_ACC(JSTaggedValue(~number));  // NOLINT(hicpp-signed-bitwise);
4772     } else {
4773         // slow path
4774         SAVE_PC();
4775         JSTaggedValue res = SlowRuntimeStub::Not(thread, value);
4776         INTERPRETER_RETURN_IF_ABRUPT(res);
4777         SET_ACC(res);
4778     }
4779     DISPATCH(DEPRECATED_NOT_PREF_V8);
4780 }
4781 
HandleDeprecatedNegPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4782 void InterpreterAssembly::HandleDeprecatedNegPrefV8(
4783     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4784     JSTaggedValue acc, int16_t hotnessCounter)
4785 {
4786     uint16_t v0 = READ_INST_8_1();
4787     LOG_INST() << "intrinsics::neg"
4788                << " v" << v0;
4789     JSTaggedValue value = GET_VREG_VALUE(v0);
4790     // fast path
4791     if (value.IsInt()) {
4792         if (value.GetInt() == 0) {
4793             SET_ACC(JSTaggedValue(-0.0));
4794         } else {
4795             SET_ACC(JSTaggedValue(-value.GetInt()));
4796         }
4797     } else if (value.IsDouble()) {
4798         SET_ACC(JSTaggedValue(-value.GetDouble()));
4799     } else {  // slow path
4800         SAVE_PC();
4801         JSTaggedValue res = SlowRuntimeStub::Neg(thread, value);
4802         INTERPRETER_RETURN_IF_ABRUPT(res);
4803         SET_ACC(res);
4804     }
4805     DISPATCH(DEPRECATED_NEG_PREF_V8);
4806 }
4807 
HandleDeprecatedTonumericPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4808 void InterpreterAssembly::HandleDeprecatedTonumericPrefV8(
4809     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4810     JSTaggedValue acc, int16_t hotnessCounter)
4811 {
4812     uint16_t v0 = READ_INST_8_1();
4813     LOG_INST() << "intrinsics::tonumeric"
4814                << " v" << v0;
4815     JSTaggedValue value = GET_VREG_VALUE(v0);
4816     if (value.IsNumber() || value.IsBigInt()) {
4817         // fast path
4818         SET_ACC(value);
4819     } else {
4820         // slow path
4821         SAVE_PC();
4822         JSTaggedValue res = SlowRuntimeStub::ToNumeric(thread, value);
4823         INTERPRETER_RETURN_IF_ABRUPT(res);
4824         SET_ACC(res);
4825     }
4826     DISPATCH(DEPRECATED_TONUMERIC_PREF_V8);
4827 }
4828 
HandleDeprecatedCallthisrangePrefImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4829 void InterpreterAssembly::HandleDeprecatedCallthisrangePrefImm16V8(
4830     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4831     JSTaggedValue acc, int16_t hotnessCounter)
4832 {
4833     DISPATCH(DEPRECATED_CALLTHISRANGE_PREF_IMM16_V8);
4834 }
4835 
HandleDeprecatedTonumberPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4836 void InterpreterAssembly::HandleDeprecatedTonumberPrefV8(
4837     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4838     JSTaggedValue acc, int16_t hotnessCounter)
4839 {
4840     uint16_t v0 = READ_INST_8_1();
4841 
4842     LOG_INST() << "intrinsics::tonumber"
4843                << " v" << v0;
4844     JSTaggedValue value = GET_VREG_VALUE(v0);
4845     if (value.IsNumber()) {
4846         // fast path
4847         SET_ACC(value);
4848     } else {
4849         // slow path
4850         SAVE_PC();
4851         JSTaggedValue res = SlowRuntimeStub::ToNumber(thread, value);
4852         INTERPRETER_RETURN_IF_ABRUPT(res);
4853         SET_ACC(res);
4854     }
4855     DISPATCH(DEPRECATED_TONUMBER_PREF_V8);
4856 }
4857 
HandleDeprecatedCreateobjectwithbufferPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4858 void InterpreterAssembly::HandleDeprecatedCreateobjectwithbufferPrefImm16(
4859     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4860     JSTaggedValue acc, int16_t hotnessCounter)
4861 {
4862     uint16_t imm = READ_INST_16_1();
4863     LOG_INST() << "intrinsics::createobjectwithbuffer"
4864                << " imm:" << imm;
4865     constpool = GetConstantPool(thread, sp);
4866     JSObject *result =
4867         JSObject::Cast(ConstantPool::GetMethodFromCache(thread, constpool, imm).GetTaggedObject());
4868 
4869     SAVE_PC();
4870     EcmaVM *ecmaVm = thread->GetEcmaVM();
4871     ObjectFactory *factory = ecmaVm->GetFactory();
4872     JSTaggedValue res = SlowRuntimeStub::CreateObjectWithBuffer(thread, factory, result);
4873     INTERPRETER_RETURN_IF_ABRUPT(res);
4874     SET_ACC(res);
4875     DISPATCH(DEPRECATED_CREATEOBJECTWITHBUFFER_PREF_IMM16);
4876 }
4877 
HandleDeprecatedCreatearraywithbufferPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4878 void InterpreterAssembly::HandleDeprecatedCreatearraywithbufferPrefImm16(
4879     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4880     JSTaggedValue acc, int16_t hotnessCounter)
4881 {
4882     uint16_t imm = READ_INST_16_1();
4883     LOG_INST() << "intrinsics::createarraywithbuffer"
4884                << " imm:" << imm;
4885     constpool = GetConstantPool(thread, sp);
4886     JSArray *result =
4887         JSArray::Cast(ConstantPool::GetMethodFromCache(thread, constpool, imm).GetTaggedObject());
4888     SAVE_PC();
4889     EcmaVM *ecmaVm = thread->GetEcmaVM();
4890     ObjectFactory *factory = ecmaVm->GetFactory();
4891     JSTaggedValue res = SlowRuntimeStub::CreateArrayWithBuffer(thread, factory, result);
4892     INTERPRETER_RETURN_IF_ABRUPT(res);
4893     SET_ACC(res);
4894     DISPATCH(DEPRECATED_CREATEARRAYWITHBUFFER_PREF_IMM16);
4895 }
4896 
HandleDeprecatedGetiteratornextPrefV8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4897 void InterpreterAssembly::HandleDeprecatedGetiteratornextPrefV8V8(
4898     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4899     JSTaggedValue acc, int16_t hotnessCounter)
4900 {
4901     uint16_t v0 = READ_INST_8_1();
4902     uint16_t v1 = READ_INST_8_2();
4903     LOG_INST() << "intrinsic::getiteratornext"
4904                << " v" << v0 << " v" << v1;
4905     JSTaggedValue obj = GET_VREG_VALUE(v0);
4906     JSTaggedValue method = GET_VREG_VALUE(v1);
4907     SAVE_PC();
4908     JSTaggedValue res = SlowRuntimeStub::GetIteratorNext(thread, obj, method);
4909     INTERPRETER_RETURN_IF_ABRUPT(res);
4910     SET_ACC(res);
4911     DISPATCH(DEPRECATED_GETITERATORNEXT_PREF_V8_V8);
4912 }
4913 
HandleDeprecatedPoplexenvPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4914 void InterpreterAssembly::HandleDeprecatedPoplexenvPrefNone(
4915     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4916     JSTaggedValue acc, int16_t hotnessCounter)
4917 {
4918     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
4919     JSTaggedValue currentLexenv = state->env;
4920     JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(thread);
4921     (reinterpret_cast<InterpretedFrame *>(sp) - 1)->env = parentLexenv;
4922     DISPATCH(DEPRECATED_POPLEXENV_PREF_NONE);
4923 }
4924 
HandleDeprecatedLdlexenvPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4925 void InterpreterAssembly::HandleDeprecatedLdlexenvPrefNone(
4926     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4927     JSTaggedValue acc, int16_t hotnessCounter)
4928 {
4929     LOG_INST() << "intrinsics::ldlexenv ";
4930     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
4931     JSTaggedValue currentLexenv = state->env;
4932     SET_ACC(currentLexenv);
4933     DISPATCH(DEPRECATED_LDLEXENV_PREF_NONE);
4934 }
4935 
HandleCallRuntime(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4936 void InterpreterAssembly::HandleCallRuntime(
4937     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4938     JSTaggedValue acc, int16_t hotnessCounter)
4939 {
4940 }
4941 
HandleWide(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4942 void InterpreterAssembly::HandleWide(
4943     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4944     JSTaggedValue acc, int16_t hotnessCounter)
4945 {
4946 }
4947 
HandleDeprecated(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4948 void InterpreterAssembly::HandleDeprecated(
4949     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4950     JSTaggedValue acc, int16_t hotnessCounter)
4951 {
4952 }
4953 
HandleJnstricteqV8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4954 void InterpreterAssembly::HandleJnstricteqV8Imm16(
4955     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4956     JSTaggedValue acc, int16_t hotnessCounter)
4957 {
4958     DISPATCH(JNSTRICTEQ_V8_IMM16);
4959 }
4960 
HandleJnstricteqV8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4961 void InterpreterAssembly::HandleJnstricteqV8Imm8(
4962     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4963     JSTaggedValue acc, int16_t hotnessCounter)
4964 {
4965     DISPATCH(JNSTRICTEQ_V8_IMM8);
4966 }
4967 
HandleJstricteqV8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4968 void InterpreterAssembly::HandleJstricteqV8Imm16(
4969     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4970     JSTaggedValue acc, int16_t hotnessCounter)
4971 {
4972     DISPATCH(JSTRICTEQ_V8_IMM16);
4973 }
4974 
HandleJstricteqV8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4975 void InterpreterAssembly::HandleJstricteqV8Imm8(
4976     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4977     JSTaggedValue acc, int16_t hotnessCounter)
4978 {
4979     DISPATCH(JSTRICTEQ_V8_IMM8);
4980 }
4981 
HandleJneV8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4982 void InterpreterAssembly::HandleJneV8Imm16(
4983     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4984     JSTaggedValue acc, int16_t hotnessCounter)
4985 {
4986     DISPATCH(JNE_V8_IMM16);
4987 }
4988 
HandleJneV8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4989 void InterpreterAssembly::HandleJneV8Imm8(
4990     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4991     JSTaggedValue acc, int16_t hotnessCounter)
4992 {
4993     DISPATCH(JNE_V8_IMM8);
4994 }
4995 
HandleJeqV8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)4996 void InterpreterAssembly::HandleJeqV8Imm16(
4997     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
4998     JSTaggedValue acc, int16_t hotnessCounter)
4999 {
5000     DISPATCH(JEQ_V8_IMM16);
5001 }
5002 
HandleJeqV8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5003 void InterpreterAssembly::HandleJeqV8Imm8(
5004     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5005     JSTaggedValue acc, int16_t hotnessCounter)
5006 {
5007     DISPATCH(JNE_V8_IMM8);
5008 }
5009 
HandleJnstrictequndefinedImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5010 void InterpreterAssembly::HandleJnstrictequndefinedImm16(
5011     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5012     JSTaggedValue acc, int16_t hotnessCounter)
5013 {
5014     DISPATCH(JNSTRICTEQUNDEFINED_IMM16);
5015 }
5016 
HandleJnstrictequndefinedImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5017 void InterpreterAssembly::HandleJnstrictequndefinedImm8(
5018     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5019     JSTaggedValue acc, int16_t hotnessCounter)
5020 {
5021     DISPATCH(JNSTRICTEQUNDEFINED_IMM8);
5022 }
5023 
HandleJstrictequndefinedImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5024 void InterpreterAssembly::HandleJstrictequndefinedImm16(
5025     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5026     JSTaggedValue acc, int16_t hotnessCounter)
5027 {
5028     DISPATCH(JSTRICTEQUNDEFINED_IMM16);
5029 }
5030 
HandleJstrictequndefinedImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5031 void InterpreterAssembly::HandleJstrictequndefinedImm8(
5032     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5033     JSTaggedValue acc, int16_t hotnessCounter)
5034 {
5035     DISPATCH(JSTRICTEQUNDEFINED_IMM8);
5036 }
5037 
HandleJneundefinedImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5038 void InterpreterAssembly::HandleJneundefinedImm16(
5039     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5040     JSTaggedValue acc, int16_t hotnessCounter)
5041 {
5042     DISPATCH(JNEUNDEFINED_IMM16);
5043 }
5044 
HandleJneundefinedImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5045 void InterpreterAssembly::HandleJneundefinedImm8(
5046     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5047     JSTaggedValue acc, int16_t hotnessCounter)
5048 {
5049     DISPATCH(JNEUNDEFINED_IMM8);
5050 }
5051 
HandleJequndefinedImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5052 void InterpreterAssembly::HandleJequndefinedImm16(
5053     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5054     JSTaggedValue acc, int16_t hotnessCounter)
5055 {
5056     DISPATCH(JEQUNDEFINED_IMM16);
5057 }
5058 
HandleJequndefinedImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5059 void InterpreterAssembly::HandleJequndefinedImm8(
5060     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5061     JSTaggedValue acc, int16_t hotnessCounter)
5062 {
5063     DISPATCH(JEQUNDEFINED_IMM8);
5064 }
5065 
HandleJnstricteqnullImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5066 void InterpreterAssembly::HandleJnstricteqnullImm16(
5067     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5068     JSTaggedValue acc, int16_t hotnessCounter)
5069 {
5070     DISPATCH(JNSTRICTEQNULL_IMM16);
5071 }
5072 
HandleJnstricteqnullImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5073 void InterpreterAssembly::HandleJnstricteqnullImm8(
5074     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5075     JSTaggedValue acc, int16_t hotnessCounter)
5076 {
5077     DISPATCH(JNSTRICTEQNULL_IMM8);
5078 }
5079 
HandleCallarg1Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5080 void InterpreterAssembly::HandleCallarg1Imm8V8(
5081     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5082     JSTaggedValue acc, int16_t hotnessCounter)
5083 {
5084     DISPATCH(CALLARG1_IMM8_V8);
5085 }
5086 
HandleJstricteqnullImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5087 void InterpreterAssembly::HandleJstricteqnullImm16(
5088     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5089     JSTaggedValue acc, int16_t hotnessCounter)
5090 {
5091     DISPATCH(JSTRICTEQNULL_IMM16);
5092 }
5093 
HandleJstricteqnullImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5094 void InterpreterAssembly::HandleJstricteqnullImm8(
5095     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5096     JSTaggedValue acc, int16_t hotnessCounter)
5097 {
5098     DISPATCH(JSTRICTEQNULL_IMM8);
5099 }
5100 
HandleJnenullImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5101 void InterpreterAssembly::HandleJnenullImm16(
5102     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5103     JSTaggedValue acc, int16_t hotnessCounter)
5104 {
5105     DISPATCH(JNENULL_IMM16);
5106 }
5107 
HandleJnenullImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5108 void InterpreterAssembly::HandleJnenullImm8(
5109     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5110     JSTaggedValue acc, int16_t hotnessCounter)
5111 {
5112     DISPATCH(JNENULL_IMM8);
5113 }
5114 
HandleStownbynamewithnamesetImm16Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5115 void InterpreterAssembly::HandleStownbynamewithnamesetImm16Id16V8(
5116     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5117     JSTaggedValue acc, int16_t hotnessCounter)
5118 {
5119     uint16_t stringId = READ_INST_16_2();
5120     uint32_t v0 = READ_INST_8_4();
5121     constpool = GetConstantPool(thread, sp);
5122     LOG_INST() << "intrinsics::stownbynamewithnameset "
5123                << "v" << v0 << " stringId:" << stringId;
5124 
5125     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5126     if (receiver.IsJSObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
5127         JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5128         JSTaggedValue value = GET_ACC();
5129         // fast path
5130         SAVE_ACC();
5131         JSTaggedValue res = FastRuntimeStub::SetPropertyByName<ObjectFastOperator::Status::UseOwn>
5132                             (thread, receiver, propKey, value);
5133         if (!res.IsHole()) {
5134             INTERPRETER_RETURN_IF_ABRUPT(res);
5135             JSFunction::SetFunctionNameNoPrefix(thread, JSFunction::Cast(value.GetTaggedObject()), propKey);
5136             RESTORE_ACC();
5137             DISPATCH(STOWNBYNAMEWITHNAMESET_IMM16_ID16_V8);
5138         }
5139         RESTORE_ACC();
5140     }
5141 
5142     SAVE_ACC();
5143     SAVE_PC();
5144     receiver = GET_VREG_VALUE(v0);                           // Maybe moved by GC
5145     auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);  // Maybe moved by GC
5146     auto value = GET_ACC();                                  // Maybe moved by GC
5147     JSTaggedValue res = SlowRuntimeStub::StOwnByNameWithNameSet(thread, receiver, propKey, value);
5148     RESTORE_ACC();
5149     INTERPRETER_RETURN_IF_ABRUPT(res);
5150     DISPATCH(STOWNBYNAMEWITHNAMESET_IMM16_ID16_V8);
5151 }
5152 
HandleStownbyvaluewithnamesetImm16V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5153 void InterpreterAssembly::HandleStownbyvaluewithnamesetImm16V8V8(
5154     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5155     JSTaggedValue acc, int16_t hotnessCounter)
5156 {
5157     uint32_t v0 = READ_INST_8_2();
5158     uint32_t v1 = READ_INST_8_3();
5159     LOG_INST() << "intrinsics::stownbyvaluewithnameset"
5160                << " v" << v0 << " v" << v1;
5161     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5162     if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
5163         SAVE_ACC();
5164         JSTaggedValue propKey = GET_VREG_VALUE(v1);
5165         JSTaggedValue value = GET_ACC();
5166         // fast path
5167         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue<ObjectFastOperator::Status::UseOwn>
5168                             (thread, receiver, propKey, value);
5169 
5170         // SetPropertyByValue maybe gc need update the value
5171         RESTORE_ACC();
5172         propKey = GET_VREG_VALUE(v1);
5173         value = GET_ACC();
5174         if (!res.IsHole()) {
5175             INTERPRETER_RETURN_IF_ABRUPT(res);
5176             JSFunction::SetFunctionNameNoPrefix(thread, JSFunction::Cast(value.GetTaggedObject()), propKey);
5177             RESTORE_ACC();
5178             DISPATCH(STOWNBYVALUEWITHNAMESET_IMM16_V8_V8);
5179         }
5180     }
5181 
5182     // slow path
5183     SAVE_ACC();
5184     SAVE_PC();
5185     receiver = GET_VREG_VALUE(v0);      // Maybe moved by GC
5186     auto propKey = GET_VREG_VALUE(v1);  // Maybe moved by GC
5187     auto value = GET_ACC();             // Maybe moved by GC
5188     JSTaggedValue res = SlowRuntimeStub::StOwnByValueWithNameSet(thread, receiver, propKey, value);
5189     RESTORE_ACC();
5190     INTERPRETER_RETURN_IF_ABRUPT(res);
5191     DISPATCH(STOWNBYVALUEWITHNAMESET_IMM16_V8_V8);
5192 }
5193 
HandleJeqnullImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5194 void InterpreterAssembly::HandleJeqnullImm16(
5195     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5196     JSTaggedValue acc, int16_t hotnessCounter)
5197 {
5198     DISPATCH(JEQNULL_IMM16);
5199 }
5200 
HandleJeqnullImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5201 void InterpreterAssembly::HandleJeqnullImm8(
5202     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5203     JSTaggedValue acc, int16_t hotnessCounter)
5204 {
5205     DISPATCH(JEQNULL_IMM8);
5206 }
5207 
HandleJnstricteqzImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5208 void InterpreterAssembly::HandleJnstricteqzImm16(
5209     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5210     JSTaggedValue acc, int16_t hotnessCounter)
5211 {
5212     DISPATCH(JNSTRICTEQZ_IMM16);
5213 }
5214 
HandleJnstricteqzImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5215 void InterpreterAssembly::HandleJnstricteqzImm8(
5216     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5217     JSTaggedValue acc, int16_t hotnessCounter)
5218 {
5219     DISPATCH(JNSTRICTEQZ_IMM8);
5220 }
5221 
HandleSttoglobalrecordImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5222 void InterpreterAssembly::HandleSttoglobalrecordImm16Id16(
5223     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5224     JSTaggedValue acc, int16_t hotnessCounter)
5225 {
5226     uint16_t stringId = READ_INST_16_2();
5227     SAVE_ACC();
5228     constpool = GetConstantPool(thread, sp);
5229     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5230     RESTORE_ACC();
5231     LOG_INST() << "intrinsics::stconsttoglobalrecord"
5232                << " stringId:" << stringId << ", "
5233                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()));
5234 
5235     JSTaggedValue value = GET_ACC();
5236     SAVE_PC();
5237     JSTaggedValue res = SlowRuntimeStub::StGlobalRecord(thread, propKey, value, true);
5238     INTERPRETER_RETURN_IF_ABRUPT(res);
5239     RESTORE_ACC();
5240     DISPATCH(STCONSTTOGLOBALRECORD_IMM16_ID16);
5241 }
5242 
HandleStconsttoglobalrecordImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5243 void InterpreterAssembly::HandleStconsttoglobalrecordImm16Id16(
5244     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5245     JSTaggedValue acc, int16_t hotnessCounter)
5246 {
5247     uint16_t stringId = READ_INST_16_2();
5248     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5249     JSTaggedValue constantPool = state->constpool;
5250     JSTaggedValue propKey = ConstantPool::Cast(constantPool.GetTaggedObject())
5251         ->GetObjectFromCache(thread, stringId);
5252     LOG_INST() << "intrinsics::stconsttoglobalrecord"
5253                << " stringId:" << stringId << ", "
5254                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()));
5255 
5256     JSTaggedValue value = GET_ACC();
5257     SAVE_ACC();
5258     SAVE_PC();
5259     JSTaggedValue res = SlowRuntimeStub::StGlobalRecord(thread, propKey, value, true);
5260     INTERPRETER_RETURN_IF_ABRUPT(res);
5261     RESTORE_ACC();
5262     DISPATCH(STCONSTTOGLOBALRECORD_IMM16_ID16);
5263 }
5264 
HandleLdlocalmodulevarImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5265 void InterpreterAssembly::HandleLdlocalmodulevarImm8(
5266     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5267     JSTaggedValue acc, int16_t hotnessCounter)
5268 {
5269     int32_t index = READ_INST_8_0();
5270 
5271     LOG_INST() << "intrinsics::ldmodulevar index:" << index;
5272 
5273     JSTaggedValue moduleVar = SlowRuntimeStub::LdLocalModuleVar(thread, index);
5274     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
5275     SET_ACC(moduleVar);
5276     DISPATCH(LDLOCALMODULEVAR_IMM8);
5277 }
5278 
HandleStsuperbynameImm16Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5279 void InterpreterAssembly::HandleStsuperbynameImm16Id16V8(
5280     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5281     JSTaggedValue acc, int16_t hotnessCounter)
5282 {
5283     uint16_t stringId = READ_INST_16_2();
5284     uint32_t v0 = READ_INST_8_4();
5285     constpool = GetConstantPool(thread, sp);
5286 
5287     JSTaggedValue obj = GET_VREG_VALUE(v0);
5288     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5289     JSTaggedValue value = GET_ACC();
5290 
5291     LOG_INST() << "intrinsics::stsuperbyname"
5292                << "v" << v0 << " stringId:" << stringId << ", "
5293                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData()
5294                << ", value:" << value.GetRawData();
5295 
5296     // slow path
5297     SAVE_ACC();
5298     SAVE_PC();
5299     JSTaggedValue thisFunc = GetFunction(sp);
5300     JSTaggedValue res = SlowRuntimeStub::StSuperByValue(thread, obj, propKey, value, thisFunc);
5301     INTERPRETER_RETURN_IF_ABRUPT(res);
5302     RESTORE_ACC();
5303     DISPATCH(STSUPERBYNAME_IMM16_ID16_V8);
5304 }
5305 
HandleLdsuperbynameImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5306 void InterpreterAssembly::HandleLdsuperbynameImm16Id16(
5307     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5308     JSTaggedValue acc, int16_t hotnessCounter)
5309 {
5310     uint16_t stringId = READ_INST_16_2();
5311     SAVE_ACC();
5312     constpool = GetConstantPool(thread, sp);
5313     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5314     RESTORE_ACC();
5315     JSTaggedValue obj = GET_ACC();
5316 
5317     LOG_INST() << "intrinsics::ldsuperbyname stringId:" << stringId << ", "
5318                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData();
5319 
5320     SAVE_PC();
5321     JSTaggedValue thisFunc = GetFunction(sp);
5322     JSTaggedValue res = SlowRuntimeStub::LdSuperByValue(thread, obj, propKey, thisFunc);
5323 
5324     INTERPRETER_RETURN_IF_ABRUPT(res);
5325     SET_ACC(res);
5326     DISPATCH(LDSUPERBYNAME_IMM16_ID16);
5327 }
5328 
HandleLdsuperbynameImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5329 void InterpreterAssembly::HandleLdsuperbynameImm8Id16(
5330     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5331     JSTaggedValue acc, int16_t hotnessCounter)
5332 {
5333     uint16_t stringId = READ_INST_16_1();
5334     SAVE_ACC();
5335     constpool = GetConstantPool(thread, sp);
5336     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5337     RESTORE_ACC();
5338 
5339     JSTaggedValue obj = GET_ACC();
5340     LOG_INST() << "intrinsics::ldsuperbyname stringId:" << stringId << ", "
5341                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData();
5342 
5343     SAVE_PC();
5344     JSTaggedValue thisFunc = GetFunction(sp);
5345     JSTaggedValue res = SlowRuntimeStub::LdSuperByValue(thread, obj, propKey, thisFunc);
5346 
5347     INTERPRETER_RETURN_IF_ABRUPT(res);
5348     SET_ACC(res);
5349     DISPATCH(LDSUPERBYNAME_IMM8_ID16);
5350 }
5351 
HandleStownbynameImm16Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5352 void InterpreterAssembly::HandleStownbynameImm16Id16V8(
5353     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5354     JSTaggedValue acc, int16_t hotnessCounter)
5355 {
5356     uint16_t stringId = READ_INST_16_2();
5357     uint32_t v0 = READ_INST_8_4();
5358     LOG_INST() << "intrinsics::stownbyname "
5359                << "v" << v0 << " stringId:" << stringId;
5360 
5361     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5362     if (receiver.IsJSObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) {
5363         SAVE_ACC();
5364         constpool = GetConstantPool(thread, sp);
5365         JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5366         RESTORE_ACC();
5367         JSTaggedValue value = GET_ACC();
5368         // fast path
5369         SAVE_ACC();
5370         receiver = GET_VREG_VALUE(v0);
5371         JSTaggedValue res = FastRuntimeStub::SetPropertyByName<ObjectFastOperator::Status::UseOwn>
5372                             (thread, receiver, propKey, value);
5373         if (!res.IsHole()) {
5374             INTERPRETER_RETURN_IF_ABRUPT(res);
5375             RESTORE_ACC();
5376             DISPATCH(STOWNBYNAME_IMM16_ID16_V8);
5377         }
5378         RESTORE_ACC();
5379     }
5380 
5381     SAVE_ACC();
5382     constpool = GetConstantPool(thread, sp);
5383     auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);  // Maybe moved by GC
5384     RESTORE_ACC();
5385     auto value = GET_ACC();                                  // Maybe moved by GC
5386     receiver = GET_VREG_VALUE(v0);                           // Maybe moved by GC
5387     JSTaggedValue res = SlowRuntimeStub::StOwnByName(thread, receiver, propKey, value);
5388     RESTORE_ACC();
5389     INTERPRETER_RETURN_IF_ABRUPT(res);
5390     DISPATCH(STOWNBYNAME_IMM16_ID16_V8);
5391 }
5392 
HandleStobjbynameImm16Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5393 void InterpreterAssembly::HandleStobjbynameImm16Id16V8(
5394     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5395     JSTaggedValue acc, int16_t hotnessCounter)
5396 {
5397     uint16_t stringId = READ_INST_16_2();
5398     uint32_t v0 = READ_INST_8_4();
5399 #if ECMSCRIPT_ENABLE_IC
5400     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5401     auto tmpProfileTypeInfo = state->profileTypeInfo;
5402     if (!tmpProfileTypeInfo.IsUndefined()) {
5403         uint16_t slotId = READ_INST_16_0();
5404         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
5405         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
5406         JSTaggedValue res = JSTaggedValue::Hole();
5407         SAVE_ACC();
5408 
5409         JSTaggedValue receiver = GET_VREG_VALUE(v0);
5410         JSTaggedValue value = GET_ACC();
5411         if (LIKELY(firstValue.IsHeapObject())) {
5412             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
5413             res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value);
5414         }
5415         if (LIKELY(!res.IsHole())) {
5416             INTERPRETER_RETURN_IF_ABRUPT(res);
5417             RESTORE_ACC();
5418             DISPATCH(STOBJBYNAME_IMM16_ID16_V8);
5419         } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic
5420             SAVE_ACC();
5421             constpool = GetConstantPool(thread, sp);
5422             JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5423             RESTORE_ACC();
5424             value = GET_ACC();
5425             receiver = GET_VREG_VALUE(v0);
5426             profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
5427             res = ICRuntimeStub::StoreICByName(thread,
5428                                                profileTypeArray,
5429                                                receiver, propKey, value, slotId);
5430             INTERPRETER_RETURN_IF_ABRUPT(res);
5431             RESTORE_ACC();
5432             DISPATCH(STOBJBYNAME_IMM16_ID16_V8);
5433         }
5434     }
5435 #endif
5436     LOG_INST() << "intrinsics::stobjbyname "
5437                << "v" << v0 << " stringId:" << stringId;
5438     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5439     if (receiver.IsHeapObject()) {
5440         SAVE_ACC();
5441         constpool = GetConstantPool(thread, sp);
5442         JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5443         RESTORE_ACC();
5444         JSTaggedValue value = GET_ACC();
5445         receiver = GET_VREG_VALUE(v0);
5446         // fast path
5447         JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, receiver, propKey, value);
5448         if (!res.IsHole()) {
5449             INTERPRETER_RETURN_IF_ABRUPT(res);
5450             RESTORE_ACC();
5451             DISPATCH(STOBJBYNAME_IMM16_ID16_V8);
5452         }
5453         RESTORE_ACC();
5454     }
5455     // slow path
5456     SAVE_ACC();
5457     SAVE_PC();
5458     constpool = GetConstantPool(thread, sp);                    // Maybe moved by GC
5459     auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);  // Maybe moved by GC
5460     RESTORE_ACC();
5461     JSTaggedValue value = GET_ACC();                                  // Maybe moved by GC
5462     receiver = GET_VREG_VALUE(v0);
5463     JSTaggedValue res = SlowRuntimeStub::StObjByName(thread, receiver, propKey, value);
5464     INTERPRETER_RETURN_IF_ABRUPT(res);
5465     RESTORE_ACC();
5466     DISPATCH(STOBJBYNAME_IMM16_ID16_V8);
5467 }
5468 
HandleLdobjbynameImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5469 void InterpreterAssembly::HandleLdobjbynameImm16Id16(
5470     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5471     JSTaggedValue acc, int16_t hotnessCounter)
5472 {
5473 #if ECMASCRIPT_ENABLE_IC
5474     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5475     auto tmpProfileTypeInfo = state->profileTypeInfo;
5476     if (!tmpProfileTypeInfo.IsUndefined()) {
5477         uint16_t slotId = READ_INST_16_0();
5478         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
5479         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
5480         JSTaggedValue res = JSTaggedValue::Hole();
5481 
5482         JSTaggedValue receiver = GET_ACC();
5483         if (LIKELY(firstValue.IsHeapObject())) {
5484             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
5485             res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue);
5486         }
5487         if (LIKELY(!res.IsHole())) {
5488             INTERPRETER_RETURN_IF_ABRUPT(res);
5489             SET_ACC(res);
5490             DISPATCH(LDOBJBYNAME_IMM16_ID16);
5491         } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic
5492             uint16_t stringId = READ_INST_16_2();
5493             SAVE_ACC();
5494             constpool = GetConstantPool(thread, sp);
5495             JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5496             RESTORE_ACC();
5497             receiver = GET_ACC();
5498             profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
5499             res = ICRuntimeStub::LoadICByName(thread,
5500                                               profileTypeArray,
5501                                               receiver, propKey, slotId);
5502             INTERPRETER_RETURN_IF_ABRUPT(res);
5503             SET_ACC(res);
5504             DISPATCH(LDOBJBYNAME_IMM16_ID16);
5505         }
5506     }
5507 #endif
5508     uint16_t stringId = READ_INST_16_2();
5509     SAVE_ACC();
5510     constpool = GetConstantPool(thread, sp);
5511     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5512     RESTORE_ACC();
5513     JSTaggedValue receiver = GET_ACC();
5514     LOG_INST() << "intrinsics::ldobjbyname stringId:" << stringId << ", "
5515                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()))
5516                << ", obj:" << receiver.GetRawData();
5517 
5518     if (LIKELY(receiver.IsHeapObject())) {
5519         // fast path
5520         JSTaggedValue res = FastRuntimeStub::GetPropertyByName(thread, receiver, propKey);
5521         if (!res.IsHole()) {
5522             ASSERT(!res.IsAccessor());
5523             INTERPRETER_RETURN_IF_ABRUPT(res);
5524             SET_ACC(res);
5525             DISPATCH(LDOBJBYNAME_IMM16_ID16);
5526         }
5527     }
5528     // not meet fast condition or fast path return hole, walk slow path
5529     // slow stub not need receiver
5530     SAVE_PC();
5531     JSTaggedValue res = SlowRuntimeStub::LdObjByName(thread, receiver, propKey, false, JSTaggedValue::Undefined());
5532     INTERPRETER_RETURN_IF_ABRUPT(res);
5533     SET_ACC(res);
5534     DISPATCH(LDOBJBYNAME_IMM16_ID16);
5535 }
5536 
HandleLdobjbynameImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5537 void InterpreterAssembly::HandleLdobjbynameImm8Id16(
5538     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5539     JSTaggedValue acc, int16_t hotnessCounter)
5540 {
5541 #if ECMASCRIPT_ENABLE_IC
5542     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5543     auto tmpProfileTypeInfo = state->profileTypeInfo;
5544     if (!tmpProfileTypeInfo.IsUndefined()) {
5545         uint16_t slotId = READ_INST_8_0();
5546         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
5547         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
5548         JSTaggedValue res = JSTaggedValue::Hole();
5549 
5550         JSTaggedValue receiver = GET_ACC();
5551         if (LIKELY(firstValue.IsHeapObject())) {
5552             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
5553             res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue);
5554         }
5555         if (LIKELY(!res.IsHole())) {
5556             INTERPRETER_RETURN_IF_ABRUPT(res);
5557             SET_ACC(res);
5558             DISPATCH(LDOBJBYNAME_IMM8_ID16);
5559         } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic
5560             uint16_t stringId = READ_INST_16_1();
5561             SAVE_ACC();
5562             constpool = GetConstantPool(thread, sp);
5563             JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5564             RESTORE_ACC();
5565             receiver = GET_ACC();
5566             profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
5567             res = ICRuntimeStub::LoadICByName(thread,
5568                                               profileTypeArray,
5569                                               receiver, propKey, slotId);
5570             INTERPRETER_RETURN_IF_ABRUPT(res);
5571             SET_ACC(res);
5572             DISPATCH(LDOBJBYNAME_IMM8_ID16);
5573         }
5574     }
5575 #endif
5576     uint16_t stringId = READ_INST_16_1();
5577     SAVE_ACC();
5578     constpool = GetConstantPool(thread, sp);
5579     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5580     RESTORE_ACC();
5581     JSTaggedValue receiver = GET_ACC();
5582     LOG_INST() << "intrinsics::ldobjbyname stringId:" << stringId << ", "
5583                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()))
5584                << ", obj:" << receiver.GetRawData();
5585 
5586     if (LIKELY(receiver.IsHeapObject())) {
5587         // fast path
5588         JSTaggedValue res = FastRuntimeStub::GetPropertyByName(thread, receiver, propKey);
5589         if (!res.IsHole()) {
5590             ASSERT(!res.IsAccessor());
5591             INTERPRETER_RETURN_IF_ABRUPT(res);
5592             SET_ACC(res);
5593             DISPATCH(LDOBJBYNAME_IMM8_ID16);
5594         }
5595     }
5596     // not meet fast condition or fast path return hole, walk slow path
5597     // slow stub not need receiver
5598     SAVE_PC();
5599     JSTaggedValue res = SlowRuntimeStub::LdObjByName(thread, receiver, propKey, false, JSTaggedValue::Undefined());
5600     INTERPRETER_RETURN_IF_ABRUPT(res);
5601     SET_ACC(res);
5602     DISPATCH(LDOBJBYNAME_IMM8_ID16);
5603 }
5604 
HandleTrystglobalbynameImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5605 void InterpreterAssembly::HandleTrystglobalbynameImm16Id16(
5606     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5607     JSTaggedValue acc, int16_t hotnessCounter)
5608 {
5609     uint16_t stringId = READ_INST_16_2();
5610     constpool = GetConstantPool(thread, sp);
5611     JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5612 
5613     EcmaVM *ecmaVm = thread->GetEcmaVM();
5614     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
5615     JSTaggedValue globalObj = globalEnv->GetGlobalObject();
5616 
5617     LOG_INST() << "intrinsics::trystglobalbyname"
5618                << " stringId:" << stringId << ", "
5619                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()));
5620 
5621 #if ECMSCRIPT_ENABLE_IC
5622     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5623     auto tmpProfileTypeInfo = state->profileTypeInfo;
5624     if (!tmpProfileTypeInfo.IsUndefined()) {
5625         uint16_t slotId = READ_INST_16_0();
5626         JSTaggedValue value = GET_ACC();
5627         SAVE_ACC();
5628         JSTaggedValue res = ICRuntimeStub::StoreGlobalICByName(thread,
5629                                                                ProfileTypeInfo::Cast(
5630                                                                    tmpProfileTypeInfo.GetTaggedObject()),
5631                                                                globalObj, propKey, value, slotId, true);
5632         INTERPRETER_RETURN_IF_ABRUPT(res);
5633         RESTORE_ACC();
5634         DISPATCH(TRYSTGLOBALBYNAME_IMM16_ID16);
5635     }
5636 #endif
5637 
5638     auto recordResult = SlowRuntimeStub::LdGlobalRecord(thread, propKey);
5639     SAVE_PC();
5640     // 1. find from global record
5641     if (!recordResult.IsUndefined()) {
5642         JSTaggedValue value = GET_ACC();
5643         SAVE_ACC();
5644         JSTaggedValue res = SlowRuntimeStub::TryUpdateGlobalRecord(thread, propKey, value);
5645         INTERPRETER_RETURN_IF_ABRUPT(res);
5646         RESTORE_ACC();
5647     } else {
5648         // 2. find from global object
5649         auto globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, propKey);
5650         if (globalResult.IsHole()) {
5651             auto result = SlowRuntimeStub::ThrowReferenceError(thread, propKey, " is not defined");
5652             INTERPRETER_RETURN_IF_ABRUPT(result);
5653         }
5654         JSTaggedValue value = GET_ACC();
5655         SAVE_ACC();
5656         JSTaggedValue res = SlowRuntimeStub::StGlobalVar(thread, propKey, value);
5657         INTERPRETER_RETURN_IF_ABRUPT(res);
5658         RESTORE_ACC();
5659     }
5660     DISPATCH(TRYSTGLOBALBYNAME_IMM16_ID16);
5661 }
5662 
HandleTryldglobalbynameImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5663 void InterpreterAssembly::HandleTryldglobalbynameImm16Id16(
5664     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5665     JSTaggedValue acc, int16_t hotnessCounter)
5666 {
5667     uint16_t stringId = READ_INST_16_2();
5668     constpool = GetConstantPool(thread, sp);
5669     auto prop = ConstantPool::GetStringFromCache(thread, constpool, stringId);
5670 
5671     EcmaVM *ecmaVm = thread->GetEcmaVM();
5672     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
5673     JSTaggedValue globalObj = globalEnv->GetGlobalObject();
5674 
5675     LOG_INST() << "intrinsics::tryldglobalbyname "
5676                << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject()));
5677 
5678 #if ECMSCRIPT_ENABLE_IC
5679     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5680     auto tmpProfileTypeInfo = state->profileTypeInfo;
5681     if (!tmpProfileTypeInfo.IsUndefined()) {
5682         uint16_t slotId = READ_INST_16_0();
5683         JSTaggedValue res = ICRuntimeStub::LoadGlobalICByName(thread,
5684                                                               ProfileTypeInfo::Cast(
5685                                                                   tmpProfileTypeInfo.GetTaggedObject()),
5686                                                               globalObj, prop, slotId, true);
5687         INTERPRETER_RETURN_IF_ABRUPT(res);
5688         SET_ACC(res);
5689         DISPATCH(TRYLDGLOBALBYNAME_IMM16_ID16);
5690     }
5691 #endif
5692 
5693     // order: 1. global record 2. global object
5694     JSTaggedValue result = SlowRuntimeStub::LdGlobalRecord(thread, prop);
5695     if (!result.IsUndefined()) {
5696         SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread));
5697     } else {
5698         JSTaggedValue globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, prop);
5699         if (!globalResult.IsHole()) {
5700             SET_ACC(globalResult);
5701         } else {
5702             // slow path
5703             SAVE_PC();
5704             JSTaggedValue res = SlowRuntimeStub::TryLdGlobalByNameFromGlobalProto(thread, globalObj, prop);
5705             INTERPRETER_RETURN_IF_ABRUPT(res);
5706             SET_ACC(res);
5707         }
5708     }
5709 
5710     DISPATCH(TRYLDGLOBALBYNAME_IMM16_ID16);
5711 }
5712 
HandleStmodulevarImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5713 void InterpreterAssembly::HandleStmodulevarImm8(
5714     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5715     JSTaggedValue acc, int16_t hotnessCounter)
5716 {
5717     int32_t index = READ_INST_8_0();
5718 
5719     LOG_INST() << "intrinsics::stmodulevar index:" << index;
5720 
5721     JSTaggedValue value = GET_ACC();
5722 
5723     SlowRuntimeStub::StModuleVar(thread, index, value);
5724     RESTORE_ACC();
5725     DISPATCH(STMODULEVAR_IMM8);
5726 }
5727 
HandleGetmodulenamespaceImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5728 void InterpreterAssembly::HandleGetmodulenamespaceImm8(
5729     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5730     JSTaggedValue acc, int16_t hotnessCounter)
5731 {
5732     int32_t index = READ_INST_8_0();
5733 
5734     LOG_INST() << "intrinsics::getmodulenamespace index:" << index;
5735 
5736     JSTaggedValue moduleNamespace = SlowRuntimeStub::GetModuleNamespace(thread, index);
5737     INTERPRETER_RETURN_IF_ABRUPT(moduleNamespace);
5738     SET_ACC(moduleNamespace);
5739     DISPATCH(GETMODULENAMESPACE_IMM8);
5740 }
5741 
HandleLdobjbyindexImm16Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5742 void InterpreterAssembly::HandleLdobjbyindexImm16Imm16(
5743     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5744     JSTaggedValue acc, int16_t hotnessCounter)
5745 {
5746     uint32_t idx = READ_INST_32_1();
5747     LOG_INST() << "intrinsics::ldobjbyindex"
5748                << " imm" << idx;
5749 
5750     JSTaggedValue receiver = GET_ACC();
5751     // fast path
5752     if (LIKELY(receiver.IsHeapObject())) {
5753         JSTaggedValue res = FastRuntimeStub::GetPropertyByIndex(thread, receiver, idx);
5754         if (!res.IsHole()) {
5755             INTERPRETER_RETURN_IF_ABRUPT(res);
5756             SET_ACC(res);
5757             DISPATCH(LDOBJBYINDEX_IMM16_IMM16);
5758         }
5759     }
5760     // not meet fast condition or fast path return hole, walk slow path
5761     // slow stub not need receiver
5762     SAVE_PC();
5763     JSTaggedValue res = SlowRuntimeStub::LdObjByIndex(thread, receiver, idx, false, JSTaggedValue::Undefined());
5764     INTERPRETER_RETURN_IF_ABRUPT(res);
5765     SET_ACC(res);
5766     DISPATCH(LDOBJBYINDEX_IMM16_IMM16);
5767 }
5768 
HandleLdobjbyindexImm8Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5769 void InterpreterAssembly::HandleLdobjbyindexImm8Imm16(
5770     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5771     JSTaggedValue acc, int16_t hotnessCounter)
5772 {
5773     uint32_t idx = READ_INST_16_1();
5774     LOG_INST() << "intrinsics::ldobjbyindex"
5775                << " imm" << idx;
5776 
5777     JSTaggedValue receiver = GET_ACC();
5778     // fast path
5779     if (LIKELY(receiver.IsHeapObject())) {
5780         JSTaggedValue res = FastRuntimeStub::GetPropertyByIndex(thread, receiver, idx);
5781         if (!res.IsHole()) {
5782             INTERPRETER_RETURN_IF_ABRUPT(res);
5783             SET_ACC(res);
5784             DISPATCH(LDOBJBYINDEX_IMM8_IMM16);
5785         }
5786     }
5787     // not meet fast condition or fast path return hole, walk slow path
5788     // slow stub not need receiver
5789     SAVE_PC();
5790     JSTaggedValue res = SlowRuntimeStub::LdObjByIndex(thread, receiver, idx, false, JSTaggedValue::Undefined());
5791     INTERPRETER_RETURN_IF_ABRUPT(res);
5792     SET_ACC(res);
5793     DISPATCH(LDOBJBYINDEX_IMM8_IMM16);
5794 }
5795 
HandleStsuperbyvalueImm16V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5796 void InterpreterAssembly::HandleStsuperbyvalueImm16V8V8(
5797     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5798     JSTaggedValue acc, int16_t hotnessCounter)
5799 {
5800     uint32_t v0 = READ_INST_8_2();
5801     uint32_t v1 = READ_INST_8_3();
5802 
5803     LOG_INST() << "intrinsics::stsuperbyvalue"
5804                << " v" << v0 << " v" << v1;
5805     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5806     JSTaggedValue propKey = GET_VREG_VALUE(v1);
5807     JSTaggedValue value = GET_ACC();
5808 
5809     // slow path
5810     SAVE_ACC();
5811     SAVE_PC();
5812     JSTaggedValue thisFunc = GetFunction(sp);
5813     JSTaggedValue res = SlowRuntimeStub::StSuperByValue(thread, receiver, propKey, value, thisFunc);
5814     INTERPRETER_RETURN_IF_ABRUPT(res);
5815     RESTORE_ACC();
5816     DISPATCH(STSUPERBYVALUE_IMM16_V8_V8);
5817 }
5818 
HandleLdsuperbyvalueImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5819 void InterpreterAssembly::HandleLdsuperbyvalueImm16V8(
5820     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5821     JSTaggedValue acc, int16_t hotnessCounter)
5822 {
5823     uint32_t v0 = READ_INST_8_2();
5824     LOG_INST() << "intrinsics::Ldsuperbyvalue"
5825                << " v" << v0;
5826 
5827     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5828     JSTaggedValue propKey = GET_ACC();
5829 
5830     // slow path
5831     SAVE_PC();
5832     JSTaggedValue thisFunc = GetFunction(sp);
5833     JSTaggedValue res = SlowRuntimeStub::LdSuperByValue(thread, receiver, propKey, thisFunc);
5834     INTERPRETER_RETURN_IF_ABRUPT(res);
5835     SET_ACC(res);
5836     DISPATCH(LDSUPERBYVALUE_IMM16_V8);
5837 }
5838 
HandleLdsuperbyvalueImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5839 void InterpreterAssembly::HandleLdsuperbyvalueImm8V8(
5840     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5841     JSTaggedValue acc, int16_t hotnessCounter)
5842 {
5843     uint32_t v0 = READ_INST_8_1();
5844     LOG_INST() << "intrinsics::Ldsuperbyvalue"
5845                << " v" << v0;
5846 
5847     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5848     JSTaggedValue propKey = GET_ACC();
5849 
5850     // slow path
5851     SAVE_PC();
5852     JSTaggedValue thisFunc = GetFunction(sp);
5853     JSTaggedValue res = SlowRuntimeStub::LdSuperByValue(thread, receiver, propKey, thisFunc);
5854     INTERPRETER_RETURN_IF_ABRUPT(res);
5855     SET_ACC(res);
5856     DISPATCH(LDSUPERBYVALUE_IMM8_V8);
5857 }
5858 
HandleLdobjbyvalueImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5859 void InterpreterAssembly::HandleLdobjbyvalueImm16V8(
5860     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5861     JSTaggedValue acc, int16_t hotnessCounter)
5862 {
5863     uint32_t v0 = READ_INST_8_2();
5864     LOG_INST() << "intrinsics::Ldobjbyvalue"
5865                << " v" << v0;
5866 
5867     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5868     JSTaggedValue propKey = GET_ACC();
5869 
5870 #if ECMSCRIPT_ENABLE_IC
5871     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5872     auto tmpProfileTypeInfo = state->profileTypeInfo;
5873     if (!tmpProfileTypeInfo.IsUndefined()) {
5874         uint16_t slotId = READ_INST_16_0();
5875         auto profileTypeArray = ProfileTypeInfo::Cast(profiltmpProfileTypeInfoeTypeInfo.GetTaggedObject());
5876         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
5877         JSTaggedValue res = JSTaggedValue::Hole();
5878 
5879         if (LIKELY(firstValue.IsHeapObject())) {
5880             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
5881             res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue);
5882         }
5883         // IC miss and not enter the megamorphic state, store as polymorphic
5884         if (res.IsHole() && !firstValue.IsHole()) {
5885             res = ICRuntimeStub::LoadICByValue(thread,
5886                                                profileTypeArray,
5887                                                receiver, propKey, slotId);
5888         }
5889 
5890         if (LIKELY(!res.IsHole())) {
5891             INTERPRETER_RETURN_IF_ABRUPT(res);
5892             SET_ACC(res);
5893             DISPATCH(LDOBJBYVALUE_IMM16_V8);
5894         }
5895     }
5896 #endif
5897     // fast path
5898     if (LIKELY(receiver.IsHeapObject())) {
5899         JSTaggedValue res = FastRuntimeStub::GetPropertyByValue(thread, receiver, propKey);
5900         if (!res.IsHole()) {
5901             ASSERT(!res.IsAccessor());
5902             INTERPRETER_RETURN_IF_ABRUPT(res);
5903             SET_ACC(res);
5904             DISPATCH(LDOBJBYVALUE_IMM16_V8);
5905         }
5906     }
5907     // slow path
5908     SAVE_PC();
5909     JSTaggedValue res = SlowRuntimeStub::LdObjByValue(thread, receiver, propKey, false, JSTaggedValue::Undefined());
5910     INTERPRETER_RETURN_IF_ABRUPT(res);
5911     SET_ACC(res);
5912     DISPATCH(LDOBJBYVALUE_IMM16_V8);
5913 }
5914 
HandleLdobjbyvalueImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5915 void InterpreterAssembly::HandleLdobjbyvalueImm8V8(
5916     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5917     JSTaggedValue acc, int16_t hotnessCounter)
5918 {
5919     uint32_t v0 = READ_INST_8_1();
5920     LOG_INST() << "intrinsics::Ldobjbyvalue"
5921                << " v" << v0;
5922 
5923     JSTaggedValue receiver = GET_VREG_VALUE(v0);
5924     JSTaggedValue propKey = GET_ACC();
5925 
5926 #if ECMSCRIPT_ENABLE_IC
5927     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
5928     auto tmpProfileTypeInfo = state->profileTypeInfo;
5929     if (!tmpProfileTypeInfo.IsUndefined()) {
5930         uint16_t slotId = READ_INST_8_0();
5931         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
5932         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
5933         JSTaggedValue res = JSTaggedValue::Hole();
5934 
5935         if (LIKELY(firstValue.IsHeapObject())) {
5936             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
5937             res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue);
5938         }
5939         // IC miss and not enter the megamorphic state, store as polymorphic
5940         if (res.IsHole() && !firstValue.IsHole()) {
5941             res = ICRuntimeStub::LoadICByValue(thread,
5942                                                profileTypeArray,
5943                                                receiver, propKey, slotId);
5944         }
5945 
5946         if (LIKELY(!res.IsHole())) {
5947             INTERPRETER_RETURN_IF_ABRUPT(res);
5948             SET_ACC(res);
5949             DISPATCH(LDOBJBYVALUE_IMM8_V8);
5950         }
5951     }
5952 #endif
5953     // fast path
5954     if (LIKELY(receiver.IsHeapObject())) {
5955         JSTaggedValue res = FastRuntimeStub::GetPropertyByValue(thread, receiver, propKey);
5956         if (!res.IsHole()) {
5957             ASSERT(!res.IsAccessor());
5958             INTERPRETER_RETURN_IF_ABRUPT(res);
5959             SET_ACC(res);
5960             DISPATCH(LDOBJBYVALUE_IMM8_V8);
5961         }
5962     }
5963     // slow path
5964     SAVE_PC();
5965     JSTaggedValue res = SlowRuntimeStub::LdObjByValue(thread, receiver, propKey, false, JSTaggedValue::Undefined());
5966     INTERPRETER_RETURN_IF_ABRUPT(res);
5967     SET_ACC(res);
5968     DISPATCH(LDOBJBYVALUE_IMM8_V8);
5969 }
5970 
HandleJstricteqzImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5971 void InterpreterAssembly::HandleJstricteqzImm16(
5972     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5973     JSTaggedValue acc, int16_t hotnessCounter)
5974 {
5975     DISPATCH(JSTRICTEQZ_IMM16);
5976 }
5977 
HandleJstricteqzImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5978 void InterpreterAssembly::HandleJstricteqzImm8(
5979     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5980     JSTaggedValue acc, int16_t hotnessCounter)
5981 {
5982     DISPATCH(JSTRICTEQZ_IMM8);
5983 }
5984 
HandleDefineclasswithbufferImm16Id16Id16Imm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)5985 void InterpreterAssembly::HandleDefineclasswithbufferImm16Id16Id16Imm16V8(
5986     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
5987     JSTaggedValue acc, int16_t hotnessCounter)
5988 {
5989     uint16_t methodId = READ_INST_16_2();
5990     uint16_t literaId = READ_INST_16(6);
5991     uint16_t length = READ_INST_16(8);
5992     uint16_t v0 = READ_INST_8_8();
5993     LOG_INST() << "intrinsics::defineclasswithbuffer"
5994                << " method id:" << methodId << " lexenv: v" << v0;
5995 
5996     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
5997     JSTaggedValue proto = GET_VREG_VALUE(v0);
5998 
5999     SAVE_PC();
6000     JSTaggedValue res =
6001         SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(thread, sp),
6002                                                methodId, literaId, GetModule(thread, sp), JSTaggedValue(length));
6003 
6004     INTERPRETER_RETURN_IF_ABRUPT(res);
6005     ASSERT(res.IsClassConstructor());
6006 
6007     SET_ACC(res);
6008     DISPATCH(DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8);
6009 }
6010 
HandleDefineclasswithbufferImm8Id16Id16Imm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6011 void InterpreterAssembly::HandleDefineclasswithbufferImm8Id16Id16Imm16V8(
6012     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6013     JSTaggedValue acc, int16_t hotnessCounter)
6014 {
6015     uint16_t methodId = READ_INST_16_1();
6016     uint16_t literaId = READ_INST_16_3();
6017     uint16_t length = READ_INST_16_5();
6018     uint16_t v0 = READ_INST_8_7();
6019     LOG_INST() << "intrinsics::defineclasswithbuffer"
6020                << " method id:" << methodId << " lexenv: v" << v0;
6021 
6022     JSTaggedValue proto = GET_VREG_VALUE(v0);
6023 
6024     SAVE_PC();
6025     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
6026     JSTaggedValue res =
6027         SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(thread, sp),
6028                                                methodId, literaId, GetModule(thread, sp), JSTaggedValue(length));
6029 
6030     INTERPRETER_RETURN_IF_ABRUPT(res);
6031     ASSERT(res.IsClassConstructor());
6032 
6033     SET_ACC(res);
6034     DISPATCH(DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8);
6035 }
6036 
HandleWideLdpatchvarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6037 void InterpreterAssembly::HandleWideLdpatchvarPrefImm16(
6038     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6039     JSTaggedValue acc, int16_t hotnessCounter)
6040 {
6041     uint32_t index = READ_INST_16_1();
6042     LOG_INST() << "intrinsics::ldpatchvar" << " imm: " << index;
6043 
6044     SAVE_PC();
6045     JSTaggedValue res = SlowRuntimeStub::LdPatchVar(thread, index);
6046     INTERPRETER_RETURN_IF_ABRUPT(res);
6047     SET_ACC(res);
6048     DISPATCH(WIDE_LDPATCHVAR_PREF_IMM16);
6049 }
6050 
HandleWideStpatchvarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6051 void InterpreterAssembly::HandleWideStpatchvarPrefImm16(
6052     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6053     JSTaggedValue acc, int16_t hotnessCounter)
6054 {
6055     uint32_t index = READ_INST_16_1();
6056     LOG_INST() << "intrinsics::stpatchvar" << " imm: " << index;
6057     JSTaggedValue value = GET_ACC();
6058 
6059     SAVE_ACC();
6060     SAVE_PC();
6061     JSTaggedValue res = SlowRuntimeStub::StPatchVar(thread, index, value);
6062     INTERPRETER_RETURN_IF_ABRUPT(res);
6063     RESTORE_ACC();
6064     DISPATCH(WIDE_STPATCHVAR_PREF_IMM16);
6065 }
6066 
HandleLdPrivatePropertyImm8Imm16Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6067 void InterpreterAssembly::HandleLdPrivatePropertyImm8Imm16Imm16(
6068     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6069     JSTaggedValue acc, int16_t hotnessCounter)
6070 {
6071     DISPATCH(LDPRIVATEPROPERTY_IMM8_IMM16_IMM16);
6072 }
6073 
HandleStPrivatePropertyImm8Imm16Imm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6074 void InterpreterAssembly::HandleStPrivatePropertyImm8Imm16Imm16V8(
6075     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6076     JSTaggedValue acc, int16_t hotnessCounter)
6077 {
6078     DISPATCH(STPRIVATEPROPERTY_IMM8_IMM16_IMM16_V8);
6079 }
6080 
HandleTestInImm8Imm16Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6081 void InterpreterAssembly::HandleTestInImm8Imm16Imm16(
6082     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6083     JSTaggedValue acc, int16_t hotnessCounter)
6084 {
6085     DISPATCH(TESTIN_IMM8_IMM16_IMM16);
6086 }
6087 
HandleCallRuntimeNotifyConcurrentResultPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6088 void InterpreterAssembly::HandleCallRuntimeNotifyConcurrentResultPrefNone(
6089     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6090     JSTaggedValue acc, int16_t hotnessCounter)
6091 {
6092     DISPATCH(CALLRUNTIME_NOTIFYCONCURRENTRESULT_PREF_NONE);
6093 }
6094 
HandleDefineFieldByNameImm8Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6095 void InterpreterAssembly::HandleDefineFieldByNameImm8Id16V8(
6096     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6097     JSTaggedValue acc, int16_t hotnessCounter)
6098 {
6099     DISPATCH(DEFINEFIELDBYNAME_IMM8_ID16_V8);
6100 }
6101 
HandleDefinePropertyByNameImm8Id16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6102 void InterpreterAssembly::HandleDefinePropertyByNameImm8Id16V8(
6103     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6104     JSTaggedValue acc, int16_t hotnessCounter)
6105 {
6106     DISPATCH(DEFINEPROPERTYBYNAME_IMM8_ID16_V8);
6107 }
6108 
HandleCallRuntimeDefineFieldByValuePrefImm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6109 void InterpreterAssembly::HandleCallRuntimeDefineFieldByValuePrefImm8V8V8(
6110     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6111     JSTaggedValue acc, int16_t hotnessCounter)
6112 {
6113     DISPATCH(CALLRUNTIME_DEFINEFIELDBYVALUE_PREF_IMM8_V8_V8);
6114 }
6115 
HandleCallRuntimeDefineFieldByIndexPrefImm8Imm32V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6116 void InterpreterAssembly::HandleCallRuntimeDefineFieldByIndexPrefImm8Imm32V8(
6117     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6118     JSTaggedValue acc, int16_t hotnessCounter)
6119 {
6120     DISPATCH(CALLRUNTIME_DEFINEFIELDBYINDEX_PREF_IMM8_IMM32_V8);
6121 }
6122 
HandleCallRuntimeToPropertyKeyPrefNone(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6123 void InterpreterAssembly::HandleCallRuntimeToPropertyKeyPrefNone(
6124     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6125     JSTaggedValue acc, int16_t hotnessCounter)
6126 {
6127     DISPATCH(CALLRUNTIME_TOPROPERTYKEY_PREF_NONE);
6128 }
6129 
HandleCallRuntimeCreatePrivatePropertyPrefImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6130 void InterpreterAssembly::HandleCallRuntimeCreatePrivatePropertyPrefImm16Id16(
6131     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6132     JSTaggedValue acc, int16_t hotnessCounter)
6133 {
6134     DISPATCH(CALLRUNTIME_CREATEPRIVATEPROPERTY_PREF_IMM16_ID16);
6135 }
6136 
HandleCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6137 void InterpreterAssembly::HandleCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8(
6138     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6139     JSTaggedValue acc, int16_t hotnessCounter)
6140 {
6141     DISPATCH(CALLRUNTIME_DEFINEPRIVATEPROPERTY_PREF_IMM8_IMM16_IMM16_V8);
6142 }
6143 
HandleCallRuntimeCallInitPrefImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6144 void InterpreterAssembly::HandleCallRuntimeCallInitPrefImm8V8(
6145     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6146     JSTaggedValue acc, int16_t hotnessCounter)
6147 {
6148     DISPATCH(CALLRUNTIME_CALLINIT_PREF_IMM8_V8);
6149 }
6150 
HandleCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6151 void InterpreterAssembly::HandleCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8(
6152     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6153     JSTaggedValue acc, int16_t hotnessCounter)
6154 {
6155     uint16_t methodId = READ_INST_16_3();
6156     uint16_t literaId = READ_INST_16_5();
6157     uint16_t length = READ_INST_16_7();
6158     uint16_t v0 = READ_INST_8_9();
6159     LOG_INST() << "intrinsics::definesendableclass"
6160                 << " method id:" << methodId << " base: v" << v0;
6161 
6162     JSTaggedValue base = GET_VREG_VALUE(v0);
6163 
6164     SAVE_PC();
6165     JSTaggedValue res =
6166         SlowRuntimeStub::CreateSharedClass(thread, base, GetConstantPool(thread, sp), methodId, literaId,
6167                                            length, GetModule(thread, sp));
6168 
6169     INTERPRETER_RETURN_IF_ABRUPT(res);
6170     ASSERT(res.IsClassConstructor());
6171     ASSERT(res.IsJSSharedFunction());
6172     SET_ACC(res);
6173     DISPATCH(CALLRUNTIME_DEFINESENDABLECLASS_PREF_IMM16_ID16_ID16_IMM16_V8);
6174 }
6175 
HandleCallRuntimeLdSendableClassPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6176 void InterpreterAssembly::HandleCallRuntimeLdSendableClassPrefImm16(
6177     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6178     JSTaggedValue acc, int16_t hotnessCounter)
6179 {
6180     uint16_t level = READ_INST_16_1();
6181     LOG_INST() << "intrinsics::LdSendableClass level: " << level;
6182     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
6183     auto res = SlowRuntimeStub::LdSendableClass(thread, state->env, level);
6184     ASSERT(res.IsJSSharedFunction());
6185     SET_ACC(res);
6186     DISPATCH(CALLRUNTIME_LDSENDABLECLASS_PREF_IMM16);
6187 }
6188 
HandleStthisbyvalueImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6189 void InterpreterAssembly::HandleStthisbyvalueImm16V8(
6190     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6191     JSTaggedValue acc, int16_t hotnessCounter)
6192 {
6193     uint32_t v0 = READ_INST_8_2();
6194 
6195     LOG_INST() << "intrinsics::stthisbyvalue"
6196                << " v" << v0;
6197 
6198     JSTaggedValue receiver = GetThis(sp);
6199 #if ECMASCRIPT_ENABLE_IC
6200     if (!profileTypeInfo.IsUndefined()) {
6201         uint16_t slotId = READ_INST_16_0();
6202         auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject());
6203         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6204         JSTaggedValue propKey = GET_VREG_VALUE(v0);
6205         JSTaggedValue value = GET_ACC();
6206         JSTaggedValue res = JSTaggedValue::Hole();
6207         SAVE_ACC();
6208 
6209         if (LIKELY(firstValue.IsHeapObject())) {
6210             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6211             res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value);
6212         }
6213         // IC miss and not enter the megamorphic state, store as polymorphic
6214         if (res.IsHole() && !firstValue.IsHole()) {
6215             res = ICRuntimeStub::StoreICByValue(thread,
6216                                                 profileTypeArray,
6217                                                 receiver, propKey, value, slotId);
6218         }
6219 
6220         if (LIKELY(!res.IsHole())) {
6221             INTERPRETER_RETURN_IF_ABRUPT(res);
6222             RESTORE_ACC();
6223             DISPATCH(STTHISBYVALUE_IMM16_V8);
6224         }
6225     }
6226 #endif
6227     if (receiver.IsHeapObject()) {
6228         SAVE_ACC();
6229         JSTaggedValue propKey = GET_VREG_VALUE(v0);
6230         JSTaggedValue value = GET_ACC();
6231         // fast path
6232         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue(thread, receiver, propKey, value);
6233         if (!res.IsHole()) {
6234             INTERPRETER_RETURN_IF_ABRUPT(res);
6235             RESTORE_ACC();
6236             DISPATCH(STTHISBYVALUE_IMM16_V8);
6237         }
6238         RESTORE_ACC();
6239     }
6240     {
6241         // slow path
6242         SAVE_ACC();
6243         receiver = GetThis(sp);                       // Maybe moved by GC
6244         JSTaggedValue propKey = GET_VREG_VALUE(v0);   // Maybe moved by GC
6245         JSTaggedValue value = GET_ACC();              // Maybe moved by GC
6246         JSTaggedValue res = SlowRuntimeStub::StObjByValue(thread, receiver, propKey, value);
6247         INTERPRETER_RETURN_IF_ABRUPT(res);
6248         RESTORE_ACC();
6249     }
6250     DISPATCH(STTHISBYVALUE_IMM16_V8);
6251 }
6252 
HandleStthisbyvalueImm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6253 void InterpreterAssembly::HandleStthisbyvalueImm8V8(
6254     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6255     JSTaggedValue acc, int16_t hotnessCounter)
6256 {
6257     uint32_t v0 = READ_INST_8_1();
6258 
6259     LOG_INST() << "intrinsics::stthisbyvalue"
6260                << " v" << v0;
6261 
6262     JSTaggedValue receiver = GetThis(sp);
6263 #if ECMASCRIPT_ENABLE_IC
6264     if (!profileTypeInfo.IsUndefined()) {
6265         uint16_t slotId = READ_INST_8_0();
6266         auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject());
6267         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6268         JSTaggedValue propKey = GET_VREG_VALUE(v0);
6269         JSTaggedValue value = GET_ACC();
6270         JSTaggedValue res = JSTaggedValue::Hole();
6271         SAVE_ACC();
6272 
6273         if (LIKELY(firstValue.IsHeapObject())) {
6274             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6275             res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value);
6276         }
6277         // IC miss and not enter the megamorphic state, store as polymorphic
6278         if (res.IsHole() && !firstValue.IsHole()) {
6279             res = ICRuntimeStub::StoreICByValue(thread,
6280                                                 profileTypeArray,
6281                                                 receiver, propKey, value, slotId);
6282         }
6283 
6284         if (LIKELY(!res.IsHole())) {
6285             INTERPRETER_RETURN_IF_ABRUPT(res);
6286             RESTORE_ACC();
6287             DISPATCH(STTHISBYVALUE_IMM8_V8);
6288         }
6289     }
6290 #endif
6291     if (receiver.IsHeapObject()) {
6292         SAVE_ACC();
6293         JSTaggedValue propKey = GET_VREG_VALUE(v0);
6294         JSTaggedValue value = GET_ACC();
6295         // fast path
6296         JSTaggedValue res = FastRuntimeStub::SetPropertyByValue(thread, receiver, propKey, value);
6297         if (!res.IsHole()) {
6298             INTERPRETER_RETURN_IF_ABRUPT(res);
6299             RESTORE_ACC();
6300             DISPATCH(STTHISBYVALUE_IMM8_V8);
6301         }
6302         RESTORE_ACC();
6303     }
6304     {
6305         // slow path
6306         SAVE_ACC();
6307         receiver = GetThis(sp);                       // Maybe moved by GC
6308         JSTaggedValue propKey = GET_VREG_VALUE(v0);   // Maybe moved by GC
6309         JSTaggedValue value = GET_ACC();              // Maybe moved by GC
6310         JSTaggedValue res = SlowRuntimeStub::StObjByValue(thread, receiver, propKey, value);
6311         INTERPRETER_RETURN_IF_ABRUPT(res);
6312         RESTORE_ACC();
6313     }
6314     DISPATCH(STTHISBYVALUE_IMM8_V8);
6315 }
6316 
HandleLdthisbyvalueImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6317 void InterpreterAssembly::HandleLdthisbyvalueImm16(
6318     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6319     JSTaggedValue acc, int16_t hotnessCounter)
6320 {
6321     LOG_INST() << "intrinsics::Ldthisbyvalue";
6322 
6323     JSTaggedValue receiver = GetThis(sp);
6324     JSTaggedValue propKey = GET_ACC();
6325 
6326 #if ECMSCRIPT_ENABLE_IC
6327     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
6328     auto tmpProfileTypeInfo = state->profileTypeInfo;
6329     if (!tmpProfileTypeInfo.IsUndefined()) {
6330         uint16_t slotId = READ_INST_16_0();
6331         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
6332         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6333         JSTaggedValue res = JSTaggedValue::Hole();
6334 
6335         if (LIKELY(firstValue.IsHeapObject())) {
6336             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6337             res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue);
6338         }
6339         // IC miss and not enter the megamorphic state, store as polymorphic
6340         if (res.IsHole() && !firstValue.IsHole()) {
6341             res = ICRuntimeStub::LoadICByValue(thread,
6342                                                profileTypeArray,
6343                                                receiver, propKey, slotId);
6344         }
6345 
6346         if (LIKELY(!res.IsHole())) {
6347             INTERPRETER_RETURN_IF_ABRUPT(res);
6348             SET_ACC(res);
6349             DISPATCH(LDTHISBYVALUE_IMM16);
6350         }
6351     }
6352 #endif
6353     if (LIKELY(receiver.IsHeapObject())) {
6354         // fast path
6355         JSTaggedValue res = FastRuntimeStub::GetPropertyByValue(thread, receiver, propKey);
6356         if (!res.IsHole()) {
6357             ASSERT(!res.IsAccessor());
6358             INTERPRETER_RETURN_IF_ABRUPT(res);
6359             SET_ACC(res);
6360             DISPATCH(LDTHISBYVALUE_IMM16);
6361         }
6362     }
6363     // slow path
6364     SAVE_PC();
6365     JSTaggedValue res = SlowRuntimeStub::LdObjByValue(thread, receiver, propKey, false, JSTaggedValue::Undefined());
6366     INTERPRETER_RETURN_IF_ABRUPT(res);
6367     SET_ACC(res);
6368     DISPATCH(LDTHISBYVALUE_IMM16);
6369 }
6370 
HandleLdthisbyvalueImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6371 void InterpreterAssembly::HandleLdthisbyvalueImm8(
6372     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6373     JSTaggedValue acc, int16_t hotnessCounter)
6374 {
6375     LOG_INST() << "intrinsics::Ldthisbyvalue";
6376 
6377     JSTaggedValue receiver = GetThis(sp);
6378     JSTaggedValue propKey = GET_ACC();
6379 
6380 #if ECMSCRIPT_ENABLE_IC
6381     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
6382     auto tmpProfileTypeInfo = state->profileTypeInfo;
6383     if (!tmpProfileTypeInfo.IsUndefined()) {
6384         uint16_t slotId = READ_INST_8_0();
6385         auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject());
6386         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6387         JSTaggedValue res = JSTaggedValue::Hole();
6388 
6389         if (LIKELY(firstValue.IsHeapObject())) {
6390             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6391             res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue);
6392         }
6393         // IC miss and not enter the megamorphic state, store as polymorphic
6394         if (res.IsHole() && !firstValue.IsHole()) {
6395             res = ICRuntimeStub::LoadICByValue(thread,
6396                                                profileTypeArray,
6397                                                receiver, propKey, slotId);
6398         }
6399 
6400         if (LIKELY(!res.IsHole())) {
6401             INTERPRETER_RETURN_IF_ABRUPT(res);
6402             SET_ACC(res);
6403             DISPATCH(LDTHISBYVALUE_IMM8);
6404         }
6405     }
6406 #endif
6407     // fast path
6408     if (LIKELY(receiver.IsHeapObject())) {
6409         JSTaggedValue res = FastRuntimeStub::GetPropertyByValue(thread, receiver, propKey);
6410         if (!res.IsHole()) {
6411             ASSERT(!res.IsAccessor());
6412             INTERPRETER_RETURN_IF_ABRUPT(res);
6413             SET_ACC(res);
6414             DISPATCH(LDTHISBYVALUE_IMM8);
6415         }
6416     }
6417     // slow path
6418     SAVE_PC();
6419     JSTaggedValue res = SlowRuntimeStub::LdObjByValue(thread, receiver, propKey, false, JSTaggedValue::Undefined());
6420     INTERPRETER_RETURN_IF_ABRUPT(res);
6421     SET_ACC(res);
6422     DISPATCH(LDTHISBYVALUE_IMM8);
6423 }
6424 
HandleStthisbynameImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6425 void InterpreterAssembly::HandleStthisbynameImm16Id16(
6426     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6427     JSTaggedValue acc, int16_t hotnessCounter)
6428 {
6429 #if ECMASCRIPT_ENABLE_IC
6430     if (!profileTypeInfo.IsUndefined()) {
6431         uint16_t slotId = READ_INST_16_0();
6432         auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject());
6433         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6434         JSTaggedValue res = JSTaggedValue::Hole();
6435         SAVE_ACC();
6436 
6437         JSTaggedValue receiver = GetThis(sp);
6438         JSTaggedValue value = GET_ACC();
6439         if (LIKELY(firstValue.IsHeapObject())) {
6440             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6441             res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value);
6442         }
6443         // IC miss and not enter the megamorphic state, store as polymorphic
6444         if (res.IsHole() && !firstValue.IsHole()) {
6445             uint16_t stringId = READ_INST_16_2();
6446             constpool = GetConstantPool(thread, sp);
6447             JSTaggedValue propKey =
6448                 ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6449             RESTORE_ACC();
6450             value = GET_ACC();
6451             receiver = GetThis(sp);
6452             profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject());
6453             res = ICRuntimeStub::StoreICByName(thread, profileTypeArray, receiver, propKey, value, slotId);
6454         }
6455 
6456         if (LIKELY(!res.IsHole())) {
6457             INTERPRETER_RETURN_IF_ABRUPT(res);
6458             RESTORE_ACC();
6459             DISPATCH(STTHISBYNAME_IMM16_ID16);
6460         }
6461         RESTORE_ACC();
6462     }
6463 #endif
6464     uint16_t stringId = READ_INST_16_2();
6465     LOG_INST() << "intrinsics::stthisbyname "
6466                << " stringId:" << stringId;
6467     JSTaggedValue receiver = GetThis(sp);
6468     if (receiver.IsHeapObject()) {
6469         SAVE_ACC();
6470         constpool = GetConstantPool(thread, sp);
6471         JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6472         RESTORE_ACC();
6473         JSTaggedValue value = GET_ACC();
6474         receiver = GetThis(sp);
6475         // fast path
6476         JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, receiver, propKey, value);
6477         if (!res.IsHole()) {
6478             INTERPRETER_RETURN_IF_ABRUPT(res);
6479             RESTORE_ACC();
6480             DISPATCH(STTHISBYNAME_IMM16_ID16);
6481         }
6482         RESTORE_ACC();
6483     }
6484     // slow path
6485     SAVE_ACC();
6486     SAVE_PC();
6487     constpool = GetConstantPool(thread, sp);
6488     auto propKey =
6489         ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);  // Maybe moved by GC
6490     RESTORE_ACC();
6491     JSTaggedValue value = GET_ACC();                  // Maybe moved by GC
6492     receiver = GetThis(sp);                           // Maybe moved by GC
6493     JSTaggedValue res = SlowRuntimeStub::StObjByName(thread, receiver, propKey, value);
6494     INTERPRETER_RETURN_IF_ABRUPT(res);
6495     RESTORE_ACC();
6496     DISPATCH(STTHISBYNAME_IMM16_ID16);
6497 }
6498 
HandleStthisbynameImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6499 void InterpreterAssembly::HandleStthisbynameImm8Id16(
6500     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6501     JSTaggedValue acc, int16_t hotnessCounter)
6502 {
6503 #if ECMASCRIPT_ENABLE_IC
6504     if (!profileTypeInfo.IsUndefined()) {
6505         uint16_t slotId = READ_INST_8_0();
6506         auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject());
6507         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6508         JSTaggedValue res = JSTaggedValue::Hole();
6509         SAVE_ACC();
6510 
6511         JSTaggedValue receiver = GetThis(sp);
6512         JSTaggedValue value = GET_ACC();
6513         if (LIKELY(firstValue.IsHeapObject())) {
6514             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6515             res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value);
6516         }
6517         // IC miss and not enter the megamorphic state, store as polymorphic
6518         if (res.IsHole() && !firstValue.IsHole()) {
6519             uint16_t stringId = READ_INST_16_1();
6520             constpool = GetConstantPool(thread, sp);
6521             JSTaggedValue propKey =
6522                 ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6523             RESTORE_ACC();
6524             value = GET_ACC();
6525             receiver = GetThis(sp);
6526             profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject());
6527             res = ICRuntimeStub::StoreICByName(thread, profileTypeArray, receiver, propKey, value, slotId);
6528         }
6529 
6530         if (LIKELY(!res.IsHole())) {
6531             INTERPRETER_RETURN_IF_ABRUPT(res);
6532             RESTORE_ACC();
6533             DISPATCH(STTHISBYNAME_IMM8_ID16);
6534         }
6535         RESTORE_ACC();
6536     }
6537 #endif
6538     uint16_t stringId = READ_INST_16_1();
6539     LOG_INST() << "intrinsics::stthisbyname "
6540                << " stringId:" << stringId;
6541     JSTaggedValue receiver = GetThis(sp);
6542     if (receiver.IsHeapObject()) {
6543         SAVE_ACC();
6544         constpool = GetConstantPool(thread, sp);
6545         JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6546         RESTORE_ACC();
6547         JSTaggedValue value = GET_ACC();
6548         receiver = GetThis(sp);
6549         // fast path
6550         JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, receiver, propKey, value);
6551         if (!res.IsHole()) {
6552             INTERPRETER_RETURN_IF_ABRUPT(res);
6553             RESTORE_ACC();
6554             DISPATCH(STTHISBYNAME_IMM8_ID16);
6555         }
6556         RESTORE_ACC();
6557     }
6558     // slow path
6559     SAVE_ACC();
6560     SAVE_PC();
6561     constpool = GetConstantPool(thread, sp);
6562     auto propKey =
6563         ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);  // Maybe moved by GC
6564     RESTORE_ACC();
6565     JSTaggedValue value = GET_ACC();                  // Maybe moved by GC
6566     receiver = GetThis(sp);                           // Maybe moved by GC
6567     JSTaggedValue res = SlowRuntimeStub::StObjByName(thread, receiver, propKey, value);
6568     INTERPRETER_RETURN_IF_ABRUPT(res);
6569     RESTORE_ACC();
6570     DISPATCH(STTHISBYNAME_IMM8_ID16);
6571 }
6572 
HandleLdthisbynameImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6573 void InterpreterAssembly::HandleLdthisbynameImm16Id16(
6574     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6575     JSTaggedValue acc, int16_t hotnessCounter)
6576 {
6577 #if ECMASCRIPT_ENABLE_IC
6578     if (!profileTypeInfo.IsUndefined()) {
6579         uint16_t slotId = READ_INST_16_0();
6580         auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject());
6581         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6582         JSTaggedValue res = JSTaggedValue::Hole();
6583 
6584         JSTaggedValue receiver = GetThis(sp);
6585         if (LIKELY(firstValue.IsHeapObject())) {
6586             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6587             res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue);
6588         }
6589         if (LIKELY(!res.IsHole())) {
6590             INTERPRETER_RETURN_IF_ABRUPT(res);
6591             SET_ACC(res);
6592             DISPATCH(LDTHISBYNAME_IMM16_ID16);
6593         } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic
6594             uint16_t stringId = READ_INST_16_2();
6595             constpool = GetConstantPool(thread, sp);
6596             JSTaggedValue propKey =
6597                 ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6598             receiver = GetThis(sp);
6599             profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject());
6600             res = ICRuntimeStub::LoadICByName(thread,
6601                                               profileTypeArray,
6602                                               receiver, propKey, slotId);
6603             INTERPRETER_RETURN_IF_ABRUPT(res);
6604             SET_ACC(res);
6605             DISPATCH(LDTHISBYNAME_IMM16_ID16);
6606         }
6607     }
6608 #endif
6609     uint16_t stringId = READ_INST_16_2();
6610     constpool = GetConstantPool(thread, sp);
6611     JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6612     JSTaggedValue receiver = GetThis(sp);
6613     LOG_INST() << "intrinsics::ldthisbyname stringId:" << stringId << ", "
6614                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()))
6615                << ", obj:" << receiver.GetRawData();
6616 
6617     if (LIKELY(receiver.IsHeapObject())) {
6618         // fast path
6619         JSTaggedValue res = FastRuntimeStub::GetPropertyByName(thread, receiver, propKey);
6620         if (!res.IsHole()) {
6621             ASSERT(!res.IsAccessor());
6622             INTERPRETER_RETURN_IF_ABRUPT(res);
6623             SET_ACC(res);
6624             DISPATCH(LDTHISBYNAME_IMM16_ID16);
6625         }
6626     }
6627     // not meet fast condition or fast path return hole, walk slow path
6628     // slow stub not need receiver
6629     SAVE_PC();
6630     JSTaggedValue res = SlowRuntimeStub::LdObjByName(thread, receiver, propKey, false, JSTaggedValue::Undefined());
6631     INTERPRETER_RETURN_IF_ABRUPT(res);
6632     SET_ACC(res);
6633     DISPATCH(LDTHISBYNAME_IMM16_ID16);
6634 }
6635 
HandleLdthisbynameImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6636 void InterpreterAssembly::HandleLdthisbynameImm8Id16(
6637     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6638     JSTaggedValue acc, int16_t hotnessCounter)
6639 {
6640 #if ECMASCRIPT_ENABLE_IC
6641     if (!profileTypeInfo.IsUndefined()) {
6642         uint16_t slotId = READ_INST_8_0();
6643         auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject());
6644         JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId);
6645         JSTaggedValue res = JSTaggedValue::Hole();
6646 
6647         JSTaggedValue receiver = GetThis(sp);
6648         if (LIKELY(firstValue.IsHeapObject())) {
6649             JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1);
6650             res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue);
6651         }
6652         if (LIKELY(!res.IsHole())) {
6653             INTERPRETER_RETURN_IF_ABRUPT(res);
6654             SET_ACC(res);
6655             DISPATCH(LDTHISBYNAME_IMM8_ID16);
6656         } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic
6657             uint16_t stringId = READ_INST_16_1();
6658             constpool = GetConstantPool(thread, sp);
6659             JSTaggedValue propKey =
6660                 ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6661             receiver = GetThis(sp);
6662             profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject());
6663             res = ICRuntimeStub::LoadICByName(thread,
6664                                               profileTypeArray,
6665                                               receiver, propKey, slotId);
6666             INTERPRETER_RETURN_IF_ABRUPT(res);
6667             SET_ACC(res);
6668             DISPATCH(LDTHISBYNAME_IMM8_ID16);
6669         }
6670     }
6671 #endif
6672     uint16_t stringId = READ_INST_16_1();
6673     constpool = GetConstantPool(thread, sp);
6674     JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId);
6675     JSTaggedValue receiver = GetThis(sp);
6676     LOG_INST() << "intrinsics::ldthisbyname stringId:" << stringId << ", "
6677                << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject()))
6678                << ", obj:" << receiver.GetRawData();
6679 
6680     if (LIKELY(receiver.IsHeapObject())) {
6681         // fast path
6682         JSTaggedValue res = FastRuntimeStub::GetPropertyByName(thread, receiver, propKey);
6683         if (!res.IsHole()) {
6684             ASSERT(!res.IsAccessor());
6685             INTERPRETER_RETURN_IF_ABRUPT(res);
6686             SET_ACC(res);
6687             DISPATCH(LDTHISBYNAME_IMM8_ID16);
6688         }
6689     }
6690     // not meet fast condition or fast path return hole, walk slow path
6691     // slow stub not need receiver
6692     SAVE_PC();
6693     JSTaggedValue res = SlowRuntimeStub::LdObjByName(thread, receiver, propKey, false, JSTaggedValue::Undefined());
6694     INTERPRETER_RETURN_IF_ABRUPT(res);
6695     SET_ACC(res);
6696     DISPATCH(LDTHISBYNAME_IMM8_ID16);
6697 }
6698 
HandleLdexternalmodulevarImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6699 void InterpreterAssembly::HandleLdexternalmodulevarImm8(
6700     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6701     JSTaggedValue acc, int16_t hotnessCounter)
6702 {
6703     int32_t index = READ_INST_8_0();
6704     LOG_INST() << "intrinsics::ldmodulevar index:" << index;
6705 
6706     JSTaggedValue moduleVar = SlowRuntimeStub::LdExternalModuleVar(thread, index);
6707     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
6708     SET_ACC(moduleVar);
6709     DISPATCH(LDEXTERNALMODULEVAR_IMM8);
6710 }
6711 
HandleCallRuntimeLdsendableexternalmodulevarImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6712 void InterpreterAssembly::HandleCallRuntimeLdsendableexternalmodulevarImm8(
6713     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6714     JSTaggedValue acc, int16_t hotnessCounter)
6715 {
6716     int32_t index = READ_INST_8_1();
6717     JSTaggedValue thisFunc = GetFunction(sp);
6718     LOG_INST() << "intrinsics::ldsendableexternalmodulevar index:" << index;
6719 
6720     JSTaggedValue moduleVar = SlowRuntimeStub::LdSendableExternalModuleVar(thread, index, thisFunc);
6721     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
6722     SET_ACC(moduleVar);
6723     DISPATCH(CALLRUNTIME_LDSENDABLEEXTERNALMODULEVAR_PREF_IMM8);
6724 }
6725 
HandleCallRuntimeNewSendableEnvImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6726 void InterpreterAssembly::HandleCallRuntimeNewSendableEnvImm8(
6727     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6728     JSTaggedValue acc, int16_t hotnessCounter)
6729 {
6730     uint8_t numVars = READ_INST_8_1();
6731     LOG_INST() << "intrinsics::newsendableenv"
6732                << " imm " << numVars;
6733     JSTaggedValue res = SlowRuntimeStub::NewSendableEnv(thread, numVars);
6734     INTERPRETER_RETURN_IF_ABRUPT(res);
6735     SET_ACC(res);
6736     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6737     moduleRecord->SetSendableEnv(thread, res);
6738     DISPATCH(CALLRUNTIME_NEWSENDABLEENV_PREF_IMM8);
6739 }
6740 
HandleCallRuntimeNewSendableEnvImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6741 void InterpreterAssembly::HandleCallRuntimeNewSendableEnvImm16(
6742     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6743     JSTaggedValue acc, int16_t hotnessCounter)
6744 {
6745     uint16_t numVars = READ_INST_16_1();
6746     LOG_INST() << "intrinsics::newsendableenv"
6747                 << " imm " << numVars;
6748 
6749     SAVE_PC();
6750     JSTaggedValue res = SlowRuntimeStub::NewSendableEnv(thread, numVars);
6751     INTERPRETER_RETURN_IF_ABRUPT(res);
6752     SET_ACC(res);
6753     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6754     moduleRecord->SetSendableEnv(thread, res);
6755     DISPATCH(CALLRUNTIME_WIDENEWSENDABLEENV_PREF_IMM16);
6756 }
6757 
HandleCallRuntimeStSendableVarImm4Imm4(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6758 void InterpreterAssembly::HandleCallRuntimeStSendableVarImm4Imm4(
6759     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6760     JSTaggedValue acc, int16_t hotnessCounter)
6761 {
6762     uint16_t level = READ_INST_4_2();
6763     uint16_t slot = READ_INST_4_3();
6764     LOG_INST() << "intrinsics::stsendablevar"
6765                << " level:" << level << " slot:" << slot;
6766 
6767     JSTaggedValue value = GET_ACC();
6768     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6769     JSTaggedValue env = moduleRecord->GetSendableEnv(thread);
6770     for (uint32_t i = 0; i < level; i++) {
6771         JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
6772         ASSERT(!taggedParentEnv.IsUndefined());
6773         env = taggedParentEnv;
6774     }
6775     SendableEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
6776 
6777     DISPATCH(CALLRUNTIME_STSENDABLEVAR_PREF_IMM4_IMM4);
6778 }
6779 
HandleCallRuntimeStSendableVarImm8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6780 void InterpreterAssembly::HandleCallRuntimeStSendableVarImm8Imm8(
6781     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6782     JSTaggedValue acc, int16_t hotnessCounter)
6783 {
6784     uint16_t level = READ_INST_8_1();
6785     uint16_t slot = READ_INST_8_2();
6786     LOG_INST() << "intrinsics::stsendablevar"
6787                 << " level:" << level << " slot:" << slot;
6788 
6789     JSTaggedValue value = GET_ACC();
6790     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6791     JSTaggedValue env = moduleRecord->GetSendableEnv(thread);
6792     for (uint32_t i = 0; i < level; i++) {
6793         JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
6794         ASSERT(!taggedParentEnv.IsUndefined());
6795         env = taggedParentEnv;
6796     }
6797     SendableEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
6798 
6799     DISPATCH(CALLRUNTIME_STSENDABLEVAR_PREF_IMM8_IMM8);
6800 }
6801 
HandleCallRuntimeStSendableVarImm16Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6802 void InterpreterAssembly::HandleCallRuntimeStSendableVarImm16Imm16(
6803     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6804     JSTaggedValue acc, int16_t hotnessCounter)
6805 {
6806     uint16_t level = READ_INST_16_1();
6807     uint16_t slot = READ_INST_16_3();
6808     LOG_INST() << "intrinsics::stsendablevar"
6809                 << " level:" << level << " slot:" << slot;
6810 
6811     JSTaggedValue value = GET_ACC();
6812     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6813     JSTaggedValue env = moduleRecord->GetSendableEnv(thread);
6814     for (uint32_t i = 0; i < level; i++) {
6815         JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
6816         ASSERT(!taggedParentEnv.IsUndefined());
6817         env = taggedParentEnv;
6818     }
6819     SendableEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, value);
6820 
6821     DISPATCH(CALLRUNTIME_WIDESTSENDABLEVAR_PREF_IMM16_IMM16);
6822 }
6823 
HandleCallRuntimeLdSendableVarImm4Imm4(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6824 void InterpreterAssembly::HandleCallRuntimeLdSendableVarImm4Imm4(
6825     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6826     JSTaggedValue acc, int16_t hotnessCounter)
6827 {
6828     uint16_t level = READ_INST_4_2();
6829     uint16_t slot = READ_INST_4_3();
6830 
6831     LOG_INST() << "intrinsics::ldsendablevar"
6832                << " level:" << level << " slot:" << slot;
6833     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6834     JSTaggedValue env = moduleRecord->GetSendableEnv(thread);
6835     for (uint32_t i = 0; i < level; i++) {
6836         JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
6837         ASSERT(!taggedParentEnv.IsUndefined());
6838         env = taggedParentEnv;
6839     }
6840     SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot));
6841     DISPATCH(CALLRUNTIME_LDSENDABLEVAR_PREF_IMM4_IMM4);
6842 }
6843 
HandleCallRuntimeLdSendableVarImm8Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6844 void InterpreterAssembly::HandleCallRuntimeLdSendableVarImm8Imm8(
6845     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6846     JSTaggedValue acc, int16_t hotnessCounter)
6847 {
6848     uint16_t level = READ_INST_8_1();
6849     uint16_t slot = READ_INST_8_2();
6850 
6851     LOG_INST() << "intrinsics::ldsendablevar"
6852                 << " level:" << level << " slot:" << slot;
6853     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6854     JSTaggedValue env = moduleRecord->GetSendableEnv(thread);
6855     for (uint32_t i = 0; i < level; i++) {
6856         JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
6857         ASSERT(!taggedParentEnv.IsUndefined());
6858         env = taggedParentEnv;
6859     }
6860     SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot));
6861     DISPATCH(CALLRUNTIME_LDSENDABLEVAR_PREF_IMM8_IMM8);
6862 }
6863 
HandleCallRuntimeLdSendableVarImm16Imm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6864 void InterpreterAssembly::HandleCallRuntimeLdSendableVarImm16Imm16(
6865     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6866     JSTaggedValue acc, int16_t hotnessCounter)
6867 {
6868     uint16_t level = READ_INST_16_1();
6869     uint16_t slot = READ_INST_16_3();
6870 
6871     LOG_INST() << "intrinsics::ldsendablevar"
6872                 << " level:" << level << " slot:" << slot;
6873     SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp));
6874     JSTaggedValue env = moduleRecord->GetSendableEnv(thread);
6875     for (uint32_t i = 0; i < level; i++) {
6876         JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread);
6877         ASSERT(!taggedParentEnv.IsUndefined());
6878         env = taggedParentEnv;
6879     }
6880     SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot));
6881     DISPATCH(CALLRUNTIME_WIDELDSENDABLEVAR_PREF_IMM16_IMM16);
6882 }
6883 
HandleDefinemethodImm16Id16Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6884 void InterpreterAssembly::HandleDefinemethodImm16Id16Imm8(
6885     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6886     JSTaggedValue acc, int16_t hotnessCounter)
6887 {
6888     uint16_t methodId = READ_INST_16_2();
6889     uint16_t length = READ_INST_8_4();
6890     LOG_INST() << "intrinsics::definemethod length: " << length;
6891     SAVE_ACC();
6892     constpool = GetConstantPool(thread, sp);
6893     Method *method =
6894         Method::Cast(ConstantPool::GetMethodFromCache(thread, constpool, methodId).GetTaggedObject());
6895     ASSERT(method != nullptr);
6896     RESTORE_ACC();
6897 
6898     SAVE_PC();
6899     JSTaggedValue homeObject = GET_ACC();
6900     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
6901     JSTaggedValue taggedCurEnv = state->env;
6902 
6903     auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetModule(thread, sp));
6904     INTERPRETER_RETURN_IF_ABRUPT(res);
6905     JSFunction *result = JSFunction::Cast(res.GetTaggedObject());
6906 
6907     SET_ACC(JSTaggedValue(result));
6908     DISPATCH(DEFINEMETHOD_IMM16_ID16_IMM8);
6909 }
6910 
HandleDeprecatedCallrangePrefImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6911 void InterpreterAssembly::HandleDeprecatedCallrangePrefImm16V8(
6912     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6913     JSTaggedValue acc, int16_t hotnessCounter)
6914 {
6915     DISPATCH(DEPRECATED_CALLRANGE_PREF_IMM16_V8);
6916 }
6917 
HandleCallrangeImm8Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6918 void InterpreterAssembly::HandleCallrangeImm8Imm8V8(
6919     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6920     JSTaggedValue acc, int16_t hotnessCounter)
6921 {
6922     DISPATCH(CALLRANGE_IMM8_IMM8_V8);
6923 }
6924 
HandleDynamicimport(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6925 void InterpreterAssembly::HandleDynamicimport(
6926     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6927     JSTaggedValue acc, int16_t hotnessCounter)
6928 {
6929     LOG_INST() << "intrinsics::dynamicimport";
6930     JSTaggedValue specifier = GET_ACC();
6931     JSTaggedValue thisFunc = GetFunction(sp);
6932     JSTaggedValue res = SlowRuntimeStub::DynamicImport(thread, specifier, thisFunc);
6933     INTERPRETER_RETURN_IF_ABRUPT(res);
6934     SET_ACC(res);
6935     DISPATCH(DYNAMICIMPORT);
6936 }
6937 
HandleDeprecatedDynamicimportPrefV8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6938 void InterpreterAssembly::HandleDeprecatedDynamicimportPrefV8(
6939     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6940     JSTaggedValue acc, int16_t hotnessCounter)
6941 {
6942     uint16_t v0 = READ_INST_8_1();
6943     LOG_INST() << "intrinsics::dynamicimport"
6944                 << " v" << v0;
6945     JSTaggedValue specifier = GET_VREG_VALUE(v0);
6946     JSTaggedValue thisFunc = GetFunction(sp);
6947     JSTaggedValue res = SlowRuntimeStub::DynamicImport(thread, specifier, thisFunc);
6948     INTERPRETER_RETURN_IF_ABRUPT(res);
6949     SET_ACC(res);
6950     DISPATCH(DEPRECATED_DYNAMICIMPORT_PREF_V8);
6951 }
6952 
HandleCallargs3Imm8V8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6953 void InterpreterAssembly::HandleCallargs3Imm8V8V8V8(
6954     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6955     JSTaggedValue acc, int16_t hotnessCounter)
6956 {
6957     DISPATCH(CALLARGS3_IMM8_V8_V8_V8);
6958 }
6959 
HandleCallargs2Imm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6960 void InterpreterAssembly::HandleCallargs2Imm8V8V8(
6961     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6962     JSTaggedValue acc, int16_t hotnessCounter)
6963 {
6964     DISPATCH(CALLARGS2_IMM8_V8_V8);
6965 }
6966 
HandleApplyImm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6967 void InterpreterAssembly::HandleApplyImm8V8V8(
6968     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6969     JSTaggedValue acc, int16_t hotnessCounter)
6970 {
6971     uint16_t v0 = READ_INST_8_0();
6972     uint16_t v1 = READ_INST_8_1();
6973     LOG_INST() << "intrinsics::callspread"
6974                 << " v" << v0 << " v" << v1;
6975     JSTaggedValue func = GET_ACC();
6976     JSTaggedValue obj = GET_VREG_VALUE(v0);
6977     JSTaggedValue array = GET_VREG_VALUE(v1);
6978 
6979     SAVE_PC();
6980     JSTaggedValue res = SlowRuntimeStub::CallSpread(thread, func, obj, array);
6981     INTERPRETER_RETURN_IF_ABRUPT(res);
6982     SET_ACC(res);
6983 
6984     DISPATCH(APPLY_IMM8_V8_V8);
6985 }
6986 
HandleCallarg0Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6987 void InterpreterAssembly::HandleCallarg0Imm8(
6988     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6989     JSTaggedValue acc, int16_t hotnessCounter)
6990 {
6991     DISPATCH(CALLARG0_IMM8);
6992 }
6993 
HandleDefinemethodImm8Id16Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)6994 void InterpreterAssembly::HandleDefinemethodImm8Id16Imm8(
6995     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
6996     JSTaggedValue acc, int16_t hotnessCounter)
6997 {
6998     uint16_t methodId = READ_INST_16_1();
6999     uint16_t length = READ_INST_8_3();
7000     LOG_INST() << "intrinsics::definemethod length: " << length;
7001     SAVE_ACC();
7002     constpool = GetConstantPool(thread, sp);
7003     Method *method =
7004         Method::Cast(ConstantPool::GetMethodFromCache(thread, constpool, methodId).GetTaggedObject());
7005     ASSERT(method != nullptr);
7006     RESTORE_ACC();
7007 
7008     SAVE_PC();
7009     JSTaggedValue homeObject = GET_ACC();
7010     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
7011     JSTaggedValue taggedCurEnv = state->env;
7012     auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetModule(thread, sp));
7013     INTERPRETER_RETURN_IF_ABRUPT(res);
7014     JSFunction *result = JSFunction::Cast(res.GetTaggedObject());
7015 
7016     SET_ACC(JSTaggedValue(result));
7017     DISPATCH(DEFINEMETHOD_IMM8_ID16_IMM8);
7018 }
7019 
HandleDefinefuncImm16Id16Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7020 void InterpreterAssembly::HandleDefinefuncImm16Id16Imm8(
7021     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7022     JSTaggedValue acc, int16_t hotnessCounter)
7023 {
7024     uint16_t methodId = READ_INST_16_2();
7025     uint16_t length = READ_INST_8_4();
7026     LOG_INST() << "intrinsics::definefunc length: " << length;
7027 
7028     constpool = GetConstantPool(thread, sp);
7029     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
7030     JSTaggedValue envHandle = state->env;
7031     JSFunction *currentFunc =
7032         JSFunction::Cast(((reinterpret_cast<InterpretedFrame *>(sp) - 1)->function).GetTaggedObject());
7033 
7034     auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, GetModule(thread, sp),
7035                                            length, envHandle, currentFunc->GetHomeObject(thread));
7036     JSFunction *jsFunc = JSFunction::Cast(res.GetTaggedObject());
7037     SET_ACC(JSTaggedValue(jsFunc));
7038 
7039     DISPATCH(DEFINEFUNC_IMM16_ID16_IMM8);
7040 }
7041 
HandleDefinefuncImm8Id16Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7042 void InterpreterAssembly::HandleDefinefuncImm8Id16Imm8(
7043     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7044     JSTaggedValue acc, int16_t hotnessCounter)
7045 {
7046     uint16_t methodId = READ_INST_16_1();
7047     uint16_t length = READ_INST_8_3();
7048     LOG_INST() << "intrinsics::definefunc length: " << length;
7049 
7050     constpool = GetConstantPool(thread, sp);
7051     AsmInterpretedFrame *state = (reinterpret_cast<AsmInterpretedFrame *>(sp) - 1);
7052     JSTaggedValue envHandle = state->env;
7053     JSFunction *currentFunc =
7054         JSFunction::Cast(((reinterpret_cast<AsmInterpretedFrame *>(sp) - 1)->function).GetTaggedObject());
7055 
7056     auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, GetModule(thread, sp),
7057                                            length, envHandle, currentFunc->GetHomeObject(thread));
7058     JSFunction *jsFunc = JSFunction::Cast(res.GetTaggedObject());
7059 
7060     SET_ACC(JSTaggedValue(jsFunc));
7061     DISPATCH(DEFINEFUNC_IMM8_ID16_IMM8);
7062 }
7063 
HandleSupercallarrowrangeImm8Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7064 void InterpreterAssembly::HandleSupercallarrowrangeImm8Imm8V8(
7065     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7066     JSTaggedValue acc, int16_t hotnessCounter)
7067 {
7068     uint16_t range = READ_INST_8_1();
7069     uint16_t v0 = READ_INST_8_2();
7070     LOG_INST() << "intrinsics::supercall"
7071                << " range: " << range << " v" << v0;
7072 
7073     JSTaggedValue thisFunc = GET_ACC();
7074     JSTaggedValue newTarget = GetNewTarget(thread, sp);
7075 
7076     SAVE_PC();
7077     JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc);
7078     INTERPRETER_RETURN_IF_ABRUPT(superCtor);
7079     JSMutableHandle<Method> methodHandle(thread, JSTaggedValue::Undefined());
7080 
7081     if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) {
7082         JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject());
7083         methodHandle.Update(superCtorFunc->GetMethod(thread));
7084         if (superCtorFunc->IsBuiltinConstructor(thread)) {
7085             ASSERT(methodHandle->GetNumVregsWithCallField() == 0);
7086             size_t frameSize =
7087                 InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs
7088             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7089             JSTaggedType *newSp = sp - frameSize;
7090             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7091                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7092             }
7093             // copy args
7094             uint32_t index = 0;
7095             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7096             EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo *>(newSp);
7097             newSp[index++] = ToUintPtr(thread);
7098             newSp[index++] = range + NUM_MANDATORY_JSFUNC_ARGS;
7099             // func
7100             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7101             newSp[index++] = superCtor.GetRawData();
7102             // newTarget
7103             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7104             newSp[index++] = newTarget.GetRawData();
7105             // this
7106             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7107             newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7108             for (size_t i = 0; i < range; ++i) {
7109                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7110                 newSp[index++] = GET_VREG(v0 + i);
7111             }
7112 
7113             InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp);
7114             state->base.prev = sp;
7115             state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME;
7116             state->pc = nullptr;
7117             state->function = superCtor;
7118             thread->SetCurrentSPFrame(newSp);
7119             LOG_INST() << "Entry: Runtime SuperCall ";
7120             JSTaggedValue retValue = reinterpret_cast<EcmaEntrypoint>(
7121                 superCtorFunc->GetNativePointer())(ecmaRuntimeCallInfo);
7122             thread->SetCurrentSPFrame(sp);
7123 
7124             if (UNLIKELY(thread->HasPendingException())) {
7125                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7126             }
7127             LOG_INST() << "Exit: Runtime SuperCall ";
7128             SET_ACC(retValue);
7129             DISPATCH(SUPERCALLARROWRANGE_IMM8_IMM8_V8);
7130         }
7131 
7132         if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) {
7133             SAVE_PC();
7134             uint32_t numVregs = methodHandle->GetNumVregsWithCallField();
7135             uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ?
7136                 methodHandle->GetNumArgsWithCallField() + 1 :  // +1 for this
7137                 methodHandle->GetNumArgsWithCallField() + 2;   // +2 for newTarget and this
7138             // +1 for hidden this, explicit this may be overwritten after bc optimizer
7139             size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs + 1;
7140             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7141             JSTaggedType *newSp = sp - frameSize;
7142             InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(newSp) - 1;
7143 
7144             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7145                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7146             }
7147 
7148             uint32_t index = 0;
7149             // initialize vregs value
7150             for (size_t i = 0; i < numVregs; ++i) {
7151                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7152             }
7153 
7154             // this
7155             JSTaggedValue thisObj;
7156             if (superCtorFunc->IsBase(thread)) {
7157                 thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state);
7158                 INTERPRETER_RETURN_IF_ABRUPT(thisObj);
7159                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7160                 newSp[index++] = thisObj.GetRawData();
7161             } else {
7162                 ASSERT(superCtorFunc->IsDerivedConstructor(thread));
7163                 newSp[index++] = newTarget.GetRawData();
7164                 thisObj = JSTaggedValue::Undefined();
7165                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7166                 newSp[index++] = thisObj.GetRawData();
7167 
7168                 state->function = superCtor;
7169                 state->constpool = methodHandle->GetConstantPool(thread);
7170                 state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread);
7171                 state->env = superCtorFunc->GetLexicalEnv(thread);
7172             }
7173 
7174             // the second condition ensure not push extra args
7175             for (size_t i = 0; i < range && index < numVregs + numDeclaredArgs; ++i) {
7176                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7177                 newSp[index++] = GET_VREG(v0 + i);
7178             }
7179 
7180             // set undefined to the extra prats of declare
7181             for (size_t i = index; i < numVregs + numDeclaredArgs; ++i) {
7182                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7183                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7184             }
7185 
7186             state->base.prev = sp;
7187             state->base.type = FrameType::INTERPRETER_FAST_NEW_FRAME;
7188             state->thisObj = thisObj;
7189             state->pc = pc = methodHandle->GetBytecodeArray();
7190             sp = newSp;
7191             state->acc = JSTaggedValue::Hole();
7192 
7193             thread->SetCurrentSPFrame(newSp);
7194             LOG_INST() << "Entry: Runtime SuperCall " << std::hex << reinterpret_cast<uintptr_t>(sp)
7195                                     << " " << std::hex << reinterpret_cast<uintptr_t>(pc);
7196             DISPATCH_OFFSET(0);
7197         }
7198     }
7199 
7200     SAVE_PC();
7201     JSTaggedValue res = SlowRuntimeStub::SuperCall(thread, thisFunc, newTarget, v0, range);
7202     INTERPRETER_RETURN_IF_ABRUPT(res);
7203     SET_ACC(res);
7204     DISPATCH(SUPERCALLARROWRANGE_IMM8_IMM8_V8);
7205 }
7206 
HandleSupercallthisrangeImm8Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7207 void InterpreterAssembly::HandleSupercallthisrangeImm8Imm8V8(
7208     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7209     JSTaggedValue acc, int16_t hotnessCounter)
7210 {
7211     uint16_t range = READ_INST_8_1();
7212     uint16_t v0 = READ_INST_8_2();
7213     LOG_INST() << "intrinsics::supercall"
7214                << " range: " << range << " v" << v0;
7215 
7216     JSTaggedValue thisFunc = GetFunction(sp);
7217     JSTaggedValue newTarget = GetNewTarget(thread, sp);
7218 
7219     SAVE_PC();
7220     JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc);
7221     INTERPRETER_RETURN_IF_ABRUPT(superCtor);
7222 
7223     JSMutableHandle<Method> methodHandle(thread, JSTaggedValue::Undefined());
7224     if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) {
7225         JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject());
7226         methodHandle.Update(superCtorFunc->GetMethod(thread));
7227         if (superCtorFunc->IsBuiltinConstructor(thread)) {
7228             ASSERT(methodHandle->GetNumVregsWithCallField() == 0);
7229             size_t frameSize =
7230                 InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs
7231             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7232             JSTaggedType *newSp = sp - frameSize;
7233             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7234                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7235             }
7236             // copy args
7237             uint32_t index = 0;
7238             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7239             EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo *>(newSp);
7240             newSp[index++] = ToUintPtr(thread);
7241             newSp[index++] = range + NUM_MANDATORY_JSFUNC_ARGS;
7242             // func
7243             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7244             newSp[index++] = superCtor.GetRawData();
7245             // newTarget
7246             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7247             newSp[index++] = newTarget.GetRawData();
7248             // this
7249             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7250             newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7251             for (size_t i = 0; i < range; ++i) {
7252                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7253                 newSp[index++] = GET_VREG(v0 + i);
7254             }
7255 
7256             InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp);
7257             state->base.prev = sp;
7258             state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME;
7259             state->pc = nullptr;
7260             state->function = superCtor;
7261             thread->SetCurrentSPFrame(newSp);
7262             LOG_INST() << "Entry: Runtime SuperCall ";
7263             JSTaggedValue retValue = reinterpret_cast<EcmaEntrypoint>(
7264                 superCtorFunc->GetNativePointer())(ecmaRuntimeCallInfo);
7265             thread->SetCurrentSPFrame(sp);
7266 
7267             if (UNLIKELY(thread->HasPendingException())) {
7268                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7269             }
7270             LOG_INST() << "Exit: Runtime SuperCall ";
7271             SET_ACC(retValue);
7272             DISPATCH(SUPERCALLTHISRANGE_IMM8_IMM8_V8);
7273         }
7274 
7275         if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) {
7276             SAVE_PC();
7277             uint32_t numVregs = methodHandle->GetNumVregsWithCallField();
7278             uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ?
7279                 methodHandle->GetNumArgsWithCallField() + 1 :  // +1 for this
7280                 methodHandle->GetNumArgsWithCallField() + 2;   // +2 for newTarget and this
7281             // +1 for hidden this, explicit this may be overwritten after bc optimizer
7282             size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs + 1;
7283             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7284             JSTaggedType *newSp = sp - frameSize;
7285             InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(newSp) - 1;
7286 
7287             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7288                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7289             }
7290 
7291             uint32_t index = 0;
7292             // initialize vregs value
7293             for (size_t i = 0; i < numVregs; ++i) {
7294                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7295             }
7296 
7297             // this
7298             JSTaggedValue thisObj;
7299             if (superCtorFunc->IsBase(thread)) {
7300                 thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state);
7301                 INTERPRETER_RETURN_IF_ABRUPT(thisObj);
7302                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7303                 newSp[index++] = thisObj.GetRawData();
7304             } else {
7305                 ASSERT(superCtorFunc->IsDerivedConstructor(thread));
7306                 newSp[index++] = newTarget.GetRawData();
7307                 thisObj = JSTaggedValue::Undefined();
7308                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7309                 newSp[index++] = thisObj.GetRawData();
7310 
7311                 state->function = superCtor;
7312                 state->constpool = methodHandle->GetConstantPool(thread);
7313                 state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread);
7314                 state->env = superCtorFunc->GetLexicalEnv(thread);
7315             }
7316 
7317             // the second condition ensure not push extra args
7318             for (size_t i = 0; i < range && index < numVregs + numDeclaredArgs; ++i) {
7319                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7320                 newSp[index++] = GET_VREG(v0 + i);
7321             }
7322 
7323             // set undefined to the extra prats of declare
7324             for (size_t i = index; i < numVregs + numDeclaredArgs; ++i) {
7325                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7326                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7327             }
7328 
7329             state->base.prev = sp;
7330             state->base.type = FrameType::INTERPRETER_FAST_NEW_FRAME;
7331             state->thisObj = thisObj;
7332             state->pc = pc = methodHandle->GetBytecodeArray();
7333             sp = newSp;
7334             state->acc = JSTaggedValue::Hole();
7335 
7336             thread->SetCurrentSPFrame(newSp);
7337             LOG_INST() << "Entry: Runtime SuperCall " << std::hex << reinterpret_cast<uintptr_t>(sp)
7338                                     << " " << std::hex << reinterpret_cast<uintptr_t>(pc);
7339             DISPATCH_OFFSET(0);
7340         }
7341     }
7342 
7343     SAVE_PC();
7344     JSTaggedValue res = SlowRuntimeStub::SuperCall(thread, thisFunc, newTarget, v0, range);
7345     INTERPRETER_RETURN_IF_ABRUPT(res);
7346     SET_ACC(res);
7347     DISPATCH(SUPERCALLTHISRANGE_IMM8_IMM8_V8);
7348 }
7349 
HandleCallthisrangeImm8Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7350 void InterpreterAssembly::HandleCallthisrangeImm8Imm8V8(
7351     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7352     JSTaggedValue acc, int16_t hotnessCounter)
7353 {
7354     DISPATCH(CALLTHISRANGE_IMM8_IMM8_V8);
7355 }
7356 
HandleCallthis3Imm8V8V8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7357 void InterpreterAssembly::HandleCallthis3Imm8V8V8V8V8(
7358     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7359     JSTaggedValue acc, int16_t hotnessCounter)
7360 {
7361     DISPATCH(CALLTHIS3_IMM8_V8_V8_V8_V8);
7362 }
7363 
HandleCallthis2Imm8V8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7364 void InterpreterAssembly::HandleCallthis2Imm8V8V8V8(
7365     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7366     JSTaggedValue acc, int16_t hotnessCounter)
7367 {
7368     DISPATCH(CALLTHIS2_IMM8_V8_V8_V8);
7369 }
7370 
HandleNewlexenvwithnameImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7371 void InterpreterAssembly::HandleNewlexenvwithnameImm8Id16(
7372     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7373     JSTaggedValue acc, int16_t hotnessCounter)
7374 {
7375     uint16_t numVars = READ_INST_8_0();
7376     uint16_t scopeId = READ_INST_16_1();
7377     LOG_INST() << "intrinsics::newlexenvwithname"
7378                << " numVars " << numVars << " scopeId " << scopeId;
7379 
7380     SAVE_PC();
7381     JSTaggedValue res = SlowRuntimeStub::NewLexicalEnvWithName(thread, numVars, scopeId);
7382     INTERPRETER_RETURN_IF_ABRUPT(res);
7383 
7384     SET_ACC(res);
7385     (reinterpret_cast<InterpretedFrame *>(sp) - 1)->env = res;
7386     DISPATCH(NEWLEXENVWITHNAME_IMM8_ID16);
7387 }
7388 
HandleNewobjrangeImm16Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7389 void InterpreterAssembly::HandleNewobjrangeImm16Imm8V8(
7390     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7391     JSTaggedValue acc, int16_t hotnessCounter)
7392 {
7393     uint16_t numArgs = READ_INST_8_2();
7394     uint16_t firstArgRegIdx = READ_INST_8_3();
7395     LOG_INST() << "intrinsics::newobjRange " << numArgs << " v" << firstArgRegIdx;
7396     JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx);
7397     JSMutableHandle<Method> methodHandle(thread, JSTaggedValue::Undefined());
7398 
7399     if (ctor.IsJSFunction() && ctor.IsConstructor()) {
7400         JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject());
7401         methodHandle.Update(ctorFunc->GetMethod(thread));
7402         if (ctorFunc->IsBuiltinConstructor(thread)) {
7403             ASSERT(methodHandle->GetNumVregsWithCallField() == 0);
7404             size_t frameSize =
7405                 InterpretedFrame::NumOfMembers() + numArgs + 4; // 4: newtarget/this & numArgs & thread
7406             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7407             JSTaggedType *newSp = sp - frameSize;
7408             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7409                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7410             }
7411             // copy args
7412             uint32_t index = 0;
7413             // numArgs
7414             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7415             EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo*>(newSp);
7416             newSp[index++] = ToUintPtr(thread);
7417             newSp[index++] = numArgs + 2; // 2: for newtarget/this
7418             // func
7419             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7420             newSp[index++] = ctor.GetRawData();
7421             // newTarget
7422             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7423             newSp[index++] = ctor.GetRawData();
7424             // this
7425             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7426             newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7427             for (size_t i = 1; i < numArgs; ++i) {  // 1: func
7428                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7429                 newSp[index++] = GET_VREG(firstArgRegIdx + i);
7430             }
7431 
7432             InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp);
7433             state->base.prev = sp;
7434             state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME;
7435             state->pc = nullptr;
7436             state->function = ctor;
7437             thread->SetCurrentSPFrame(newSp);
7438 
7439             LOG_INST() << "Entry: Runtime New.";
7440             SAVE_PC();
7441             JSTaggedValue retValue = reinterpret_cast<EcmaEntrypoint>(
7442                 ctorFunc->GetNativePointer())(ecmaRuntimeCallInfo);
7443             thread->SetCurrentSPFrame(sp);
7444             if (UNLIKELY(thread->HasPendingException())) {
7445                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7446             }
7447             LOG_INST() << "Exit: Runtime New.";
7448             SET_ACC(retValue);
7449             DISPATCH(NEWOBJRANGE_IMM16_IMM8_V8);
7450         }
7451 
7452         if (AssemblyIsFastNewFrameEnter(thread, ctorFunc, methodHandle)) {
7453             SAVE_PC();
7454             uint32_t numVregs = methodHandle->GetNumVregsWithCallField();
7455             uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ?
7456                                        methodHandle->GetNumArgsWithCallField() + 1 :  // +1 for this
7457                                        methodHandle->GetNumArgsWithCallField() + 2;   // +2 for newTarget and this
7458             size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs;
7459             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7460             JSTaggedType *newSp = sp - frameSize;
7461             InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(newSp) - 1);
7462 
7463             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7464                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7465             }
7466 
7467             uint32_t index = 0;
7468             // initialize vregs value
7469             for (size_t i = 0; i < numVregs; ++i) {
7470                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7471             }
7472 
7473             // this
7474             JSTaggedValue thisObj;
7475             if (ctorFunc->IsBase(thread)) {
7476                 thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state);
7477                 INTERPRETER_RETURN_IF_ABRUPT(thisObj);
7478                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7479                 newSp[index++] = thisObj.GetRawData();
7480             } else {
7481                 ASSERT(ctorFunc->IsDerivedConstructor(thread));
7482                 newSp[index++] = ctor.GetRawData();
7483                 thisObj = JSTaggedValue::Undefined();
7484                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7485                 newSp[index++] = thisObj.GetRawData();
7486 
7487                 state->function = ctor;
7488                 state->constpool = methodHandle->GetConstantPool(thread);
7489                 state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread);
7490                 state->env = ctorFunc->GetLexicalEnv(thread);
7491             }
7492 
7493             // the second condition ensure not push extra args
7494             for (size_t i = 1; i < numArgs && index < numVregs + numDeclaredArgs; ++i) {  // 2: func and newTarget
7495                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7496                 newSp[index++] = GET_VREG(firstArgRegIdx + i);
7497             }
7498 
7499             // set undefined to the extra prats of declare
7500             for (size_t i = index; i < numVregs + numDeclaredArgs; ++i) {
7501                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7502                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7503             }
7504 
7505             state->base.prev = sp;
7506             state->base.type = FrameType::INTERPRETER_FAST_NEW_FRAME;
7507             state->thisObj = thisObj;
7508             state->pc = pc = methodHandle->GetBytecodeArray();
7509             sp = newSp;
7510             state->acc = JSTaggedValue::Hole();
7511 
7512             thread->SetCurrentSPFrame(newSp);
7513             LOG_INST() << "Entry: Runtime New " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
7514                                     << std::hex << reinterpret_cast<uintptr_t>(pc);
7515             DISPATCH_OFFSET(0);
7516         }
7517     }
7518 
7519     // bound function, proxy, other call types, enter slow path
7520     constexpr uint16_t firstArgOffset = 1;
7521     // Exclude func and newTarget
7522     uint16_t firstArgIdx = firstArgRegIdx + firstArgOffset;
7523     uint16_t length = numArgs - firstArgOffset;
7524 
7525     SAVE_PC();
7526     JSTaggedValue res = SlowRuntimeStub::NewObjRange(thread, ctor, ctor, firstArgIdx, length);
7527     INTERPRETER_RETURN_IF_ABRUPT(res);
7528     SET_ACC(res);
7529     DISPATCH(NEWOBJRANGE_IMM16_IMM8_V8);
7530 }
7531 
HandleNewobjrangeImm8Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7532 void InterpreterAssembly::HandleNewobjrangeImm8Imm8V8(
7533     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7534     JSTaggedValue acc, int16_t hotnessCounter)
7535 {
7536     uint16_t numArgs = READ_INST_8_1();
7537     uint16_t firstArgRegIdx = READ_INST_8_2();
7538     LOG_INST() << "intrinsics::newobjRange " << numArgs << " v" << firstArgRegIdx;
7539     JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx);
7540     JSMutableHandle<Method> methodHandle(thread, JSTaggedValue::Undefined());
7541 
7542     if (ctor.IsJSFunction() && ctor.IsConstructor()) {
7543         JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject());
7544         methodHandle.Update(ctorFunc->GetMethod(thread));
7545         if (ctorFunc->IsBuiltinConstructor(thread)) {
7546             ASSERT(methodHandle->GetNumVregsWithCallField() == 0);
7547             size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4;  // 2: numArgs & thread
7548             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7549             JSTaggedType *newSp = sp - frameSize;
7550             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7551                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7552             }
7553             // copy args
7554             uint32_t index = 0;
7555             // numArgs
7556             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7557             EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo*>(newSp);
7558             newSp[index++] = ToUintPtr(thread);
7559             newSp[index++] = numArgs + 2; // 2: for newtarget / this
7560             // func
7561             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7562             newSp[index++] = ctor.GetRawData();
7563             // newTarget
7564             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7565             newSp[index++] = ctor.GetRawData();
7566             // this
7567             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7568             newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7569             for (size_t i = 1; i < numArgs; ++i) {
7570                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7571                 newSp[index++] = GET_VREG(firstArgRegIdx + i);
7572             }
7573 
7574             InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp);
7575             state->base.prev = sp;
7576             state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME;
7577             state->pc = nullptr;
7578             state->function = ctor;
7579             thread->SetCurrentSPFrame(newSp);
7580 
7581             LOG_INST() << "Entry: Runtime New.";
7582             SAVE_PC();
7583             JSTaggedValue retValue = reinterpret_cast<EcmaEntrypoint>(
7584                 ctorFunc->GetNativePointer())(ecmaRuntimeCallInfo);
7585             thread->SetCurrentSPFrame(sp);
7586             if (UNLIKELY(thread->HasPendingException())) {
7587                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7588             }
7589             LOG_INST() << "Exit: Runtime New.";
7590             SET_ACC(retValue);
7591             DISPATCH(NEWOBJRANGE_IMM8_IMM8_V8);
7592         }
7593 
7594         if (AssemblyIsFastNewFrameEnter(thread, ctorFunc, methodHandle)) {
7595             SAVE_PC();
7596             uint32_t numVregs = methodHandle->GetNumVregsWithCallField();
7597             uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ?
7598                                        methodHandle->GetNumArgsWithCallField() + 1 :  // +1 for this
7599                                        methodHandle->GetNumArgsWithCallField() + 2;   // +2 for newTarget and this
7600             size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs;
7601             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7602             JSTaggedType *newSp = sp - frameSize;
7603             InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(newSp) - 1);
7604 
7605             if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) {
7606                 INTERPRETER_GOTO_EXCEPTION_HANDLER();
7607             }
7608 
7609             uint32_t index = 0;
7610             // initialize vregs value
7611             for (size_t i = 0; i < numVregs; ++i) {
7612                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7613             }
7614 
7615             // this
7616             JSTaggedValue thisObj;
7617             if (ctorFunc->IsBase(thread)) {
7618                 thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state);
7619                 INTERPRETER_RETURN_IF_ABRUPT(thisObj);
7620                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7621                 newSp[index++] = thisObj.GetRawData();
7622             } else {
7623                 ASSERT(ctorFunc->IsDerivedConstructor(thread));
7624                 newSp[index++] = ctor.GetRawData();
7625                 thisObj = JSTaggedValue::Undefined();
7626                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7627                 newSp[index++] = thisObj.GetRawData();
7628 
7629                 state->function = ctor;
7630                 state->constpool = methodHandle->GetConstantPool(thread);
7631                 state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread);
7632                 state->env = ctorFunc->GetLexicalEnv(thread);
7633             }
7634 
7635             // the second condition ensure not push extra args
7636             for (size_t i = 1; i < numArgs && index < numVregs + numDeclaredArgs; ++i) {
7637                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7638                 newSp[index++] = GET_VREG(firstArgRegIdx + i);
7639             }
7640 
7641             // set undefined to the extra prats of declare
7642             for (size_t i = index; i < numVregs + numDeclaredArgs; ++i) {
7643                 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7644                 newSp[index++] = JSTaggedValue::VALUE_UNDEFINED;
7645             }
7646 
7647             state->base.prev = sp;
7648             state->base.type = FrameType::INTERPRETER_FAST_NEW_FRAME;
7649             state->thisObj = thisObj;
7650             state->pc = pc = methodHandle->GetBytecodeArray();
7651             sp = newSp;
7652             state->acc = JSTaggedValue::Hole();
7653 
7654             thread->SetCurrentSPFrame(newSp);
7655             LOG_INST() << "Entry: Runtime New " << std::hex << reinterpret_cast<uintptr_t>(sp) << " "
7656                                     << std::hex << reinterpret_cast<uintptr_t>(pc);
7657             DISPATCH_OFFSET(0);
7658         }
7659     }
7660 
7661     // bound function, proxy, other call types, enter slow path
7662     constexpr uint16_t firstArgOffset = 1;
7663     // Exclude func and newTarget
7664     uint16_t firstArgIdx = firstArgRegIdx + firstArgOffset;
7665     uint16_t length = numArgs - firstArgOffset;
7666 
7667     SAVE_PC();
7668     JSTaggedValue res = SlowRuntimeStub::NewObjRange(thread, ctor, ctor, firstArgIdx, length);
7669     INTERPRETER_RETURN_IF_ABRUPT(res);
7670     SET_ACC(res);
7671     DISPATCH(NEWOBJRANGE_IMM8_IMM8_V8);
7672 }
7673 
HandleNewobjapplyImm16V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7674 void InterpreterAssembly::HandleNewobjapplyImm16V8(
7675     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7676     JSTaggedValue acc, int16_t hotnessCounter)
7677 {
7678     uint16_t v0 = READ_INST_8_2();
7679     LOG_INST() << "intrinsic::newobjspeard"
7680                << " v" << v0;
7681     JSTaggedValue func = GET_VREG_VALUE(v0);
7682     JSTaggedValue array = GET_ACC();
7683     SAVE_PC();
7684     JSTaggedValue res = SlowRuntimeStub::NewObjApply(thread, func, array);
7685     INTERPRETER_RETURN_IF_ABRUPT(res);
7686     SET_ACC(res);
7687     DISPATCH(NEWOBJAPPLY_IMM16_V8);
7688 }
7689 
HandleCreateregexpwithliteralImm16Id16Imm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7690 void InterpreterAssembly::HandleCreateregexpwithliteralImm16Id16Imm8(
7691     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7692     JSTaggedValue acc, int16_t hotnessCounter)
7693 {
7694     uint16_t stringId = READ_INST_16_2();
7695     SAVE_ACC();
7696     constpool = GetConstantPool(thread, sp);
7697     JSTaggedValue pattern = ConstantPool::GetStringFromCache(thread, constpool, stringId);
7698     uint8_t flags = READ_INST_8_4();
7699     LOG_INST() << "intrinsics::createregexpwithliteral "
7700                << "stringId:" << stringId << ", "
7701                << ConvertToString(thread, EcmaString::Cast(pattern.GetTaggedObject()))
7702                << ", flags:" << flags;
7703     JSTaggedValue res = SlowRuntimeStub::CreateRegExpWithLiteral(thread, pattern, flags);
7704     INTERPRETER_RETURN_IF_ABRUPT(res);
7705     SET_ACC(res);
7706     DISPATCH(CREATEREGEXPWITHLITERAL_IMM16_ID16_IMM8);
7707 }
7708 
HandleCreateobjectwithbufferImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7709 void InterpreterAssembly::HandleCreateobjectwithbufferImm16Id16(
7710     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7711     JSTaggedValue acc, int16_t hotnessCounter)
7712 {
7713     uint16_t imm = READ_INST_16_2();
7714     LOG_INST() << "intrinsics::createobjectwithbuffer"
7715                << " imm:" << imm;
7716     constpool = GetUnsharedConstpool(thread, sp);
7717     JSObject *result = JSObject::Cast(
7718         ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(
7719             thread, constpool, imm, GetModule(thread, sp)).GetTaggedObject());
7720     SAVE_PC();
7721     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
7722     EcmaVM *ecmaVm = thread->GetEcmaVM();
7723     ObjectFactory *factory = ecmaVm->GetFactory();
7724     JSTaggedValue res = SlowRuntimeStub::CreateObjectHavingMethod(thread, factory, result, state->env);
7725     INTERPRETER_RETURN_IF_ABRUPT(res);
7726     SET_ACC(res);
7727     DISPATCH(CREATEOBJECTWITHBUFFER_IMM16_ID16);
7728 }
7729 
HandleCreateobjectwithbufferImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7730 void InterpreterAssembly::HandleCreateobjectwithbufferImm8Id16(
7731     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7732     JSTaggedValue acc, int16_t hotnessCounter)
7733 {
7734     uint16_t imm = READ_INST_16_1();
7735     LOG_INST() << "intrinsics::createobjectwithbuffer"
7736                << " imm:" << imm;
7737     constpool = GetUnsharedConstpool(thread, sp);
7738     JSObject *result = JSObject::Cast(
7739         ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(
7740             thread, constpool, imm, GetModule(thread, sp)).GetTaggedObject());
7741     SAVE_PC();
7742     InterpretedFrame *state = (reinterpret_cast<InterpretedFrame *>(sp) - 1);
7743     EcmaVM *ecmaVm = thread->GetEcmaVM();
7744     ObjectFactory *factory = ecmaVm->GetFactory();
7745     JSTaggedValue res = SlowRuntimeStub::CreateObjectHavingMethod(thread, factory, result, state->env);
7746     INTERPRETER_RETURN_IF_ABRUPT(res);
7747     SET_ACC(res);
7748     DISPATCH(CREATEOBJECTWITHBUFFER_IMM8_ID16);
7749 }
7750 
HandleLdnewtarget(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7751 void InterpreterAssembly::HandleLdnewtarget(
7752     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7753     JSTaggedValue acc, int16_t hotnessCounter)
7754 {
7755     DISPATCH(LDNEWTARGET);
7756 }
7757 
HandleLdthis(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7758 void InterpreterAssembly::HandleLdthis(
7759     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7760     JSTaggedValue acc, int16_t hotnessCounter)
7761 {
7762     LOG_INST() << "intrinsics::ldthis";
7763     SET_ACC(GetThis(sp));
7764     DISPATCH(LDTHIS);
7765 }
7766 
HandleCreatearraywithbufferImm8Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7767 void InterpreterAssembly::HandleCreatearraywithbufferImm8Id16(
7768     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7769     JSTaggedValue acc, int16_t hotnessCounter)
7770 {
7771     uint16_t imm = READ_INST_16_1();
7772     LOG_INST() << "intrinsics::createarraywithbuffer"
7773                << " imm:" << imm;
7774     constpool = GetUnsharedConstpool(thread, sp);
7775     JSArray *result = JSArray::Cast(
7776         ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
7777             thread, constpool, imm, GetModule(thread, sp)).GetTaggedObject());
7778     SAVE_PC();
7779     EcmaVM *ecmaVm = thread->GetEcmaVM();
7780     ObjectFactory *factory = ecmaVm->GetFactory();
7781     JSTaggedValue res = SlowRuntimeStub::CreateArrayWithBuffer(thread, factory, result);
7782     INTERPRETER_RETURN_IF_ABRUPT(res);
7783     SET_ACC(res);
7784     DISPATCH(CREATEARRAYWITHBUFFER_IMM8_ID16);
7785 }
7786 
HandleCreatearraywithbufferImm16Id16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7787 void InterpreterAssembly::HandleCreatearraywithbufferImm16Id16(
7788     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7789     JSTaggedValue acc, int16_t hotnessCounter)
7790 {
7791     uint16_t imm = READ_INST_16_2();
7792     EcmaVM *ecmaVm = thread->GetEcmaVM();
7793     ObjectFactory *factory = ecmaVm->GetFactory();
7794     LOG_INST() << "intrinsics::createarraywithbuffer"
7795                << " imm:" << imm;
7796     InterpretedFrame *state = reinterpret_cast<InterpretedFrame *>(sp) - 1;
7797     JSTaggedValue constantPool = state->constpool;
7798     JSArray *result = JSArray::Cast(ConstantPool::Cast(constantPool.GetTaggedObject())
7799         ->GetObjectFromCache(thread, imm).GetTaggedObject());
7800     SAVE_PC();
7801     JSTaggedValue res = SlowRuntimeStub::CreateArrayWithBuffer(thread, factory, result);
7802     INTERPRETER_RETURN_IF_ABRUPT(res);
7803     SET_ACC(res);
7804     DISPATCH(CREATEARRAYWITHBUFFER_IMM16_ID16);
7805 }
7806 
HandleCallthis0Imm8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7807 void InterpreterAssembly::HandleCallthis0Imm8V8(
7808     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7809     JSTaggedValue acc, int16_t hotnessCounter)
7810 {
7811     DISPATCH(CALLTHIS0_IMM8_V8);
7812 }
7813 
HandleCallthis1Imm8V8V8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7814 void InterpreterAssembly::HandleCallthis1Imm8V8V8(
7815     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7816     JSTaggedValue acc, int16_t hotnessCounter)
7817 {
7818     DISPATCH(CALLTHIS1_IMM8_V8_V8);
7819 }
7820 
HandleNop(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7821 void InterpreterAssembly::HandleNop(
7822     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7823     JSTaggedValue acc, int16_t hotnessCounter)
7824 {
7825     LOG_INST() << "intrinsics::nop";
7826     DISPATCH(NOP);
7827 }
7828 
ExceptionHandler(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7829 void InterpreterAssembly::ExceptionHandler(
7830     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7831     JSTaggedValue acc, int16_t hotnessCounter)
7832 {
7833     FrameHandler frameHandler(thread);
7834     uint32_t pcOffset = panda_file::INVALID_OFFSET;
7835     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
7836         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
7837             thread->SetLastFp(frameHandler.GetFp());
7838             return;
7839         }
7840         auto method = frameHandler.GetMethod();
7841         pcOffset = method->FindCatchBlock(thread, frameHandler.GetBytecodeOffset());
7842         if (pcOffset != INVALID_INDEX) {
7843             thread->SetCurrentFrame(frameHandler.GetSp());
7844             thread->SetLastFp(frameHandler.GetFp());
7845             // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7846             pc = method->GetBytecodeArray() + pcOffset;
7847             break;
7848         }
7849     }
7850     if (pcOffset == INVALID_INDEX) {
7851         return;
7852     }
7853 
7854     auto exception = thread->GetException();
7855     SET_ACC(exception);
7856     thread->ClearException();
7857     DISPATCH_OFFSET(0);
7858 }
7859 
HandleCallRuntimeLdLazyModuleVarPrefImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7860 void InterpreterAssembly::HandleCallRuntimeLdLazyModuleVarPrefImm8(
7861     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7862     JSTaggedValue acc, int16_t hotnessCounter)
7863 {
7864     int32_t index = READ_INST_8_1();
7865     JSTaggedValue thisFunc = GetFunction(sp);
7866     LOG_INST() << "intrinsics::ldlazyexternalmodulevar index:" << index;
7867 
7868     JSTaggedValue moduleVar = SlowRuntimeStub::LdLazyExternalModuleVar(thread, index, thisFunc);
7869     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
7870     SET_ACC(moduleVar);
7871     DISPATCH(CALLRUNTIME_LDLAZYMODULEVAR_PREF_IMM8);
7872 }
7873 
HandleCallRuntimeWideLdLazyModuleVarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7874 void InterpreterAssembly::HandleCallRuntimeWideLdLazyModuleVarPrefImm16(
7875     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7876     JSTaggedValue acc, int16_t hotnessCounter)
7877 {
7878     int32_t index = READ_INST_16_1();
7879     JSTaggedValue thisFunc = GetFunction(sp);
7880     LOG_INST() << "intrinsics::ldlazyexternalmodulevar index:" << index;
7881 
7882     JSTaggedValue moduleVar = SlowRuntimeStub::LdLazyExternalModuleVar(thread, index, thisFunc);
7883     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
7884     SET_ACC(moduleVar);
7885     DISPATCH(CALLRUNTIME_WIDELDLAZYMODULEVAR_PREF_IMM16);
7886 }
7887 
HandleCallRuntimeLdLazySendableModuleVarPrefImm8(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7888 void InterpreterAssembly::HandleCallRuntimeLdLazySendableModuleVarPrefImm8(
7889     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7890     JSTaggedValue acc, int16_t hotnessCounter)
7891 {
7892     int32_t index = READ_INST_8_1();
7893     JSTaggedValue thisFunc = GetFunction(sp);
7894     LOG_INST() << "intrinsics::ldlazysendableexternalmodulevar index:" << index;
7895 
7896     JSTaggedValue moduleVar = SlowRuntimeStub::LdLazySendableExternalModuleVar(thread, index, thisFunc);
7897     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
7898     SET_ACC(moduleVar);
7899     DISPATCH(CALLRUNTIME_LDLAZYSENDABLEMODULEVAR_PREF_IMM8);
7900 }
7901 
HandleCallRuntimeWideLdLazySendableModuleVarPrefImm16(JSThread * thread,const uint8_t * pc,JSTaggedType * sp,JSTaggedValue constpool,JSTaggedValue profileTypeInfo,JSTaggedValue acc,int16_t hotnessCounter)7902 void InterpreterAssembly::HandleCallRuntimeWideLdLazySendableModuleVarPrefImm16(
7903     JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo,
7904     JSTaggedValue acc, int16_t hotnessCounter)
7905 {
7906     int32_t index = READ_INST_16_1();
7907     JSTaggedValue thisFunc = GetFunction(sp);
7908     LOG_INST() << "intrinsics::ldlazysendableexternalmodulevar index:" << index;
7909 
7910     JSTaggedValue moduleVar = SlowRuntimeStub::LdLazySendableExternalModuleVar(thread, index, thisFunc);
7911     INTERPRETER_RETURN_IF_ABRUPT(moduleVar);
7912     SET_ACC(moduleVar);
7913     DISPATCH(CALLRUNTIME_WIDELDLAZYSENDABLEMODULEVAR_PREF_IMM16);
7914 }
7915 
7916 #define DECLARE_UNUSED_ASM_HANDLE(name)                                                 \
7917     void InterpreterAssembly::name(                                                     \
7918         JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, \
7919         JSTaggedValue profileTypeInfo, JSTaggedValue acc, int16_t hotnessCounter)       \
7920     {                                                                                   \
7921         LOG_INTERPRETER(FATAL) << #name;                                                \
7922     }
ASM_UNUSED_BC_STUB_LIST(DECLARE_UNUSED_ASM_HANDLE)7923 ASM_UNUSED_BC_STUB_LIST(DECLARE_UNUSED_ASM_HANDLE)
7924 #undef DECLARE_UNUSED_ASM_HANDLE
7925 #endif
7926 
7927 inline void InterpreterAssembly::InterpreterFrameCopyArgs(
7928     JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs, uint32_t numDeclaredArgs, bool haveExtraArgs)
7929 {
7930     size_t i = 0;
7931     for (; i < numVregs; i++) {
7932         // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7933         newSp[i] = JSTaggedValue::VALUE_UNDEFINED;
7934     }
7935     for (i = numActualArgs; i < numDeclaredArgs; i++) {
7936         // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7937         newSp[numVregs + i] = JSTaggedValue::VALUE_UNDEFINED;
7938     }
7939     if (haveExtraArgs) {
7940         // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7941         newSp[numVregs + i] = JSTaggedValue(numActualArgs).GetRawData();  // numActualArgs is stored at the end
7942     }
7943 }
7944 
GetFunction(JSTaggedType * sp)7945 JSTaggedValue InterpreterAssembly::GetFunction(JSTaggedType *sp)
7946 {
7947     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7948     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
7949     return JSTaggedValue(state->function);
7950 }
7951 
GetThis(JSTaggedType * sp)7952 JSTaggedValue InterpreterAssembly::GetThis(JSTaggedType *sp)
7953 {
7954     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7955     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
7956     return JSTaggedValue(state->thisObj);
7957 }
7958 
GetNewTarget(JSThread * thread,JSTaggedType * sp)7959 JSTaggedValue InterpreterAssembly::GetNewTarget(JSThread *thread, JSTaggedType *sp)
7960 {
7961     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7962     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
7963     Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
7964     ASSERT(method->HaveNewTargetWithCallField());
7965     uint32_t numVregs = method->GetNumVregsWithCallField();
7966     bool haveFunc = method->HaveFuncWithCallField();
7967     return JSTaggedValue(sp[numVregs + haveFunc]);
7968 }
7969 
GetConstantPool(JSThread * thread,JSTaggedType * sp)7970 JSTaggedValue InterpreterAssembly::GetConstantPool(JSThread *thread, JSTaggedType *sp)
7971 {
7972     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7973     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
7974     Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
7975     return method->GetConstantPool(thread);
7976 }
7977 
GetUnsharedConstpool(JSThread * thread,JSTaggedType * sp)7978 JSTaggedValue InterpreterAssembly::GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp)
7979 {
7980     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
7981     Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
7982     return thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(method->GetConstantPool(thread));
7983 }
7984 
GetModule(JSThread * thread,JSTaggedType * sp)7985 JSTaggedValue InterpreterAssembly::GetModule(JSThread* thread, JSTaggedType *sp)
7986 {
7987     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7988     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
7989     return JSFunction::Cast(state->function.GetTaggedObject())->GetModule(thread);
7990 }
7991 
GetProfileTypeInfo(JSThread * thread,JSTaggedType * sp)7992 JSTaggedValue InterpreterAssembly::GetProfileTypeInfo(JSThread* thread, JSTaggedType *sp)
7993 {
7994     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7995     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
7996     JSFunction *function = JSFunction::Cast(state->function.GetTaggedObject());
7997     return function->GetProfileTypeInfo(thread);
7998 }
7999 
GetAsmInterpreterFramePointer(AsmInterpretedFrame * state)8000 JSTaggedType *InterpreterAssembly::GetAsmInterpreterFramePointer(AsmInterpretedFrame *state)
8001 {
8002     return state->GetCurrentFramePointer();
8003 }
8004 
GetNumArgs(JSThread * thread,JSTaggedType * sp,uint32_t restIdx,uint32_t & startIdx)8005 uint32_t InterpreterAssembly::GetNumArgs(JSThread *thread, JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx)
8006 {
8007     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
8008     AsmInterpretedFrame *state = reinterpret_cast<AsmInterpretedFrame *>(sp) - 1;
8009     Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread);
8010     ASSERT(method->HaveExtraWithCallField());
8011 
8012     uint32_t numVregs = method->GetNumVregsWithCallField();
8013     bool haveFunc = method->HaveFuncWithCallField();
8014     bool haveNewTarget = method->HaveNewTargetWithCallField();
8015     bool haveThis = method->HaveThisWithCallField();
8016     uint32_t copyArgs = haveFunc + haveNewTarget + haveThis;
8017     uint32_t numArgs = method->GetNumArgsWithCallField();
8018 
8019     JSTaggedType *fp = GetAsmInterpreterFramePointer(state);
8020     if (static_cast<uint32_t>(fp - sp) > numVregs + copyArgs + numArgs) {
8021         // In this case, actualNumArgs is in the end
8022         // If not, then actualNumArgs == declaredNumArgs, therefore do nothing
8023         // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
8024         numArgs = static_cast<uint32_t>(JSTaggedValue(*(fp - 1)).GetInt());
8025     }
8026     startIdx = numVregs + copyArgs + restIdx;
8027     return ((numArgs > restIdx) ? (numArgs - restIdx) : 0);
8028 }
8029 
GetJumpSizeAfterCall(const uint8_t * prevPc)8030 inline size_t InterpreterAssembly::GetJumpSizeAfterCall(const uint8_t *prevPc)
8031 {
8032     auto op = BytecodeInstruction(prevPc).GetOpcode();
8033     size_t jumpSize = BytecodeInstruction::Size(op);
8034     return jumpSize;
8035 }
8036 
UpdateHotnessCounter(JSThread * thread,JSTaggedType * sp)8037 inline JSTaggedValue InterpreterAssembly::UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp)
8038 {
8039     AsmInterpretedFrame *state = GET_ASM_FRAME(sp);
8040     thread->CheckSafepoint();
8041     JSFunction* function = JSFunction::Cast(state->function.GetTaggedObject());
8042     JSTaggedValue profileTypeInfo = function->GetProfileTypeInfo(thread);
8043     if (profileTypeInfo.IsUndefined()) {
8044         return SlowRuntimeStub::NotifyInlineCache(thread, function);
8045     }
8046     return profileTypeInfo;
8047 }
8048 #undef LOG_INST
8049 #undef ADVANCE_PC
8050 #undef GOTO_NEXT
8051 #undef DISPATCH_OFFSET
8052 #undef GET_ASM_FRAME
8053 #undef GET_ENTRY_FRAME
8054 #undef SAVE_PC
8055 #undef SAVE_ACC
8056 #undef RESTORE_ACC
8057 #undef INTERPRETER_GOTO_EXCEPTION_HANDLER
8058 #undef INTERPRETER_HANDLE_RETURN
8059 #undef UPDATE_HOTNESS_COUNTER
8060 #undef GET_VREG
8061 #undef GET_VREG_VALUE
8062 #undef SET_VREG
8063 #undef GET_ACC
8064 #undef SET_ACC
8065 #if defined(__clang__)
8066 #pragma clang diagnostic pop
8067 #elif defined(__GNUC__)
8068 #pragma GCC diagnostic pop
8069 #endif
8070 }  // namespace panda::ecmascript
8071