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