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