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