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