1 /*
2 * Copyright (c) 2022 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 #include "ecmascript/js_runtime_options.h"
17
18 #include <getopt.h>
19
20 #include "ecmascript/compiler/aot_file/an_file_data_manager.h"
21 #include "ecmascript/compiler/ecma_opcode_des.h"
22 #include "ecmascript/platform/os.h"
23
24 namespace panda::ecmascript {
25 const std::string PUBLIC_API COMMON_HELP_HEAD_MSG =
26 "Usage: jsvm <option> <filename.abc>\n"
27 "\n"
28 "Options:\n";
29
30 const std::string PUBLIC_API COMPILER_HELP_HEAD_MSG =
31 "Usage: ark_aot_compiler <option> --aot-file=<filename> <filename.abc>\n"
32 "\n"
33 "Options:\n";
34
35 const std::string PUBLIC_API STUB_HELP_HEAD_MSG =
36 "Usage: ark_stub_compiler <option>\n"
37 "\n"
38 "Options:\n";
39
40 const std::string PUBLIC_API HELP_OPTION_MSG =
41 "--aot-file: Path (file suffix not needed) to AOT output file. Default: 'aot_file'\n"
42 "--ark-properties: Set ark properties\n"
43 "--ark-bundle-name: Set ark bundle name\n"
44 "--asm-interpreter: Enable asm interpreter. Default: 'true'\n"
45 "--asm-opcode-disable-range: Opcode range when asm interpreter is enabled.\n"
46 "--builtins-lazy: Load some builtins function later.This option is only valid in workervm.\n"
47 "--compiler-log: Log Option For aot compiler and stub compiler,\n"
48 " 'none': no log,\n"
49 " 'allllircirasm' or 'all012': print all log for all methods,\n"
50 " 'allcir' or 'all0': print IR info for all methods,\n"
51 " 'allllir' or 'all1': print llir info for all methods,\n"
52 " 'allasm' or 'all2': print asm log for all methods,\n"
53 " 'alltype' or 'all3': print type infer log for all methods,\n"
54 " 'cerllircirasm' or 'cer0112': print all log for certain method defined\n"
55 " in 'mlist-for-log',\n"
56 " 'cercir' or 'cer0': print IR for methods in 'mlist-for-log',\n"
57 " 'cerasm' or 'cer2': print log for methods in 'mlist-for-log',\n"
58 " Default: 'none'\n"
59 "--compiler-log-methods: Specific method list for compiler log, only used when compiler-log. "
60 " Default: 'none'\n"
61 "--compiler-type-threshold: enable to skip methods whose type is no more than threshold. Default: -1\n"
62 "--compiler-log-snapshot: Enable to print snapshot information. Default: 'false'\n"
63 "--compiler-log-time: Enable to print pass compiler time. Default: 'false'\n"
64 "--enable-ark-tools: Enable ark tools to debug. Default: 'false'\n"
65 "--open-ark-tools: Open ark tools to return specific implementation. Default: 'false'\n"
66 "--pgo-trace: Enable pgo trace for JS runtime. Default: 'false'\n"
67 "--compiler-trace-bc: Enable tracing bytecode for aot runtime. Default: 'false'\n"
68 "--compiler-trace-deopt: Enable tracing deopt for aot runtime. Default: 'false'\n"
69 "--compiler-trace-inline: Enable tracing inline function for aot runtime. Default: 'false'\n"
70 "--compiler-trace-builtins: Enable tracing builtins function for aot runtime. Default: 'false'\n"
71 "--compiler-trace-value-numbering: Enable tracing value numbering for aot runtime. Default: 'false'\n"
72 "--compiler-max-inline-bytecodes Set max bytecodes count which aot function can be inlined. Default: '25'\n"
73 "--compiler-deopt-threshold: Set max count which aot function can occur deoptimization. Default: '10'\n"
74 "--compiler-stress-deopt: Enable stress deopt for aot compiler. Default: 'false'\n"
75 "--compiler-opt-code-profiler: Enable opt code Bytecode Statistics for aot runtime. Default: 'false'\n"
76 "--compiler-opt-bc-range: Range list for EcmaOpCode range Example '1:2,5:8'\n"
77 "--compiler-opt-bc-range-help: Range list for EcmaOpCode range help. Default: 'false''\n"
78 "--enable-force-gc: Enable force gc when allocating object. Default: 'true'\n"
79 "--force-shared-gc-frequency: How frequency force shared gc . Default: '1'\n"
80 "--enable-ic: Switch of inline cache. Default: 'true'\n"
81 "--enable-runtime-stat: Enable statistics of runtime state. Default: 'false'\n"
82 "--compiler-opt-array-bounds-check-elimination: Enable Index Check elimination. Default: 'true'\n"
83 "--compiler-opt-constant-folding: Enable constant folding. Default: 'true'\n"
84 "--compiler-opt-type-lowering: Enable all type optimization pass for aot compiler. Default: 'true'\n"
85 "--compiler-opt-early-elimination: Enable EarlyElimination for aot compiler. Default: 'true'\n"
86 "--compiler-opt-later-elimination: Enable LaterElimination for aot compiler. Default: 'true'\n"
87 "--compiler-opt-string: Enable string optimization pass for aot compiler. Default: 'true'\n"
88 "--compiler-opt-value-numbering: Enable ValueNumbering for aot compiler. Default: 'true'\n"
89 "--compiler-opt-inlining: Enable inlining function for aot compiler: Default: 'true'\n"
90 "--compiler-opt-pgotype: Enable pgo type for aot compiler: Default: 'true'\n"
91 "--compiler-opt-track-field: Enable track field for aot compiler: Default: 'false'\n"
92 "--entry-point: Full name of entrypoint function. Default: '_GLOBAL::func_main_0'\n"
93 "--force-full-gc: If true trigger full gc, else trigger semi and old gc. Default: 'true'\n"
94 "--framework-abc-file: Snapshot file. Default: 'strip.native.min.abc'\n"
95 "--gc-long-paused-time: Set gc's longPauseTime in millisecond. Default: '40'\n"
96 "--gc-thread-num: Set gc thread number. Default: '7'\n"
97 "--heap-size-limit: Max heap size (MB). Default: '512'\n"
98 "--help: Print this message and exit\n"
99 "--icu-data-path: Path to generated icu data file. Default: 'default'\n"
100 "--enable-worker: Whether is worker vm. Default: 'false'\n"
101 "--log-level: Log level: ['debug', 'info', 'warning', 'error', 'fatal'].\n"
102 "--log-components: Enable logs from specified components: ['all', 'gc', 'ecma','interpreter',\n"
103 " 'debugger', 'compiler', 'builtins', 'trace', 'jit', 'baselinejit', 'all'].\n"
104 " Default: 'all'\n"
105 "--log-debug: Enable debug or above logs for components: ['all', 'gc', 'ecma',\n"
106 " 'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
107 " 'baselinejit', 'all']. Default: 'all'\n"
108 "--log-error: Enable error log for components: ['all', 'gc', 'ecma',\n"
109 " 'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
110 " 'baselinejit', 'all']. Default: 'all'\n"
111 "--log-fatal: Enable fatal log for components: ['all', 'gc', 'ecma',\n"
112 " 'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
113 " 'baselinejit', 'all']. Default: 'all'\n"
114 "--log-info: Enable info log for components: ['all', 'gc', 'ecma',\n"
115 " 'interpreter', 'debugger', 'compiler', 'builtins', 'trace', 'jit',\n"
116 " 'baselinejit', 'all']. Default: 'all'\n"
117 "--log-warning: Enable warning log for components: ['all', 'gc', 'ecma',\n"
118 " 'interpreter', 'debugger', 'compiler', 'trace', 'jit', \n"
119 " 'baselinejit', 'builtins', 'all']. Default: 'all'\n"
120 "--compiler-opt-max-method: Enable aot compiler to skip method larger than limit (KB). Default: '32'\n"
121 "--compiler-module-methods: The number of max compiled methods in a module. Default: '100'\n"
122 "--max-unmovable-space: Set max unmovable space capacity\n"
123 "--merge-abc: ABC file is merge abc. Default: 'false'\n"
124 "--compiler-opt-level: Optimization level configuration of aot compiler. Default: '3'\n"
125 "--options: Print compiler and runtime options\n"
126 "--serializer-buffer-size-limit: Max serializer buffer size used by the VM in Byte. Default size is 2GB\n"
127 "--snapshot-file: Snapshot file. Default: '/system/etc/snapshot'\n"
128 "--startup-time: Print the start time of command execution. Default: 'false'\n"
129 "--stub-file: Path of file includes common stubs module compiled by stub compiler. \n"
130 " Default: 'stub.an'\n"
131 "--enable-pgo-profiler: Enable pgo profiler to sample jsfunction call and output to file. "
132 "Default: 'false'\n"
133 "--enable-mutant-array: Enable transition between mutant array and tagged array. Default: 'false'\n"
134 "--enable-elements-kind: Enable initialization of elements kind in array. Default: 'false'\n"
135 "--compiler-pgo-hotness-threshold: Set hotness threshold for pgo in aot compiler. Default: '2'\n"
136 "--compiler-pgo-profiler-path: The pgo file output dir or the pgo file dir of AOT compiler. Default: ''\n"
137 "--compiler-pgo-save-min-interval: Set the minimum time interval for automatically saving profile, "
138 "Unit seconds. Default: '30s'\n"
139 "--compiler-baseline-pgo: Enable compile the baseline Ap file. \n"
140 " Default: 'false'\n"
141 "--compiler-target-triple: CPU triple for aot compiler or stub compiler. \n"
142 " values: ['x86_64-unknown-linux-gnu', 'arm-unknown-linux-gnu', \n"
143 " 'aarch64-unknown-linux-gnu'], Default: 'x86_64-unknown-linux-gnu'\n"
144 "--enable-print-execute-time: Enable print execute panda file spent time\n"
145 "--compiler-verify-vtable: Verify vtable result for aot compiler. Default: 'false'\n"
146 "--compiler-select-methods Compiler selected methods for aot. Only work in full compiling mode\n"
147 " Format:--compile-methods=record1:m1,m2,record2:m3\n"
148 "--compiler-skip-methods Compiler skpped methods for aot. Only work in full compiling mode\n"
149 " Format:--compile-skip-methods=record1:m1,m2,record2:m3\n"
150 "--target-compiler-mode The compilation mode at the device side, including partial, full and none.\n"
151 " Default: ''\n"
152 "--hap-path(Deprecated) The path of the app hap. Default: ''\n"
153 "--hap-abc-offset(Deprecated) The offset of the abc file in app hap. Default: '0'\n"
154 "--hap-abc-size(Deprecated) The size of the abc file in app hap. Default: '0'\n"
155 "--compiler-fast-compile Disable some time-consuming pass. Default: 'true'\n"
156 "--compiler-no-check Enable remove checks for aot compiler. Default: 'false'\n"
157 "--compiler-pipeline-host-aot Enable pipeline host aot compiler. Default: 'false'\n"
158 "--compiler-opt-loop-peeling: Enable loop peeling for aot compiler: Default: 'true'\n"
159 "--compiler-pkg-info Specify the package json info for ark aot compiler\n"
160 "--compiler-external-pkg-info Specify the external package json info for ark aot compiler\n"
161 "--compiler-enable-external-pkg Enable compile with external package for ark aot compiler\n"
162 "--compiler-enable-lexenv-specialization: Enable replace ldlexvar with specific values: Default: 'true'\n"
163 "--compiler-enable-native-inline: Enable inline native function: Default: 'false'\n"
164 "--compiler-enable-lowering-builtin: Enable lowering global object: Default: 'false'\n"
165 "--compiler-opt-array-onheap-check: Enable TypedArray on heap check for aot compiler: Default: 'false'\n"
166 "--compiler-enable-litecg: Enable LiteCG: Default: 'false'\n"
167 "--compiler-enable-jit: Enable jit: Default: 'false'\n"
168 "--compiler-enable-osr: Enable osr: Default: 'false'\n"
169 "--compiler-enable-framework-aot: Enable frame aot: Default: 'true'\n"
170 "--compiler-enable-pgo-space: Enable pgo space used for compiler. Default: 'true'\n"
171 "--compiler-jit-hotness-threshold: Set hotness threshold for jit. Default: '2'\n"
172 "--compiler-jit-call-threshold: Set call threshold for jit. Default: '0'\n"
173 "--compiler-osr-hotness-threshold: Set hotness threshold for osr. Default: '2'\n"
174 "--compiler-force-jit-compile-main: Enable jit compile main function: Default: 'false'\n"
175 "--compiler-trace-jit: Enable trace jit: Default: 'false'\n"
176 "--compiler-enable-jit-pgo: Enable jit pgo: Default: 'true'\n"
177 "--compiler-typed-op-profiler: Enable Typed Opcode Statistics for aot runtime. Default: 'false'\n"
178 "--compiler-opt-branch-profiling: Enable branch profiling for aot compiler. Default: 'true'\n"
179 "--test-assert: Set Assert Model. Default: 'false'\n"
180 "--compiler-methods-range: Enable aot compiler to compile only in-range methods.\n"
181 " Default: '0:4294967295'\n"
182 "--compiler-codegen-options: Compile options passed to codegen. Default: ''\n"
183 "--compiler-opt-escape-analysis: Enable escape analysis for aot compiler. Default: 'true'\n"
184 "--compiler-trace-escape-analysis: Enable tracing escape analysis for aot compiler. Default: 'false'\n"
185 "--compiler-opt-induction-variable: Enable induciton variable analysis for aot compiler. Default: 'false'\n"
186 "--compiler-trace-induction-variable: Enable tracing induction variable for aot compiler. Default: 'false'\n"
187 "--compiler-memory-analysis: Enable memory analysis for aot compiler. Default: 'true'\n"
188 "--compiler-enable-jit-fast-compile: Enable jit fast compile. Default: 'false'\n"
189 "--compiler-enable-jitfort: Enable jit fort memory space. Default: 'false'\n"
190 "--compiler-codesign-disable: Disable codesign for jit fort. Default: 'true'\n"
191 "--compiler-enable-async-copytofort: Enable jit fort allocation and code copy in Jit thread. Default: 'true'\n"
192 "--compiler-pgo-force-dump: Enable pgo dump not interrupted by GC. Default: 'true'\n"
193 "--async-load-abc: Enable asynchronous load abc. Default: 'true'\n"
194 "--async-load-abc-test: Enable asynchronous load abc test. Default: 'false'\n"
195 "--compiler-enable-store-barrier: Enable store barrier optimization. Default: 'true'\n"
196 "--compiler-enable-concurrent: Enable concurrent compile(only support in ark_stub_compiler).\n"
197 "--compile-enable-jit-verify-pass: Enable jit compile with verify pass. Default: 'false'\n\n"
198 " Default: 'true'\n"
199 "--compiler-opt-frame-state-elimination: Enable frame state elimination. Default: 'true'\n"
200 "--enable-inline-property-optimization: Enable inline property optimization(also enable slack tracking).\n"
201 "--compiler-enable-aot-code-comment Enable generate aot_code_comment.txt file during compilation.\n"
202 " Default : 'false'\n"
203 "--compiler-an-file-max-size: Max size of compiler .an file in MB. '0' means Default\n"
204 " Default: No limit for Host, '100' for TargetCompilerMode\n"
205 // Please add new options above this line for keep a blank line after help message.
206 "\n";
207
ParseCommand(const int argc,const char ** argv)208 bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
209 {
210 const struct option longOptions[] = {
211 {"aot-file", required_argument, nullptr, OPTION_AOT_FILE},
212 {"ark-properties", required_argument, nullptr, OPTION_ARK_PROPERTIES},
213 {"ark-bundleName", required_argument, nullptr, OPTION_ARK_BUNDLENAME},
214 {"asm-interpreter", required_argument, nullptr, OPTION_ENABLE_ASM_INTERPRETER},
215 {"asm-opcode-disable-range", required_argument, nullptr, OPTION_ASM_OPCODE_DISABLE_RANGE},
216 {"builtins-lazy", required_argument, nullptr, OPTION_ENABLE_BUILTINS_LAZY},
217 {"compiler-log", required_argument, nullptr, OPTION_COMPILER_LOG_OPT},
218 {"compiler-log-methods", required_argument, nullptr, OPTION_COMPILER_LOG_METHODS},
219 {"compiler-log-snapshot", required_argument, nullptr, OPTION_COMPILER_LOG_SNAPSHOT},
220 {"compiler-log-time", required_argument, nullptr, OPTION_COMPILER_LOG_TIME},
221 {"compiler-type-threshold", required_argument, nullptr, OPTION_COMPILER_TYPE_THRESHOLD},
222 {"enable-ark-tools", required_argument, nullptr, OPTION_ENABLE_ARK_TOOLS},
223 {"open-ark-tools", required_argument, nullptr, OPTION_OPEN_ARK_TOOLS},
224 {"pgo-trace", required_argument, nullptr, OPTION_PGO_TRACE},
225 {"compiler-trace-bc", required_argument, nullptr, OPTION_COMPILER_TRACE_BC},
226 {"compiler-trace-deopt", required_argument, nullptr, OPTION_COMPILER_TRACE_DEOPT},
227 {"compiler-trace-inline", required_argument, nullptr, OPTION_COMPILER_TRACE_INLINE},
228 {"compiler-trace-value-numbering", required_argument, nullptr, OPTION_COMPILER_TRACE_VALUE_NUMBERING},
229 {"compiler-trace-instruction-combine", required_argument, nullptr, OPTION_COMPILER_TRACE_INSTRUCTION_COMBINE},
230 {"compiler-max-inline-bytecodes", required_argument, nullptr, OPTION_COMPILER_MAX_INLINE_BYTECODES},
231 {"compiler-deopt-threshold", required_argument, nullptr, OPTION_COMPILER_DEOPT_THRESHOLD},
232 {"compiler-device-state", required_argument, nullptr, OPTION_COMPILER_DEVICE_STATE},
233 {"compiler-thermal-level", required_argument, nullptr, OPTION_COMPILER_THERMAL_LEVEL},
234 {"compiler-stress-deopt", required_argument, nullptr, OPTION_COMPILER_STRESS_DEOPT},
235 {"compiler-opt-code-profiler", required_argument, nullptr, OPTION_COMPILER_OPT_CODE_PROFILER},
236 {"compiler-opt-bc-range", required_argument, nullptr, OPTION_COMPILER_OPT_BC_RANGE},
237 {"compiler-opt-bc-range-help", required_argument, nullptr, OPTION_COMPILER_OPT_BC_RANGE_HELP},
238 {"enable-force-gc", required_argument, nullptr, OPTION_ENABLE_FORCE_GC},
239 {"enable-ic", required_argument, nullptr, OPTION_ENABLE_IC},
240 {"enable-runtime-stat", required_argument, nullptr, OPTION_ENABLE_RUNTIME_STAT},
241 {"compiler-opt-constant-folding", required_argument, nullptr, OPTION_COMPILER_OPT_CONSTANT_FOLDING},
242 {"compiler-opt-array-bounds-check-elimination", required_argument, nullptr,
243 OPTION_COMPILER_OPT_ARRAY_BOUNDS_CHECK_ELIMINATION},
244 {"compiler-opt-type-lowering", required_argument, nullptr, OPTION_COMPILER_OPT_TYPE_LOWERING},
245 {"compiler-opt-early-elimination", required_argument, nullptr, OPTION_COMPILER_OPT_EARLY_ELIMINATION},
246 {"compiler-opt-later-elimination", required_argument, nullptr, OPTION_COMPILER_OPT_LATER_ELIMINATION},
247 {"compiler-opt-instr-combine", required_argument, nullptr, OPTION_COMPILER_OPT_INSTRUCTIONE_COMBINE},
248 {"compiler-opt-string", required_argument, nullptr, OPTION_COMPILER_OPT_STRING},
249 {"compiler-opt-value-numbering", required_argument, nullptr, OPTION_COMPILER_OPT_VALUE_NUMBERING},
250 {"compiler-opt-new-value-numbering", required_argument, nullptr, OPTION_COMPILER_OPT_NEW_VALUE_NUMBERING},
251 {"compiler-opt-inlining", required_argument, nullptr, OPTION_COMPILER_OPT_INLINING},
252 {"compiler-opt-pgotype", required_argument, nullptr, OPTION_COMPILER_OPT_PGOTYPE},
253 {"compiler-opt-track-field", required_argument, nullptr, OPTION_COMPILER_OPT_TRACK_FIELD},
254 {"entry-point", required_argument, nullptr, OPTION_ENTRY_POINT},
255 {"force-full-gc", required_argument, nullptr, OPTION_FORCE_FULL_GC},
256 {"force-shared-gc-frequency", required_argument, nullptr, OPTION_ENABLE_FORCE_SHARED_GC_FREQUENCY},
257 {"enable-heap-verify", required_argument, nullptr, OPTION_ENABLE_HEAP_VERIFY},
258 {"gc-thread-num", required_argument, nullptr, OPTION_GC_THREADNUM},
259 {"heap-size-limit", required_argument, nullptr, OPTION_HEAP_SIZE_LIMIT},
260 {"help", no_argument, nullptr, OPTION_HELP},
261 {"icu-data-path", required_argument, nullptr, OPTION_ICU_DATA_PATH},
262 {"enable-worker", required_argument, nullptr, OPTION_ENABLE_WORKER},
263 {"log-components", required_argument, nullptr, OPTION_LOG_COMPONENTS},
264 {"log-debug", required_argument, nullptr, OPTION_LOG_DEBUG},
265 {"log-error", required_argument, nullptr, OPTION_LOG_ERROR},
266 {"log-fatal", required_argument, nullptr, OPTION_LOG_FATAL},
267 {"log-info", required_argument, nullptr, OPTION_LOG_INFO},
268 {"log-level", required_argument, nullptr, OPTION_LOG_LEVEL},
269 {"log-warning", required_argument, nullptr, OPTION_LOG_WARNING},
270 {"gc-long-paused-time", required_argument, nullptr, OPTION_GC_LONG_PAUSED_TIME},
271 {"compiler-opt-max-method", required_argument, nullptr, OPTION_COMPILER_OPT_MAX_METHOD},
272 {"compiler-module-methods", required_argument, nullptr, OPTION_COMPILER_MODULE_METHODS},
273 {"max-unmovable-space", required_argument, nullptr, OPTION_MAX_UNMOVABLE_SPACE},
274 {"merge-abc", required_argument, nullptr, OPTION_MERGE_ABC},
275 {"enable-context", required_argument, nullptr, OPTION_ENABLE_CONTEXT},
276 {"compiler-opt-level", required_argument, nullptr, OPTION_ASM_OPT_LEVEL},
277 {"reloc-mode", required_argument, nullptr, OPTION_RELOCATION_MODE},
278 {"serializer-buffer-size-limit", required_argument, nullptr, OPTION_SERIALIZER_BUFFER_SIZE_LIMIT},
279 {"startup-time", required_argument, nullptr, OPTION_STARTUP_TIME},
280 {"stub-file", required_argument, nullptr, OPTION_STUB_FILE},
281 {"compiler-target-triple", required_argument, nullptr, OPTION_COMPILER_TARGET_TRIPLE},
282 {"enable-print-execute-time", required_argument, nullptr, OPTION_PRINT_EXECUTE_TIME},
283 {"enable-pgo-profiler", required_argument, nullptr, OPTION_ENABLE_PGO_PROFILER},
284 {"enable-mutant-array", required_argument, nullptr, OPTION_ENABLE_MUTANT_ARRAY},
285 {"enable-elements-kind", required_argument, nullptr, OPTION_ENABLE_ELEMENTS_KIND},
286 {"compiler-pgo-profiler-path", required_argument, nullptr, OPTION_COMPILER_PGO_PROFILER_PATH},
287 {"compiler-pgo-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_PGO_HOTNESS_THRESHOLD},
288 {"compiler-pgo-save-min-interval", required_argument, nullptr, OPTION_COMPILER_PGO_SAVE_MIN_INTERVAL},
289 {"compiler-baseline-pgo", required_argument, nullptr, OPTION_COMPILER_BASELINE_PGO},
290 {"compiler-verify-vtable", required_argument, nullptr, OPTION_COMPILER_VERIFY_VTABLE},
291 {"compiler-select-methods", required_argument, nullptr, OPTION_COMPILER_SELECT_METHODS},
292 {"compiler-skip-methods", required_argument, nullptr, OPTION_COMPILER_SKIP_METHODS},
293 {"target-compiler-mode", required_argument, nullptr, OPTION_TARGET_COMPILER_MODE},
294 {"hap-path", required_argument, nullptr, OPTION_HAP_PATH},
295 {"hap-abc-offset", required_argument, nullptr, OPTION_HAP_ABC_OFFSET},
296 {"hap-abc-size", required_argument, nullptr, OPTION_HAP_ABC_SIZE},
297 {"compiler-no-check", required_argument, nullptr, OPTION_COMPILER_NOCHECK},
298 {"compiler-pipeline-host-aot", required_argument, nullptr, OPTION_COMPILER_PIPELINE_HOST_AOT},
299 {"compiler-fast-compile", required_argument, nullptr, OPTION_FAST_AOT_COMPILE_MODE},
300 {"compiler-opt-loop-peeling", required_argument, nullptr, OPTION_COMPILER_OPT_LOOP_PEELING},
301 {"compiler-opt-array-onheap-check", required_argument, nullptr, OPTION_COMPILER_OPT_ON_HEAP_CHECK},
302 {"compiler-pkg-info", required_argument, nullptr, OPTION_COMPILER_PKG_INFO},
303 {"compiler-external-pkg-info", required_argument, nullptr, OPTION_COMPILER_EXTERNAL_PKG_INFO},
304 {"compiler-enable-external-pkg", required_argument, nullptr, OPTION_COMPILER_ENABLE_EXTERNAL_PKG},
305 {"compiler-framework-abc-path", required_argument, nullptr, OPTION_COMPILER_FRAMEWORK_ABC_PATH},
306 {"compiler-enable-lexenv-specialization", required_argument, nullptr,
307 OPTION_COMPILER_ENABLE_LEXENV_SPECIALIZATION},
308 {"compiler-enable-native-inline", required_argument, nullptr, OPTION_COMPILER_ENABLE_NATIVE_INLINE},
309 {"compiler-enable-lowering-builtin", required_argument, nullptr, OPTION_COMPILER_ENABLE_LOWERING_BUILTIN},
310 {"compiler-enable-litecg", required_argument, nullptr, OPTION_COMPILER_ENABLE_LITECG},
311 {"compiler-enable-jit", required_argument, nullptr, OPTION_COMPILER_ENABLE_JIT},
312 {"compiler-enable-dfx-hisys-event", required_argument, nullptr, OPTION_COMPILER_ENABLE_DFX_HISYS_EVENT},
313 {"compiler-enable-osr", required_argument, nullptr, OPTION_COMPILER_ENABLE_OSR},
314 {"compiler-trace-jit", required_argument, nullptr, OPTION_COMPILER_TRACE_JIT},
315 {"compiler-jit-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_JIT_HOTNESS_THRESHOLD},
316 {"compiler-jit-call-threshold", required_argument, nullptr, OPTION_COMPILER_JIT_CALL_THRESHOLD},
317 {"compiler-osr-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_OSR_HOTNESS_THRESHOLD},
318 {"compiler-force-jit-compile-main", required_argument, nullptr, OPTION_COMPILER_FORCE_JIT_COMPILE_MAIN},
319 {"compiler-enable-jit-pgo", required_argument, nullptr, OPTION_COMPILER_ENABLE_JIT_PGO},
320 {"compiler-enable-aot-pgo", required_argument, nullptr, OPTION_COMPILER_ENABLE_AOT_PGO},
321 {"compiler-enable-framework-aot", required_argument, nullptr, OPTION_COMPILER_ENABLE_FRAMEWORK_AOT},
322 {"compiler-enable-profile-dump", required_argument, nullptr, OPTION_COMPILER_ENABLE_PROPFILE_DUMP},
323 {"compiler-typed-op-profiler", required_argument, nullptr, OPTION_COMPILER_TYPED_OP_PROFILER},
324 {"compiler-opt-branch-profiling", required_argument, nullptr, OPTION_COMPILER_OPT_BRANCH_PROFILING},
325 {"test-assert", required_argument, nullptr, OPTION_TEST_ASSERT},
326 {"compiler-methods-range", required_argument, nullptr, OPTION_COMPILER_METHODS_RANGE},
327 {"compiler-codegen-options", required_argument, nullptr, OPTION_COMPILER_CODEGEN_OPT},
328 {"compiler-opt-escape-analysis", required_argument, nullptr, OPTION_COMPILER_OPT_ESCAPE_ANALYSIS},
329 {"compiler-trace-escape-analysis", required_argument, nullptr, OPTION_COMPILER_TRACE_ESCAPE_ANALYSIS},
330 {"compiler-opt-induction-variable", required_argument, nullptr, OPTION_COMPILER_OPT_INDUCTION_VARIABLE},
331 {"compiler-trace-induction-variable", required_argument, nullptr, OPTION_COMPILER_TRACE_INDUCTION_VARIABLE},
332 {"compiler-memory-analysis", required_argument, nullptr, OPTION_COMPILER_MEMORY_ANALYSIS},
333 {"compiler-check-pgo-version", required_argument, nullptr, OPTION_COMPILER_CHECK_PGO_VERSION},
334 {"compiler-enable-mega-ic", required_argument, nullptr, OPTION_COMPILER_ENABLE_MEGA_IC},
335 {"compiler-enable-baselinejit", required_argument, nullptr, OPTION_COMPILER_ENABLE_BASELINEJIT},
336 {"compiler-baselinejit-hotness-threshold", required_argument, nullptr, OPTION_COMPILER_BASELINEJIT_HOTNESS_THRESHOLD},
337 {"compiler-force-baselinejit-compile-main", required_argument, nullptr, OPTION_COMPILER_FORCE_BASELINEJIT_COMPILE_MAIN},
338 {"compiler-enable-jit-fast-compile", required_argument, nullptr, OPTION_COMPILER_ENABLE_JIT_FAST_COMPILE},
339 {"compiler-enable-jitfort", required_argument, nullptr, OPTION_ENABLE_JITFORT},
340 {"compiler-codesign-disable", required_argument, nullptr, OPTION_CODESIGN_DISABLE},
341 {"compiler-enable-async-copytofort", required_argument, nullptr, OPTION_ENABLE_ASYNC_COPYTOFORT},
342 {"compiler-pgo-force-dump", required_argument, nullptr, OPTION_COMPILER_PGO_FORCE_DUMP},
343 {"compiler-enable-pgo-space", required_argument, nullptr, OPTION_COMPILER_ENABLE_PGO_SPACE},
344 {"async-load-abc", required_argument, nullptr, OPTION_ASYNC_LOAD_ABC},
345 {"async-load-abc-test", required_argument, nullptr, OPTION_ASYNC_LOAD_ABC_TEST},
346 {"compiler-enable-store-barrier", required_argument, nullptr, OPTION_COMPILER_ENABLE_STORE_BARRIER_OPT},
347 {"compiler-enable-concurrent", required_argument, nullptr, OPTION_COMPILER_ENABLE_CONCURRENT},
348 {"compiler-opt-frame-state-elimination", required_argument, nullptr,
349 OPTION_COMPILER_OPT_FRAME_STATE_ELIMINATION},
350 {"enable-inline-property-optimization", required_argument, nullptr, OPTION_ENABLE_INLINE_PROPERTY_OPTIMIZATION},
351 {"compiler-enable-aot-code-comment", required_argument, nullptr, OPTION_COMPILER_ENABLE_AOT_CODE_COMMENT},
352 {"compile-enable-jit-verify-pass", required_argument, nullptr, OPTION_ENABLE_JIT_VERIFY_PASS},
353 {"compiler-an-file-max-size", required_argument, nullptr, OPTION_COMPILER_AN_FILE_MAX_SIZE},
354 {"compiler-trace-builtins", required_argument, nullptr, OPTION_COMPILER_TRACE_BUILTINS},
355 {nullptr, 0, nullptr, 0},
356
357 };
358
359 int index = 0;
360 opterr = 0;
361 bool ret = false;
362 int option = 0;
363 arg_list_t argListStr;
364 uint32_t argUint32 = 0;
365 uint64_t argUInt64 = 0;
366 int argInt = 0;
367 bool argBool = false;
368 double argDouble = 0.0;
369 static std::string COLON = ":";
370
371 if (argc <= 1) {
372 return true;
373 }
374
375 while (true) {
376 option = getopt_long_only(argc, const_cast<char **>(argv), "", longOptions, &index);
377 LOG_ECMA(INFO) << "option: " << option << ", optopt: " << optopt << ", optind: " << optind;
378
379 if (optind <= 0 || optind > argc) {
380 return false;
381 }
382
383 if (option == -1) {
384 // set dependency between options at here
385 if (!IsEnableElementsKind() && IsEnableMutantArray()) {
386 LOG_ECMA(ERROR) << "'enable-mutant-array' must set to false while 'enable-elements-kind' is disabled\n";
387 return false;
388 }
389 return true;
390 }
391
392 // unknown option or required_argument option has no argument
393 if (option == OPTION_DEFAULT) {
394 ret = SetDefaultValue(const_cast<char *>(argv[optind - 1]));
395 if (ret) {
396 continue;
397 } else {
398 return ret;
399 }
400 }
401
402 WasSet(option);
403 switch (option) {
404 case OPTION_AOT_FILE:
405 SetAOTOutputFile(optarg);
406 ecmascript::AnFileDataManager::GetInstance()->SetEnable(true);
407 break;
408 case OPTION_ARK_PROPERTIES:
409 ret = ParseIntParam("ark-properties", &argInt);
410 if (ret) {
411 SetArkProperties(argInt);
412 } else {
413 return false;
414 }
415 break;
416 case OPTION_ARK_BUNDLENAME:
417 SetArkBundleName(optarg);
418 break;
419 case OPTION_ENABLE_ASM_INTERPRETER:
420 ret = ParseBoolParam(&argBool);
421 if (ret) {
422 SetEnableAsmInterpreter(argBool);
423 } else {
424 return false;
425 }
426 break;
427 case OPTION_ASM_OPCODE_DISABLE_RANGE:
428 SetAsmOpcodeDisableRange(optarg);
429 break;
430 case OPTION_ENABLE_BUILTINS_LAZY:
431 ret = ParseBoolParam(&argBool);
432 if (ret) {
433 SetEnableBuiltinsLazy(argBool);
434 } else {
435 return false;
436 }
437 break;
438 case OPTION_COMPILER_LOG_OPT:
439 SetCompilerLogOption(optarg);
440 break;
441 case OPTION_COMPILER_LOG_SNAPSHOT:
442 ret = ParseBoolParam(&argBool);
443 if (ret) {
444 SetCompilerLogSnapshot(argBool);
445 } else {
446 return false;
447 }
448 break;
449 case OPTION_COMPILER_LOG_TIME:
450 ret = ParseBoolParam(&argBool);
451 if (ret) {
452 SetCompilerLogTime(argBool);
453 } else {
454 return false;
455 }
456 break;
457 case OPTION_ENABLE_ARK_TOOLS:
458 ret = ParseBoolParam(&argBool);
459 if (ret) {
460 SetEnableArkTools(argBool);
461 } else {
462 return false;
463 }
464 break;
465 case OPTION_OPEN_ARK_TOOLS:
466 ret = ParseBoolParam(&argBool);
467 if (ret) {
468 SetOpenArkTools(argBool);
469 } else {
470 return false;
471 }
472 break;
473 case OPTION_PGO_TRACE:
474 ret = ParseBoolParam(&argBool);
475 if (ret) {
476 SetPGOTrace(argBool);
477 } else {
478 return false;
479 }
480 break;
481 case OPTION_COMPILER_TRACE_BC:
482 ret = ParseBoolParam(&argBool);
483 if (ret) {
484 SetTraceBc(argBool);
485 } else {
486 return false;
487 }
488 break;
489 case OPTION_COMPILER_TRACE_DEOPT:
490 ret = ParseBoolParam(&argBool);
491 if (ret) {
492 SetTraceDeopt(argBool);
493 } else {
494 return false;
495 }
496 break;
497 case OPTION_COMPILER_TRACE_INLINE:
498 ret = ParseBoolParam(&argBool);
499 if (ret) {
500 SetTraceInline(argBool);
501 } else {
502 return false;
503 }
504 break;
505 case OPTION_COMPILER_TRACE_VALUE_NUMBERING:
506 ret = ParseBoolParam(&argBool);
507 if (ret) {
508 SetTraceValueNumbering(argBool);
509 } else {
510 return false;
511 }
512 break;
513 case OPTION_COMPILER_TRACE_INSTRUCTION_COMBINE:
514 ret = ParseBoolParam(&argBool);
515 if (ret) {
516 SetTraceInstructionCombine(argBool);
517 } else {
518 return false;
519 }
520 break;
521 case OPTION_COMPILER_MAX_INLINE_BYTECODES:
522 ret = ParseUint32Param("max-inline-bytecodes", &argUint32);
523 if (ret) {
524 SetMaxInlineBytecodes(argUint32);
525 } else {
526 return false;
527 }
528 break;
529 case OPTION_COMPILER_DEOPT_THRESHOLD:
530 ret = ParseUint32Param("deopt-threshol", &argUint32);
531 if (ret) {
532 SetDeoptThreshold(argUint32);
533 } else {
534 return false;
535 }
536 break;
537 case OPTION_COMPILER_DEVICE_STATE:
538 ret = ParseBoolParam(&argBool);
539 if (ret) {
540 SetDeviceState(argBool);
541 } else {
542 return false;
543 }
544 break;
545 case OPTION_COMPILER_THERMAL_LEVEL:
546 ret = ParseIntParam("compiler-thermal-level", &argInt);
547 if (ret) {
548 SetThermalLevel(argInt);
549 } else {
550 return false;
551 }
552 break;
553 case OPTION_COMPILER_STRESS_DEOPT:
554 ret = ParseBoolParam(&argBool);
555 if (ret) {
556 SetStressDeopt(argBool);
557 } else {
558 return false;
559 }
560 break;
561 case OPTION_COMPILER_OPT_CODE_PROFILER:
562 ret = ParseBoolParam(&argBool);
563 if (ret) {
564 SetOptCodeProfiler(argBool);
565 } else {
566 return false;
567 }
568 break;
569 case OPTION_COMPILER_OPT_BC_RANGE:
570 SetOptCodeRange(optarg);
571 break;
572 case OPTION_COMPILER_OPT_BC_RANGE_HELP:
573 ret = ParseBoolParam(&argBool);
574 if (ret) {
575 std::string helpInfo = kungfu::GetHelpForEcmaCodeListForRange();
576 LOG_COMPILER(ERROR) << helpInfo.c_str();
577 exit(1);
578 }
579 break;
580 case OPTION_ENABLE_FORCE_GC:
581 ret = ParseBoolParam(&argBool);
582 if (ret) {
583 SetEnableForceGC(argBool);
584 } else {
585 return false;
586 }
587 break;
588 case OPTION_FORCE_FULL_GC:
589 ret = ParseBoolParam(&argBool);
590 if (ret) {
591 SetForceFullGC(argBool);
592 } else {
593 return false;
594 }
595 break;
596 case OPTION_ENABLE_FORCE_SHARED_GC_FREQUENCY:
597 ret = ParseUint32Param("force-shared-gc-frequency", &argUint32);
598 if (ret) {
599 SetForceSharedGCFrequency(argUint32);
600 } else {
601 return false;
602 }
603 break;
604 case OPTION_ENABLE_HEAP_VERIFY:
605 ret = ParseBoolParam(&argBool);
606 if (ret) {
607 SetEnableHeapVerify(argBool);
608 } else {
609 return false;
610 }
611 break;
612 case OPTION_ENABLE_IC:
613 ret = ParseBoolParam(&argBool);
614 if (ret) {
615 SetEnableIC(argBool);
616 } else {
617 return false;
618 }
619 break;
620 case OPTION_ENABLE_RUNTIME_STAT:
621 ret = ParseBoolParam(&argBool);
622 if (ret) {
623 SetEnableRuntimeStat(argBool);
624 } else {
625 return false;
626 }
627 break;
628 case OPTION_GC_THREADNUM:
629 ret = ParseUint32Param("gc-thread-num", &argUint32);
630 if (ret) {
631 SetGcThreadNum(argUint32);
632 } else {
633 return false;
634 }
635 break;
636 case OPTION_HEAP_SIZE_LIMIT:
637 ret = ParseUint32Param("heap-size-limit", &argUint32);
638 if (ret) {
639 SetHeapSizeLimit(argUint32);
640 } else {
641 return false;
642 }
643 break;
644 case OPTION_HELP:
645 return false;
646 case OPTION_ICU_DATA_PATH:
647 SetIcuDataPath(optarg);
648 break;
649 case OPTION_ENABLE_WORKER:
650 ret = ParseBoolParam(&argBool);
651 if (ret) {
652 SetIsWorker(argBool);
653 } else {
654 return false;
655 }
656 break;
657 case OPTION_LOG_COMPONENTS:
658 ParseListArgParam(optarg, &argListStr, COLON);
659 SetLogComponents(argListStr);
660 break;
661 case OPTION_LOG_DEBUG:
662 ParseListArgParam(optarg, &argListStr, COLON);
663 SetLogDebug(argListStr);
664 break;
665 case OPTION_LOG_ERROR:
666 ParseListArgParam(optarg, &argListStr, COLON);
667 SetLogError(argListStr);
668 break;
669 case OPTION_LOG_FATAL:
670 ParseListArgParam(optarg, &argListStr, COLON);
671 SetLogFatal(argListStr);
672 break;
673 case OPTION_LOG_INFO:
674 ParseListArgParam(optarg, &argListStr, COLON);
675 SetLogInfo(argListStr);
676 break;
677 case OPTION_LOG_LEVEL:
678 SetLogLevel(optarg);
679 break;
680 case OPTION_LOG_WARNING:
681 ParseListArgParam(optarg, &argListStr, COLON);
682 SetLogWarning(argListStr);
683 break;
684 case OPTION_GC_LONG_PAUSED_TIME:
685 ret = ParseUint32Param("gc-long-paused-time", &argUint32);
686 if (ret) {
687 SetLongPauseTime(argUint32);
688 } else {
689 return false;
690 }
691 break;
692 case OPTION_COMPILER_OPT_MAX_METHOD:
693 ret = ParseUint32Param("compiler-opt-max-method", &argUint32);
694 if (ret) {
695 SetMaxAotMethodSize(argUint32);
696 } else {
697 return false;
698 }
699 break;
700 case OPTION_COMPILER_MODULE_METHODS:
701 ret = ParseUint32Param("compiler-module-methods", &argUint32);
702 if (!ret) {
703 return false;
704 }
705 SetCompilerModuleMethods(argUint32);
706 break;
707 case OPTION_COMPILER_TYPE_THRESHOLD:
708 ret = ParseDoubleParam("compiler-type-threshold", &argDouble);
709 if (ret) {
710 SetTypeThreshold(argDouble);
711 } else {
712 return false;
713 }
714 break;
715 case OPTION_MAX_UNMOVABLE_SPACE:
716 ret = ParseUint32Param("max-unmovable-space", &argUint32);
717 if (ret) {
718 SetMaxNonmovableSpaceCapacity(argUint32);
719 } else {
720 return false;
721 }
722 break;
723 case OPTION_COMPILER_LOG_METHODS:
724 SetMethodsListForLog(optarg);
725 break;
726 case OPTION_ASM_OPT_LEVEL:
727 ret = ParseUint32Param("compiler-opt-level", &argUint32);
728 if (ret) {
729 SetOptLevel(argUint32);
730 } else {
731 return false;
732 }
733 break;
734 case OPTION_PRINT_EXECUTE_TIME:
735 ret = ParseBoolParam(&argBool);
736 if (ret) {
737 SetEnablePrintExecuteTime(argBool);
738 } else {
739 return false;
740 }
741 break;
742 case OPTION_ENABLE_PGO_PROFILER:
743 ret = ParseBoolParam(&argBool);
744 if (ret) {
745 SetEnablePGOProfiler(argBool);
746 } else {
747 return false;
748 }
749 break;
750 case OPTION_ENABLE_MUTANT_ARRAY:
751 ret = ParseBoolParam(&argBool);
752 if (ret) {
753 SetEnableMutantArray(argBool);
754 } else {
755 return false;
756 }
757 break;
758 case OPTION_ENABLE_ELEMENTS_KIND:
759 ret = ParseBoolParam(&argBool);
760 if (ret) {
761 SetEnableElementsKind(argBool);
762 } else {
763 return false;
764 }
765 break;
766 case OPTION_COMPILER_PGO_PROFILER_PATH:
767 if (*optarg == '\0') {
768 return false;
769 }
770 SetPGOProfilerPath(optarg);
771 break;
772 case OPTION_COMPILER_PGO_HOTNESS_THRESHOLD:
773 ret = ParseUint32Param("pgo-hotness-threshold", &argUint32);
774 if (ret) {
775 SetPGOHotnessThreshold(argUint32);
776 } else {
777 return false;
778 }
779 break;
780 case OPTION_COMPILER_PGO_SAVE_MIN_INTERVAL:
781 ret = ParseUint32Param("compiler-pgo-save-min-interval", &argUint32);
782 if (ret) {
783 SetPGOSaveMinInterval(argUint32);
784 } else {
785 return false;
786 }
787 break;
788 case OPTION_COMPILER_BASELINE_PGO:
789 ret = ParseBoolParam(&argBool);
790 if (ret) {
791 SetEnableBaselinePgo(argBool);
792 } else {
793 return false;
794 }
795 break;
796 case OPTION_RELOCATION_MODE:
797 ret = ParseUint32Param("reloc-mode", &argUint32);
798 if (ret) {
799 SetRelocMode(argUint32);
800 } else {
801 return false;
802 }
803 break;
804 case OPTION_SERIALIZER_BUFFER_SIZE_LIMIT:
805 ret = ParseUint64Param("serializer-buffer-size-limit", &argUInt64);
806 if (ret) {
807 SetSerializerBufferSizeLimit(argUInt64);
808 } else {
809 return false;
810 }
811 break;
812 case OPTION_STARTUP_TIME:
813 ret = ParseBoolParam(&argBool);
814 if (ret) {
815 SetStartupTime(argBool);
816 } else {
817 return false;
818 }
819 break;
820 case OPTION_STUB_FILE:
821 SetStubFile(optarg);
822 break;
823 case OPTION_COMPILER_TARGET_TRIPLE:
824 SetTargetTriple(optarg);
825 break;
826 case OPTION_ENTRY_POINT:
827 SetEntryPoint(optarg);
828 break;
829 case OPTION_MERGE_ABC:
830 ret = ParseBoolParam(&argBool);
831 if (ret) {
832 SetMergeAbc(argBool);
833 } else {
834 return false;
835 }
836 break;
837 case OPTION_ENABLE_CONTEXT:
838 ret = ParseBoolParam(&argBool);
839 if (ret) {
840 SetEnableContext(argBool);
841 } else {
842 return false;
843 }
844 break;
845 case OPTION_COMPILER_OPT_TYPE_LOWERING:
846 ret = ParseBoolParam(&argBool);
847 if (ret) {
848 SetEnableTypeLowering(argBool);
849 } else {
850 return false;
851 }
852 break;
853 case OPTION_COMPILER_OPT_ARRAY_BOUNDS_CHECK_ELIMINATION:
854 ret = ParseBoolParam(&argBool);
855 if (ret) {
856 SetEnableArrayBoundsCheckElimination(argBool);
857 } else {
858 return false;
859 }
860 break;
861 case OPTION_COMPILER_OPT_FRAME_STATE_ELIMINATION:
862 ret = ParseBoolParam(&argBool);
863 if (ret) {
864 SetEnableFrameStateElimination(argBool);
865 } else {
866 return false;
867 }
868 break;
869 case OPTION_COMPILER_OPT_EARLY_ELIMINATION:
870 ret = ParseBoolParam(&argBool);
871 if (ret) {
872 SetEnableEarlyElimination(argBool);
873 } else {
874 return false;
875 }
876 break;
877 case OPTION_COMPILER_OPT_LATER_ELIMINATION:
878 ret = ParseBoolParam(&argBool);
879 if (ret) {
880 SetEnableLaterElimination(argBool);
881 } else {
882 return false;
883 }
884 break;
885 case OPTION_COMPILER_OPT_INSTRUCTIONE_COMBINE:
886 ret = ParseBoolParam(&argBool);
887 if (ret) {
888 SetEnableInstrcutionCombine(argBool);
889 } else {
890 return false;
891 }
892 break;
893 case OPTION_COMPILER_OPT_STRING:
894 ret = ParseBoolParam(&argBool);
895 if (ret) {
896 SetEnableOptString(argBool);
897 } else {
898 return false;
899 }
900 break;
901 case OPTION_COMPILER_OPT_VALUE_NUMBERING:
902 ret = ParseBoolParam(&argBool);
903 if (ret) {
904 SetEnableValueNumbering(argBool);
905 } else {
906 return false;
907 }
908 break;
909 case OPTION_COMPILER_OPT_NEW_VALUE_NUMBERING:
910 ret = ParseBoolParam(&argBool);
911 if (ret) {
912 SetEnableNewValueNumbering(argBool);
913 } else {
914 return false;
915 }
916 break;
917 case OPTION_COMPILER_OPT_INLINING:
918 ret = ParseBoolParam(&argBool);
919 if (ret) {
920 SetEnableOptInlining(argBool);
921 } else {
922 return false;
923 }
924 break;
925 case OPTION_COMPILER_OPT_PGOTYPE:
926 ret = ParseBoolParam(&argBool);
927 if (ret) {
928 SetEnableOptPGOType(argBool);
929 } else {
930 return false;
931 }
932 break;
933 case OPTION_COMPILER_OPT_TRACK_FIELD:
934 ret = ParseBoolParam(&argBool);
935 if (ret) {
936 SetEnableOptTrackField(argBool);
937 } else {
938 return false;
939 }
940 break;
941 case OPTION_COMPILER_VERIFY_VTABLE:
942 ret = ParseBoolParam(&argBool);
943 if (ret) {
944 SetVerifyVTable(argBool);
945 } else {
946 return false;
947 }
948 break;
949 case OPTION_COMPILER_SELECT_METHODS:
950 SetCompilerSelectMethods(optarg);
951 break;
952 case OPTION_COMPILER_SKIP_METHODS:
953 SetCompilerSkipMethods(optarg);
954 break;
955 case OPTION_TARGET_COMPILER_MODE:
956 SetTargetCompilerMode(optarg);
957 break;
958 case OPTION_COMPILER_FRAMEWORK_ABC_PATH:
959 SetCompilerFrameworkAbcPath(optarg);
960 break;
961 case OPTION_HAP_PATH:
962 SetHapPath(optarg);
963 break;
964 case OPTION_HAP_ABC_OFFSET:
965 ret = ParseUint32Param("hap-abc-offset", &argUint32);
966 if (!ret) {
967 return false;
968 }
969 SetHapAbcOffset(argUint32);
970 break;
971 case OPTION_HAP_ABC_SIZE:
972 ret = ParseUint32Param("hap-abc-size", &argUint32);
973 if (!ret) {
974 return false;
975 }
976 SetHapAbcSize(argUint32);
977 break;
978 case OPTION_COMPILER_NOCHECK:
979 ret = ParseBoolParam(&argBool);
980 if (!ret) {
981 return false;
982 }
983 SetCompilerNoCheck(argBool);
984 break;
985 case OPTION_COMPILER_PIPELINE_HOST_AOT:
986 ret = ParseBoolParam(&argBool);
987 if (!ret) {
988 return false;
989 }
990 SetCompilerPipelineHostAOT(argBool);
991 break;
992 case OPTION_FAST_AOT_COMPILE_MODE:
993 ret = ParseBoolParam(&argBool);
994 if (!ret) {
995 return false;
996 }
997 SetFastAOTCompileMode(argBool);
998 break;
999 case OPTION_COMPILER_OPT_CONSTANT_FOLDING:
1000 ret = ParseBoolParam(&argBool);
1001 if (ret) {
1002 SetEnableOptConstantFolding(argBool);
1003 } else {
1004 return false;
1005 }
1006 break;
1007 case OPTION_COMPILER_OPT_LOOP_PEELING:
1008 ret = ParseBoolParam(&argBool);
1009 if (ret) {
1010 SetEnableOptLoopPeeling(argBool);
1011 } else {
1012 return false;
1013 }
1014 break;
1015 case OPTION_COMPILER_OPT_ON_HEAP_CHECK:
1016 ret = ParseBoolParam(&argBool);
1017 if (ret) {
1018 SetEnableOptOnHeapCheck(argBool);
1019 } else {
1020 return false;
1021 }
1022 break;
1023 case OPTION_COMPILER_PKG_INFO:
1024 SetCompilerPkgJsonInfo(optarg);
1025 break;
1026 case OPTION_COMPILER_EXTERNAL_PKG_INFO:
1027 SetCompilerExternalPkgJsonInfo(optarg);
1028 break;
1029 case OPTION_COMPILER_ENABLE_EXTERNAL_PKG:
1030 ret = ParseBoolParam(&argBool);
1031 if (ret) {
1032 SetCompilerEnableExternalPkg(argBool);
1033 } else {
1034 return false;
1035 }
1036 break;
1037 case OPTION_COMPILER_ENABLE_LEXENV_SPECIALIZATION:
1038 ret = ParseBoolParam(&argBool);
1039 if (ret) {
1040 SetEnableLexenvSpecialization(argBool);
1041 } else {
1042 return false;
1043 }
1044 break;
1045 case OPTION_COMPILER_ENABLE_NATIVE_INLINE:
1046 ret = ParseBoolParam(&argBool);
1047 if (ret) {
1048 SetEnableNativeInline(argBool);
1049 } else {
1050 return false;
1051 }
1052 break;
1053 case OPTION_COMPILER_ENABLE_LOWERING_BUILTIN:
1054 ret = ParseBoolParam(&argBool);
1055 if (ret) {
1056 SetEnableLoweringBuiltin(argBool);
1057 } else {
1058 return false;
1059 }
1060 break;
1061 case OPTION_COMPILER_ENABLE_LITECG:
1062 ret = ParseBoolParam(&argBool);
1063 if (ret) {
1064 SetCompilerEnableLiteCG(argBool);
1065 } else {
1066 return false;
1067 }
1068 break;
1069 case OPTION_COMPILER_ENABLE_JIT:
1070 ret = ParseBoolParam(&argBool);
1071 if (ret) {
1072 SetEnableJIT(argBool);
1073 } else {
1074 return false;
1075 }
1076 break;
1077 case OPTION_COMPILER_ENABLE_DFX_HISYS_EVENT:
1078 ret = ParseBoolParam(&argBool);
1079 if (ret) {
1080 SetEnableDFXHiSysEvent(argBool);
1081 } else {
1082 return false;
1083 }
1084 break;
1085 case OPTION_COMPILER_ENABLE_OSR:
1086 ret = ParseBoolParam(&argBool);
1087 if (ret) {
1088 SetEnableOSR(argBool);
1089 } else {
1090 return false;
1091 }
1092 break;
1093 case OPTION_COMPILER_JIT_HOTNESS_THRESHOLD:
1094 ret = ParseUint32Param("compiler-jit-hotness-threshold", &argUint32);
1095 if (ret) {
1096 uint16_t val = argUint32 > std::numeric_limits<uint16_t>::max() ?
1097 std::numeric_limits<uint16_t>::max() : static_cast<uint16_t>(argUint32);
1098 SetJitHotnessThreshold(val);
1099 } else {
1100 return false;
1101 }
1102 break;
1103 case OPTION_COMPILER_JIT_CALL_THRESHOLD:
1104 ret = ParseUint32Param("compiler-jit-call-threshold", &argUint32);
1105 if (ret) {
1106 uint16_t val = argUint32 > std::numeric_limits<uint16_t>::max() ?
1107 std::numeric_limits<uint16_t>::max() : static_cast<uint16_t>(argUint32);
1108 SetJitCallThreshold(val);
1109 } else {
1110 return false;
1111 }
1112 break;
1113 case OPTION_COMPILER_OSR_HOTNESS_THRESHOLD:
1114 ret = ParseUint32Param("compiler-osr-hotness-threshold", &argUint32);
1115 if (ret) {
1116 uint16_t val = argUint32 > std::numeric_limits<uint16_t>::max() ?
1117 std::numeric_limits<uint16_t>::max() : static_cast<uint16_t>(argUint32);
1118 SetOsrHotnessThreshold(val);
1119 } else {
1120 return false;
1121 }
1122 break;
1123 case OPTION_COMPILER_FORCE_JIT_COMPILE_MAIN:
1124 ret = ParseBoolParam(&argBool);
1125 if (ret) {
1126 SetForceJitCompileMain(argBool);
1127 } else {
1128 return false;
1129 }
1130 break;
1131 case OPTION_COMPILER_TRACE_JIT:
1132 ret = ParseBoolParam(&argBool);
1133 if (ret) {
1134 SetTraceJIT(argBool);
1135 } else {
1136 return false;
1137 }
1138 break;
1139 case OPTION_COMPILER_TYPED_OP_PROFILER:
1140 ret = ParseBoolParam(&argBool);
1141 if (ret) {
1142 SetTypedOpProfiler(argBool);
1143 } else {
1144 return false;
1145 }
1146 break;
1147 case OPTION_COMPILER_OPT_BRANCH_PROFILING:
1148 ret = ParseBoolParam(&argBool);
1149 if (ret) {
1150 SetEnableBranchProfiling(argBool);
1151 } else {
1152 return false;
1153 }
1154 break;
1155 case OPTION_TEST_ASSERT:
1156 ret = ParseBoolParam(&argBool);
1157 if (ret) {
1158 SetTestAssert(argBool);
1159 } else {
1160 return false;
1161 }
1162 break;
1163 case OPTION_COMPILER_ENABLE_JIT_PGO:
1164 ret = ParseBoolParam(&argBool);
1165 if (ret) {
1166 SetEnableJITPGO(argBool);
1167 } else {
1168 return false;
1169 }
1170 break;
1171 case OPTION_COMPILER_ENABLE_PROPFILE_DUMP:
1172 ret = ParseBoolParam(&argBool);
1173 if (ret) {
1174 SetEnableProfileDump(argBool);
1175 } else {
1176 return false;
1177 }
1178 break;
1179 case OPTION_COMPILER_ENABLE_AOT_PGO:
1180 ret = ParseBoolParam(&argBool);
1181 if (ret) {
1182 SetEnableAOTPGO(argBool);
1183 } else {
1184 return false;
1185 }
1186 break;
1187 case OPTION_COMPILER_ENABLE_FRAMEWORK_AOT:
1188 ret = ParseBoolParam(&argBool);
1189 if (ret) {
1190 SetEnableFrameworkAOT(argBool);
1191 } else {
1192 return false;
1193 }
1194 break;
1195 case OPTION_COMPILER_ENABLE_BASELINEJIT:
1196 ret = ParseBoolParam(&argBool);
1197 if (ret) {
1198 SetEnableBaselineJIT(argBool);
1199 } else {
1200 return false;
1201 }
1202 break;
1203 case OPTION_COMPILER_METHODS_RANGE:
1204 ParseListArgParam(optarg, &argListStr, COLON);
1205 SetCompilerMethodsRange(&argListStr);
1206 break;
1207 case OPTION_COMPILER_CODEGEN_OPT:
1208 ParseListArgParam(optarg, &argListStr, " ");
1209 SetCompilerCodegenOptions(argListStr);
1210 break;
1211 case OPTION_COMPILER_OPT_ESCAPE_ANALYSIS:
1212 ret = ParseBoolParam(&argBool);
1213 if (ret) {
1214 SetEnableEscapeAnalysis(argBool);
1215 } else {
1216 return false;
1217 }
1218 break;
1219 case OPTION_COMPILER_TRACE_ESCAPE_ANALYSIS:
1220 ret = ParseBoolParam(&argBool);
1221 if (ret) {
1222 SetEnableTraceEscapeAnalysis(argBool);
1223 } else {
1224 return false;
1225 }
1226 break;
1227 case OPTION_COMPILER_OPT_INDUCTION_VARIABLE:
1228 ret = ParseBoolParam(&argBool);
1229 if (ret) {
1230 SetEnableInductionVariableAnalysis(argBool);
1231 } else {
1232 return false;
1233 }
1234 break;
1235 case OPTION_COMPILER_TRACE_INDUCTION_VARIABLE:
1236 ret = ParseBoolParam(&argBool);
1237 if (ret) {
1238 SetEnableTraceInductionVariableAnalysis(argBool);
1239 } else {
1240 return false;
1241 }
1242 break;
1243 case OPTION_COMPILER_BASELINEJIT_HOTNESS_THRESHOLD:
1244 ret = ParseUint32Param("compiler-baselinejit-hotness-threshold", &argUint32);
1245 if (ret) {
1246 uint16_t val = argUint32 > std::numeric_limits<uint16_t>::max() ?
1247 std::numeric_limits<uint16_t>::max() : static_cast<uint16_t>(argUint32);
1248 SetBaselineJitHotnessThreshold(val);
1249 } else {
1250 return false;
1251 }
1252 break;
1253 case OPTION_COMPILER_MEMORY_ANALYSIS:
1254 ret = ParseBoolParam(&argBool);
1255 if (ret) {
1256 SetEnableMemoryAnalysis(argBool);
1257 } else {
1258 return false;
1259 }
1260 break;
1261 case OPTION_COMPILER_CHECK_PGO_VERSION:
1262 ret = ParseBoolParam(&argBool);
1263 if (ret) {
1264 SetCheckPgoVersion(argBool);
1265 } else {
1266 return false;
1267 }
1268 break;
1269 case OPTION_COMPILER_FORCE_BASELINEJIT_COMPILE_MAIN:
1270 ret = ParseBoolParam(&argBool);
1271 if (ret) {
1272 SetForceBaselineCompileMain(argBool);
1273 } else {
1274 return false;
1275 }
1276 break;
1277 case OPTION_COMPILER_ENABLE_JIT_FAST_COMPILE:
1278 ret = ParseBoolParam(&argBool);
1279 if (ret) {
1280 SetEnableJitFastCompile(argBool);
1281 } else {
1282 return false;
1283 }
1284 break;
1285 case OPTION_COMPILER_ENABLE_MEGA_IC:
1286 ret = ParseBoolParam(&argBool);
1287 if (ret) {
1288 SetEnableMegaIC(argBool);
1289 } else {
1290 return false;
1291 }
1292 break;
1293 case OPTION_ASYNC_LOAD_ABC:
1294 ret = ParseBoolParam(&argBool);
1295 if (ret) {
1296 SetAsyncLoadAbc(argBool);
1297 } else {
1298 return false;
1299 }
1300 break;
1301 case OPTION_ASYNC_LOAD_ABC_TEST:
1302 ret = ParseBoolParam(&argBool);
1303 if (ret) {
1304 SetAsyncLoadAbcTest(argBool);
1305 } else {
1306 return false;
1307 }
1308 break;
1309 case OPTION_ENABLE_JITFORT:
1310 ret = ParseBoolParam(&argBool);
1311 if (ret) {
1312 SetEnableJitFort(argBool);
1313 } else {
1314 return false;
1315 }
1316 break;
1317 case OPTION_CODESIGN_DISABLE:
1318 ret = ParseBoolParam(&argBool);
1319 if (ret) {
1320 SetDisableCodeSign(argBool);
1321 } else {
1322 return false;
1323 }
1324 break;
1325 case OPTION_ENABLE_ASYNC_COPYTOFORT:
1326 ret = ParseBoolParam(&argBool);
1327 if (ret) {
1328 SetEnableAsyncCopyToFort(argBool);
1329 } else {
1330 return false;
1331 }
1332 break;
1333 case OPTION_COMPILER_ENABLE_CONCURRENT:
1334 ret = ParseBoolParam(&argBool);
1335 if (ret) {
1336 SetConcurrentCompile(argBool);
1337 } else {
1338 return false;
1339 }
1340 break;
1341 case OPTION_COMPILER_ENABLE_STORE_BARRIER_OPT:
1342 ret = ParseBoolParam(&argBool);
1343 if (ret) {
1344 SetStoreBarrierOpt(argBool);
1345 } else {
1346 return false;
1347 }
1348 break;
1349 case OPTION_COMPILER_PGO_FORCE_DUMP:
1350 ret = ParseBoolParam(&argBool);
1351 if (ret) {
1352 SetPgoForceDump(argBool);
1353 } else {
1354 return false;
1355 }
1356 break;
1357 case OPTION_COMPILER_ENABLE_PGO_SPACE:
1358 ret = ParseBoolParam(&argBool);
1359 if (ret) {
1360 SetCompilerEnablePgoSpace(argBool);
1361 } else {
1362 return false;
1363 }
1364 break;
1365 case OPTION_COMPILER_ENABLE_AOT_CODE_COMMENT:
1366 ret = ParseBoolParam(&argBool);
1367 if (ret) {
1368 SetEnableAotCodeComment(argBool);
1369 } else {
1370 return false;
1371 }
1372 break;
1373 case OPTION_ENABLE_INLINE_PROPERTY_OPTIMIZATION:
1374 ret = ParseBoolParam(&argBool);
1375 if (ret) {
1376 SetEnableInlinePropertyOptimization(argBool);
1377 } else {
1378 return false;
1379 }
1380 break;
1381 case OPTION_ENABLE_JIT_VERIFY_PASS:
1382 ret = ParseBoolParam(&argBool);
1383 if (ret) {
1384 SetEnableJitVerifyPass(argBool);
1385 } else {
1386 return false;
1387 }
1388 break;
1389 case OPTION_COMPILER_TRACE_BUILTINS:
1390 ret = ParseBoolParam(&argBool);
1391 if (ret) {
1392 SetTraceBuiltins(argBool);
1393 } else {
1394 return false;
1395 }
1396 break;
1397 case OPTION_COMPILER_AN_FILE_MAX_SIZE:
1398 ret = ParseUint64Param("compiler-an-file-max-size", &argUInt64);
1399 if (ret) {
1400 SetCompilerAnFileMaxByteSize(argUInt64 * 1_MB);
1401 } else {
1402 return false;
1403 }
1404 break;
1405 default:
1406 LOG_ECMA(ERROR) << "Invalid option\n";
1407 return false;
1408 }
1409 }
1410 }
1411
SetDefaultValue(char * argv)1412 bool JSRuntimeOptions::SetDefaultValue(char* argv)
1413 {
1414 WasSet(optopt);
1415
1416 if (optopt == OPTION_DEFAULT) { // unknown option
1417 LOG_ECMA(ERROR) << " Invalid option \"" << argv << "\"";
1418 return false;
1419 }
1420
1421 if (optopt >= OPTION_LAST) { // unknown argument
1422 LOG_ECMA(ERROR) << "getopt: \"" << argv <<"\" argument has invalid parameter value \n";
1423 return false;
1424 }
1425 return true;
1426 }
1427
ParseBoolParam(bool * argBool)1428 bool JSRuntimeOptions::ParseBoolParam(bool* argBool)
1429 {
1430 if ((strcmp(optarg, "false") == 0) || (strcmp(optarg, "0") == 0)) {
1431 *argBool = false;
1432 } else {
1433 *argBool = true;
1434 }
1435 return true;
1436 }
1437
ParseDoubleParam(const std::string & option,double * argDouble)1438 bool JSRuntimeOptions::ParseDoubleParam(const std::string &option, double *argDouble)
1439 {
1440 *argDouble = std::strtod(optarg, nullptr);
1441 if (errno == ERANGE) {
1442 LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1443 return false;
1444 }
1445 return true;
1446 }
1447
ParseIntParam(const std::string & option,int * argInt)1448 bool JSRuntimeOptions::ParseIntParam(const std::string &option, int *argInt)
1449 {
1450 int64_t val;
1451 if (StartsWith(optarg, "0x")) {
1452 const int HEX = 16;
1453 val = std::strtoll(optarg, nullptr, HEX);
1454 } else {
1455 const int DEC = 10;
1456 val = std::strtoll(optarg, nullptr, DEC);
1457 }
1458
1459 if (errno == ERANGE || val < INT_MIN || val > INT_MAX) {
1460 LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1461 return false;
1462 }
1463 *argInt = static_cast<int>(val);
1464 return true;
1465 }
1466
ParseUint32Param(const std::string & option,uint32_t * argUInt32)1467 bool JSRuntimeOptions::ParseUint32Param(const std::string &option, uint32_t *argUInt32)
1468 {
1469 if (StartsWith(optarg, "0x")) {
1470 const int HEX = 16;
1471 *argUInt32 = std::strtoull(optarg, nullptr, HEX);
1472 } else {
1473 const int DEC = 10;
1474 *argUInt32 = std::strtoull(optarg, nullptr, DEC);
1475 }
1476
1477 if (errno == ERANGE) {
1478 LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1479 return false;
1480 }
1481 return true;
1482 }
1483
ParseUint64Param(const std::string & option,uint64_t * argUInt64)1484 bool JSRuntimeOptions::ParseUint64Param(const std::string &option, uint64_t *argUInt64)
1485 {
1486 if (StartsWith(optarg, "0x")) {
1487 const int HEX = 16;
1488 *argUInt64 = std::strtoull(optarg, nullptr, HEX);
1489 } else {
1490 const int DEC = 10;
1491 *argUInt64 = std::strtoull(optarg, nullptr, DEC);
1492 }
1493
1494 if (errno == ERANGE) {
1495 LOG_ECMA(ERROR) << "getopt: \"" << option << "\" argument has invalid parameter value \"" << optarg <<"\"\n";
1496 return false;
1497 }
1498 return true;
1499 }
1500
ParseListArgParam(const std::string & option,arg_list_t * argListStr,std::string delimiter)1501 void JSRuntimeOptions::ParseListArgParam(const std::string &option, arg_list_t *argListStr, std::string delimiter)
1502 {
1503 argListStr->clear();
1504 std::size_t strIndex = 0;
1505 std::size_t pos = option.find_first_of(delimiter, strIndex);
1506 while ((pos < option.size()) && (pos > strIndex)) {
1507 argListStr->push_back(option.substr(strIndex, pos - strIndex));
1508 strIndex = pos;
1509 strIndex = option.find_first_not_of(delimiter, strIndex);
1510 pos = option.find_first_of(delimiter, strIndex);
1511 }
1512 if (pos > strIndex) {
1513 argListStr->push_back(option.substr(strIndex, pos - strIndex));
1514 }
1515 return;
1516 }
1517
BindCPUCoreForTargetCompilation()1518 void JSRuntimeOptions::BindCPUCoreForTargetCompilation()
1519 {
1520 if (!deviceIsScreenOff_ || deviceThermalLevel_ > 0) {
1521 BindSmallCpuCore();
1522 } else {
1523 BindMidCpuCore();
1524 }
1525 }
1526
SetOptionsForTargetCompilation()1527 void JSRuntimeOptions::SetOptionsForTargetCompilation()
1528 {
1529 if (IsApplicationCompilation()) {
1530 SetTargetTriple("aarch64-unknown-linux-gnu");
1531 SetMaxAotMethodSize(MAX_APP_COMPILE_METHOD_SIZE);
1532 SetEnableOptTrackField(false);
1533 SetEnableOptInlining(false);
1534 SetEnableArrayBoundsCheckElimination(false);
1535 SetCompilerEnableLiteCG(true);
1536 SetEnableOptPGOType(true);
1537 if (IsCompilerAnFileMaxByteSizeDefault()) {
1538 SetCompilerAnFileMaxByteSize(100_MB);
1539 }
1540 }
1541
1542 if (IsTargetCompilerMode()) {
1543 if (UNLIKELY(IsFullCompilerMode())) {
1544 SetEnableOptPGOType(false);
1545 SetPGOProfilerPath("");
1546 }
1547 BindCPUCoreForTargetCompilation();
1548 }
1549
1550 if (IsCompilerPipelineHostAOT()) {
1551 SetFastAOTCompileMode(true);
1552 SetOptLevel(DEFAULT_OPT_LEVEL);
1553 SetEnableLoweringBuiltin(false);
1554 }
1555 }
1556 }
1557