14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#include "ecmascript/jit/jit.h"
174514f5e3Sopenharmony_ci#include "ecmascript/jit/jit_task.h"
184514f5e3Sopenharmony_ci#include "ecmascript/dfx/vmstat/jit_warmup_profiler.h"
194514f5e3Sopenharmony_ci#include "ecmascript/ohos/jit_tools.h"
204514f5e3Sopenharmony_ci
214514f5e3Sopenharmony_cinamespace panda::ecmascript {
224514f5e3Sopenharmony_civoid (*Jit::initJitCompiler_)(JSRuntimeOptions options) = nullptr;
234514f5e3Sopenharmony_cibool(*Jit::jitCompile_)(void*, JitTask*) = nullptr;
244514f5e3Sopenharmony_cibool(*Jit::jitFinalize_)(void*, JitTask*) = nullptr;
254514f5e3Sopenharmony_civoid*(*Jit::createJitCompilerTask_)(JitTask*) = nullptr;
264514f5e3Sopenharmony_civoid(*Jit::deleteJitCompile_)(void*) = nullptr;
274514f5e3Sopenharmony_civoid *Jit::libHandle_ = nullptr;
284514f5e3Sopenharmony_ci
294514f5e3Sopenharmony_ciJit *Jit::GetInstance()
304514f5e3Sopenharmony_ci{
314514f5e3Sopenharmony_ci    static Jit instance_;
324514f5e3Sopenharmony_ci    return &instance_;
334514f5e3Sopenharmony_ci}
344514f5e3Sopenharmony_ci
354514f5e3Sopenharmony_civoid Jit::SetJitEnablePostFork(EcmaVM *vm, const std::string &bundleName)
364514f5e3Sopenharmony_ci{
374514f5e3Sopenharmony_ci    JSRuntimeOptions &options = vm->GetJSOptions();
384514f5e3Sopenharmony_ci    bool jitEnable = ohos::JitTools::GetJitEscapeDisable() || !AotCrashInfo::IsJitEscape();
394514f5e3Sopenharmony_ci    jitEnable &= ohos::EnableAotJitListHelper::GetInstance()->IsEnableJit(bundleName);
404514f5e3Sopenharmony_ci    jitEnable &= !vm->GetJSOptions().GetAOTHasException();
414514f5e3Sopenharmony_ci    if (jitEnable) {
424514f5e3Sopenharmony_ci        bool isEnableFastJit = options.IsEnableJIT() && options.GetEnableAsmInterpreter();
434514f5e3Sopenharmony_ci        bool isEnableBaselineJit = options.IsEnableBaselineJIT() && options.GetEnableAsmInterpreter();
444514f5e3Sopenharmony_ci
454514f5e3Sopenharmony_ci        options.SetEnableJitFrame(ohos::JitTools::GetJitFrameEnable());
464514f5e3Sopenharmony_ci        options.SetEnableAPPJIT(true);
474514f5e3Sopenharmony_ci        // for app threshold
484514f5e3Sopenharmony_ci        uint32_t defaultSize = 3000;
494514f5e3Sopenharmony_ci        uint32_t threshold = ohos::JitTools::GetJitHotnessThreshold(defaultSize);
504514f5e3Sopenharmony_ci        options.SetJitHotnessThreshold(threshold);
514514f5e3Sopenharmony_ci        bundleName_ = bundleName;
524514f5e3Sopenharmony_ci        isEnableAppPGO_ = pgo::PGOProfilerManager::GetInstance()->IsEnable();
534514f5e3Sopenharmony_ci
544514f5e3Sopenharmony_ci        SetEnableOrDisable(options, isEnableFastJit, isEnableBaselineJit);
554514f5e3Sopenharmony_ci        if (fastJitEnable_ || baselineJitEnable_) {
564514f5e3Sopenharmony_ci            ConfigJit(vm);
574514f5e3Sopenharmony_ci        }
584514f5e3Sopenharmony_ci    }
594514f5e3Sopenharmony_ci}
604514f5e3Sopenharmony_ci
614514f5e3Sopenharmony_civoid Jit::SwitchProfileStubs(EcmaVM *vm)
624514f5e3Sopenharmony_ci{
634514f5e3Sopenharmony_ci    JSThread *thread = vm->GetAssociatedJSThread();
644514f5e3Sopenharmony_ci    JSRuntimeOptions &options = vm->GetJSOptions();
654514f5e3Sopenharmony_ci    std::shared_ptr<PGOProfiler> pgoProfiler = vm->GetPGOProfiler();
664514f5e3Sopenharmony_ci    if (!options.IsEnableJITPGO() || pgoProfiler == nullptr || (isApp_ && !isEnableAppPGO_)) {
674514f5e3Sopenharmony_ci        thread->SwitchJitProfileStubs(false);
684514f5e3Sopenharmony_ci        options.SetEnableJITPGO(false);
694514f5e3Sopenharmony_ci    } else {
704514f5e3Sopenharmony_ci        // if not enable aot pgo
714514f5e3Sopenharmony_ci        if (!pgo::PGOProfilerManager::GetInstance()->IsEnable()) {
724514f5e3Sopenharmony_ci            // disable dump
734514f5e3Sopenharmony_ci            options.SetEnableProfileDump(false);
744514f5e3Sopenharmony_ci            SetProfileNeedDump(false);
754514f5e3Sopenharmony_ci            // enable profiler
764514f5e3Sopenharmony_ci            options.SetEnablePGOProfiler(true);
774514f5e3Sopenharmony_ci            pgoProfiler->Reset(true);
784514f5e3Sopenharmony_ci            // switch pgo stub
794514f5e3Sopenharmony_ci            thread->SwitchJitProfileStubs(true);
804514f5e3Sopenharmony_ci        }
814514f5e3Sopenharmony_ci        pgoProfiler->InitJITProfiler();
824514f5e3Sopenharmony_ci    }
834514f5e3Sopenharmony_ci}
844514f5e3Sopenharmony_ci
854514f5e3Sopenharmony_civoid Jit::ConfigOptions(EcmaVM *vm) const
864514f5e3Sopenharmony_ci{
874514f5e3Sopenharmony_ci    JSRuntimeOptions &options = vm->GetJSOptions();
884514f5e3Sopenharmony_ci
894514f5e3Sopenharmony_ci    options.SetEnableAPPJIT(isApp_);
904514f5e3Sopenharmony_ci    options.SetEnableProfileDump(isProfileNeedDump_);
914514f5e3Sopenharmony_ci
924514f5e3Sopenharmony_ci    bool jitEnableLitecg = ohos::JitTools::IsJitEnableLitecg(options.IsCompilerEnableLiteCG());
934514f5e3Sopenharmony_ci    options.SetCompilerEnableLiteCG(jitEnableLitecg);
944514f5e3Sopenharmony_ci
954514f5e3Sopenharmony_ci    uint8_t jitCallThreshold = ohos::JitTools::GetJitCallThreshold(options.GetJitCallThreshold());
964514f5e3Sopenharmony_ci    options.SetJitCallThreshold(jitCallThreshold);
974514f5e3Sopenharmony_ci
984514f5e3Sopenharmony_ci    uint32_t jitHotnessThreshold = GetHotnessThreshold();
994514f5e3Sopenharmony_ci    options.SetJitHotnessThreshold(jitHotnessThreshold);
1004514f5e3Sopenharmony_ci
1014514f5e3Sopenharmony_ci    bool jitDisableCodeSign = ohos::JitTools::GetCodeSignDisable(options.GetDisableCodeSign());
1024514f5e3Sopenharmony_ci    options.SetDisableCodeSign(jitDisableCodeSign);
1034514f5e3Sopenharmony_ci
1044514f5e3Sopenharmony_ci    bool jitEnableJitFort = ohos::JitTools::GetEnableJitFort(options.GetEnableJitFort());
1054514f5e3Sopenharmony_ci    options.SetEnableJitFort(jitEnableJitFort);
1064514f5e3Sopenharmony_ci
1074514f5e3Sopenharmony_ci    bool jitEnableAsyncCopyToFort = ohos::JitTools::GetEnableAsyncCopyToFort(options.GetEnableAsyncCopyToFort());
1084514f5e3Sopenharmony_ci    options.SetEnableAsyncCopyToFort(jitEnableAsyncCopyToFort);
1094514f5e3Sopenharmony_ci
1104514f5e3Sopenharmony_ci    vm->SetEnableJitLogSkip(ohos::JitTools::GetSkipJitLogEnable());
1114514f5e3Sopenharmony_ci
1124514f5e3Sopenharmony_ci    LOG_JIT(INFO) << "enable jit bundle:" << bundleName_ <<
1134514f5e3Sopenharmony_ci        ", litecg:" << jitEnableLitecg <<
1144514f5e3Sopenharmony_ci        ", call threshold:" << static_cast<int>(jitCallThreshold) <<
1154514f5e3Sopenharmony_ci        ", hotness threshold:" << jitHotnessThreshold <<
1164514f5e3Sopenharmony_ci        ", disable codesigner:" << jitDisableCodeSign;
1174514f5e3Sopenharmony_ci}
1184514f5e3Sopenharmony_ci
1194514f5e3Sopenharmony_civoid Jit::ConfigJit(EcmaVM *vm)
1204514f5e3Sopenharmony_ci{
1214514f5e3Sopenharmony_ci    SwitchProfileStubs(vm);
1224514f5e3Sopenharmony_ci    ConfigOptions(vm);
1234514f5e3Sopenharmony_ci    ConfigJitFortOptions(vm);
1244514f5e3Sopenharmony_ci}
1254514f5e3Sopenharmony_ci
1264514f5e3Sopenharmony_civoid Jit::ConfigJitFortOptions(EcmaVM *vm)
1274514f5e3Sopenharmony_ci{
1284514f5e3Sopenharmony_ci    SetDisableCodeSign(vm->GetJSOptions().GetDisableCodeSign());
1294514f5e3Sopenharmony_ci    SetEnableJitFort(vm->GetJSOptions().GetEnableJitFort());
1304514f5e3Sopenharmony_ci    SetEnableAsyncCopyToFort(vm->GetJSOptions().GetEnableAsyncCopyToFort());
1314514f5e3Sopenharmony_ci}
1324514f5e3Sopenharmony_ci
1334514f5e3Sopenharmony_civoid Jit::SetEnableOrDisable(const JSRuntimeOptions &options, bool isEnableFastJit, bool isEnableBaselineJit)
1344514f5e3Sopenharmony_ci{
1354514f5e3Sopenharmony_ci    LockHolder holder(setEnableLock_);
1364514f5e3Sopenharmony_ci
1374514f5e3Sopenharmony_ci    bool needInitialize = false;
1384514f5e3Sopenharmony_ci    if (!isEnableFastJit) {
1394514f5e3Sopenharmony_ci        fastJitEnable_ = false;
1404514f5e3Sopenharmony_ci    } else {
1414514f5e3Sopenharmony_ci        needInitialize = true;
1424514f5e3Sopenharmony_ci    }
1434514f5e3Sopenharmony_ci    if (!isEnableBaselineJit) {
1444514f5e3Sopenharmony_ci        baselineJitEnable_ = false;
1454514f5e3Sopenharmony_ci    } else {
1464514f5e3Sopenharmony_ci        needInitialize = true;
1474514f5e3Sopenharmony_ci    }
1484514f5e3Sopenharmony_ci    if (!needInitialize) {
1494514f5e3Sopenharmony_ci        return;
1504514f5e3Sopenharmony_ci    }
1514514f5e3Sopenharmony_ci    if (!initialized_) {
1524514f5e3Sopenharmony_ci        Initialize();
1534514f5e3Sopenharmony_ci    }
1544514f5e3Sopenharmony_ci    if (initialized_) {
1554514f5e3Sopenharmony_ci        bool jitEnable = false;
1564514f5e3Sopenharmony_ci        if (isEnableFastJit && !fastJitEnable_) {
1574514f5e3Sopenharmony_ci            fastJitEnable_ = true;
1584514f5e3Sopenharmony_ci            jitEnable = true;
1594514f5e3Sopenharmony_ci        }
1604514f5e3Sopenharmony_ci        if (isEnableBaselineJit && !baselineJitEnable_) {
1614514f5e3Sopenharmony_ci            baselineJitEnable_ = true;
1624514f5e3Sopenharmony_ci            jitEnable = true;
1634514f5e3Sopenharmony_ci        }
1644514f5e3Sopenharmony_ci        if (jitEnable) {
1654514f5e3Sopenharmony_ci            jitDfx_ = JitDfx::GetInstance();
1664514f5e3Sopenharmony_ci            jitDfx_->Init(options, bundleName_);
1674514f5e3Sopenharmony_ci
1684514f5e3Sopenharmony_ci            isApp_ = options.IsEnableAPPJIT();
1694514f5e3Sopenharmony_ci            hotnessThreshold_ = options.GetJitHotnessThreshold();
1704514f5e3Sopenharmony_ci            initJitCompiler_(options);
1714514f5e3Sopenharmony_ci            bool enableCodeSign = !ohos::JitTools::GetCodeSignDisable(options.GetDisableCodeSign());
1724514f5e3Sopenharmony_ci            bool shouldCompileMain =
1734514f5e3Sopenharmony_ci                options.IsEnableForceJitCompileMain() || options.IsEnableForceBaselineCompileMain();
1744514f5e3Sopenharmony_ci            if (enableCodeSign && shouldCompileMain) {
1754514f5e3Sopenharmony_ci                JitFort::InitJitFortResource();
1764514f5e3Sopenharmony_ci            }
1774514f5e3Sopenharmony_ci            JitTaskpool::GetCurrentTaskpool()->Initialize(enableCodeSign && !shouldCompileMain);
1784514f5e3Sopenharmony_ci        }
1794514f5e3Sopenharmony_ci    }
1804514f5e3Sopenharmony_ci}
1814514f5e3Sopenharmony_ci
1824514f5e3Sopenharmony_civoid Jit::Destroy()
1834514f5e3Sopenharmony_ci{
1844514f5e3Sopenharmony_ci    if (!initialized_) {
1854514f5e3Sopenharmony_ci        return;
1864514f5e3Sopenharmony_ci    }
1874514f5e3Sopenharmony_ci
1884514f5e3Sopenharmony_ci    LockHolder holder(setEnableLock_);
1894514f5e3Sopenharmony_ci
1904514f5e3Sopenharmony_ci    JitTaskpool::GetCurrentTaskpool()->Destroy();
1914514f5e3Sopenharmony_ci    initialized_ = false;
1924514f5e3Sopenharmony_ci    fastJitEnable_ = false;
1934514f5e3Sopenharmony_ci    baselineJitEnable_ = false;
1944514f5e3Sopenharmony_ci    if (libHandle_ != nullptr) {
1954514f5e3Sopenharmony_ci        CloseLib(libHandle_);
1964514f5e3Sopenharmony_ci        libHandle_ = nullptr;
1974514f5e3Sopenharmony_ci    }
1984514f5e3Sopenharmony_ci}
1994514f5e3Sopenharmony_ci
2004514f5e3Sopenharmony_cibool Jit::IsEnableFastJit() const
2014514f5e3Sopenharmony_ci{
2024514f5e3Sopenharmony_ci    return fastJitEnable_;
2034514f5e3Sopenharmony_ci}
2044514f5e3Sopenharmony_ci
2054514f5e3Sopenharmony_cibool Jit::IsEnableBaselineJit() const
2064514f5e3Sopenharmony_ci{
2074514f5e3Sopenharmony_ci    return baselineJitEnable_;
2084514f5e3Sopenharmony_ci}
2094514f5e3Sopenharmony_ci
2104514f5e3Sopenharmony_cibool Jit::IsEnableJitFort() const
2114514f5e3Sopenharmony_ci{
2124514f5e3Sopenharmony_ci    return isEnableJitFort_;
2134514f5e3Sopenharmony_ci}
2144514f5e3Sopenharmony_ci
2154514f5e3Sopenharmony_civoid Jit::SetEnableJitFort(bool isEnableJitFort)
2164514f5e3Sopenharmony_ci{
2174514f5e3Sopenharmony_ci    isEnableJitFort_ = isEnableJitFort;
2184514f5e3Sopenharmony_ci}
2194514f5e3Sopenharmony_ci
2204514f5e3Sopenharmony_cibool Jit::IsDisableCodeSign() const
2214514f5e3Sopenharmony_ci{
2224514f5e3Sopenharmony_ci    return isDisableCodeSign_;
2234514f5e3Sopenharmony_ci}
2244514f5e3Sopenharmony_ci
2254514f5e3Sopenharmony_civoid Jit::SetDisableCodeSign(bool isDisableCodeSign)
2264514f5e3Sopenharmony_ci{
2274514f5e3Sopenharmony_ci    isDisableCodeSign_ = isDisableCodeSign;
2284514f5e3Sopenharmony_ci}
2294514f5e3Sopenharmony_ci
2304514f5e3Sopenharmony_cibool Jit::IsEnableAsyncCopyToFort() const
2314514f5e3Sopenharmony_ci{
2324514f5e3Sopenharmony_ci    return isEnableAsyncCopyToFort_;
2334514f5e3Sopenharmony_ci}
2344514f5e3Sopenharmony_ci
2354514f5e3Sopenharmony_civoid Jit::SetEnableAsyncCopyToFort(bool isEnableAsyncCopyToFort)
2364514f5e3Sopenharmony_ci{
2374514f5e3Sopenharmony_ci    isEnableAsyncCopyToFort_ = isEnableAsyncCopyToFort;
2384514f5e3Sopenharmony_ci}
2394514f5e3Sopenharmony_ci
2404514f5e3Sopenharmony_civoid Jit::Initialize()
2414514f5e3Sopenharmony_ci{
2424514f5e3Sopenharmony_ci    static const std::string CREATEJITCOMPILETASK = "CreateJitCompilerTask";
2434514f5e3Sopenharmony_ci    static const std::string JITCOMPILEINIT = "InitJitCompiler";
2444514f5e3Sopenharmony_ci    static const std::string JITCOMPILE = "JitCompile";
2454514f5e3Sopenharmony_ci    static const std::string JITFINALIZE = "JitFinalize";
2464514f5e3Sopenharmony_ci    static const std::string DELETEJITCOMPILE = "DeleteJitCompile";
2474514f5e3Sopenharmony_ci    static const std::string LIBARK_JSOPTIMIZER = "libark_jsoptimizer.so";
2484514f5e3Sopenharmony_ci
2494514f5e3Sopenharmony_ci    libHandle_ = LoadLib(LIBARK_JSOPTIMIZER);
2504514f5e3Sopenharmony_ci    if (libHandle_ == nullptr) {
2514514f5e3Sopenharmony_ci        char *error = LoadLibError();
2524514f5e3Sopenharmony_ci        LOG_JIT(ERROR) << "jit dlopen libark_jsoptimizer.so failed, as:" <<
2534514f5e3Sopenharmony_ci            ((error == nullptr) ? "unknown error" : error);
2544514f5e3Sopenharmony_ci        return;
2554514f5e3Sopenharmony_ci    }
2564514f5e3Sopenharmony_ci
2574514f5e3Sopenharmony_ci    initJitCompiler_ = reinterpret_cast<void(*)(JSRuntimeOptions)>(FindSymbol(libHandle_, JITCOMPILEINIT.c_str()));
2584514f5e3Sopenharmony_ci    if (initJitCompiler_ == nullptr) {
2594514f5e3Sopenharmony_ci        LOG_JIT(ERROR) << "jit can't find symbol initJitCompiler";
2604514f5e3Sopenharmony_ci        return;
2614514f5e3Sopenharmony_ci    }
2624514f5e3Sopenharmony_ci    jitCompile_ = reinterpret_cast<bool(*)(void*, JitTask*)>(FindSymbol(libHandle_, JITCOMPILE.c_str()));
2634514f5e3Sopenharmony_ci    if (jitCompile_ == nullptr) {
2644514f5e3Sopenharmony_ci        LOG_JIT(ERROR) << "jit can't find symbol jitCompile";
2654514f5e3Sopenharmony_ci        return;
2664514f5e3Sopenharmony_ci    }
2674514f5e3Sopenharmony_ci
2684514f5e3Sopenharmony_ci    jitFinalize_ = reinterpret_cast<bool(*)(void*, JitTask*)>(FindSymbol(libHandle_, JITFINALIZE.c_str()));
2694514f5e3Sopenharmony_ci    if (jitFinalize_ == nullptr) {
2704514f5e3Sopenharmony_ci        LOG_JIT(ERROR) << "jit can't find symbol jitFinalize";
2714514f5e3Sopenharmony_ci        return;
2724514f5e3Sopenharmony_ci    }
2734514f5e3Sopenharmony_ci
2744514f5e3Sopenharmony_ci    createJitCompilerTask_ = reinterpret_cast<void*(*)(JitTask*)>(FindSymbol(libHandle_,
2754514f5e3Sopenharmony_ci        CREATEJITCOMPILETASK.c_str()));
2764514f5e3Sopenharmony_ci    if (createJitCompilerTask_ == nullptr) {
2774514f5e3Sopenharmony_ci        LOG_JIT(ERROR) << "jit can't find symbol createJitCompilertask";
2784514f5e3Sopenharmony_ci        return;
2794514f5e3Sopenharmony_ci    }
2804514f5e3Sopenharmony_ci
2814514f5e3Sopenharmony_ci    deleteJitCompile_ = reinterpret_cast<void(*)(void*)>(FindSymbol(libHandle_, DELETEJITCOMPILE.c_str()));
2824514f5e3Sopenharmony_ci    if (deleteJitCompile_ == nullptr) {
2834514f5e3Sopenharmony_ci        LOG_JIT(ERROR) << "jit can't find symbol deleteJitCompile";
2844514f5e3Sopenharmony_ci        return;
2854514f5e3Sopenharmony_ci    }
2864514f5e3Sopenharmony_ci    initialized_= true;
2874514f5e3Sopenharmony_ci    return;
2884514f5e3Sopenharmony_ci}
2894514f5e3Sopenharmony_ci
2904514f5e3Sopenharmony_ciJit::~Jit()
2914514f5e3Sopenharmony_ci{
2924514f5e3Sopenharmony_ci}
2934514f5e3Sopenharmony_ci
2944514f5e3Sopenharmony_cibool Jit::SupportJIT(JSHandle<JSFunction> &jsFunction, [[maybe_unused]] EcmaVM *vm, CompilerTier tier) const
2954514f5e3Sopenharmony_ci{
2964514f5e3Sopenharmony_ci    Method *method = Method::Cast(jsFunction->GetMethod().GetTaggedObject());
2974514f5e3Sopenharmony_ci    if (jsFunction.GetTaggedValue().IsJSSharedFunction()) {
2984514f5e3Sopenharmony_ci        LOG_JIT(DEBUG) << "method does not support compile shared function:" <<
2994514f5e3Sopenharmony_ci            method->GetRecordNameStr() + "." + method->GetMethodName();
3004514f5e3Sopenharmony_ci        return false;
3014514f5e3Sopenharmony_ci    }
3024514f5e3Sopenharmony_ci
3034514f5e3Sopenharmony_ci    FunctionKind kind = method->GetFunctionKind();
3044514f5e3Sopenharmony_ci    switch (kind) {
3054514f5e3Sopenharmony_ci        case FunctionKind::NORMAL_FUNCTION:
3064514f5e3Sopenharmony_ci        case FunctionKind::GETTER_FUNCTION:
3074514f5e3Sopenharmony_ci        case FunctionKind::SETTER_FUNCTION:
3084514f5e3Sopenharmony_ci        case FunctionKind::ARROW_FUNCTION:
3094514f5e3Sopenharmony_ci        case FunctionKind::BASE_CONSTRUCTOR:
3104514f5e3Sopenharmony_ci        case FunctionKind::CLASS_CONSTRUCTOR:
3114514f5e3Sopenharmony_ci        case FunctionKind::DERIVED_CONSTRUCTOR:
3124514f5e3Sopenharmony_ci        case FunctionKind::NONE_FUNCTION:
3134514f5e3Sopenharmony_ci            return true;
3144514f5e3Sopenharmony_ci        default:
3154514f5e3Sopenharmony_ci            break;
3164514f5e3Sopenharmony_ci    }
3174514f5e3Sopenharmony_ci    std::stringstream msgStr;
3184514f5e3Sopenharmony_ci    msgStr << "method does not support jit:" << method->GetRecordNameStr() + "." + method->GetMethodName() <<
3194514f5e3Sopenharmony_ci     ", kind:" << static_cast<int>(kind);
3204514f5e3Sopenharmony_ci    if (tier == CompilerTier::BASELINE) {
3214514f5e3Sopenharmony_ci        LOG_BASELINEJIT(DEBUG) << msgStr.str();
3224514f5e3Sopenharmony_ci    } else {
3234514f5e3Sopenharmony_ci        LOG_JIT(DEBUG) << msgStr.str();
3244514f5e3Sopenharmony_ci    }
3254514f5e3Sopenharmony_ci    return false;
3264514f5e3Sopenharmony_ci}
3274514f5e3Sopenharmony_ci
3284514f5e3Sopenharmony_civoid Jit::DeleteJitCompile(void *compiler)
3294514f5e3Sopenharmony_ci{
3304514f5e3Sopenharmony_ci    deleteJitCompile_(compiler);
3314514f5e3Sopenharmony_ci}
3324514f5e3Sopenharmony_ci
3334514f5e3Sopenharmony_civoid Jit::CountInterpExecFuncs(JSHandle<JSFunction> &jsFunction)
3344514f5e3Sopenharmony_ci{
3354514f5e3Sopenharmony_ci    Method *method = Method::Cast(jsFunction->GetMethod().GetTaggedObject());
3364514f5e3Sopenharmony_ci    auto jSPandaFile = method->GetJSPandaFile();
3374514f5e3Sopenharmony_ci    ASSERT(jSPandaFile != nullptr);
3384514f5e3Sopenharmony_ci    CString fileDesc = jSPandaFile->GetJSPandaFileDesc();
3394514f5e3Sopenharmony_ci    CString methodInfo = fileDesc + ":" + method->GetRecordNameStr() + "." + CString(method->GetMethodName());
3404514f5e3Sopenharmony_ci    auto &profMap = JitWarmupProfiler::GetInstance()->profMap_;
3414514f5e3Sopenharmony_ci    if (profMap.find(methodInfo) == profMap.end()) {
3424514f5e3Sopenharmony_ci        profMap.insert({methodInfo, false});
3434514f5e3Sopenharmony_ci    }
3444514f5e3Sopenharmony_ci}
3454514f5e3Sopenharmony_ci
3464514f5e3Sopenharmony_civoid Jit::Compile(EcmaVM *vm, JSHandle<JSFunction> &jsFunction, CompilerTier tier,
3474514f5e3Sopenharmony_ci                  int32_t offset, JitCompileMode mode)
3484514f5e3Sopenharmony_ci{
3494514f5e3Sopenharmony_ci    auto jit = Jit::GetInstance();
3504514f5e3Sopenharmony_ci    if ((!jit->IsEnableBaselineJit() && tier == CompilerTier::BASELINE) ||
3514514f5e3Sopenharmony_ci        (!jit->IsEnableFastJit() && tier == CompilerTier::FAST)) {
3524514f5e3Sopenharmony_ci        return;
3534514f5e3Sopenharmony_ci    }
3544514f5e3Sopenharmony_ci
3554514f5e3Sopenharmony_ci    if (!vm->IsEnableOsr() && offset != MachineCode::INVALID_OSR_OFFSET) {
3564514f5e3Sopenharmony_ci        return;
3574514f5e3Sopenharmony_ci    }
3584514f5e3Sopenharmony_ci
3594514f5e3Sopenharmony_ci    Method *method = Method::Cast(jsFunction->GetMethod().GetTaggedObject());
3604514f5e3Sopenharmony_ci    auto jSPandaFile = method->GetJSPandaFile();
3614514f5e3Sopenharmony_ci    ASSERT(jSPandaFile != nullptr);
3624514f5e3Sopenharmony_ci    CString fileDesc = jSPandaFile->GetJSPandaFileDesc();
3634514f5e3Sopenharmony_ci    CString methodName = fileDesc + ":" + method->GetRecordNameStr() + "." + CString(method->GetMethodName());
3644514f5e3Sopenharmony_ci    uint32_t codeSize = method->GetCodeSize();
3654514f5e3Sopenharmony_ci    CString methodInfo = methodName + ", bytecode size:" + ToCString(codeSize);
3664514f5e3Sopenharmony_ci    ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, ConvertToStdString("JIT::Compile:" + methodInfo));
3674514f5e3Sopenharmony_ci
3684514f5e3Sopenharmony_ci    uint32_t maxSize = 9000;
3694514f5e3Sopenharmony_ci    if (vm->GetJSOptions().IsEnableJitFastCompile()) {
3704514f5e3Sopenharmony_ci        maxSize = 15; // 15 is method codesize threshold during fast compiling
3714514f5e3Sopenharmony_ci    }
3724514f5e3Sopenharmony_ci    if (codeSize > maxSize && !(vm->GetJSOptions().IsEnableForceJitCompileMain() && mode == SYNC)) {
3734514f5e3Sopenharmony_ci        if (tier == CompilerTier::BASELINE) {
3744514f5e3Sopenharmony_ci            LOG_BASELINEJIT(DEBUG) << "skip jit task, as too large:" << methodInfo;
3754514f5e3Sopenharmony_ci        } else {
3764514f5e3Sopenharmony_ci            LOG_JIT(DEBUG) << "skip jit task, as too large:" << methodInfo;
3774514f5e3Sopenharmony_ci        }
3784514f5e3Sopenharmony_ci
3794514f5e3Sopenharmony_ci        return;
3804514f5e3Sopenharmony_ci    }
3814514f5e3Sopenharmony_ci    if (vm->IsEnableOsr() && offset != MachineCode::INVALID_OSR_OFFSET && method->HasCatchBlock()) {
3824514f5e3Sopenharmony_ci        LOG_JIT(DEBUG) << "skip jit task, as osr does not support catch blocks: " << methodInfo;
3834514f5e3Sopenharmony_ci        return;
3844514f5e3Sopenharmony_ci    }
3854514f5e3Sopenharmony_ci
3864514f5e3Sopenharmony_ci    CString msg = "compile method:" + methodInfo + ", in work thread";
3874514f5e3Sopenharmony_ci    TimeScope scope(vm, msg, tier, true, true);
3884514f5e3Sopenharmony_ci    if (vm->GetJSThread()->IsMachineCodeLowMemory()) {
3894514f5e3Sopenharmony_ci        if (tier == CompilerTier::BASELINE) {
3904514f5e3Sopenharmony_ci            LOG_BASELINEJIT(DEBUG) << "skip jit task, as low code memory:" << methodInfo;
3914514f5e3Sopenharmony_ci        } else {
3924514f5e3Sopenharmony_ci            LOG_JIT(DEBUG) << "skip jit task, as low code memory:" << methodInfo;
3934514f5e3Sopenharmony_ci        }
3944514f5e3Sopenharmony_ci
3954514f5e3Sopenharmony_ci        return;
3964514f5e3Sopenharmony_ci    }
3974514f5e3Sopenharmony_ci    if (!jit->SupportJIT(jsFunction, vm, tier)) {
3984514f5e3Sopenharmony_ci        return;
3994514f5e3Sopenharmony_ci    }
4004514f5e3Sopenharmony_ci    bool needCompile = jit->CheckJitCompileStatus(jsFunction, methodName, tier);
4014514f5e3Sopenharmony_ci    if (!needCompile) {
4024514f5e3Sopenharmony_ci        return;
4034514f5e3Sopenharmony_ci    }
4044514f5e3Sopenharmony_ci
4054514f5e3Sopenharmony_ci    // using hole value to indecate compiling. todo: reset when failed
4064514f5e3Sopenharmony_ci    if (tier == CompilerTier::FAST) {
4074514f5e3Sopenharmony_ci        jsFunction->SetMachineCode(vm->GetJSThread(), JSTaggedValue::Hole());
4084514f5e3Sopenharmony_ci        jit->GetJitDfx()->SetTriggerCount(false);
4094514f5e3Sopenharmony_ci    } else {
4104514f5e3Sopenharmony_ci        ASSERT(tier == CompilerTier::BASELINE);
4114514f5e3Sopenharmony_ci        jsFunction->SetBaselineCode(vm->GetJSThread(), JSTaggedValue::Hole());
4124514f5e3Sopenharmony_ci        jit->GetJitDfx()->SetTriggerCount(true);
4134514f5e3Sopenharmony_ci    }
4144514f5e3Sopenharmony_ci
4154514f5e3Sopenharmony_ci    {
4164514f5e3Sopenharmony_ci        JitTaskpool::GetCurrentTaskpool()->WaitForJitTaskPoolReady();
4174514f5e3Sopenharmony_ci        EcmaVM *compilerVm = JitTaskpool::GetCurrentTaskpool()->GetCompilerVm();
4184514f5e3Sopenharmony_ci        std::shared_ptr<JitTask> jitTask = std::make_shared<JitTask>(vm->GetJSThread(),
4194514f5e3Sopenharmony_ci            // avoid check fail when enable multi-thread check
4204514f5e3Sopenharmony_ci            compilerVm->GetJSThreadNoCheck(),
4214514f5e3Sopenharmony_ci            jit, jsFunction, tier, methodName, offset, vm->GetJSThread()->GetThreadId(), mode);
4224514f5e3Sopenharmony_ci
4234514f5e3Sopenharmony_ci        jitTask->PrepareCompile();
4244514f5e3Sopenharmony_ci        JitTaskpool::GetCurrentTaskpool()->PostTask(
4254514f5e3Sopenharmony_ci            std::make_unique<JitTask::AsyncTask>(jitTask, vm->GetJSThread()->GetThreadId()));
4264514f5e3Sopenharmony_ci        if (mode == SYNC) {
4274514f5e3Sopenharmony_ci            // sync mode, also compile in taskpool as litecg unsupport parallel compile,
4284514f5e3Sopenharmony_ci            // wait task compile finish then install code
4294514f5e3Sopenharmony_ci            jitTask->WaitFinish();
4304514f5e3Sopenharmony_ci            jitTask->InstallCode();
4314514f5e3Sopenharmony_ci        }
4324514f5e3Sopenharmony_ci        int spendTime = scope.TotalSpentTimeInMicroseconds();
4334514f5e3Sopenharmony_ci        jitTask->SetMainThreadCompilerTime(spendTime);
4344514f5e3Sopenharmony_ci        jit->GetJitDfx()->RecordSpentTimeAndPrintStatsLogInJsThread(spendTime);
4354514f5e3Sopenharmony_ci    }
4364514f5e3Sopenharmony_ci}
4374514f5e3Sopenharmony_ci
4384514f5e3Sopenharmony_civoid Jit::RequestInstallCode(std::shared_ptr<JitTask> jitTask)
4394514f5e3Sopenharmony_ci{
4404514f5e3Sopenharmony_ci    LockHolder holder(threadTaskInfoLock_);
4414514f5e3Sopenharmony_ci    ThreadTaskInfo &info = threadTaskInfo_[jitTask->GetHostThread()];
4424514f5e3Sopenharmony_ci    if (info.skipInstallTask_) {
4434514f5e3Sopenharmony_ci        return;
4444514f5e3Sopenharmony_ci    }
4454514f5e3Sopenharmony_ci    info.installJitTasks_.push_back(jitTask);
4464514f5e3Sopenharmony_ci
4474514f5e3Sopenharmony_ci    // set
4484514f5e3Sopenharmony_ci    jitTask->GetHostThread()->SetInstallMachineCode(true);
4494514f5e3Sopenharmony_ci    jitTask->GetHostThread()->SetCheckSafePointStatus();
4504514f5e3Sopenharmony_ci}
4514514f5e3Sopenharmony_ci
4524514f5e3Sopenharmony_cibool Jit::CheckJitCompileStatus(JSHandle<JSFunction> &jsFunction,
4534514f5e3Sopenharmony_ci                                const CString &methodName, CompilerTier tier)
4544514f5e3Sopenharmony_ci{
4554514f5e3Sopenharmony_ci    if (tier == CompilerTier::FAST &&
4564514f5e3Sopenharmony_ci        jsFunction->GetMachineCode() == JSTaggedValue::Hole()) {
4574514f5e3Sopenharmony_ci        LOG_JIT(DEBUG) << "skip method, as it compiling:" << methodName;
4584514f5e3Sopenharmony_ci#if ECMASCRIPT_ENABLE_JIT_WARMUP_PROFILER
4594514f5e3Sopenharmony_ci        auto &profMap = JitWarmupProfiler::GetInstance()->profMap_;
4604514f5e3Sopenharmony_ci        if (profMap.find(methodName) != profMap.end()) {
4614514f5e3Sopenharmony_ci            profMap.erase(methodName);
4624514f5e3Sopenharmony_ci        }
4634514f5e3Sopenharmony_ci#endif
4644514f5e3Sopenharmony_ci        return false;
4654514f5e3Sopenharmony_ci    }
4664514f5e3Sopenharmony_ci
4674514f5e3Sopenharmony_ci    if (tier == CompilerTier::BASELINE &&
4684514f5e3Sopenharmony_ci        jsFunction->GetBaselineCode() == JSTaggedValue::Hole()) {
4694514f5e3Sopenharmony_ci        LOG_BASELINEJIT(DEBUG) << "skip method, as it compiling:" << methodName;
4704514f5e3Sopenharmony_ci        return false;
4714514f5e3Sopenharmony_ci    }
4724514f5e3Sopenharmony_ci
4734514f5e3Sopenharmony_ci    if (tier == CompilerTier::FAST && jsFunction->IsCompiledCode()) {
4744514f5e3Sopenharmony_ci        JSTaggedValue machineCode = jsFunction->GetMachineCode();
4754514f5e3Sopenharmony_ci        if (machineCode.IsMachineCodeObject() &&
4764514f5e3Sopenharmony_ci            MachineCode::Cast(machineCode.GetTaggedObject())->GetOSROffset() == MachineCode::INVALID_OSR_OFFSET) {
4774514f5e3Sopenharmony_ci            LOG_JIT(DEBUG) << "skip method, as it has been jit compiled:" << methodName;
4784514f5e3Sopenharmony_ci            return false;
4794514f5e3Sopenharmony_ci        }
4804514f5e3Sopenharmony_ci        return true;
4814514f5e3Sopenharmony_ci    }
4824514f5e3Sopenharmony_ci
4834514f5e3Sopenharmony_ci    if (tier == CompilerTier::BASELINE &&
4844514f5e3Sopenharmony_ci        jsFunction->GetBaselineCode() != JSTaggedValue::Undefined()) {
4854514f5e3Sopenharmony_ci        LOG_BASELINEJIT(DEBUG) << "skip method, as it has been jit compiled:" << methodName;
4864514f5e3Sopenharmony_ci        return false;
4874514f5e3Sopenharmony_ci    }
4884514f5e3Sopenharmony_ci    return true;
4894514f5e3Sopenharmony_ci}
4904514f5e3Sopenharmony_ci
4914514f5e3Sopenharmony_ciuint32_t Jit::GetRunningTaskCnt(EcmaVM *vm)
4924514f5e3Sopenharmony_ci{
4934514f5e3Sopenharmony_ci    uint32_t cnt = 0;
4944514f5e3Sopenharmony_ci    JitTaskpool::GetCurrentTaskpool()->ForEachTask([&cnt, &vm](Task *task) {
4954514f5e3Sopenharmony_ci        JitTask::AsyncTask *asyncTask = static_cast<JitTask::AsyncTask*>(task);
4964514f5e3Sopenharmony_ci        if (asyncTask->GetHostVM() == vm) {
4974514f5e3Sopenharmony_ci            cnt ++;
4984514f5e3Sopenharmony_ci        }
4994514f5e3Sopenharmony_ci    });
5004514f5e3Sopenharmony_ci    LockHolder holder(threadTaskInfoLock_);
5014514f5e3Sopenharmony_ci    ThreadTaskInfo &info = threadTaskInfo_[vm->GetJSThread()];
5024514f5e3Sopenharmony_ci    auto &taskQueue = info.installJitTasks_;
5034514f5e3Sopenharmony_ci    return taskQueue.size() + cnt;
5044514f5e3Sopenharmony_ci}
5054514f5e3Sopenharmony_ci
5064514f5e3Sopenharmony_civoid Jit::InstallTasks(JSThread *jsThread)
5074514f5e3Sopenharmony_ci{
5084514f5e3Sopenharmony_ci    LockHolder holder(threadTaskInfoLock_);
5094514f5e3Sopenharmony_ci    ThreadTaskInfo &info = threadTaskInfo_[jsThread];
5104514f5e3Sopenharmony_ci    auto &taskQueue = info.installJitTasks_;
5114514f5e3Sopenharmony_ci
5124514f5e3Sopenharmony_ci    ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, ConvertToStdString("Jit::InstallTasks count:" + ToCString(taskQueue.size())));
5134514f5e3Sopenharmony_ci
5144514f5e3Sopenharmony_ci    for (auto it = taskQueue.begin(); it != taskQueue.end(); it++) {
5154514f5e3Sopenharmony_ci        std::shared_ptr<JitTask> task = *it;
5164514f5e3Sopenharmony_ci        // check task state
5174514f5e3Sopenharmony_ci        task->InstallCode();
5184514f5e3Sopenharmony_ci    }
5194514f5e3Sopenharmony_ci    taskQueue.clear();
5204514f5e3Sopenharmony_ci}
5214514f5e3Sopenharmony_ci
5224514f5e3Sopenharmony_cibool Jit::JitCompile(void *compiler, JitTask *jitTask)
5234514f5e3Sopenharmony_ci{
5244514f5e3Sopenharmony_ci    ASSERT(jitCompile_ != nullptr);
5254514f5e3Sopenharmony_ci    return jitCompile_(compiler, jitTask);
5264514f5e3Sopenharmony_ci}
5274514f5e3Sopenharmony_ci
5284514f5e3Sopenharmony_cibool Jit::JitFinalize(void *compiler, JitTask *jitTask)
5294514f5e3Sopenharmony_ci{
5304514f5e3Sopenharmony_ci    ASSERT(jitFinalize_ != nullptr);
5314514f5e3Sopenharmony_ci    return jitFinalize_(compiler, jitTask);
5324514f5e3Sopenharmony_ci}
5334514f5e3Sopenharmony_ci
5344514f5e3Sopenharmony_civoid *Jit::CreateJitCompilerTask(JitTask *jitTask)
5354514f5e3Sopenharmony_ci{
5364514f5e3Sopenharmony_ci    ASSERT(createJitCompilerTask_ != nullptr);
5374514f5e3Sopenharmony_ci    return createJitCompilerTask_(jitTask);
5384514f5e3Sopenharmony_ci}
5394514f5e3Sopenharmony_ci
5404514f5e3Sopenharmony_civoid Jit::ClearTask(const std::function<bool(Task *task)> &checkClear)
5414514f5e3Sopenharmony_ci{
5424514f5e3Sopenharmony_ci    JitTaskpool::GetCurrentTaskpool()->ForEachTask([&checkClear](Task *task) {
5434514f5e3Sopenharmony_ci        JitTask::AsyncTask *asyncTask = static_cast<JitTask::AsyncTask*>(task);
5444514f5e3Sopenharmony_ci        if (checkClear(asyncTask)) {
5454514f5e3Sopenharmony_ci            asyncTask->Terminated();
5464514f5e3Sopenharmony_ci        }
5474514f5e3Sopenharmony_ci    });
5484514f5e3Sopenharmony_ci}
5494514f5e3Sopenharmony_ci
5504514f5e3Sopenharmony_civoid Jit::ClearTask(EcmaContext *ecmaContext)
5514514f5e3Sopenharmony_ci{
5524514f5e3Sopenharmony_ci    ClearTask([ecmaContext](Task *task) {
5534514f5e3Sopenharmony_ci        JitTask::AsyncTask *asyncTask = static_cast<JitTask::AsyncTask*>(task);
5544514f5e3Sopenharmony_ci        return ecmaContext == asyncTask->GetEcmaContext();
5554514f5e3Sopenharmony_ci    });
5564514f5e3Sopenharmony_ci}
5574514f5e3Sopenharmony_ci
5584514f5e3Sopenharmony_civoid Jit::ClearTaskWithVm(EcmaVM *vm)
5594514f5e3Sopenharmony_ci{
5604514f5e3Sopenharmony_ci    ClearTask([vm](Task *task) {
5614514f5e3Sopenharmony_ci        JitTask::AsyncTask *asyncTask = static_cast<JitTask::AsyncTask*>(task);
5624514f5e3Sopenharmony_ci        return vm == asyncTask->GetHostVM();
5634514f5e3Sopenharmony_ci    });
5644514f5e3Sopenharmony_ci
5654514f5e3Sopenharmony_ci    {
5664514f5e3Sopenharmony_ci        LockHolder holder(threadTaskInfoLock_);
5674514f5e3Sopenharmony_ci        ThreadTaskInfo &info = threadTaskInfo_[vm->GetJSThread()];
5684514f5e3Sopenharmony_ci        info.skipInstallTask_ = true;
5694514f5e3Sopenharmony_ci        auto &taskQueue = info.installJitTasks_;
5704514f5e3Sopenharmony_ci        taskQueue.clear();
5714514f5e3Sopenharmony_ci
5724514f5e3Sopenharmony_ci        if (info.jitTaskCnt_.load() != 0) {
5734514f5e3Sopenharmony_ci            info.jitTaskCntCv_.Wait(&threadTaskInfoLock_);
5744514f5e3Sopenharmony_ci        }
5754514f5e3Sopenharmony_ci    }
5764514f5e3Sopenharmony_ci}
5774514f5e3Sopenharmony_ci
5784514f5e3Sopenharmony_civoid Jit::IncJitTaskCnt(JSThread *thread)
5794514f5e3Sopenharmony_ci{
5804514f5e3Sopenharmony_ci    LockHolder holder(threadTaskInfoLock_);
5814514f5e3Sopenharmony_ci    ThreadTaskInfo &info = threadTaskInfo_[thread];
5824514f5e3Sopenharmony_ci    info.jitTaskCnt_.fetch_add(1);
5834514f5e3Sopenharmony_ci}
5844514f5e3Sopenharmony_ci
5854514f5e3Sopenharmony_civoid Jit::DecJitTaskCnt(JSThread *thread)
5864514f5e3Sopenharmony_ci{
5874514f5e3Sopenharmony_ci    LockHolder holder(threadTaskInfoLock_);
5884514f5e3Sopenharmony_ci    ThreadTaskInfo &info = threadTaskInfo_[thread];
5894514f5e3Sopenharmony_ci    uint32_t old = info.jitTaskCnt_.fetch_sub(1);
5904514f5e3Sopenharmony_ci    if (old == 1) {
5914514f5e3Sopenharmony_ci        info.jitTaskCntCv_.Signal();
5924514f5e3Sopenharmony_ci    }
5934514f5e3Sopenharmony_ci}
5944514f5e3Sopenharmony_ci
5954514f5e3Sopenharmony_civoid Jit::CheckMechineCodeSpaceMemory(JSThread *thread, int remainSize)
5964514f5e3Sopenharmony_ci{
5974514f5e3Sopenharmony_ci    if (!thread->IsMachineCodeLowMemory()) {
5984514f5e3Sopenharmony_ci        return;
5994514f5e3Sopenharmony_ci    }
6004514f5e3Sopenharmony_ci    if (remainSize > MIN_CODE_SPACE_SIZE) {
6014514f5e3Sopenharmony_ci        thread->SetMachineCodeLowMemory(false);
6024514f5e3Sopenharmony_ci    }
6034514f5e3Sopenharmony_ci}
6044514f5e3Sopenharmony_ci
6054514f5e3Sopenharmony_civoid Jit::ChangeTaskPoolState(bool inBackground)
6064514f5e3Sopenharmony_ci{
6074514f5e3Sopenharmony_ci    if (fastJitEnable_ || baselineJitEnable_) {
6084514f5e3Sopenharmony_ci        if (inBackground) {
6094514f5e3Sopenharmony_ci            JitTaskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::BACKGROUND);
6104514f5e3Sopenharmony_ci        } else {
6114514f5e3Sopenharmony_ci            JitTaskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::FOREGROUND);
6124514f5e3Sopenharmony_ci        }
6134514f5e3Sopenharmony_ci    }
6144514f5e3Sopenharmony_ci}
6154514f5e3Sopenharmony_ci
6164514f5e3Sopenharmony_ciJit::TimeScope::~TimeScope()
6174514f5e3Sopenharmony_ci{
6184514f5e3Sopenharmony_ci    if (!outPutLog_) {
6194514f5e3Sopenharmony_ci        return;
6204514f5e3Sopenharmony_ci    }
6214514f5e3Sopenharmony_ci    if (isDebugLevel_) {
6224514f5e3Sopenharmony_ci        if (tier_ == CompilerTier::BASELINE) {
6234514f5e3Sopenharmony_ci            LOG_BASELINEJIT(DEBUG) << message_ << ": " << TotalSpentTime() << "ms";
6244514f5e3Sopenharmony_ci            return;
6254514f5e3Sopenharmony_ci        }
6264514f5e3Sopenharmony_ci        ASSERT(tier_ == CompilerTier::FAST);
6274514f5e3Sopenharmony_ci        LOG_JIT(DEBUG) << message_ << ": " << TotalSpentTime() << "ms";
6284514f5e3Sopenharmony_ci    } else {
6294514f5e3Sopenharmony_ci        if (tier_ == CompilerTier::BASELINE) {
6304514f5e3Sopenharmony_ci            LOG_BASELINEJIT(INFO) << message_ << ": " << TotalSpentTime() << "ms";
6314514f5e3Sopenharmony_ci            return;
6324514f5e3Sopenharmony_ci        }
6334514f5e3Sopenharmony_ci        ASSERT(tier_ == CompilerTier::FAST);
6344514f5e3Sopenharmony_ci        auto bundleName = vm_->GetBundleName();
6354514f5e3Sopenharmony_ci        if (vm_->GetEnableJitLogSkip() && bundleName != "" && message_.find(bundleName) == std::string::npos) {
6364514f5e3Sopenharmony_ci            return;
6374514f5e3Sopenharmony_ci        }
6384514f5e3Sopenharmony_ci        LOG_JIT(INFO) << message_ << ": " << TotalSpentTime() << "ms";
6394514f5e3Sopenharmony_ci    }
6404514f5e3Sopenharmony_ci}
6414514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
642