diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 6c5b86494e516aa9295ba699f5a28288313e436a..e63585b209244f6b2cf261639925ce2e9de8f7a3 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -5098,11 +5098,6 @@ void JSNApi::PreFork(EcmaVM *vm) void JSNApi::PostFork(EcmaVM *vm, const RuntimeOption &option) { JSRuntimeOptions &jsOption = vm->GetJSOptions(); - LOG_ECMA(INFO) << "asmint: " << jsOption.GetEnableAsmInterpreter() - << ", aot: " << jsOption.GetEnableAOT() - << ", jit: " << option.GetEnableJIT() - << ", baseline jit: " << option.GetEnableBaselineJIT() - << ", bundle name: " << option.GetBundleName(); jsOption.SetEnablePGOProfiler(option.GetEnableProfile()); jsOption.SetEnableJIT(option.GetEnableJIT()); jsOption.SetEnableBaselineJIT(option.GetEnableBaselineJIT()); @@ -5113,11 +5108,22 @@ void JSNApi::PostFork(EcmaVM *vm, const RuntimeOption &option) runtimeOptions.SetLogLevel(Log::LevelToString(Log::ConvertFromRuntime(option.GetLogLevel()))); Log::Initialize(runtimeOptions); - if (jsOption.GetEnableAOT() && option.GetAnDir().size()) { + // 1. system switch 2. an file dir exits 3. whitelist 4. escape mechanism + bool enableAOT = jsOption.GetEnableAOT() && + !option.GetAnDir().empty() && + EnableAotJitListHelper::GetInstance()->IsEnableAot(option.GetBundleName()) && + !ecmascript::AotCrashInfo::IsAotEscaped(); + if (enableAOT) { ecmascript::AnFileDataManager::GetInstance()->SetDir(option.GetAnDir()); ecmascript::AnFileDataManager::GetInstance()->SetEnable(true); } + LOG_ECMA(INFO) << "asmint: " << jsOption.GetEnableAsmInterpreter() + << ", aot: " << enableAOT + << ", jit: " << option.GetEnableJIT() + << ", baseline jit: " << option.GetEnableBaselineJIT() + << ", bundle name: " << option.GetBundleName(); + vm->PostFork(); } diff --git a/ecmascript/platform/aot_crash_info.h b/ecmascript/platform/aot_crash_info.h index fa68d1e5d54ec92b94d4dfcc919d5a46ee98bb53..cc1b987a48a3123fee88625f948124ca32d48eb5 100644 --- a/ecmascript/platform/aot_crash_info.h +++ b/ecmascript/platform/aot_crash_info.h @@ -39,6 +39,7 @@ constexpr static int AOT_CRASH_COUNT = 1; constexpr static int OTHERS_CRASH_COUNT = 3; constexpr static int JIT_CRASH_COUNT = 1; constexpr static int JS_CRASH_COUNT = 3; +constexpr static int OPT_CODE_CRASH_THRESHOLD = 1; public: explicit AotCrashInfo() = default; virtual ~AotCrashInfo() = default; @@ -62,4 +63,4 @@ public: static int GetOthersCrashCount(); }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_PLATFORM_AOT_RUNTIME_INFO_H \ No newline at end of file +#endif // ECMASCRIPT_PLATFORM_AOT_RUNTIME_INFO_H diff --git a/ecmascript/platform/unix/aot_crash_info.cpp b/ecmascript/platform/unix/aot_crash_info.cpp index 67f066df4c1eca02d6d04e496af722925dc18814..c378182180b4d0abaf8db3114a53971e9635be62 100644 --- a/ecmascript/platform/unix/aot_crash_info.cpp +++ b/ecmascript/platform/unix/aot_crash_info.cpp @@ -128,18 +128,21 @@ bool AotCrashInfo::IsAotEscaped(const std::string &pgoRealPath) return false; } auto escapeMap = ohos::AotRuntimeInfo::GetInstance().CollectCrashSum(pgoRealPath); - return escapeMap[ohos::RuntimeInfoType::AOT_CRASH] >= AotCrashInfo::GetAotCrashCount() || - escapeMap[ohos::RuntimeInfoType::OTHERS] >= AotCrashInfo::GetOthersCrashCount() || - escapeMap[ohos::RuntimeInfoType::JS] >= AotCrashInfo::GetJsCrashCount(); + int totalCrashes = escapeMap[ohos::RuntimeInfoType::AOT_CRASH] + + escapeMap[ohos::RuntimeInfoType::JIT] + + escapeMap[ohos::RuntimeInfoType::OTHERS] + + escapeMap[ohos::RuntimeInfoType::JS]; + return totalCrashes >= OPT_CODE_CRASH_THRESHOLD; } bool AotCrashInfo::IsJitEscape() { auto escapeMap = ohos::AotRuntimeInfo::GetInstance().CollectCrashSum(); - return escapeMap[ohos::RuntimeInfoType::JIT] >= AotCrashInfo::GetJitCrashCount() || - escapeMap[ohos::RuntimeInfoType::AOT_CRASH] >= AotCrashInfo::GetAotCrashCount() || - escapeMap[ohos::RuntimeInfoType::OTHERS] >= AotCrashInfo::GetOthersCrashCount() || - escapeMap[ohos::RuntimeInfoType::JS] >= AotCrashInfo::GetJsCrashCount(); + int totalCrashes = escapeMap[ohos::RuntimeInfoType::AOT_CRASH] + + escapeMap[ohos::RuntimeInfoType::JIT] + + escapeMap[ohos::RuntimeInfoType::OTHERS] + + escapeMap[ohos::RuntimeInfoType::JS]; + return totalCrashes >= OPT_CODE_CRASH_THRESHOLD; } bool AotCrashInfo::GetAotEscapeDisable() @@ -175,4 +178,4 @@ int AotCrashInfo::GetOthersCrashCount() return OTHERS_CRASH_COUNT; } -} // namespace panda::ecmascript \ No newline at end of file +} // namespace panda::ecmascript