code review

Signed-off-by: songzhengchao <songzhengchao@huawei.com>
This commit is contained in:
songzhengchao 2021-10-30 18:58:52 +08:00 committed by songzhengchao
parent baa25ddebe
commit 0c38b6b94d
17 changed files with 61 additions and 50 deletions

View File

@ -1163,7 +1163,7 @@ void FastModStub::GenerateCircuit()
}
}
void FastMulGCStub::GenerateCircuit()
void FastMulGCTestStub::GenerateCircuit()
{
auto env = GetEnvironment();
env->GetCircuit()->SetFrameType(FrameType::OPTIMIZED_ENTRY_FRAME);
@ -1226,10 +1226,10 @@ void FastMulGCStub::GenerateCircuit()
}
Bind(&xIsDoubleAndyIsDouble);
doubleX = DoubleMul(*doubleX, *doubleY);
StubDescriptor *getTaggedArrayPtr = GET_STUBDESCRIPTOR(GetTaggedArrayPtr);
AddrShift ptr1 = CallRuntime(getTaggedArrayPtr, thread, GetWord64Constant(FAST_STUB_ID(GetTaggedArrayPtr)),
StubDescriptor *getTaggedArrayPtr = GET_STUBDESCRIPTOR(GetTaggedArrayPtrTest);
AddrShift ptr1 = CallRuntime(getTaggedArrayPtr, thread, GetWord64Constant(FAST_STUB_ID(GetTaggedArrayPtrTest)),
{thread});
AddrShift ptr2 = CallRuntime(getTaggedArrayPtr, thread, GetWord64Constant(FAST_STUB_ID(GetTaggedArrayPtr)),
AddrShift ptr2 = CallRuntime(getTaggedArrayPtr, thread, GetWord64Constant(FAST_STUB_ID(GetTaggedArrayPtrTest)),
{thread});
(void)ptr2;
auto value = Load(MachineType::INT64_TYPE, ptr1);

View File

@ -60,13 +60,13 @@ public:
void GenerateCircuit() override;
};
class FastMulGCStub : public Stub {
class FastMulGCTestStub : public Stub {
public:
// 3 : 3 means argument counts
explicit FastMulGCStub(Circuit *circuit) : Stub("FastMulGC", 3, circuit) {}
~FastMulGCStub() = default;
NO_MOVE_SEMANTIC(FastMulGCStub);
NO_COPY_SEMANTIC(FastMulGCStub);
explicit FastMulGCTestStub(Circuit *circuit) : Stub("FastMulGCTest", 3, circuit) {}
~FastMulGCTestStub() = default;
NO_MOVE_SEMANTIC(FastMulGCTestStub);
NO_COPY_SEMANTIC(FastMulGCTestStub);
void GenerateCircuit() override;
};

View File

@ -31,7 +31,7 @@ namespace kungfu {
V(StringGetHashCode, 1) \
V(FloatMod, 2) \
V(SetValueWithBarrier, 4) \
V(GetTaggedArrayPtr, 1) \
V(GetTaggedArrayPtrTest, 1) \
V(NewInternalString, 2)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
@ -66,7 +66,7 @@ namespace kungfu {
V(SetPropertyByIndex, 4) \
V(GetPropertyByValue, 3) \
V(SetPropertyByValue, 4) \
V(FastMulGC, 3)
V(FastMulGCTest, 3)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define TEST_FUNC_LIST(V) \

View File

@ -41,10 +41,14 @@ bool LLVMStackMapParser::StackMapByAddr(uintptr_t funcAddr, DwarfRegAndOffsetTyp
{
bool found = false;
for (auto it: callSiteInfos_) {
#ifndef NDEBUG
LOG_ECMA(INFO) << __FUNCTION__ << std::hex << " addr:" << it.first << std::endl;
#endif
if (it.first == funcAddr) {
DwarfRegAndOffsetType info = it.second;
#ifndef NDEBUG
LOG_ECMA(INFO) << __FUNCTION__ << " info <" << info.first << " ," << info.second << " >" << std::endl;
#endif
infos.push_back(info);
found = true;
}
@ -72,9 +76,11 @@ bool LLVMStackMapParser::StackMapByFuncAddrFp(uintptr_t funcAddr, uintptr_t fram
address = nullptr;
abort();
}
#ifndef NDEBUG
LOG_ECMA(INFO) << std::hex << "stackMap ref addr:" << address;
LOG_ECMA(INFO) << " value:" << *address;
LOG_ECMA(INFO) << " *value :" << **address << std::endl;
#endif
slotAddrs.insert(reinterpret_cast<uintptr_t>(address));
}
return true;
@ -163,13 +169,17 @@ bool LLVMStackMapParser::CalculateStackMap(const uint8_t *stackMapAddr,
return ret;
}
// update functionAddress from host side to device side
#ifndef NDEBUG
LOG_ECMA(INFO) << "stackmap calculate update funcitonaddress " << std::endl;
#endif
for (size_t i = 0; i < llvmStackMap_.StkSizeRecords.size(); i++) {
uintptr_t hostAddr = llvmStackMap_.StkSizeRecords[i].functionAddress;
uintptr_t deviceAddr = hostAddr - hostCodeSectionAddr + deviceCodeSectionAddr;
llvmStackMap_.StkSizeRecords[i].functionAddress = deviceAddr;
#ifndef NDEBUG
LOG_ECMA(INFO) << std::dec << i << "th function " << std::hex << hostAddr << " ---> " << deviceAddr
<< std::endl;
#endif
}
callSiteInfos_.clear();
CalcCallSite();

View File

@ -66,22 +66,26 @@ void LLVMModuleAssembler::AssembleModule()
void LLVMModuleAssembler::AssembleStubModule(StubModule *module)
{
auto codeBuff = reinterpret_cast<Address>(assembler_.GetCodeBuffer());
auto codeBuff = reinterpret_cast<uintptr_t>(assembler_.GetCodeBuffer());
auto engine = assembler_.GetEngine();
std::map<uint64_t, std::string> addr2name;
for (int i = 0; i < FAST_STUB_MAXCOUNT; i++) {
auto stubfunction = stubmodule_->GetStubFunction(i);
#ifndef NDEBUG
LOG_ECMA(INFO) << " AssembleStubModule :" << i << " th " << std::endl;
#endif
if (stubfunction != nullptr) {
Address stubEntry = reinterpret_cast<Address>(LLVMGetPointerToGlobal(engine, stubfunction));
uintptr_t stubEntry = reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(engine, stubfunction));
module->SetStubEntry(i, stubEntry - codeBuff);
addr2name[stubEntry] = GET_STUBDESCRIPTOR_BY_ID(i)->GetName();
addr2name[stubEntry] = FastStubDescriptors::GetInstance().GetStubDescriptor(i)->GetName();
#ifndef NDEBUG
LOG_ECMA(INFO) << "name : " << addr2name[codeBuff] << std::endl;
#endif
}
}
module->SetHostCodeSectionAddr(codeBuff);
// stackmaps ptr and size
module->SetStackMapAddr(reinterpret_cast<Address>(assembler_.GetStackMapsSection()));
module->SetStackMapAddr(reinterpret_cast<uintptr_t>(assembler_.GetStackMapsSection()));
module->SetStackMapSize(assembler_.GetStackMapsSize());
#ifndef NDEBUG
assembler_.Disassemble(addr2name);

View File

@ -813,7 +813,7 @@ AddrShift Stub::Store(MachineType type, AddrShift thread, AddrShift base, AddrSh
} else {
UNREACHABLE();
}
// write barrier
// write barrier will implemented in IR later
if (type == MachineType::TAGGED_POINTER_TYPE || type == MachineType::TAGGED_TYPE) {
StubDescriptor *setValueWithBarrier = GET_STUBDESCRIPTOR(SetValueWithBarrier);
CallRuntime(setValueWithBarrier, thread, GetWord64Constant(FAST_STUB_ID(SetValueWithBarrier)),

View File

@ -149,7 +149,7 @@ void StubAotCompiler::BuildStubModuleAndSave(const char *triple, panda::ecmascri
SET_STUB_TO_MODULE(module, FastAdd) \
SET_STUB_TO_MODULE(module, FastSub) \
SET_STUB_TO_MODULE(module, FastMul) \
SET_STUB_TO_MODULE(module, FastMulGC) \
SET_STUB_TO_MODULE(module, FastMulGCTest) \
SET_STUB_TO_MODULE(module, FastDiv) \
SET_STUB_TO_MODULE(module, FastMod) \
SET_STUB_TO_MODULE(module, FastTypeOf) \

View File

@ -22,7 +22,6 @@
namespace kungfu {
class Stub;
class circuit;
using Address = uintptr_t;
class StubAotCompiler {
public:
StubAotCompiler()

View File

@ -65,10 +65,10 @@ CALL_STUB_INIT_DESCRIPTOR(FastMul)
descriptor->SetParameters(params.data());
}
CALL_STUB_INIT_DESCRIPTOR(FastMulGC)
CALL_STUB_INIT_DESCRIPTOR(FastMulGCTest)
{
// 3 : 3 input parameters
StubDescriptor fastMulGC("FastMulGC", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE);
StubDescriptor fastMulGC("FastMulGCTest", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE);
*descriptor = fastMulGC;
// 3 : 3 input parameters
std::array<MachineType, 3> params = {
@ -294,9 +294,9 @@ CALL_STUB_INIT_DESCRIPTOR(AddElementInternal)
descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB);
}
CALL_STUB_INIT_DESCRIPTOR(GetTaggedArrayPtr)
CALL_STUB_INIT_DESCRIPTOR(GetTaggedArrayPtrTest)
{
StubDescriptor getTaggedArrayPtr("GetTaggedArrayPtr", 0, 1, ArgumentsOrder::DEFAULT_ORDER,
StubDescriptor getTaggedArrayPtr("GetTaggedArrayPtrTest", 0, 1, ArgumentsOrder::DEFAULT_ORDER,
MachineType::TAGGED_POINTER_TYPE);
*descriptor = getTaggedArrayPtr;
std::array<MachineType, 1> params = {

View File

@ -142,7 +142,6 @@ private:
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define GET_STUBDESCRIPTOR(name) FastStubDescriptors::GetInstance().GetStubDescriptor(FAST_STUB_ID(name))
#define GET_STUBDESCRIPTOR_BY_ID(id) FastStubDescriptors::GetInstance().GetStubDescriptor(id)
class FastStubDescriptors {
public:

View File

@ -228,7 +228,6 @@
#endif
namespace panda::ecmascript {
using TaggedType = coretypes::TaggedType;
class JSThread;
enum class FrameType: uintptr_t {
OPTIMIZED_FRAME = 0,
@ -248,13 +247,13 @@ public:
class InterpretedFrameStateBase {
public:
TaggedType *prev; // for llvm :c-fp ; for interrupt: thread-fp for gc
JSTaggedType *prev; // for llvm :c-fp ; for interrupt: thread-fp for gc
uintptr_t frameType;
};
class OptimizedEntryFrameState {
public:
TaggedType *threadFp; // for gc
JSTaggedType *threadFp; // for gc
OptimizedFrameStateBase base;
static size_t GetFrameStateOffsetFromSp()
{

View File

@ -233,6 +233,6 @@ void JSThread::LoadFastStubModule(const char *moduleFile)
kungfu::LLVMStackMapParser::GetInstance().Print();
stubCode_ = stubModule.GetCode();
stubStackMap_ = stubModule.GetData();
stubStackMap_ = stubModule.GetStackMapData();
}
} // namespace panda::ecmascript

View File

@ -43,18 +43,19 @@ public:
return reinterpret_cast<uintptr_t>(this) + DATA_OFFSET;
}
void SetData(const uint8_t *codeData, size_t codeLength)
void SetData(const uint8_t *stackMapData, size_t codeLength)
{
if (codeData == nullptr) {
if (stackMapData == nullptr) {
LOG_ECMA_MEM(ERROR) << "data is null in creating new code object";
return;
}
if (memcpy_s(reinterpret_cast<void *>(this->GetDataOffsetAddress()),
this->GetInstructionSizeInBytes().GetInt(), codeData, codeLength) != EOK) {
this->GetInstructionSizeInBytes().GetInt(), stackMapData, codeLength) != EOK) {
LOG_ECMA_MEM(ERROR) << "memcpy fail in creating new code object ";
return;
}
}
void VisitRangeSlot(const EcmaObjectRangeVisitor &v)
{
// left blank deliberately,only need to visit TaggedObject type object.

View File

@ -151,7 +151,7 @@ void RuntimeTrampolines::PrintHeapReginInfo(uint64_t argThread)
});
}
TaggedArray* RuntimeTrampolines::GetTaggedArrayPtr(uint64_t argThread)
TaggedArray* RuntimeTrampolines::GetTaggedArrayPtrTest(uint64_t argThread)
{
uintptr_t *curFp = nullptr;
auto thread = reinterpret_cast<JSThread *>(argThread);

View File

@ -50,7 +50,7 @@ public:
static uint32_t GetHash32(uint64_t key, uint64_t len);
static int32_t FindElementWithCache(uint64_t argThread, uint64_t hClass, uint64_t key, int32_t num);
static uint32_t StringGetHashCode(uint64_t ecmaString);
static TaggedArray* GetTaggedArrayPtr(uint64_t argThread);
static TaggedArray* GetTaggedArrayPtrTest(uint64_t argThread);
static uint64_t Execute(uint64_t argThread, uint64_t argFunc, uint64_t thisArg, uint32_t argc, uint64_t argArgv);
static void SetValueWithBarrier(uint64_t argThread, uint64_t argAddr, uint64_t argOffset, uint64_t argValue);
static double FloatMod(double left, double right);

View File

@ -79,12 +79,12 @@ void StubModule::Load(JSThread *thread, const std::string &filename)
auto dataHandle = factory->NewMachineCodeObject(stackmapSize, nullptr);
modulefile.read(reinterpret_cast<char *>(dataHandle->GetDataOffsetAddress()), stackmapSize);
SetData(*dataHandle);
SetStackMapData(*dataHandle);
#ifndef NDEBUG
LOG_ECMA(INFO) << "stackmapSize adress for device:" << std::hex << dataHandle->GetDataOffsetAddress()
<< " stackmapSize:"<< stackmapSize << std::endl;
#endif
SetStackMapAddr(reinterpret_cast<Address>(dataHandle->GetDataOffsetAddress()));
SetStackMapAddr(reinterpret_cast<uintptr_t>(dataHandle->GetDataOffsetAddress()));
modulefile.close();
}
} // namespace panda::ecmascript

View File

@ -22,10 +22,9 @@
#include "libpandabase/macros.h"
namespace panda::ecmascript {
using Address = uintptr_t;
class PUBLIC_API StubModule {
public:
Address GetStubEntry(int index)
uintptr_t GetStubEntry(int index)
{
return code_->GetDataOffsetAddress() + fastStubEntries_[index];
}
@ -35,19 +34,19 @@ public:
{
code_ = code;
}
void SetData(MachineCode *data)
void SetStackMapData(MachineCode *stackMapData)
{
data_ = data;
stackMapData_ = stackMapData;
}
void SetStubEntry(int index, Address offset)
void SetStubEntry(int index, uintptr_t offset)
{
fastStubEntries_[index] = offset;
}
void SetHostCodeSectionAddr(Address addr)
void SetHostCodeSectionAddr(uintptr_t addr)
{
hostCodeSectionAddr_ = addr;
}
Address GetHostCodeSectionAddr()
uintptr_t GetHostCodeSectionAddr() const
{
return hostCodeSectionAddr_;
}
@ -63,15 +62,15 @@ public:
{
return JSTaggedValue(code_);
}
JSTaggedValue GetData()
JSTaggedValue GetStackMapData() const
{
return JSTaggedValue(data_);
return JSTaggedValue(stackMapData_);
}
void SetStackMapAddr(Address addr)
void SetStackMapAddr(uintptr_t addr)
{
stackMapAddr_ = addr;
}
Address GetStackMapAddr()
uintptr_t GetStackMapAddr() const
{
return stackMapAddr_;
}
@ -79,18 +78,18 @@ public:
{
stackMapSize_ = len;
}
int GetStackMapSize()
int GetStackMapSize() const
{
return stackMapSize_;
}
private:
std::array<Address, kungfu::FAST_STUB_MAXCOUNT> fastStubEntries_ {-1};
Address hostCodeSectionAddr_ = 0;
std::array<uintptr_t, kungfu::FAST_STUB_MAXCOUNT> fastStubEntries_ {-1};
uintptr_t hostCodeSectionAddr_ = 0;
uintptr_t devicesCodeSectionAddr_ = 0;
MachineCode *code_ {nullptr};
MachineCode *data_ {nullptr};
Address stackMapAddr_ = 0;
MachineCode *stackMapData_ {nullptr};
uintptr_t stackMapAddr_ = 0;
int stackMapSize_ = 0;
};
} // namespace panda::ecmascript