• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #ifndef ECMASCRIPT_JS_RUNTIME_OPTIONS_H_
17 #define ECMASCRIPT_JS_RUNTIME_OPTIONS_H_
18 
19 #include "runtime/include/runtime_options.h"
20 #include "utils/logger.h"
21 
22 // namespace panda {
23 namespace panda::ecmascript {
24 enum ArkProperties {
25     DEFAULT = -1,
26     OPTIONAL_LOG = 1,
27     GC_STATS_PRINT = 1 << 1,
28     PARALLEL_GC = 1 << 2,
29     CONCURRENT_MARK = 1 << 3,
30     CONCURRENT_SWEEP = 1 << 4,
31     THREAD_CHECK = 1 << 5,
32 };
33 
34 class JSRuntimeOptions : public RuntimeOptions {
35 public:
RuntimeOptions(exePath)36     explicit JSRuntimeOptions(const std::string &exePath = "") : RuntimeOptions(exePath) {}
37     ~JSRuntimeOptions() = default;
38     DEFAULT_COPY_SEMANTIC(JSRuntimeOptions);
39     DEFAULT_MOVE_SEMANTIC(JSRuntimeOptions);
40 
AddOptions(PandArgParser * parser)41     void AddOptions(PandArgParser *parser)
42     {
43         RuntimeOptions::AddOptions(parser);
44         parser->Add(&enableArkTools_);
45         parser->Add(&enableStubAot_);
46         parser->Add(&stubModuleFile_);
47         parser->Add(&enableCpuprofiler_);
48         parser->Add(&arkProperties_);
49         parser->Add(&enableTsAot_);
50         parser->Add(&maxNonmovableSpaceCapacity_);
51     }
52 
IsEnableArkTools()53     bool IsEnableArkTools() const
54     {
55         return enableArkTools_.GetValue();
56     }
57 
SetEnableArkTools(bool value)58     void SetEnableArkTools(bool value)
59     {
60         enableArkTools_.SetValue(value);
61     }
62 
WasSetEnableArkTools()63     bool WasSetEnableArkTools() const
64     {
65         return enableArkTools_.WasSet();
66     }
67 
IsEnableStubAot()68     bool IsEnableStubAot() const
69     {
70         return enableStubAot_.GetValue();
71     }
72 
SetEnableStubAot(bool value)73     void SetEnableStubAot(bool value)
74     {
75         enableStubAot_.SetValue(value);
76     }
77 
WasSetEnableStubAot()78     bool WasSetEnableStubAot() const
79     {
80         return enableStubAot_.WasSet();
81     }
82 
GetStubModuleFile()83     std::string GetStubModuleFile() const
84     {
85         return stubModuleFile_.GetValue();
86     }
87 
SetStubModuleFile(std::string value)88     void SetStubModuleFile(std::string value)
89     {
90         stubModuleFile_.SetValue(std::move(value));
91     }
92 
WasSetStubModuleFile()93     bool WasSetStubModuleFile() const
94     {
95         return stubModuleFile_.WasSet();
96     }
97 
IsEnableForceGC()98     bool IsEnableForceGC() const
99     {
100         return enableForceGc_.GetValue();
101     }
102 
SetEnableForceGC(bool value)103     void SetEnableForceGC(bool value)
104     {
105         enableForceGc_.SetValue(value);
106     }
107 
IsForceFullGC()108     bool IsForceFullGC() const
109     {
110         return forceFullGc_.GetValue();
111     }
112 
SetForceFullGC(bool value)113     void SetForceFullGC(bool value)
114     {
115         forceFullGc_.SetValue(value);
116     }
117 
IsEnableCpuProfiler()118     bool IsEnableCpuProfiler() const
119     {
120         return enableCpuprofiler_.GetValue();
121     }
122 
SetEnableCpuprofiler(bool value)123     void SetEnableCpuprofiler(bool value)
124     {
125         enableCpuprofiler_.SetValue(value);
126     }
127 
IsEnableTsAot()128     bool IsEnableTsAot() const
129     {
130         return enableTsAot_.GetValue();
131     }
132 
SetEnableTsAot(bool value)133     void SetEnableTsAot(bool value)
134     {
135         enableTsAot_.SetValue(value);
136     }
137 
WasSetEnableTsAot()138     bool WasSetEnableTsAot() const
139     {
140         return enableTsAot_.WasSet();
141     }
142 
SetArkProperties(int prop)143     void SetArkProperties(int prop)
144     {
145         if (prop != ArkProperties::DEFAULT) {
146             arkProperties_.SetValue(prop);
147         }
148     }
149 
GetDefaultProperties()150     int GetDefaultProperties()
151     {
152         return ArkProperties::PARALLEL_GC | ArkProperties::CONCURRENT_MARK | ArkProperties::CONCURRENT_SWEEP;
153     }
154 
GetArkProperties()155     int GetArkProperties()
156     {
157         return arkProperties_.GetValue();
158     }
159 
IsEnableOptionalLog()160     bool IsEnableOptionalLog() const
161     {
162         return (arkProperties_.GetValue() & ArkProperties::OPTIONAL_LOG) != 0;
163     }
164 
IsEnableGCStatsPrint()165     bool IsEnableGCStatsPrint() const
166     {
167         return (arkProperties_.GetValue() & ArkProperties::GC_STATS_PRINT) != 0;
168     }
169 
IsEnableParallelGC()170     bool IsEnableParallelGC() const
171     {
172         return (arkProperties_.GetValue() & ArkProperties::PARALLEL_GC) != 0;
173     }
174 
IsEnableConcurrentMark()175     bool IsEnableConcurrentMark() const
176     {
177         return (arkProperties_.GetValue() & ArkProperties::CONCURRENT_MARK) != 0;
178     }
179 
IsEnableConcurrentSweep()180     bool IsEnableConcurrentSweep() const
181     {
182         return (arkProperties_.GetValue() & ArkProperties::CONCURRENT_SWEEP) != 0;
183     }
184 
IsEnableThreadCheck()185     bool IsEnableThreadCheck() const
186     {
187         return (arkProperties_.GetValue() & ArkProperties::THREAD_CHECK) != 0;
188     }
189 
MaxSemiSpaceCapacity()190     size_t MaxSemiSpaceCapacity() const
191     {
192         return maxSemiSpaceCapacity_.GetValue();
193     }
194 
MaxOldSpaceCapacity()195     size_t MaxOldSpaceCapacity() const
196     {
197         return maxOldSpaceCapacity_.GetValue();
198     }
199 
MaxNonmovableSpaceCapacity()200     size_t MaxNonmovableSpaceCapacity() const
201     {
202         return maxNonmovableSpaceCapacity_.GetValue();
203     }
204 
MaxMachineCodeSpaceCapacity()205     size_t MaxMachineCodeSpaceCapacity() const
206     {
207         return maxMachineCodeSpaceCapacity_.GetValue();
208     }
209 
MaxSnapshotSpaceCapacity()210     size_t MaxSnapshotSpaceCapacity() const
211     {
212         return maxSnapshotSpaceCapacity_.GetValue();
213     }
214 
DefaultSemiSpaceCapacity()215     size_t DefaultSemiSpaceCapacity() const
216     {
217         return defaultSemiSpaceCapacity_.GetValue();
218     }
219 
DefaultSnapshotSpaceCapacity()220     size_t DefaultSnapshotSpaceCapacity() const
221     {
222         return defaultSnapshotSpaceCapacity_.GetValue();
223     }
224 
225 private:
226     PandArg<bool> enableArkTools_ {"enable-ark-tools", false, R"(Enable ark tools to debug. Default: false)"};
227     PandArg<bool> enableCpuprofiler_ {"enable-cpuprofiler", false,
228         R"(Enable cpuprofiler to sample call stack and output to json file. Default: false)"};
229     PandArg<bool> enableStubAot_ {"enable-stub-aot", false, R"(enable aot of fast stub. Default: false)"};
230     PandArg<std::string> stubModuleFile_ {"stub-module-file",
231         R"(stub.m)",
232         R"(Path to stub module file. Default: "stub.m")"};
233     PandArg<bool> enableForceGc_ {"enable-force-gc", true, R"(enable force gc when allocating object)"};
234     PandArg<bool> forceFullGc_ {"force-full-gc",
235         true,
236         R"(if true trigger full gc, else trigger semi and old gc)"};
237     PandArg<int> arkProperties_ {"ark-properties", GetDefaultProperties(), R"(set ark properties)"};
238     PandArg<int> enableTsAot_ {"enable-ts-aot", false, R"(enable aot of fast stub. Default: false)"};
239     PandArg<size_t> maxSemiSpaceCapacity_ {"maxSemiSpaceCapacity",
240         16 * 1024 * 1024,
241         R"(set max semi space capacity)"};
242     PandArg<size_t> maxOldSpaceCapacity_ {"maxOldSpaceCapacity",
243         256 * 1024 * 1024,
244         R"(set max old space capacity)"};
245     PandArg<size_t> maxNonmovableSpaceCapacity_ {"maxNonmovableSpaceCapacity",
246         4 * 1024 * 1024,
247         R"(set max nonmovable space capacity)"};
248     PandArg<size_t> maxMachineCodeSpaceCapacity_ {"maxMachineCodeSpaceCapacity",
249         8 * 1024 * 1024,
250         R"(set max machine code space capacity)"};
251     PandArg<size_t> maxSnapshotSpaceCapacity_ {"maxSnapshotSpaceCapacity",
252         8 * 1024 * 1024,
253         R"(set max snapshot space capacity)"};
254     PandArg<size_t> defaultSemiSpaceCapacity_ {"defaultSemiSpaceCapacity",
255         2 * 1024 * 1024,
256         R"(set default semi space capacity)"};
257     PandArg<size_t> defaultSnapshotSpaceCapacity_ {"defaultSnapshotSpaceCapacity",
258         256 * 1024,
259         R"(set default snapshot space capacity)"};
260 };
261 }  // namespace panda::ecmascript
262 
263 #endif  // ECMASCRIPT_JS_RUNTIME_OPTIONS_H_
264