From 6ae49f8dbdb228870e2449c3344ba4f5aee73c1a Mon Sep 17 00:00:00 2001 From: wupengyong Date: Tue, 11 Jan 2022 10:18:17 +0800 Subject: [PATCH] add HANDLE_STCONSTTOGLOBALRECORD_PREF_ID32 HANDLE_STCLASSTOGLOBALRECORD_PREF_ID32, HANDLE_STOWNBYVALUEWITHNAMESET_PREF_V8_V8 Signed-off-by: wupengyong Change-Id: I1f2cfbf7de9c5f0fb0de1c95f0d93182e8a1c0a1 --- ecmascript/compiler/fast_stub_define.h | 1 + ecmascript/compiler/interpreter_stub.cpp | 90 +++++++++++++++++++ ecmascript/compiler/interpreter_stub.h | 1 - ecmascript/compiler/interpreter_stub_define.h | 23 ++--- ecmascript/compiler/stub-inl.h | 29 +++++- ecmascript/compiler/stub.h | 3 + ecmascript/compiler/stub_descriptor.cpp | 16 ++++ ecmascript/frames.h | 13 ++- ecmascript/js_thread.cpp | 7 +- ecmascript/runtime_trampolines.cpp | 6 ++ ecmascript/runtime_trampolines.h | 1 + 11 files changed, 176 insertions(+), 14 deletions(-) diff --git a/ecmascript/compiler/fast_stub_define.h b/ecmascript/compiler/fast_stub_define.h index 5933319b87..fe352198b5 100644 --- a/ecmascript/compiler/fast_stub_define.h +++ b/ecmascript/compiler/fast_stub_define.h @@ -47,6 +47,7 @@ namespace panda::ecmascript::kungfu { V(NoticeThroughChainAndRefreshUser, 3) \ V(JumpToCInterpreter, 7) \ V(DebugPrint, 1) \ + V(StGlobalRecord, 4) \ V(IncDyn, 2) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) diff --git a/ecmascript/compiler/interpreter_stub.cpp b/ecmascript/compiler/interpreter_stub.cpp index 2b5852ffec..2c84b9334b 100644 --- a/ecmascript/compiler/interpreter_stub.cpp +++ b/ecmascript/compiler/interpreter_stub.cpp @@ -289,4 +289,94 @@ void HandleIncdynPrefV8Stub::GenerateCircuit(const CompilationConfig *cfg) Bind(&accDispatch); Dispatch(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, GetArchRelateConstant(3)); } + +void HandleStconsttoglobalrecordPrefId32Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + auto env = GetEnvironment(); + GateRef glue = PtrArgument(0); + GateRef pc = PtrArgument(1); + GateRef sp = PtrArgument(2); /* 2 : 3rd parameter is value */ + GateRef constpool = TaggedPointerArgument(3); /* 3 : 4th parameter is value */ + GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is value */ + DEFVARIABLE(acc, MachineType::TAGGED, TaggedArgument(5)); /* 5: 6th parameter is value */ + GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is value */ + Label isException(env); + Label notException(env); + GateRef stringId = ReadInst32_1(pc); + GateRef propKey = GetValueFromTaggedArray(MachineType::TAGGED, constpool, stringId); + SaveAcc(glue, sp, *acc); + StubDescriptor *stGlobalRecord = GET_STUBDESCRIPTOR(StGlobalRecord); + GateRef result = CallRuntime(stGlobalRecord, glue, GetWord64Constant(FAST_STUB_ID(StGlobalRecord)), + { glue, propKey, *acc, TrueConstant() }); + Branch(TaggedIsException(result), &isException, ¬Exception); + Bind(&isException); + { + SavePc(glue, sp, pc); + DispatchLast(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, GetArchRelateConstant(6)); + } + Bind(¬Exception); + acc = RestoreAcc(sp); + Dispatch(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, GetArchRelateConstant(6)); +} + +void HandleStlettoglobalrecordPrefId32Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + auto env = GetEnvironment(); + GateRef glue = PtrArgument(0); + GateRef pc = PtrArgument(1); + GateRef sp = PtrArgument(2); /* 2 : 3rd parameter is value */ + GateRef constpool = TaggedPointerArgument(3); /* 3 : 4th parameter is value */ + GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is value */ + DEFVARIABLE(acc, MachineType::TAGGED, TaggedArgument(5)); /* 5: 6th parameter is value */ + GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is value */ + Label isException(env); + Label notException(env); + GateRef stringId = ReadInst32_1(pc); + GateRef propKey = GetValueFromTaggedArray(MachineType::TAGGED, constpool, stringId); + SaveAcc(glue, sp, *acc); + StubDescriptor *stGlobalRecord = GET_STUBDESCRIPTOR(StGlobalRecord); + GateRef result = CallRuntime(stGlobalRecord, glue, GetWord64Constant(FAST_STUB_ID(StGlobalRecord)), + { glue, propKey, *acc, FalseConstant() }); + Branch(TaggedIsException(result), &isException, ¬Exception); + Bind(&isException); + { + SavePc(glue, sp, pc); + DispatchLast(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, GetArchRelateConstant(6)); + } + Bind(¬Exception); + acc = RestoreAcc(sp); + Dispatch(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, GetArchRelateConstant(6)); +} + +void HandleStclasstoglobalrecordPrefId32Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + auto env = GetEnvironment(); + GateRef glue = PtrArgument(0); + GateRef pc = PtrArgument(1); + GateRef sp = PtrArgument(2); /* 2 : 3rd parameter is value */ + GateRef constpool = TaggedPointerArgument(3); /* 3 : 4th parameter is value */ + GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is value */ + DEFVARIABLE(acc, MachineType::TAGGED, TaggedArgument(5)); /* 5: 6th parameter is value */ + GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is value */ + Label isException(env); + Label notException(env); + GateRef stringId = ReadInst32_1(pc); + GateRef propKey = GetValueFromTaggedArray(MachineType::TAGGED, constpool, stringId); + SaveAcc(glue, sp, *acc); + StubDescriptor *stGlobalRecord = GET_STUBDESCRIPTOR(StGlobalRecord); + GateRef result = CallRuntime(stGlobalRecord, glue, GetWord64Constant(FAST_STUB_ID(StGlobalRecord)), + { glue, propKey, *acc, FalseConstant() }); + Branch(TaggedIsException(result), &isException, ¬Exception); + Bind(&isException); + { + SavePc(glue, sp, pc); + DispatchLast(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, GetArchRelateConstant(6)); + } + Bind(¬Exception); + acc = RestoreAcc(sp); + Dispatch(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, GetArchRelateConstant(6)); +} } // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/interpreter_stub.h b/ecmascript/compiler/interpreter_stub.h index 4020eb5b1e..321f153c15 100644 --- a/ecmascript/compiler/interpreter_stub.h +++ b/ecmascript/compiler/interpreter_stub.h @@ -21,7 +21,6 @@ namespace panda::ecmascript::kungfu { }; INTERPRETER_STUB_LIST(DECLARE_HANDLE_STUB_CLASS) #undef DECLARE_HANDLE_STUB_CLASS - } // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_INTERPRETER_STUB_H diff --git a/ecmascript/compiler/interpreter_stub_define.h b/ecmascript/compiler/interpreter_stub_define.h index 4e682189a5..f08b629fb9 100644 --- a/ecmascript/compiler/interpreter_stub_define.h +++ b/ecmascript/compiler/interpreter_stub_define.h @@ -6,16 +6,19 @@ namespace panda::ecmascript::kungfu { #define INTERPRETER_STUB_HELPER_LIST(V) \ V(AsmInterpreterEntry, 7) -#define INTERPRETER_STUB_LIST(V) \ - V(SingleStepDebugging, 7) \ - V(HandleLdnanPref, 7) \ - V(HandleLdInfinityPref, 7) \ - V(HandleLdaDyn, 7) \ - V(HandleStaDyn, 7) \ - V(HandleLdLexVarDynPrefImm4Imm4, 7) \ - V(HandleLdLexVarDynPrefImm8Imm8, 7) \ - V(HandleLdLexVarDynPrefImm16Imm16, 7) \ - V(HandleIncdynPrefV8, 7) +#define INTERPRETER_STUB_LIST(V) \ + V(SingleStepDebugging, 7) \ + V(HandleLdnanPref, 7) \ + V(HandleLdInfinityPref, 7) \ + V(HandleLdaDyn, 7) \ + V(HandleStaDyn, 7) \ + V(HandleLdLexVarDynPrefImm4Imm4, 7) \ + V(HandleLdLexVarDynPrefImm8Imm8, 7) \ + V(HandleLdLexVarDynPrefImm16Imm16, 7) \ + V(HandleIncdynPrefV8, 7) \ + V(HandleStconsttoglobalrecordPrefId32, 7) \ + V(HandleStlettoglobalrecordPrefId32, 7) \ + V(HandleStclasstoglobalrecordPrefId32, 7) enum InterpreterStubId { #define DEF_STUB(name, counter) name##Id, diff --git a/ecmascript/compiler/stub-inl.h b/ecmascript/compiler/stub-inl.h index 0db36faa43..28e04a8769 100644 --- a/ecmascript/compiler/stub-inl.h +++ b/ecmascript/compiler/stub-inl.h @@ -1826,7 +1826,7 @@ GateRef Stub::ReadInst16_5(GateRef pc) GateRef Stub::GetFrame(GateRef CurrentSp) { - return ArchRelateSub(CurrentSp, GetArchRelateConstant(sizeof(InterpretedFrame))); + return ArchRelateSub(CurrentSp, GetArchRelateConstant(InterpretedFrame::GetSize(env_.IsArm32()))); } GateRef Stub::GetPcFromFrame(GateRef frame) @@ -1879,6 +1879,22 @@ void Stub::SaveAcc(GateRef glue, GateRef CurrentSp, GateRef acc) Store(MachineType::UINT64, glue, GetFrame(CurrentSp), GetArchRelateConstant(InterpretedFrame::GetAccOffset(env_.IsArm32())), acc); } +GateRef Stub::RestoreAcc(GateRef CurrentSp) +{ + return Load(MachineType::TAGGED, GetFrame(CurrentSp), GetArchRelateConstant(InterpretedFrame::GetAccOffset(env_.IsArm32()))); +} + +GateRef Stub::ReadInst32_0(GateRef pc) +{ + GateRef currentInst = ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(4))); + GateRef currentInst1 = Word32LSL(currentInst, GetInt32Constant(8)); + GateRef currentInst2 = Int32Add(currentInst1, ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(3)))); + GateRef currentInst3 = Word32LSL(currentInst2, GetInt32Constant(8)); + GateRef currentInst4 = Int32Add(currentInst3, ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(2)))); + GateRef currentInst5 = Word32LSL(currentInst4, GetInt32Constant(8)); + return Int32Add(currentInst5, ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(1)))); +} + GateRef Stub::ReadInst32_1(GateRef pc) { GateRef currentInst = ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(5))); @@ -1890,6 +1906,17 @@ GateRef Stub::ReadInst32_1(GateRef pc) return Int32Add(currentInst5, ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(2)))); } +GateRef Stub::ReadInst32_2(GateRef pc) +{ + GateRef currentInst = ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(6))); + GateRef currentInst1 = Word32LSL(currentInst, GetInt32Constant(8)); + GateRef currentInst2 = Int32Add(currentInst1, ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(5)))); + GateRef currentInst3 = Word32LSL(currentInst2, GetInt32Constant(8)); + GateRef currentInst4 = Int32Add(currentInst3, ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(4)))); + GateRef currentInst5 = Word32LSL(currentInst4, GetInt32Constant(8)); + return Int32Add(currentInst5, ZExtInt8ToInt32(ReadInst8(pc, GetArchRelateConstant(3)))); +} + void Stub::Dispatch(GateRef glue, GateRef pc, GateRef sp, GateRef constpool, GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter, GateRef format) { diff --git a/ecmascript/compiler/stub.h b/ecmascript/compiler/stub.h index cedfb02a33..1853c2bca4 100644 --- a/ecmascript/compiler/stub.h +++ b/ecmascript/compiler/stub.h @@ -774,11 +774,14 @@ public: inline GateRef GetProfileTypeInfoFromFrame(GateRef frame); inline GateRef GetAccFromFrame(GateRef frame); inline GateRef GetEnvFromFrame(GateRef frame); + inline GateRef ReadInst32_0(GateRef pc); inline GateRef ReadInst32_1(GateRef pc); + inline GateRef ReadInst32_2(GateRef pc); // inline GateRef GetBaseFromFrame(GateRef frame); inline void SavePc(GateRef glue, GateRef CurrentSp, GateRef pc); inline GateRef LoadAccFromSp(GateRef glue, GateRef CurrentSp); inline void SaveAcc(GateRef glue, GateRef CurrentSp, GateRef acc); + inline GateRef RestoreAcc(GateRef CurrentSp); inline void Dispatch(GateRef glue, GateRef pc, GateRef sp, GateRef constpool, GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter, GateRef format); inline void DispatchLast(GateRef glue, GateRef pc, GateRef sp, GateRef constpool, diff --git a/ecmascript/compiler/stub_descriptor.cpp b/ecmascript/compiler/stub_descriptor.cpp index 4f144fee9c..4d478b62d9 100644 --- a/ecmascript/compiler/stub_descriptor.cpp +++ b/ecmascript/compiler/stub_descriptor.cpp @@ -736,6 +736,22 @@ CALL_STUB_INIT_DESCRIPTOR(IncDyn) std::array params = { MachineType::NATIVE_POINTER, MachineType::TAGGED, + }; + descriptor->SetParameters(params.data()); + descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); +} + +CALL_STUB_INIT_DESCRIPTOR(StGlobalRecord) +{ + // 4 : 4 input parameters + StubDescriptor stGlobalRecord("StGlobalRecord", 0, 4, + ArgumentsOrder::DEFAULT_ORDER, MachineType::TAGGED); + *descriptor = stGlobalRecord; + std::array params = { // 7 : 7 input parameters + MachineType::NATIVE_POINTER, + MachineType::TAGGED, + MachineType::TAGGED, + MachineType::BOOL, }; descriptor->SetParameters(params.data()); descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); diff --git a/ecmascript/frames.h b/ecmascript/frames.h index 9586648823..a3e5912c57 100755 --- a/ecmascript/frames.h +++ b/ecmascript/frames.h @@ -191,7 +191,10 @@ static constexpr uint32_t INTERPRETED_FRAME_PC_OFFSET_64 = 0U; static constexpr uint32_t INTERPRETED_FRAME_##name##_OFFSET_64 = INTERPRETED_FRAME_##lastName##_OFFSET_64 + (lastSize64); INTERPRETED_FRAME_OFFSET_LIST(INTERPRETED_FRAME_OFFSET_MACRO) #undef INTERPRETED_FRAME_OFFSET_MACRO - +static constexpr uint32_t SIZEOF_INTERPRETED_FRAME_32 = INTERPRETED_FRAME_ENV_OFFSET_32 + + JSTaggedValue::TaggedTypeSize() + sizeof(uint32_t) + sizeof(uint64_t); +static constexpr uint32_t SIZEOF_INTERPRETED_FRAME_64 = INTERPRETED_FRAME_ENV_OFFSET_64 + + JSTaggedValue::TaggedTypeSize() + sizeof(uint64_t) + sizeof(uint64_t); // align with 8 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) struct InterpretedFrame { @@ -265,6 +268,14 @@ struct InterpretedFrame { } return INTERPRETED_FRAME_BASE_OFFSET_64; } + + static constexpr uint32_t GetSize(bool isArm32) + { + if (isArm32) { + return SIZEOF_INTERPRETED_FRAME_32; + } + return SIZEOF_INTERPRETED_FRAME_64; + } }; struct OptLeaveFrame { diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp index 14656b6b4a..afdb541b90 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp @@ -242,7 +242,12 @@ void JSThread::LoadStubModule(const char *moduleFile) bytecodeHandlers_[EcmaOpcode::LDLEXVARDYN_PREF_IMM16_IMM16] = stubModule.GetStubEntry(kungfu::StubId::STUB_HandleLdLexVarDynPrefImm16Imm16); bytecodeHandlers_[EcmaOpcode::INCDYN_PREF_V8] = stubModule.GetStubEntry(kungfu::StubId::STUB_HandleIncdynPrefV8); - + bytecodeHandlers_[EcmaOpcode::STCONSTTOGLOBALRECORD_PREF_ID32] = + stubModule.GetStubEntry(kungfu::StubId::STUB_HandleStconsttoglobalrecordPrefId32); + bytecodeHandlers_[EcmaOpcode::STLETTOGLOBALRECORD_PREF_ID32] = + stubModule.GetStubEntry(kungfu::StubId::STUB_HandleStlettoglobalrecordPrefId32); + bytecodeHandlers_[EcmaOpcode::STCLASSTOGLOBALRECORD_PREF_ID32] = + stubModule.GetStubEntry(kungfu::StubId::STUB_HandleStclasstoglobalrecordPrefId32); #ifdef NDEBUG kungfu::LLVMStackMapParser::GetInstance().Print(); #endif diff --git a/ecmascript/runtime_trampolines.cpp b/ecmascript/runtime_trampolines.cpp index a3debfb20e..8002a3e881 100644 --- a/ecmascript/runtime_trampolines.cpp +++ b/ecmascript/runtime_trampolines.cpp @@ -398,4 +398,10 @@ JSTaggedType RuntimeTrampolines::IncDyn(uintptr_t argGlue, JSTaggedType value) JSTaggedNumber number = JSTaggedValue::ToNumber(thread, valueHandle); return (++number).GetRawData(); } + +JSTaggedType RuntimeTrampolines::StGlobalRecord(uintptr_t argGlue, JSTaggedType prop, JSTaggedType value, bool isConst) +{ + auto thread = JSThread::GlueToJSThread(argGlue); + return SlowRuntimeStub::StGlobalRecord(thread, JSTaggedValue(prop), JSTaggedValue(value), isConst).GetRawData(); +} } // namespace panda::ecmascript diff --git a/ecmascript/runtime_trampolines.h b/ecmascript/runtime_trampolines.h index 7f11aedb0d..4887e28a1b 100644 --- a/ecmascript/runtime_trampolines.h +++ b/ecmascript/runtime_trampolines.h @@ -80,6 +80,7 @@ public: uint64_t constpool, uint64_t profileTypeInfo, uint64_t acc, int32_t hotnessCounter); static JSTaggedType IncDyn(uintptr_t argGlue, JSTaggedType value); + static JSTaggedType StGlobalRecord(uintptr_t argGlue, JSTaggedType prop, JSTaggedType value, bool isConst); }; } // namespace panda::ecmascript #endif -- Gitee