1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef ECMASCRIPT_JIT_TOOLS_H
16 #define ECMASCRIPT_JIT_TOOLS_H
17 
18 #include "ecmascript/ohos/enable_aot_list_helper.h"
19 #include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
20 #include "ecmascript/platform/aot_crash_info.h"
21 
22 #if defined(JIT_ESCAPE_ENABLE) || defined(GET_PARAMETER_FOR_JIT) || defined(JIT_ENABLE_CODE_SIGN)
23 #include "base/startup/init/interfaces/innerkits/include/syspara/parameters.h"
24 #endif
25 #if defined(JIT_ENABLE_CODE_SIGN)
26 #include "jit_buffer_integrity.h"
27 #endif
28 
29 namespace panda::ecmascript::ohos {
30 using PGOProfilerManager = panda::ecmascript::pgo::PGOProfilerManager;
31 class JitTools {
32 public:
33 
GetInstance()34     static JitTools &GetInstance()
35     {
36         static JitTools singleJitTools;
37         return singleJitTools;
38     }
39 
GetJitEscapeDisable()40     static bool GetJitEscapeDisable()
41     {
42     #ifdef JIT_ESCAPE_ENABLE
43         return OHOS::system::GetBoolParameter("ark.jit.escape.disable", false);
44     #endif
45         return true;
46     }
47 
IsJitEnableLitecg(bool value)48     static bool IsJitEnableLitecg(bool value)
49     {
50     #ifdef GET_PARAMETER_FOR_JIT
51         return OHOS::system::GetBoolParameter("ark.jit.enable.litecg", true);
52     #endif
53         return value;
54     }
55 
GetJitHotnessThreshold([[maybe_unused]] uint32_t threshold)56     static uint32_t GetJitHotnessThreshold([[maybe_unused]] uint32_t threshold)
57     {
58     #ifdef GET_PARAMETER_FOR_JIT
59         return OHOS::system::GetUintParameter("ark.jit.hotness.threshold", threshold);
60     #endif
61         return threshold;
62     }
63 
GetJitCallThreshold(uint8_t threshold)64     static uint8_t GetJitCallThreshold(uint8_t threshold)
65     {
66     #ifdef GET_PARAMETER_FOR_JIT
67         return OHOS::system::GetUintParameter("ark.jit.call.threshold", static_cast<uint8_t>(0));
68     #endif
69         return threshold;
70     }
71 
GetJitDumpObjEanble()72     static bool GetJitDumpObjEanble()
73     {
74     #ifdef JIT_ESCAPE_ENABLE
75         return OHOS::system::GetBoolParameter("ark.jit.enable.dumpobj", false);
76     #endif
77         return false;
78     }
79 
GetJitFrameEnable()80     static bool GetJitFrameEnable()
81     {
82     #ifdef JIT_ESCAPE_ENABLE
83         return OHOS::system::GetBoolParameter("ark.jit.enable.jitframe", false);
84     #endif
85         return false;
86     }
87 
GetCodeSignDisable(bool value)88     static bool GetCodeSignDisable(bool value)
89     {
90     #ifdef JIT_ENABLE_CODE_SIGN
91         return OHOS::system::GetBoolParameter("persist.ark.jit.codesign.disable", false) ||
92                !OHOS::Security::CodeSign::IsSupportJitCodeSigner();
93     #endif
94         return value;
95     }
96 
GetEnableJitFort(bool value)97     static bool GetEnableJitFort(bool value)
98     {
99     #ifdef GET_PARAMETER_FOR_JIT
100         return OHOS::system::GetBoolParameter("persist.ark.jit.enable.jitfort", true);
101     #endif
102         return value;
103     }
104 
GetEnableAsyncCopyToFort(bool value)105     static bool GetEnableAsyncCopyToFort(bool value)
106     {
107     #ifdef GET_PARAMETER_FOR_JIT
108         return OHOS::system::GetBoolParameter("persist.ark.jit.enable.async.copytofort", true);
109     #endif
110         return value;
111     }
112 
GetSkipJitLogEnable()113     static bool GetSkipJitLogEnable()
114     {
115     #ifdef GET_PARAMETER_FOR_JIT
116         return OHOS::system::GetBoolParameter("ark.jit.enable.jitLogSkip", true);
117     #endif
118         // host no need skip jit log
119         return false;
120     }
121 };
122 }
123 #endif  // ECMASCRIPT_JIT_TOOLS_H
124