!902 refactor load stub in jsthread

Merge pull request !902 from wanghuan2022/master
This commit is contained in:
openharmony_ci
2022-03-28 13:42:03 +00:00
committed by Gitee
6 changed files with 102 additions and 92 deletions
+2 -1
View File
@@ -415,7 +415,8 @@ void InterpreterStub::DispatchCommonCall(GateRef glue, GateRef callType, GateRef
GateRef actualArgc, Args... args)
{
GateRef opcodeOffset = IntPtrMul(
GetIntPtrConstant(BCHandlers::BC_COUNT + BytecodeHelperId::HandleCommonCallId), GetIntPtrSize());
GetIntPtrConstant(BCStubEntries::BC_HANDLER_STUB_ENTRIES_COUNT + BytecodeHelperId::HandleCommonCallId),
GetIntPtrSize());
const CallSignature *signature = RuntimeStubCSigns::Get(RTSTUB_ID(HandleCommonCall));
DispatchBase(opcodeOffset, signature, glue, callType, sp, funcReg, actualArgc, args...);
Return();
+7 -6
View File
@@ -504,11 +504,11 @@ void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector<GateRef> &i
if (circuit_->GetFrameType() == FrameType::INTERPRETER_FRAME ||
circuit_->GetFrameType() == FrameType::OPTIMIZED_ENTRY_FRAME) {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetRTInterfacesOffset(compCfg_->Is32Bit()) +
JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) +
(RTSTUB_ID(AsmIntCallRuntime)) * slotSize_, 0);
} else if (circuit_->GetFrameType() == FrameType::OPTIMIZED_FRAME) {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetRTInterfacesOffset(compCfg_->Is32Bit()) +
JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) +
(RTSTUB_ID(OptimizedCallRuntime)) * slotSize_, 0);
} else {
abort();
@@ -625,10 +625,10 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector<GateRef> &inList,
// runtime case
if (op == OpCode::CALL) {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetStubEntriesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0);
JSThread::GlueData::GetCOStubEntriesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0);
} else {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetRTInterfacesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0);
JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0);
}
LLVMValueRef rtbaseoffset = LLVMBuildAdd(builder_, glue, rtoffset, "");
LLVMValueRef rtbaseAddr = LLVMBuildIntToPtr(builder_, rtbaseoffset, LLVMPointerType(glueType, 0), "");
@@ -674,7 +674,8 @@ void LLVMIRBuilder::VisitBytecodeCall(GateRef gate, const std::vector<GateRef> &
ASSERT(llvmModule_ != nullptr);
LLVMValueRef callee;
LLVMTypeRef rtfuncType;
if (BCHandlers::GetHandlerOffset(BCHandlers::BC_COUNT + BytecodeHelperId::HandleCommonCallId) == inList[1]) {
if (BCStubEntries::GetStubEntryOffset(
BCStubEntries::BC_HANDLER_STUB_ENTRIES_COUNT + BytecodeHelperId::HandleCommonCallId) == inList[1]) {
const CallSignature *signature = RuntimeStubCSigns::Get(RTSTUB_ID(HandleCommonCall));
rtfuncType = llvmModule_->GetFuncType(signature);
} else {
@@ -686,7 +687,7 @@ void LLVMIRBuilder::VisitBytecodeCall(GateRef gate, const std::vector<GateRef> &
LLVMValueRef glue = gateToLLVMMaps_[inList[2]]; // 2 : 2 means skip two input gates (target glue)
LLVMTypeRef glueType = LLVMTypeOf(glue);
LLVMValueRef bytecodeoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetBCHandlersOffset(compCfg_->Is32Bit()),
JSThread::GlueData::GetBCStubEntriesOffset(compCfg_->Is32Bit()),
0);
LLVMValueRef rtbaseoffset = LLVMBuildAdd(
builder_, glue, LLVMBuildAdd(builder_, bytecodeoffset, opcodeOffset, ""), "");
@@ -59,7 +59,7 @@ public:
#undef DEF_HANDLER
};
static std::array<DispatchEntryPoint, BCHandlers::BC_COUNT> asmDispatchTable {
static std::array<DispatchEntryPoint, BCStubEntries::BC_HANDLER_STUB_ENTRIES_COUNT> asmDispatchTable {
#define DEF_HANDLER(name, counter) InterpreterAssembly::name,
ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER)
#undef DEF_HANDLER
+8 -2
View File
@@ -306,8 +306,14 @@ public:
if (pos != std::string::npos) {
std::string strStart = handleDisableRange.substr(0, pos);
std::string strEnd = handleDisableRange.substr(pos + 1);
asmInterParsedOption_.handleStart = strStart.empty() ? 0 : std::stoi(strStart);
asmInterParsedOption_.handleEnd = strEnd.empty() ? kungfu::BYTECODE_STUB_END_ID : std::stoi(strEnd);
int start = strStart.empty() ? 0 : std::stoi(strStart);
int end = strEnd.empty() ? kungfu::BYTECODE_STUB_END_ID : std::stoi(strEnd);
if (start >= 0 && start < kungfu::BytecodeStubCSigns::NUM_OF_ALL_STUBS
&& end >= 0 && end < kungfu::BytecodeStubCSigns::NUM_OF_ALL_STUBS
&& start <= end) {
asmInterParsedOption_.handleStart = start;
asmInterParsedOption_.handleEnd = end;
}
}
}
}
+31 -29
View File
@@ -240,6 +240,34 @@ void JSThread::ResetGuardians()
stableArrayElementsGuardians_ = true;
}
void AdjustBCStubEntries(BCStubEntries& bcStubEntries,
const std::vector<AotCodeInfo::StubDes>& stubs, const AsmInterParsedOption& asmInterOpt)
{
auto defaultBCStubDes = stubs[CommonStubCSigns::SingleStepDebugging];
auto defaultNonexistentBCStubDes = stubs[CommonStubCSigns::HandleOverflow];
bcStubEntries.SetUnrealizedBCHandlerStubEntries(defaultBCStubDes.codeAddr_);
bcStubEntries.SetNonexistentBCHandlerStubEntries(defaultNonexistentBCStubDes.codeAddr_);
#define UNDEF_STUB(name, counter) \
bcStubEntries.Set(BytecodeStubCSigns::ID_##name, defaultBCStubDes.codeAddr_);
INTERPRETER_IGNORED_BC_STUB_LIST(UNDEF_STUB)
#undef UNDEF_STUB
#define ADD_COMMON_BC_HELPER(name) \
bcStubEntries.Set(BCStubEntries::BC_HANDLER_STUB_ENTRIES_COUNT + kungfu::BytecodeHelperId::name##Id, \
stubs[CommonStubCSigns::name].codeAddr_);
COMMON_EXPROTED_TO_BC_STUB_LIST(ADD_COMMON_BC_HELPER)
#undef ADD_COMMON_BC_HELPER
#define ADD_RUNTIME_BC_HELPER(name) \
bcStubEntries.Set(BCStubEntries::BC_HANDLER_STUB_ENTRIES_COUNT + kungfu::BytecodeHelperId::name##Id, \
reinterpret_cast<uintptr_t>(name));
RUNTIME_EXPROTED_TO_BC_STUB_LIST(ADD_RUNTIME_BC_HELPER)
#undef ADD_RUNTIME_BC_HELPER
for (int i = asmInterOpt.handleStart; i <= asmInterOpt.handleEnd && i >= 0; i++) {
bcStubEntries.Set(static_cast<size_t>(i), defaultBCStubDes.codeAddr_);
}
}
void JSThread::LoadStubsFromFile(std::string &fileName)
{
AotCodeInfo aotInfo;
@@ -250,41 +278,15 @@ void JSThread::LoadStubsFromFile(std::string &fileName)
for (size_t i = 0; i < stubs.size(); i++) {
auto des = stubs[i];
if (des.IsCommonStub()) {
glueData_.stubEntries_.Set(des.indexInKind_, des.codeAddr_);
glueData_.coStubEntries_.Set(des.indexInKind_, des.codeAddr_);
} else if (des.IsBCHandler()) {
glueData_.bcHandlers_.Set(des.indexInKind_, des.codeAddr_);
glueData_.bcStubEntries_.Set(des.indexInKind_, des.codeAddr_);
} else {
UNREACHABLE();
}
}
auto defaultBCHandlerDes = stubs[CommonStubCSigns::SingleStepDebugging];
glueData_.bcHandlers_.SetUnrealizedBCHandlers(defaultBCHandlerDes.codeAddr_);
auto defaultUnusedBCSlotsDes = stubs[CommonStubCSigns::HandleOverflow];
glueData_.bcHandlers_.SetUnusedBCSlotsHandlers(defaultUnusedBCSlotsDes.codeAddr_);
#define UNDEF_STUB(name, counter) \
glueData_.bcHandlers_.Set(BytecodeStubCSigns::ID_##name, defaultBCHandlerDes.codeAddr_);
INTERPRETER_IGNORED_BC_STUB_LIST(UNDEF_STUB)
#undef UNDEF_STUB
#define ADD_COMMON_BC_HELPER(name) \
glueData_.bcHandlers_.Set(BCHandlers::BC_COUNT + kungfu::BytecodeHelperId::name##Id, \
stubs[CommonStubCSigns::name].codeAddr_);
COMMON_EXPROTED_TO_BC_STUB_LIST(ADD_COMMON_BC_HELPER)
#undef ADD_COMMON_BC_HELPER
#define ADD_RUNTIME_BC_HELPER(name) \
glueData_.bcHandlers_.Set(BCHandlers::BC_COUNT + kungfu::BytecodeHelperId::name##Id, \
reinterpret_cast<uintptr_t>(name));
RUNTIME_EXPROTED_TO_BC_STUB_LIST(ADD_RUNTIME_BC_HELPER)
#undef ADD_RUNTIME_BC_HELPER
AsmInterParsedOption asmInterOpt = GetEcmaVM()->GetJSOptions().GetAsmInterParsedOption();
if (asmInterOpt.handleStart >= 0 && asmInterOpt.handleStart < kungfu::BytecodeStubCSigns::NUM_OF_ALL_STUBS
&& asmInterOpt.handleEnd >= 0 && asmInterOpt.handleEnd < kungfu::BytecodeStubCSigns::NUM_OF_ALL_STUBS
&& asmInterOpt.handleStart <= asmInterOpt.handleEnd) {
for (int i = asmInterOpt.handleStart; i <= asmInterOpt.handleEnd; i++) {
glueData_.bcHandlers_.Set(static_cast<size_t>(i), defaultBCHandlerDes.codeAddr_);
}
}
AdjustBCStubEntries(glueData_.bcStubEntries_, stubs, asmInterOpt);
#ifdef NDEBUG
kungfu::LLVMStackMapParser::GetInstance().Print();
#endif
+53 -53
View File
@@ -40,61 +40,61 @@ enum class MarkStatus : uint8_t {
MARK_FINISHED,
};
struct BCHandlers {
static constexpr size_t BC_HANDER_COUNT = kungfu::BytecodeStubCSigns::NUM_OF_ALL_STUBS;
struct BCStubEntries {
static constexpr size_t EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT = kungfu::BytecodeStubCSigns::NUM_OF_ALL_STUBS;
// The number of bytecodes.
static constexpr size_t BC_COUNT = 0x100;
static constexpr size_t BC_HANDLER_STUB_ENTRIES_COUNT = 0x100;
// Add bytecode helper handlers at the end of bytecode handlers.
static constexpr size_t BC_HELPER_COUNT = kungfu::BytecodeHelperId::NUM_OF_BYTECODE_HELPERS;
static constexpr size_t ALL_SLOTS_COUNT = BC_COUNT + BC_HELPER_COUNT;
static_assert(BC_HANDER_COUNT <= BC_COUNT);
Address handlers_[ALL_SLOTS_COUNT] = {0};
static constexpr size_t BC_HELPER_STUB_ENTRIES_COUNT = kungfu::BytecodeHelperId::NUM_OF_BYTECODE_HELPERS;
static constexpr size_t ALL_BC_STUB_ENTRIES_COUNT = BC_HANDLER_STUB_ENTRIES_COUNT + BC_HELPER_STUB_ENTRIES_COUNT;
static_assert(EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT <= BC_HANDLER_STUB_ENTRIES_COUNT);
Address stubEntries_[ALL_BC_STUB_ENTRIES_COUNT] = {0};
static constexpr size_t SizeArch32 = sizeof(uint32_t) * ALL_SLOTS_COUNT;
static constexpr size_t SizeArch64 = sizeof(uint64_t) * ALL_SLOTS_COUNT;
static constexpr size_t SizeArch32 = sizeof(uint32_t) * ALL_BC_STUB_ENTRIES_COUNT;
static constexpr size_t SizeArch64 = sizeof(uint64_t) * ALL_BC_STUB_ENTRIES_COUNT;
void Set(size_t index, Address addr)
{
assert(index < ALL_SLOTS_COUNT);
handlers_[index] = addr;
assert(index < ALL_BC_STUB_ENTRIES_COUNT);
stubEntries_[index] = addr;
}
void SetUnrealizedBCHandlers(Address addr)
void SetUnrealizedBCHandlerStubEntries(Address addr)
{
for (size_t i = 0; i < BC_HANDER_COUNT; i++) {
if (handlers_[i] == 0) {
handlers_[i] = addr;
for (size_t i = 0; i < EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT; i++) {
if (stubEntries_[i] == 0) {
stubEntries_[i] = addr;
}
}
}
void SetUnusedBCSlotsHandlers(Address addr)
void SetNonexistentBCHandlerStubEntries(Address addr)
{
for (size_t i = BC_HANDER_COUNT; i < BC_COUNT; i++) {
if (handlers_[i] == 0) {
handlers_[i] = addr;
for (size_t i = EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT; i < BC_HANDLER_STUB_ENTRIES_COUNT; i++) {
if (stubEntries_[i] == 0) {
stubEntries_[i] = addr;
}
}
}
Address* GetAddr()
{
return reinterpret_cast<Address*>(handlers_);
return reinterpret_cast<Address*>(stubEntries_);
}
static int32_t GetHandlerOffset(int32_t handlerId)
static int32_t GetStubEntryOffset(int32_t stubId)
{
#ifdef PANDA_TARGET_32
return handlerId * sizeof(uint32_t);
return stubId * sizeof(uint32_t);
#else
return handlerId * sizeof(uint64_t);
return stubId * sizeof(uint64_t);
#endif
}
};
STATIC_ASSERT_EQ_ARCH(sizeof(BCHandlers), BCHandlers::SizeArch32, BCHandlers::SizeArch64);
STATIC_ASSERT_EQ_ARCH(sizeof(BCStubEntries), BCStubEntries::SizeArch32, BCStubEntries::SizeArch64);
struct RTInterfaces {
struct RTStubEntries {
static constexpr size_t COUNT = kungfu::RuntimeStubCSigns::NUM_OF_STUBS;
Address interfaces_[COUNT];
Address stubEntries_[COUNT];
static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
@@ -102,14 +102,14 @@ struct RTInterfaces {
void Set(size_t index, Address addr)
{
assert(index < COUNT);
interfaces_[index] = addr;
stubEntries_[index] = addr;
}
};
STATIC_ASSERT_EQ_ARCH(sizeof(RTInterfaces), RTInterfaces::SizeArch32, RTInterfaces::SizeArch64);
STATIC_ASSERT_EQ_ARCH(sizeof(RTStubEntries), RTStubEntries::SizeArch32, RTStubEntries::SizeArch64);
struct StubEntries {
struct COStubEntries {
static constexpr size_t COUNT = kungfu::CommonStubCSigns::NUM_OF_STUBS;
Address entries_[COUNT];
Address stubEntries_[COUNT];
static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
@@ -117,16 +117,16 @@ struct StubEntries {
void Set(size_t index, Address addr)
{
assert(index < COUNT);
entries_[index] = addr;
stubEntries_[index] = addr;
}
Address Get(size_t index)
{
assert(index < COUNT);
return entries_[index];
return stubEntries_[index];
}
};
STATIC_ASSERT_EQ_ARCH(sizeof(StubEntries), StubEntries::SizeArch32, StubEntries::SizeArch64);
STATIC_ASSERT_EQ_ARCH(sizeof(COStubEntries), COStubEntries::SizeArch32, COStubEntries::SizeArch64);
class JSThread : public ManagedThread {
public:
@@ -273,22 +273,22 @@ public:
void RegisterRTInterface(size_t id, Address addr)
{
ASSERT(id < kungfu::RuntimeStubCSigns::NUM_OF_STUBS);
glueData_.rtInterfaces_.Set(id, addr);
glueData_.rtStubEntries_.Set(id, addr);
}
Address GetFastStubEntry(uint32_t id)
{
return glueData_.stubEntries_.Get(id);
return glueData_.coStubEntries_.Get(id);
}
void SetFastStubEntry(size_t id, Address entry)
{
glueData_.stubEntries_.Set(id, entry);
glueData_.coStubEntries_.Set(id, entry);
}
Address *GetBytecodeHandler()
{
return glueData_.bcHandlers_.GetAddr();
return glueData_.bcStubEntries_.GetAddr();
}
void LoadStubsFromFile(std::string &fileName);
@@ -386,9 +386,9 @@ public:
JSTaggedValue,
base::AlignedPointer,
base::AlignedPointer,
BCHandlers,
RTInterfaces,
StubEntries,
BCStubEntries,
RTStubEntries,
COStubEntries,
base::AlignedUint64,
base::AlignedPointer,
GlobalEnvConstants> {
@@ -397,9 +397,9 @@ public:
GlobalObjIndex,
CurrentFrameIndex,
LeaveFrameIndex,
BCHandlersIndex,
RTInterfacesIndex,
StubEntriesIndex,
BCStubEntriesIndex,
RTStubEntriesIndex,
COStubEntriesIndex,
StateBitFieldIndex,
FrameBaseIndex,
GlobalConstIndex,
@@ -437,19 +437,19 @@ public:
return GetOffset<static_cast<size_t>(Index::LeaveFrameIndex)>(isArch32);
}
static size_t GetBCHandlersOffset(bool isArch32)
static size_t GetBCStubEntriesOffset(bool isArch32)
{
return GetOffset<static_cast<size_t>(Index::BCHandlersIndex)>(isArch32);
return GetOffset<static_cast<size_t>(Index::BCStubEntriesIndex)>(isArch32);
}
static size_t GetRTInterfacesOffset(bool isArch32)
static size_t GetRTStubEntriesOffset(bool isArch32)
{
return GetOffset<static_cast<size_t>(Index::RTInterfacesIndex)>(isArch32);
return GetOffset<static_cast<size_t>(Index::RTStubEntriesIndex)>(isArch32);
}
static size_t GetStubEntriesOffset(bool isArch32)
static size_t GetCOStubEntriesOffset(bool isArch32)
{
return GetOffset<static_cast<size_t>(Index::StubEntriesIndex)>(isArch32);
return GetOffset<static_cast<size_t>(Index::COStubEntriesIndex)>(isArch32);
}
static size_t GetFrameBaseOffset(bool isArch32)
@@ -461,14 +461,14 @@ public:
alignas(EAS) JSTaggedValue globalObject_ {JSTaggedValue::Hole()};
alignas(EAS) JSTaggedType *currentFrame_ {nullptr};
alignas(EAS) JSTaggedType *leaveFrame_ {nullptr};
alignas(EAS) BCHandlers bcHandlers_;
alignas(EAS) RTInterfaces rtInterfaces_;
alignas(EAS) StubEntries stubEntries_;
alignas(EAS) BCStubEntries bcStubEntries_;
alignas(EAS) RTStubEntries rtStubEntries_;
alignas(EAS) COStubEntries coStubEntries_;
alignas(EAS) volatile uint64_t threadStateBitField_ {0ULL};
alignas(EAS) JSTaggedType *frameBase_ {nullptr};
alignas(EAS) GlobalEnvConstants globalConst_;
};
static_assert(MEMBER_OFFSET(GlueData, rtInterfaces_) == ASM_GLUE_RUNTIME_FUNCTIONS_OFFSET);
static_assert(MEMBER_OFFSET(GlueData, rtStubEntries_) == ASM_GLUE_RUNTIME_FUNCTIONS_OFFSET);
static_assert(MEMBER_OFFSET(GlueData, currentFrame_) == ASM_GLUE_CURRENT_FRAME_OFFSET);
static_assert(MEMBER_OFFSET(GlueData, leaveFrame_) == ASM_GLUE_LEAVE_FRAME_OFFSET);
STATIC_ASSERT_EQ_ARCH(sizeof(GlueData), GlueData::SizeArch32, GlueData::SizeArch64);