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