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