Support skip aot function where too many deopts occur

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I662CB
Signed-off-by: xujie <xujie101@huawei.com>
Change-Id: Ie7195f725ee4cd4b917e436046e9faafcbf8e84b
This commit is contained in:
xujie 2022-12-13 19:30:54 +08:00
parent b0343f5d9d
commit b6d01825e0
6 changed files with 48 additions and 0 deletions

View File

@ -646,6 +646,7 @@ void AOTFileManager::SetAOTMainFuncEntry(JSHandle<JSFunction> mainFunc, const JS
mainMethod->SetAotCodeBit(true); mainMethod->SetAotCodeBit(true);
mainMethod->SetNativeBit(false); mainMethod->SetNativeBit(false);
Method *method = mainFunc->GetCallTarget(); Method *method = mainFunc->GetCallTarget();
method->SetDeoptThreshold(vm_->GetJSOptions().GetDeoptThreshold());
method->SetCodeEntryAndMarkAOT(reinterpret_cast<uintptr_t>(mainEntry)); method->SetCodeEntryAndMarkAOT(reinterpret_cast<uintptr_t>(mainEntry));
#ifndef NDEBUG #ifndef NDEBUG
PrintAOTEntry(jsPandaFile, method, mainEntry); PrintAOTEntry(jsPandaFile, method, mainEntry);
@ -664,6 +665,7 @@ void AOTFileManager::SetAOTFuncEntry(const JSPandaFile *jsPandaFile, Method *met
if (!codeEntry) { if (!codeEntry) {
return; return;
} }
method->SetDeoptThreshold(vm_->GetJSOptions().GetDeoptThreshold());
method->SetCodeEntryAndMarkAOT(codeEntry); method->SetCodeEntryAndMarkAOT(codeEntry);
} }

View File

@ -244,6 +244,13 @@ JSTaggedType Deoptimizier::ConstructAsmInterpretFrame()
auto method = GetMethod(callTarget); auto method = GetMethod(callTarget);
Dump(method); Dump(method);
ASSERT(thread_ != nullptr); ASSERT(thread_ != nullptr);
uint16_t deoptThreshold = method->GetDeoptThreshold();
if (deoptThreshold > 0) {
method->SetDeoptThreshold(--deoptThreshold);
} else {
method->SetAotCodeBit(false);
method->SetCodeEntryOrLiteral(reinterpret_cast<uintptr_t>(nullptr));
}
FrameWriter frameWriter(this); FrameWriter frameWriter(this);
// Push asm interpreter frame // Push asm interpreter frame

View File

@ -58,6 +58,7 @@ const std::string PUBLIC_API HELP_OPTION_MSG =
"--enable-ark-tools: Enable ark tools to debug. Default: false\n" "--enable-ark-tools: Enable ark tools to debug. Default: false\n"
"--trace-bc: enable tracing bytecode for aot runtime. Default: false\n" "--trace-bc: enable tracing bytecode for aot runtime. Default: false\n"
"--trace-deopt: enable tracing deopt for aot runtime. Default: false\n" "--trace-deopt: enable tracing deopt for aot runtime. Default: false\n"
"--deopt-threshold: set max count which aot function can occur deoptimization. Default: 10\n"
"--enable-cpuprofiler: Enable cpuprofiler to sample call stack and output to json file. Default: false\n" "--enable-cpuprofiler: Enable cpuprofiler to sample call stack and output to json file. Default: false\n"
"--enable-force-gc: enable force gc when allocating object. Default: true\n" "--enable-force-gc: enable force gc when allocating object. Default: true\n"
"--enable-ic: switch of inline cache. Default: true\n" "--enable-ic: switch of inline cache. Default: true\n"
@ -126,6 +127,7 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"enable-ark-tools", required_argument, nullptr, OPTION_ENABLE_ARK_TOOLS}, {"enable-ark-tools", required_argument, nullptr, OPTION_ENABLE_ARK_TOOLS},
{"trace-bc", required_argument, nullptr, OPTION_TRACE_BC}, {"trace-bc", required_argument, nullptr, OPTION_TRACE_BC},
{"trace-deopt", required_argument, nullptr, OPTION_TRACE_DEOPT}, {"trace-deopt", required_argument, nullptr, OPTION_TRACE_DEOPT},
{"deopt-threshold", required_argument, nullptr, OPTION_DEOPT_THRESHOLD},
{"enable-cpuprofiler", required_argument, nullptr, OPTION_ENABLE_CPUPROFILER}, {"enable-cpuprofiler", required_argument, nullptr, OPTION_ENABLE_CPUPROFILER},
{"enable-force-gc", required_argument, nullptr, OPTION_ENABLE_FORCE_GC}, {"enable-force-gc", required_argument, nullptr, OPTION_ENABLE_FORCE_GC},
{"enable-ic", required_argument, nullptr, OPTION_ENABLE_IC}, {"enable-ic", required_argument, nullptr, OPTION_ENABLE_IC},

View File

@ -88,6 +88,7 @@ enum CommandValues {
OPTION_BUILTINS_DTS, OPTION_BUILTINS_DTS,
OPTION_TRACE_BC, OPTION_TRACE_BC,
OPTION_TRACE_DEOPT, OPTION_TRACE_DEOPT,
OPTION_DEOPT_THRESHOLD,
OPTION_LOG_LEVEL, OPTION_LOG_LEVEL,
OPTION_LOG_DEBUG, OPTION_LOG_DEBUG,
OPTION_LOG_INFO, OPTION_LOG_INFO,
@ -821,6 +822,16 @@ public:
{ {
return traceDeopt_; return traceDeopt_;
} }
void SetDeoptThreshold(uint16_t value)
{
deoptThreshold_ = value;
}
uint32_t GetDeoptThreshold() const
{
return deoptThreshold_;
}
private: private:
static bool StartsWith(const std::string &haystack, const std::string &needle) static bool StartsWith(const std::string &haystack, const std::string &needle)
{ {
@ -889,6 +900,7 @@ private:
uint32_t pgoHotnessThreshold_ {2}; uint32_t pgoHotnessThreshold_ {2};
std::string pgoProfilerPath_ {""}; std::string pgoProfilerPath_ {""};
bool traceDeopt_{false}; bool traceDeopt_{false};
uint32_t deoptThreshold_ {10};
}; };
} // namespace panda::ecmascript } // namespace panda::ecmascript

View File

@ -213,8 +213,10 @@ public:
static constexpr size_t BUILTINID_NUM_BITS = 8; static constexpr size_t BUILTINID_NUM_BITS = 8;
static constexpr size_t FUNCTION_KIND_NUM_BITS = 4; static constexpr size_t FUNCTION_KIND_NUM_BITS = 4;
static constexpr size_t DEOPT_THRESHOLD_BITS = 16;
using BuiltinIdBits = BitField<uint8_t, 0, BUILTINID_NUM_BITS>; // offset 0-7 using BuiltinIdBits = BitField<uint8_t, 0, BUILTINID_NUM_BITS>; // offset 0-7
using FunctionKindBits = BuiltinIdBits::NextField<FunctionKind, FUNCTION_KIND_NUM_BITS>; // offset 8-11 using FunctionKindBits = BuiltinIdBits::NextField<FunctionKind, FUNCTION_KIND_NUM_BITS>; // offset 8-11
using DeoptCountBits = FunctionKindBits::NextField<uint16_t, DEOPT_THRESHOLD_BITS>; // offset 12-28
inline NO_THREAD_SANITIZE void SetHotnessCounter(int16_t counter) inline NO_THREAD_SANITIZE void SetHotnessCounter(int16_t counter)
{ {
@ -308,6 +310,16 @@ public:
return BuiltinIdBits::Update(literalInfo, id); return BuiltinIdBits::Update(literalInfo, id);
} }
static uint64_t SetDeoptThreshold(uint64_t literalInfo, uint16_t count)
{
return DeoptCountBits::Update(literalInfo, count);
}
static uint16_t GetDeoptThreshold(uint64_t literalInfo)
{
return DeoptCountBits::Decode(literalInfo);
}
static uint32_t PUBLIC_API GetNumVregs(const JSPandaFile *jsPandaFile, const MethodLiteral *methodLiteral); static uint32_t PUBLIC_API GetNumVregs(const JSPandaFile *jsPandaFile, const MethodLiteral *methodLiteral);
static const char * PUBLIC_API GetMethodName(const JSPandaFile *jsPandaFile, EntityId methodId); static const char * PUBLIC_API GetMethodName(const JSPandaFile *jsPandaFile, EntityId methodId);
static std::string PUBLIC_API ParseFunctionName(const JSPandaFile *jsPandaFile, EntityId methodId); static std::string PUBLIC_API ParseFunctionName(const JSPandaFile *jsPandaFile, EntityId methodId);

View File

@ -200,6 +200,19 @@ public:
SetExtraLiteralInfo(newValue); SetExtraLiteralInfo(newValue);
} }
void SetDeoptThreshold(uint16_t count)
{
uint64_t extraLiteralInfo = GetExtraLiteralInfo();
uint64_t newValue = MethodLiteral::SetDeoptThreshold(extraLiteralInfo, count);
SetExtraLiteralInfo(newValue);
}
uint16_t GetDeoptThreshold() const
{
uint64_t extraLiteralInfo = GetExtraLiteralInfo();
return MethodLiteral::GetDeoptThreshold(extraLiteralInfo);
}
const void* GetNativePointer() const const void* GetNativePointer() const
{ {
return GetNativePointerOrBytecodeArray(); return GetNativePointerOrBytecodeArray();