fixed for arm32 js frame

issue:[Add JSFunction EntryFrame & LeaveFrame for arm32](https://gitee.com/openharmony/ark_js_runtime/issues/I4WRJP?from=project-issue)
Signed-off-by: getingke <getingke@huawei.com>

Change-Id: If65fd5064fa3c626f8f0ae3bae550465414af5e7
This commit is contained in:
getingke
2022-03-08 11:01:20 +08:00
parent a1c25110cd
commit ce112c3182
13 changed files with 193 additions and 99 deletions
+1 -1
View File
@@ -338,7 +338,7 @@ GateRef CircuitBuilder::NewRuntimeCallGate(GateRef glue, GateRef target,
inputs.push_back(arg);
}
OpCode opcode(OpCode::RUNTIME_CALL);
StubDescriptor *descriptor = GET_STUBDESCRIPTOR(CallRuntimeTrampoline);
StubDescriptor *descriptor = GET_STUBDESCRIPTOR(RuntimeCallTrampoline);
MachineType machineType = GetCallMachineTypeFromVariableType(descriptor->GetReturnType());
GateType type = VariableType2GateType(descriptor->GetReturnType());
// 2 : 2 means extra two input gates (target glue)
+1 -1
View File
@@ -19,7 +19,7 @@
#include "ecmascript/base/config.h"
#include "ecmascript/ecma_macros.h"
#define ECMASCRIPT_ENABLE_COMPILER_LOG 0
#define ECMASCRIPT_ENABLE_COMPILER_LOG 1
#define COMPILER_LOG(level) ECMASCRIPT_ENABLE_COMPILER_LOG && LOG_ECMA(level)
+14
View File
@@ -135,6 +135,7 @@ namespace panda::ecmascript::kungfu {
V(Mul2Dyn, 3) \
V(Div2Dyn, 3) \
V(Mod2Dyn, 3) \
<<<<<<< HEAD
V(GetLexicalEnv, 1) \
V(LoadValueFromConstantPool, 3) \
V(CreateEmptyObject, 1) \
@@ -160,10 +161,14 @@ namespace panda::ecmascript::kungfu {
V(SuperCall, 5) \
I(DoubleToInt, 1) \
I(CallRuntimeTrampoline, 4)
=======
I(RuntimeCallTrampoline, 4)
>>>>>>> 90e2164... fixed for debug compile arm32
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define FAST_STUB_LIST(V) \
<<<<<<< HEAD
V(FastAdd, 3) \
V(FastSub, 3) \
V(FastMul, 3) \
@@ -182,6 +187,9 @@ namespace panda::ecmascript::kungfu {
V(TryLoadICByValue, 5) \
V(TryStoreICByName, 5) \
V(TryStoreICByValue, 6)
=======
V(FastMulGCTest, 3)
>>>>>>> 90e2164... fixed for debug compile arm32
#if ECMASCRIPT_COMPILE_INTERPRETER_ASM
#define FAST_RUNTIME_STUB_LIST(V) \
@@ -194,7 +202,13 @@ namespace panda::ecmascript::kungfu {
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define TEST_FUNC_LIST(V) \
<<<<<<< HEAD
V(FastMulGCTest, 3) \
=======
V(PhiGateTest, 1) \
V(LoopTest, 1) \
V(LoopTest1, 1) \
>>>>>>> 90e2164... fixed for debug compile arm32
V(TestAbsoluteAddressRelocation, 2)
#define CALL_STUB_LIST(V) \
+36 -12
View File
@@ -43,7 +43,7 @@ LLVMIRBuilder::LLVMIRBuilder(const std::vector<std::vector<GateRef>> *schedule,
if (circuit_->GetFrameType() == FrameType::INTERPRETER_FRAME) {
LLVMSetFunctionCallConv(function_, LLVMGHCCallConv);
} else if (circuit_->GetFrameType() == FrameType::OPTIMIZED_FRAME) {
LLVMSetFunctionCallConv(function_, LLVMWebKitJSCallConv);
// LLVMSetFunctionCallConv(function_, LLVMWebKitJSCallConv);
}
LLVMSetGC(function_, "statepoint-example");
if (compCfg_->Is32Bit()) {
@@ -300,9 +300,9 @@ void LLVMIRBuilder::GenPrologue(LLVMModuleRef &module, LLVMBuilderRef &builder)
-8 type
-16 current sp before call other function
*/
if (compCfg_->Is32Bit()) {
return;
}
// if (compCfg_->Is32Bit()) {
// return;
// }
auto frameType = circuit_->GetFrameType();
if (frameType != FrameType::OPTIMIZED_FRAME) {
return;
@@ -458,12 +458,12 @@ void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector<GateRef> &i
ASSERT(stubModule_ != nullptr);
LLVMValueRef callee;
LLVMValueRef rtoffset;
LLVMTypeRef rtfuncType = stubModule_->GetStubFunctionType(FAST_STUB_ID(CallRuntimeTrampoline));
LLVMTypeRef rtfuncType = stubModule_->GetStubFunctionType(FAST_STUB_ID(RuntimeCallTrampoline));
LLVMTypeRef rtfuncTypePtr = LLVMPointerType(rtfuncType, 0);
LLVMValueRef glue = gateToLLVMMaps_[inList[2]]; // 2 : 2 means skip two input gates (target glue)
LLVMTypeRef glue_type = LLVMTypeOf(glue);
rtoffset = LLVMConstInt(glue_type, compCfg_->GetGlueOffset(JSThread::GlueID::RUNTIME_FUNCTIONS) +
(FAST_STUB_ID(CallRuntimeTrampoline) - FAST_STUB_MAXCOUNT) * slotSize_, 0);
(FAST_STUB_ID(RuntimeCallTrampoline) - FAST_STUB_MAXCOUNT) * slotSize_, 0);
LLVMValueRef rtbaseoffset = LLVMBuildAdd(builder_, glue, rtoffset, "");
LLVMValueRef rtbaseAddr = LLVMBuildIntToPtr(builder_, rtbaseoffset, LLVMPointerType(glue_type, 0), "");
LLVMValueRef llvmAddr = LLVMBuildLoad(builder_, rtbaseAddr, "");
@@ -484,7 +484,7 @@ void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector<GateRef> &i
return;
}
LLVMValueRef runtimeCall = LLVMBuildCall(builder_, callee, params, inList.size() + 1, "");
LLVMSetInstructionCallConv(runtimeCall, LLVMWebKitJSCallConv);
// LLVMSetInstructionCallConv(runtimeCall, LLVMWebKitJSCallConv);
gateToLLVMMaps_[gate] = runtimeCall;
}
@@ -584,9 +584,19 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector<GateRef> &inList)
callee = LLVMBuildIntToPtr(builder_, llvmAddr, rtfuncTypePtr, "cast");
// 16 : params limit
LLVMValueRef params[16];
int extraParameterCnt = 0;
for (size_t paraIdx = paraStartIndex; paraIdx < inList.size(); ++paraIdx) {
GateRef gateTmp = inList[paraIdx];
params[paraIdx - paraStartIndex] = gateToLLVMMaps_[gateTmp];
if (compCfg_->Is32Bit() && (paraIdx - paraStartIndex == 0)) {
// for is32 push multiple paramer in order to use r0-r4
if (calleeDescriptor->GetStubKind() != StubDescriptor::CallStubKind::RUNTIME_STUB) {
for (int i = 0; i < reservedSlotForArm32; i++) {
params[paraIdx - paraStartIndex] = gateToLLVMMaps_[gateTmp];
}
extraParameterCnt += reservedSlotForArm32;
}
}
}
if (callee == nullptr) {
COMPILER_LOG(ERROR) << "callee nullptr";
@@ -596,7 +606,7 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector<GateRef> &inList)
SaveCurrentSP();
}
gateToLLVMMaps_[gate] = LLVMBuildCall(builder_, callee, params, inList.size() - paraStartIndex, "");
gateToLLVMMaps_[gate] = LLVMBuildCall(builder_, callee, params, inList.size() - paraStartIndex + extraParameterCnt, "");
return;
}
@@ -816,7 +826,7 @@ void LLVMIRBuilder::VisitConstant(GateRef gate, std::bitset<64> value) // 64: bi
llvmValue = LLVMBuildIntToPtr(builder_, llvmValue, type, "");
} else if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) {
LLVMValueRef tmp1Value =
LLVMBuildLShr(builder_, llvmValue, LLVMConstInt(LLVMInt32Type(), 32, 0), ""); // 32: offset
LLVMBuildLShr(builder_, llvmValue, LLVMConstInt(LLVMInt64Type(), 32, 0), ""); // 32: offset
LLVMValueRef tmp2Value = LLVMBuildIntCast(builder_, llvmValue, LLVMInt32Type(), ""); // low
LLVMValueRef emptyValue = LLVMGetUndef(type);
tmp1Value = LLVMBuildIntToPtr(builder_, tmp1Value, LLVMPointerType(LLVMInt8Type(), 1), "");
@@ -880,7 +890,11 @@ void LLVMIRBuilder::VisitParameter(GateRef gate)
{
int argth = circuit_->LoadGatePtrConst(gate)->GetBitField();
COMPILER_LOG(DEBUG) << " Parameter value" << argth;
if (compCfg_->Is32Bit() && argth > 0) {
argth += reservedSlotForArm32;
}
LLVMValueRef value = LLVMGetParam(function_, argth);
ASSERT(LLVMTypeOf(value) == ConvertLLVMTypeFromGate(gate));
gateToLLVMMaps_[gate] = value;
COMPILER_LOG(DEBUG) << "VisitParameter set gate:" << gate << " value:" << value;
@@ -1544,7 +1558,7 @@ void LLVMIRBuilder::VisitZExtInt(GateRef gate, GateRef e1)
COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value);
ASSERT(GetBitWidthFromMachineType(circuit_->LoadGatePtrConst(e1)->GetMachineType()) <=
GetBitWidthFromMachineType(circuit_->LoadGatePtrConst(gate)->GetMachineType()));
LLVMValueRef result = LLVMBuildZExt(builder_, e1Value, ConvertLLVMTypeFromGate(gate), "");
LLVMValueRef result = LLVMBuildZExt(builder_, e1Value, ConvertLLVMTypeFromGate(gate), "gtk");
gateToLLVMMaps_[gate] = result;
COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result);
}
@@ -1614,7 +1628,7 @@ void LLVMIRBuilder::VisitChangeInt64ToTagged(GateRef gate, GateRef e1)
LLVMValueRef result;
if (compCfg_->Is32Bit()) {
LLVMValueRef tmp1Value =
LLVMBuildLShr(builder_, e1Value, LLVMConstInt(LLVMInt32Type(), 32, 0), ""); // 32: offset
LLVMBuildLShr(builder_, e1Value, LLVMConstInt(LLVMInt64Type(), 32, 0), ""); // 32: offset
LLVMValueRef tmp2Value = LLVMBuildIntCast(builder_, e1Value, LLVMInt32Type(), ""); // low
LLVMTypeRef vectorType = LLVMVectorType(LLVMPointerType(LLVMInt8Type(), 1), 2); // 2: packed vector type
LLVMValueRef emptyValue = LLVMGetUndef(vectorType);
@@ -1711,11 +1725,21 @@ LLVMTypeRef LLVMStubModule::GetLLVMFunctionTypeStubDescriptor(StubDescriptor *st
LLVMTypeRef returnType = ConvertLLVMTypeFromVariableType(stubDescriptor->GetReturnType());
std::vector<LLVMTypeRef> paramTys;
auto paramCount = stubDescriptor->GetParametersCount();
int extraParameterCnt = 0;
for (int i = 0; i < paramCount; i++) {
auto paramsType = stubDescriptor->GetParametersType();
if (compCfg_.Is32Bit() && (i == 0)) {
if (stubDescriptor->GetStubKind() != StubDescriptor::CallStubKind::RUNTIME_STUB) {
// for is32 push extra multiple paramer in order to use r0-r4
for (int t = 0; t < reservedSlotForArm32; t++) {
paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType[i]));
}
extraParameterCnt += reservedSlotForArm32;
}
}
paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType[i]));
}
auto functype = LLVMFunctionType(returnType, paramTys.data(), paramCount, stubDescriptor->GetVariableArgs());
auto functype = LLVMFunctionType(returnType, paramTys.data(), paramCount + extraParameterCnt, stubDescriptor->GetVariableArgs());
return functype;
}
+2
View File
@@ -155,6 +155,7 @@ private:
#endif
LLVMModuleRef module_;
CompilationConfig compCfg_;
static constexpr int reservedSlotForArm32 = 3; // r1-r3
};
@@ -275,6 +276,7 @@ private:
std::set<OpCode::Op> opCodeHandleIgnore;
int slotSize_;
LLVMTypeRef slotType_;
static constexpr int reservedSlotForArm32 = 3; // r1-r3
};
} // namespace panda::ecmascript::kungfu
#endif // PANDA_RUNTIME_ECMASCRIPT_COMPILER_LLVM_IR_BUILDER_H
+12 -1
View File
@@ -1045,9 +1045,10 @@ CALL_STUB_INIT_DESCRIPTOR(IterNext)
descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB);
}
CALL_STUB_INIT_DESCRIPTOR(CallRuntimeTrampoline)
CALL_STUB_INIT_DESCRIPTOR(RuntimeCallTrampoline)
{
/* 4 : 4 input parameters */
<<<<<<< HEAD
StubDescriptor CallRuntimeTrampoline("CallRuntimeTrampoline", 0, 4,
ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY());
*descriptor = CallRuntimeTrampoline;
@@ -1056,6 +1057,16 @@ CALL_STUB_INIT_DESCRIPTOR(CallRuntimeTrampoline)
VariableType::INT64(),
VariableType::INT64(),
VariableType::INT64(),
=======
StubDescriptor runtimeCallTrampoline("RuntimeCallTrampoline", 0, 4,
ArgumentsOrder::DEFAULT_ORDER, StubMachineType::TAGGED);
*descriptor = runtimeCallTrampoline;
std::array<StubMachineType, 4> params = { /* 4 : 4 input parameters */
StubMachineType::NATIVE_POINTER,
StubMachineType::UINT64,
StubMachineType::UINT64,
StubMachineType::UINT64,
>>>>>>> 90e2164... fixed for debug compile arm32
};
descriptor->SetVariableArgs(true);
descriptor->SetParameters(params.data());
+9 -3
View File
@@ -220,7 +220,7 @@
namespace panda::ecmascript {
class JSThread;
enum class FrameType: uint64_t {
enum class FrameType: uint64_t {
OPTIMIZED_FRAME = 0,
OPTIMIZED_ENTRY_FRAME = 1,
INTERPRETER_FRAME = 2,
@@ -245,8 +245,8 @@ public:
#ifdef PANDA_TARGET_ARM32
static constexpr int SP_DWARF_REG_NUM = 13;
static constexpr int FP_DWARF_REG_NUM = 11;
static constexpr int CALLSITE_SP_TO_FP_DELTA = 0;
static constexpr int INTERPER_FRAME_FP_TO_FP_DELTA = 0;
static constexpr int CALLSITE_SP_TO_FP_DELTA = -2;
static constexpr int INTERPER_FRAME_FP_TO_FP_DELTA = -2;
#else
static constexpr int SP_DWARF_REG_NUM = 0;
static constexpr int FP_DWARF_REG_NUM = 0;
@@ -443,7 +443,9 @@ struct OptimizedLeaveFrame {
FrameType type;
uintptr_t callsiteFp; // thread sp set here
uintptr_t returnAddr;
#ifndef PANDA_TARGET_32
uint64_t argRuntimeId;
#endif
uint64_t argPatchId;
uint64_t argc;
// argv[] is dynamic
@@ -454,7 +456,11 @@ struct OptimizedLeaveFrame {
}
uintptr_t GetCallSiteSp()
{
#ifndef PANDA_TARGET_32
return ToUintPtr(this) + MEMBER_OFFSET(OptimizedLeaveFrame, argRuntimeId);
#else
return ToUintPtr(this) + MEMBER_OFFSET(OptimizedLeaveFrame, argPatchId);
#endif
}
};
+1 -8
View File
@@ -334,18 +334,11 @@ void FrameIterator::Iterate(const RootVisitor &v0, const RootRangeVisitor &v1) c
OptimizedLeaveFrame *frame = OptimizedLeaveFrame::GetFrameFromSp(current);
OptimizedLeaveFrameHandler(reinterpret_cast<uintptr_t *>(current)).Iterate(v0,
v1, derivedPointers, isVerifying);
// arm32 only support stub, optimized entry frame don't exist, when interpret call stub
// don't customed prologue handle. when stub call runtime, generate optimized Leave Frame.
// arm64 and x86_64 support stub and aot, when aot/stub call runtime, generate Optimized
// arm32, arm64 and x86_64 support stub and aot, when aot/stub call runtime, generate Optimized
// Leave Frame.
#ifdef PANDA_TARGET_ARM32
current = reinterpret_cast<JSTaggedType *>(frame->callsiteFp);
ASSERT(FrameHandler(current).IsInterpretedFrame());
#else
current = reinterpret_cast<JSTaggedType *>(frame->callsiteFp);
ASSERT(FrameHandler(current).GetFrameType() == FrameType::OPTIMIZED_ENTRY_FRAME ||
FrameHandler(current).GetFrameType() == FrameType::OPTIMIZED_FRAME);
#endif
}
}
}
+23 -15
View File
@@ -16,6 +16,7 @@
#ifndef ECMASCRIPT_INTERPRETER_INTERPRETER_INL_H
#define ECMASCRIPT_INTERPRETER_INTERPRETER_INL_H
#include "ecmascript/trampoline/trampoline.h"
#include "ecmascript/class_linker/program_object-inl.h"
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
@@ -1296,7 +1297,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
}
HANDLE_OPCODE(HANDLE_TYPEOFDYN_PREF) {
LOG_INST() << "intrinsics::typeofdyn";
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(FastTypeOf));
typedef JSTaggedType (*PFFastTypeOf)(uintptr_t, JSTaggedType);
auto fastTypeOfPtr = reinterpret_cast<PFFastTypeOf>(stubAddr);
@@ -1472,10 +1473,17 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
JSTaggedValue left = GET_VREG_VALUE(v0);
JSTaggedValue right = acc;
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(FastMul));
typedef JSTaggedType (*PFFastMul)(JSTaggedType, JSTaggedType);
auto fastMulPtr = reinterpret_cast<PFFastMul>(stubAddr);
JSTaggedValue value = JSTaggedValue(fastMulPtr(left.GetRawData(), right.GetRawData()));
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(FastMulGCTest));
// typedef JSTaggedType (*PFFastMul)(JSTaggedType, JSTaggedType);
// auto fastMulPtr = reinterpret_cast<PFFastMul>(stubAddr);
// JSTaggedValue value = JSTaggedValue(fastMulPtr(left.GetRawData(), right.GetRawData()));
JSTaggedType argV[2] = {0x0a, 0x0a};
argV[0] = left.GetRawData();
argV[1] = right.GetRawData();
JSTaggedValue res1(JSFunctionEntry(thread->GetGlueAddr(),
reinterpret_cast<uintptr_t>(thread->GetCurrentSPFrame()), 2, 2, argV, stubAddr));
(void)res1;
JSTaggedValue value = FastRuntimeStub::FastMul(left, right);
#else
JSTaggedValue value = FastRuntimeStub::FastMul(left, right);
#endif
@@ -1516,7 +1524,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
JSTaggedValue left = GET_VREG_VALUE(vs);
JSTaggedValue right = GET_ACC();
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(FastMod));
typedef JSTaggedType (*PFFastMod)(uintptr_t, JSTaggedType, JSTaggedType);
auto fastModPtr = reinterpret_cast<PFFastMod>(stubAddr);
@@ -1542,7 +1550,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
<< " v" << v0;
JSTaggedValue left = GET_VREG_VALUE(v0);
JSTaggedValue right = acc;
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(FastEqual));
typedef JSTaggedType (*PFFastEqual)(JSTaggedType, JSTaggedType);
auto fastEqualPtr = reinterpret_cast<PFFastEqual>(stubAddr);
@@ -2490,7 +2498,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
JSTaggedValue value = GET_ACC();
// fast path
SAVE_ACC();
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(SetPropertyByNameWithOwn));
typedef JSTaggedType (*PFSetPropertyByName)(uintptr_t, JSTaggedType, JSTaggedType, JSTaggedType);
auto setPropertyByNamePtr = reinterpret_cast<PFSetPropertyByName>(stubAddr);
@@ -2842,7 +2850,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
JSTaggedValue receiver = GET_VREG_VALUE(v0);
// fast path
if (LIKELY(receiver.IsHeapObject())) {
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(GetPropertyByIndex));
typedef JSTaggedType (*PFGetPropertyByIndex)(uintptr_t, JSTaggedType, uint32_t);
auto getPropertyByIndex = reinterpret_cast<PFGetPropertyByIndex>(stubAddr);
@@ -2875,7 +2883,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
SAVE_ACC();
JSTaggedValue value = GET_ACC();
// fast path
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(SetPropertyByIndex));
typedef JSTaggedType (*PFSetPropertyByIndex)(uintptr_t, JSTaggedType, uint32_t, JSTaggedType);
auto setPropertyByIndex = reinterpret_cast<PFSetPropertyByIndex>(stubAddr);
@@ -2938,7 +2946,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
#endif
// fast path
if (LIKELY(receiver.IsHeapObject())) {
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(GetPropertyByValue));
typedef JSTaggedType (*PFGetPropertyByValue)(uintptr_t, JSTaggedType, JSTaggedType);
auto getPropertyByValuePtr = reinterpret_cast<PFGetPropertyByValue>(stubAddr);
@@ -3240,7 +3248,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
JSTaggedValue value = GET_ACC();
// fast path
SAVE_ACC();
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(SetPropertyByNameWithOwn));
typedef JSTaggedType (*PFSetPropertyByName)(uintptr_t, JSTaggedType, JSTaggedType, JSTaggedType);
auto setPropertyByNamePtr = reinterpret_cast<PFSetPropertyByName>(stubAddr);
@@ -3338,7 +3346,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
if (LIKELY(receiver.IsHeapObject())) {
// fast path
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(GetPropertyByName));
typedef JSTaggedType (*PFGetPropertyByName)(uintptr_t, JSTaggedType, JSTaggedType);
auto getPropertyByNamePtr = reinterpret_cast<PFGetPropertyByName>(stubAddr);
@@ -3377,7 +3385,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
if (LIKELY(firstValue.IsHeapObject())) {
JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1);
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(TryStoreICByName));
typedef JSTaggedType (*PFTryStoreICByName)(uintptr_t,
JSTaggedType, JSTaggedType, JSTaggedType, JSTaggedType);
@@ -3413,7 +3421,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
value = GET_ACC();
// fast path
SAVE_ACC();
#ifdef ECMASCRIPT_ENABLE_STUB_AOT
#ifdef ECMASCRIPT_ENABLE_STUB_AOT1
auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(SetPropertyByName));
typedef JSTaggedType (*PFSetPropertyByName)(uintptr_t, JSTaggedType, JSTaggedType, JSTaggedType);
auto setPropertyByNamePtr = reinterpret_cast<PFSetPropertyByName>(stubAddr);
+1 -1
View File
@@ -21,7 +21,7 @@
#include "ecmascript/js_thread.h"
namespace panda::ecmascript {
extern "C" JSTaggedType CallRuntimeTrampoline(uintptr_t glue, uint64_t runtime_id, uint64_t patch_id,
extern "C" JSTaggedType RuntimeCallTrampoline(uintptr_t glue, uint64_t runtime_id, uint64_t patch_id,
uint64_t argc, ...);
class RuntimeTrampolines {
public:
@@ -26,6 +26,7 @@
pushq %rdi
.endm
/* JSFunctionEntry Callee Register restore Macro */
.macro POP_GENERAL_REGS
/* caller restore */
popq %rdi
@@ -98,7 +99,7 @@ JSFunctionEntry:
// uint64_t CallRuntimeTrampoline(uintptr_t glue, uint64_t runtime_id, uint64_t patch_id, uint64_t argc, ...);
// uint64_t RuntimeCallTrampoline(uintptr_t glue, uint64_t runtime_id, uint64_t patch_id, uint64_t argc, ...);
// webkit_jscc calling convention call runtime_id's runtion function(c-abi)
// JSTaggedType (*)(uintptr_t argGlue, uint64_t argc, JSTaggedType argv[])
// Input:
@@ -133,9 +134,9 @@ JSFunctionEntry:
// sp - 16: rbp <---------current rbp & current sp
// current sp - 8: type
.global CallRuntimeTrampoline
.type CallRuntimeTrampoline, %function
CallRuntimeTrampoline:
.global RuntimeCallTrampoline
.type RuntimeCallTrampoline, %function
RuntimeCallTrampoline:
pushq %rbp
movq %rsp, %rbp // set frame pointer
movq %rbp, ASM_GLUE_CURRENT_FRAME_OFFSET(%rax) // save to thread->currentFrame_
+86 -51
View File
@@ -13,22 +13,30 @@
* limitations under the License.
*/
// uint64_t JSFunctionCallTrampoline(uintptr_t glue, uintptr_t prevFp, uint32_t expectedNumArgs,
#include "ecma_asm_defines.h"
// uint64_t JSFunctionEntry(uintptr_t glue, uintptr_t prevFp, uint32_t expectedNumArgs,
// uint32_t actualNumArgs, const JSTaggedType argV[], uintptr_t codeAddr);
// Input:
// %r0 - glue
// %r1 - prevFp
// %r2 - expectedNumArgs
// %r3 - actualNumArgs
// %r5 - argV
// %r12 - codeAddr
.global JSFunctionCallTrampoline
.type JSFunctionCallTrampoline, %function
JSFunctionCallTrampoline:
push {r4, r5, r6, r7, r8, r9, r10, r11, lr}
add r11, sp, #28
sub sp, sp, #4
mov r10, r2
.global JSFunctionEntry
.type JSFunctionEntry, %function
JSFunctionEntry:
push {r4, r5, r6, r7, r8, r9, r10, lr} // callee save
push {r11} // rbp
mov r11, sp // set frame pointer
// construct frame
mov r6, #0
mov r8, #JS_ENTRY_FRAME_TYPE
push {r6, r8} // frame type
push {r1} // prev managed frame
push {r0}
mov r10, r2 // save expected
cmp r2, r3
bls .LCopyArguments
mov r6, #0
@@ -46,64 +54,91 @@ JSFunctionCallTrampoline:
rscs r5, r4, #0
blo .LCopyExtraAument
.LCopyArguments:
ldr r12, [r11, #12]
ldr lr, [r11, #40] // load js function code address
cmp r10, r3
add lr, r1, #8
add r2, r1, #16
movls r3, r10
add r3, r3, #3 // add 3 for calltarget newtarget this LCopyArguments
ldr r4, [r11, #8]
mov r7, #0
cmp r3, #0
beq .LInvokeJSFunction
ldr r4, [r11, #36] // load argv address
add r5, r4, r3, lsl #3
.LCopyLoop: @ =>This Inner Loop Header: Depth=1
ldr r6, [r5, #4]
ldr r8, [r5]
.LCopyLoop:
sub r5, r5, #8
subs r3, r3, #1
mov r9, r6
ldr r8, [r5, #4]
ldr r6, [r5]
push {r6, r8}
bne .LCopyLoop
mov r2, r12
bl InvokeCompiledJSFunction
mov r2, #24
.LInvokeJSFunction:
mov r10, #OPTIMIZE_FRAME_TYPE // set frame type
blx lr
mov r2, #0 // need fix for calltarget thisTarget NewTarget
add r2, r2, r10, lsl #3
add sp, sp, r2
sub sp, r11, #28
pop {r4, r5, r6, r7, r8, r9, r10, r11, lr}
pop {r4}
pop {r1}
str r1, [r4, #ASM_GLUE_CURRENT_FRAME_OFFSET]
add sp, sp, #8
pop {r11}
pop {r4, r5, r6, r7, r8, r9, r10, lr}
bx lr
// uint64_t InvokeCompiledJSFunction
// uint64_t RuntimeCallTrampoline(uintptr_t glue, uint64_t runtime_id, uint64_t patch_id, uint64_t argc, ...);
// webkit_jscc calling convention call runtime_id's runtion function(c-abi)
// JSTaggedType (*)(uintptr_t argGlue, uint64_t argc, JSTaggedType argv[])
// Input:
// %r0 - glue
// %r1 - prev fp
// %r2 - code address
// %r2, %r3 - runtime_id
// stack layout:
// sp + N*8 argvN
// ........
// sp + 24: argv1
// sp + 16: argv0
// sp + 8: argc
// sp: patch_id
// construct Leave Frame:
// +--------------------------+
// | argv[] |
// +--------------------------+ ---
// | argc | ^
// |- - - - - - -- - - - - - -| |
// | patchID | Fixed
// |- - - - - - - -- - -- - -| OptLeaveFrame
// | returnAddr | |
// |- - - - - - - - -- - - - -| |
// | callsiteFp | |
// |-------------------- - - -| |
// | frameType | v
// +--------------------------+ ---
// | callee save registers |
// +--------------------------+
.global InvokeCompiledJSFunction
.type InvokeCompiledJSFunction, %function
InvokeCompiledJSFunction:
// construct the frame
push {r11, lr}
mov lr, #1
push {lr, r1} // js entry frame type, prev managerd fp
add r11, sp, #8
mov lr, r2
blx lr
add sp, sp, #8
pop {r11, lr}
bx lr
.global RuntimeCallTrampoline
.type RuntimeCallTrampoline, %function
RuntimeCallTrampoline:
push {r11, lr} // save register for fp, rip
mov r11, sp // set frame pointer = callsiteFp
str r11, [r0, #ASM_GLUE_CURRENT_FRAME_OFFSET] // save to thread->currentFrame_
add sp, sp, #-8 // increase frame size
push {r4, r5} // callee save
// construct leave frame
mov r4, #0
mov r5, #LEAVE_FRAME_TYPE
str r4, [r11, #-4]
str r5, [r11, #-8] // save frame type
// uint64_t CallRuntimeTrampoline(uintptr_t glue, uint32_t runtime_id, uint32_t patch_id, uint64_t argc, ...);
// webkit_jscc calling convention
.global CallRuntimeTrampoline
.type CallRuntimeTrampoline, %function
CallRuntimeTrampoline: // todo : need to rewrite
push {r4, r5, r6, r7, r8, r9, r10, r11, lr}
add r11, sp, #28
sub sp, sp, #4
bx lr
// load runtime trampoline address
add r2, r0, r2, lsl #2
ldr r4, [r2, #ASM_GLUE_RUNTIME_FUNCTIONS_OFFSET]
ldr r1, [r11, #16] // argc
add r2, r11, #24 // argv[]
bx r4
// descontruct leave frame and callee save register
pop {r4, r5}
add sp, sp, #8
pop {r11, lr}
bx lr
+2 -2
View File
@@ -13,9 +13,9 @@
ark_root = "//ark/runtime_core"
js_root = "//ark/js_runtime"
compile_llvm_online = false
compile_llvm_online = true
run_with_asan = false
enable_stub_aot = false
enable_stub_aot = true
asan_lib_path = "/usr/lib/llvm-10/lib/clang/10.0.0/lib/linux"
# For OpenHarmony build, always link with the static lib: