14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 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#ifndef ECMASCRIPT_JIT_TOOLS_H
164514f5e3Sopenharmony_ci#define ECMASCRIPT_JIT_TOOLS_H
174514f5e3Sopenharmony_ci
184514f5e3Sopenharmony_ci#include "ecmascript/ohos/enable_aot_list_helper.h"
194514f5e3Sopenharmony_ci#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
204514f5e3Sopenharmony_ci#include "ecmascript/platform/aot_crash_info.h"
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_ci#if defined(JIT_ESCAPE_ENABLE) || defined(GET_PARAMETER_FOR_JIT) || defined(JIT_ENABLE_CODE_SIGN)
234514f5e3Sopenharmony_ci#include "base/startup/init/interfaces/innerkits/include/syspara/parameters.h"
244514f5e3Sopenharmony_ci#endif
254514f5e3Sopenharmony_ci#if defined(JIT_ENABLE_CODE_SIGN)
264514f5e3Sopenharmony_ci#include "jit_buffer_integrity.h"
274514f5e3Sopenharmony_ci#endif
284514f5e3Sopenharmony_ci
294514f5e3Sopenharmony_cinamespace panda::ecmascript::ohos {
304514f5e3Sopenharmony_ciusing PGOProfilerManager = panda::ecmascript::pgo::PGOProfilerManager;
314514f5e3Sopenharmony_ciclass JitTools {
324514f5e3Sopenharmony_cipublic:
334514f5e3Sopenharmony_ci
344514f5e3Sopenharmony_ci    static JitTools &GetInstance()
354514f5e3Sopenharmony_ci    {
364514f5e3Sopenharmony_ci        static JitTools singleJitTools;
374514f5e3Sopenharmony_ci        return singleJitTools;
384514f5e3Sopenharmony_ci    }
394514f5e3Sopenharmony_ci
404514f5e3Sopenharmony_ci    static bool GetJitEscapeDisable()
414514f5e3Sopenharmony_ci    {
424514f5e3Sopenharmony_ci    #ifdef JIT_ESCAPE_ENABLE
434514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("ark.jit.escape.disable", false);
444514f5e3Sopenharmony_ci    #endif
454514f5e3Sopenharmony_ci        return true;
464514f5e3Sopenharmony_ci    }
474514f5e3Sopenharmony_ci
484514f5e3Sopenharmony_ci    static bool IsJitEnableLitecg(bool value)
494514f5e3Sopenharmony_ci    {
504514f5e3Sopenharmony_ci    #ifdef GET_PARAMETER_FOR_JIT
514514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("ark.jit.enable.litecg", true);
524514f5e3Sopenharmony_ci    #endif
534514f5e3Sopenharmony_ci        return value;
544514f5e3Sopenharmony_ci    }
554514f5e3Sopenharmony_ci
564514f5e3Sopenharmony_ci    static uint32_t GetJitHotnessThreshold([[maybe_unused]] uint32_t threshold)
574514f5e3Sopenharmony_ci    {
584514f5e3Sopenharmony_ci    #ifdef GET_PARAMETER_FOR_JIT
594514f5e3Sopenharmony_ci        return OHOS::system::GetUintParameter("ark.jit.hotness.threshold", threshold);
604514f5e3Sopenharmony_ci    #endif
614514f5e3Sopenharmony_ci        return threshold;
624514f5e3Sopenharmony_ci    }
634514f5e3Sopenharmony_ci
644514f5e3Sopenharmony_ci    static uint8_t GetJitCallThreshold(uint8_t threshold)
654514f5e3Sopenharmony_ci    {
664514f5e3Sopenharmony_ci    #ifdef GET_PARAMETER_FOR_JIT
674514f5e3Sopenharmony_ci        return OHOS::system::GetUintParameter("ark.jit.call.threshold", static_cast<uint8_t>(0));
684514f5e3Sopenharmony_ci    #endif
694514f5e3Sopenharmony_ci        return threshold;
704514f5e3Sopenharmony_ci    }
714514f5e3Sopenharmony_ci
724514f5e3Sopenharmony_ci    static bool GetJitDumpObjEanble()
734514f5e3Sopenharmony_ci    {
744514f5e3Sopenharmony_ci    #ifdef JIT_ESCAPE_ENABLE
754514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("ark.jit.enable.dumpobj", false);
764514f5e3Sopenharmony_ci    #endif
774514f5e3Sopenharmony_ci        return false;
784514f5e3Sopenharmony_ci    }
794514f5e3Sopenharmony_ci
804514f5e3Sopenharmony_ci    static bool GetJitFrameEnable()
814514f5e3Sopenharmony_ci    {
824514f5e3Sopenharmony_ci    #ifdef JIT_ESCAPE_ENABLE
834514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("ark.jit.enable.jitframe", false);
844514f5e3Sopenharmony_ci    #endif
854514f5e3Sopenharmony_ci        return false;
864514f5e3Sopenharmony_ci    }
874514f5e3Sopenharmony_ci
884514f5e3Sopenharmony_ci    static bool GetCodeSignDisable(bool value)
894514f5e3Sopenharmony_ci    {
904514f5e3Sopenharmony_ci    #ifdef JIT_ENABLE_CODE_SIGN
914514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("persist.ark.jit.codesign.disable", false) ||
924514f5e3Sopenharmony_ci               !OHOS::Security::CodeSign::IsSupportJitCodeSigner();
934514f5e3Sopenharmony_ci    #endif
944514f5e3Sopenharmony_ci        return value;
954514f5e3Sopenharmony_ci    }
964514f5e3Sopenharmony_ci
974514f5e3Sopenharmony_ci    static bool GetEnableJitFort(bool value)
984514f5e3Sopenharmony_ci    {
994514f5e3Sopenharmony_ci    #ifdef GET_PARAMETER_FOR_JIT
1004514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("persist.ark.jit.enable.jitfort", true);
1014514f5e3Sopenharmony_ci    #endif
1024514f5e3Sopenharmony_ci        return value;
1034514f5e3Sopenharmony_ci    }
1044514f5e3Sopenharmony_ci
1054514f5e3Sopenharmony_ci    static bool GetEnableAsyncCopyToFort(bool value)
1064514f5e3Sopenharmony_ci    {
1074514f5e3Sopenharmony_ci    #ifdef GET_PARAMETER_FOR_JIT
1084514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("persist.ark.jit.enable.async.copytofort", true);
1094514f5e3Sopenharmony_ci    #endif
1104514f5e3Sopenharmony_ci        return value;
1114514f5e3Sopenharmony_ci    }
1124514f5e3Sopenharmony_ci
1134514f5e3Sopenharmony_ci    static bool GetSkipJitLogEnable()
1144514f5e3Sopenharmony_ci    {
1154514f5e3Sopenharmony_ci    #ifdef GET_PARAMETER_FOR_JIT
1164514f5e3Sopenharmony_ci        return OHOS::system::GetBoolParameter("ark.jit.enable.jitLogSkip", true);
1174514f5e3Sopenharmony_ci    #endif
1184514f5e3Sopenharmony_ci        // host no need skip jit log
1194514f5e3Sopenharmony_ci        return false;
1204514f5e3Sopenharmony_ci    }
1214514f5e3Sopenharmony_ci};
1224514f5e3Sopenharmony_ci}
1234514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_JIT_TOOLS_H
124