• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_JS_RUNTIME_OPTIONS_H_
17 #define ECMASCRIPT_JS_RUNTIME_OPTIONS_H_
18 
19 #include <optional>
20 #include <string>
21 #include <string_view>
22 #include <vector>
23 
24 #include "ecmascript/compiler/bc_call_signature.h"
25 #include "ecmascript/mem/mem_common.h"
26 
27 // namespace panda {
28 namespace panda::ecmascript {
29 using arg_list_t = std::vector<std::string>;
30 enum ArkProperties {
31     DEFAULT = -1,  // default value 1000001011100 -> 0x105c
32     OPTIONAL_LOG = 1,
33     GC_STATS_PRINT = 1 << 1,
34     PARALLEL_GC = 1 << 2,  // default enable
35     CONCURRENT_MARK = 1 << 3,  // default enable
36     CONCURRENT_SWEEP = 1 << 4,  // default enable
37     THREAD_CHECK = 1 << 5,
38     ENABLE_ARKTOOLS = 1 << 6,  // default enable
39     ENABLE_SNAPSHOT_SERIALIZE = 1 << 7,
40     ENABLE_SNAPSHOT_DESERIALIZE = 1 << 8,
41     EXCEPTION_BACKTRACE = 1 << 9,
42     GLOBAL_OBJECT_LEAK_CHECK = 1 << 10,
43     GLOBAL_PRIMITIVE_LEAK_CHECK = 1 << 11,
44     ENABLE_IDLE_GC = 1 << 12,  // default enable
45     CPU_PROFILER_COLD_START_MAIN_THREAD = 1 << 13,
46     ENABLE_CPU_PROFILER_VM_TAG = 1 << 14,
47     ENABLE_GC_TRACER = 1 << 15,
48     CPU_PROFILER_COLD_START_WORKER_THREAD = 1 << 16,
49     CPU_PROFILER_ANY_TIME_MAIN_THREAD = 1 << 17,
50     CPU_PROFILER_ANY_TIME_WORKER_THREAD = 1 << 18
51 };
52 
53 // asm interpreter control parsed option
54 struct AsmInterParsedOption {
55     int handleStart {-1};
56     int handleEnd {-1};
57     bool enableAsm {false};
58 };
59 
60 extern const std::string PUBLIC_API COMMON_HELP_HEAD_MSG;
61 extern const std::string PUBLIC_API STUB_HELP_HEAD_MSG;
62 extern const std::string PUBLIC_API COMPILER_HELP_HEAD_MSG;
63 extern const std::string PUBLIC_API HELP_OPTION_MSG;
64 
65 enum CommandValues {
66     OPTION_DEFAULT,
67     OPTION_ENABLE_ARK_TOOLS,
68     OPTION_STUB_FILE,
69     OPTION_ENABLE_FORCE_GC,
70     OPTION_FORCE_FULL_GC,
71     OPTION_ARK_PROPERTIES,
72     OPTION_ARK_BUNDLENAME,
73     OPTION_GC_THREADNUM,
74     OPTION_GC_LONG_PAUSED_TIME,
75     OPTION_AOT_FILE,
76     OPTION_COMPILER_TARGET_TRIPLE,
77     OPTION_ASM_OPT_LEVEL,
78     OPTION_RELOCATION_MODE,
79     OPTION_MAX_UNMOVABLE_SPACE,
80     OPTION_ENABLE_ASM_INTERPRETER,
81     OPTION_ENABLE_BUILTINS_LAZY,
82     OPTION_ASM_OPCODE_DISABLE_RANGE,
83     OPTION_SERIALIZER_BUFFER_SIZE_LIMIT,
84     OPTION_HEAP_SIZE_LIMIT,
85     OPTION_ENABLE_IC,
86     OPTION_ICU_DATA_PATH,
87     OPTION_STARTUP_TIME,
88     OPTION_COMPILER_LOG_OPT,
89     OPTION_COMPILER_LOG_METHODS,
90     OPTION_COMPILER_TYPE_THRESHOLD,
91     OPTION_ENABLE_RUNTIME_STAT,
92     OPTION_COMPILER_ASSERT_TYPES,
93     OPTION_COMPILER_PRINT_TYPE_INFO,
94     OPTION_COMPILER_LOG_SNAPSHOT,
95     OPTION_COMPILER_LOG_TIME,
96     OPTION_ENABLE_WORKER,
97     OPTION_BUILTINS_DTS,
98     OPTION_COMPILER_TRACE_BC,
99     OPTION_COMPILER_TRACE_DEOPT,
100     OPTION_COMPILER_TRACE_INLINE,
101     OPTION_COMPILER_MAX_INLINE_BYTECODES,
102     OPTION_COMPILER_DEOPT_THRESHOLD,
103     OPTION_COMPILER_STRESS_DEOPT,
104     OPTION_COMPILER_OPT_CODE_PROFILER,
105     OPTION_LOG_LEVEL,
106     OPTION_LOG_DEBUG,
107     OPTION_LOG_INFO,
108     OPTION_LOG_WARNING,
109     OPTION_LOG_ERROR,
110     OPTION_LOG_FATAL,
111     OPTION_LOG_COMPONENTS,
112     OPTION_COMPILER_OPT_MAX_METHOD,
113     OPTION_COMPILER_MODULE_METHODS,
114     OPTION_ENTRY_POINT,
115     OPTION_MERGE_ABC,
116     OPTION_COMPILER_OPT_TYPE_LOWERING,
117     OPTION_COMPILER_OPT_EARLY_ELIMINATION,
118     OPTION_COMPILER_OPT_LATER_ELIMINATION,
119     OPTION_COMPILER_OPT_VALUE_NUMBERING,
120     OPTION_COMPILER_OPT_INLINING,
121     OPTION_COMPILER_OPT_PGOTYPE,
122     OPTION_COMPILER_OPT_TRACK_FIELD,
123     OPTION_COMPILER_OPT_GLOBAL_TYPEINFER,
124     OPTION_HELP,
125     OPTION_COMPILER_PGO_PROFILER_PATH,
126     OPTION_COMPILER_PGO_HOTNESS_THRESHOLD,
127     OPTION_ENABLE_PGO_PROFILER,
128     OPTION_OPTIONS,
129     OPTION_PRINT_EXECUTE_TIME,
130     OPTION_COMPILER_VERIFY_VTABLE,
131     OPTION_COMPILER_SELECT_METHODS,
132     OPTION_COMPILER_SKIP_METHODS,
133     OPTION_TARGET_COMPILER_MODE,
134     OPTION_HAP_PATH,
135     OPTION_HAP_ABC_OFFSET,
136     OPTION_HAP_ABC_SIZE,
137     OPTION_COMPILER_NOCHECK,
138     OPTION_FAST_AOT_COMPILE_MODE,
139     OPTION_COMPILER_OPT_LOOP_PEELING,
140 };
141 
142 class PUBLIC_API JSRuntimeOptions {
143 public:
JSRuntimeOptions()144     JSRuntimeOptions() {}
145     ~JSRuntimeOptions() = default;
146     DEFAULT_COPY_SEMANTIC(JSRuntimeOptions);
147     DEFAULT_MOVE_SEMANTIC(JSRuntimeOptions);
148 
149     bool ParseCommand(const int argc, const char **argv);
150     bool SetDefaultValue(char* argv);
151 
EnableArkTools()152     bool EnableArkTools() const
153     {
154         return (enableArkTools_) ||
155             ((static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_ARKTOOLS) != 0);
156     }
157 
SetEnableArkTools(bool value)158     void SetEnableArkTools(bool value) {
159         enableArkTools_ = value;
160     }
161 
WasSetEnableArkTools()162     bool WasSetEnableArkTools() const
163     {
164         return WasOptionSet(OPTION_ENABLE_ARK_TOOLS);
165     }
166 
IsEnableRuntimeStat()167     bool IsEnableRuntimeStat() const
168     {
169         return enableRuntimeStat_;
170     }
171 
SetEnableRuntimeStat(bool value)172     void SetEnableRuntimeStat(bool value)
173     {
174         enableRuntimeStat_ = value;
175     }
176 
WasSetEnableRuntimeStat()177     bool WasSetEnableRuntimeStat() const
178     {
179         return WasOptionSet(OPTION_ENABLE_RUNTIME_STAT);
180     }
181 
GetStubFile()182     std::string GetStubFile() const
183     {
184         return stubFile_;
185     }
186 
SetStubFile(std::string value)187     void SetStubFile(std::string value)
188     {
189         stubFile_ = std::move(value);
190     }
191 
WasStubFileSet()192     bool WasStubFileSet() const
193     {
194         return WasOptionSet(OPTION_STUB_FILE);
195     }
196 
SetEnableAOT(bool value)197     void SetEnableAOT(bool value)
198     {
199         enableAOT_ = value;
200     }
201 
GetEnableAOT()202     bool GetEnableAOT() const
203     {
204         return enableAOT_;
205     }
206 
GetAOTOutputFile()207     std::string GetAOTOutputFile() const
208     {
209         return aotOutputFile_;
210     }
211 
SetAOTOutputFile(const std::string & value)212     void SetAOTOutputFile(const std::string& value)
213     {
214         aotOutputFile_ = panda::os::file::File::GetExtendedFilePath(value);
215     }
216 
WasAOTOutputFileSet()217     bool WasAOTOutputFileSet() const
218     {
219         return WasOptionSet(OPTION_AOT_FILE);
220     }
221 
GetTargetTriple()222     std::string GetTargetTriple() const
223     {
224         return targetTriple_;
225     }
226 
SetTargetTriple(std::string value)227     void SetTargetTriple(std::string value)
228     {
229         targetTriple_ = std::move(value);
230     }
231 
GetOptLevel()232     size_t GetOptLevel() const
233     {
234         return asmOptLevel_;
235     }
236 
SetOptLevel(size_t value)237     void SetOptLevel(size_t value)
238     {
239         asmOptLevel_ = value;
240     }
241 
GetRelocMode()242     size_t GetRelocMode() const
243     {
244         return relocationMode_;
245     }
246 
SetRelocMode(size_t value)247     void SetRelocMode(size_t value)
248     {
249         relocationMode_ = value;
250     }
251 
EnableForceGC()252     bool EnableForceGC() const
253     {
254         return enableForceGc_;
255     }
256 
SetEnableForceGC(bool value)257     void SetEnableForceGC(bool value)
258     {
259         enableForceGc_ = value;
260     }
261 
ForceFullGC()262     bool ForceFullGC() const
263     {
264         return forceFullGc_;
265     }
266 
SetForceFullGC(bool value)267     void SetForceFullGC(bool value)
268     {
269         forceFullGc_ = value;
270     }
271 
SetGcThreadNum(size_t num)272     void SetGcThreadNum(size_t num)
273     {
274         gcThreadNum_ = num;
275     }
276 
GetGcThreadNum()277     size_t GetGcThreadNum() const
278     {
279         return gcThreadNum_;
280     }
281 
SetLongPauseTime(size_t time)282     void SetLongPauseTime(size_t time)
283     {
284         longPauseTime_ = time;
285     }
286 
GetLongPauseTime()287     size_t GetLongPauseTime() const
288     {
289         return longPauseTime_;
290     }
291 
SetArkProperties(int prop)292     void SetArkProperties(int prop)
293     {
294         if (prop != ArkProperties::DEFAULT) {
295             arkProperties_ = prop;
296         }
297     }
298 
SetArkBundleName(std::string bundleName)299     void SetArkBundleName(std::string bundleName)
300     {
301         if (bundleName != "") {
302             arkBundleName_ = bundleName;
303         }
304     }
305 
GetDefaultProperties()306     int GetDefaultProperties()
307     {
308         return ArkProperties::PARALLEL_GC | ArkProperties::CONCURRENT_MARK | ArkProperties::CONCURRENT_SWEEP |
309             ArkProperties::ENABLE_ARKTOOLS | ArkProperties::ENABLE_IDLE_GC;
310     }
311 
GetArkProperties()312     int GetArkProperties()
313     {
314         return arkProperties_;
315     }
316 
GetArkBundleName()317     std::string GetArkBundleName() const
318     {
319         return arkBundleName_;
320     }
321 
EnableOptionalLog()322     bool EnableOptionalLog() const
323     {
324         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::OPTIONAL_LOG) != 0;
325     }
326 
EnableGCStatsPrint()327     bool EnableGCStatsPrint() const
328     {
329         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::GC_STATS_PRINT) != 0;
330     }
331 
EnableParallelGC()332     bool EnableParallelGC() const
333     {
334         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::PARALLEL_GC) != 0;
335     }
336 
EnableConcurrentMark()337     bool EnableConcurrentMark() const
338     {
339         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CONCURRENT_MARK) != 0;
340     }
341 
EnableExceptionBacktrace()342     bool EnableExceptionBacktrace() const
343     {
344         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::EXCEPTION_BACKTRACE) != 0;
345     }
346 
EnableConcurrentSweep()347     bool EnableConcurrentSweep() const
348     {
349         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CONCURRENT_SWEEP) != 0;
350     }
351 
EnableThreadCheck()352     bool EnableThreadCheck() const
353     {
354         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::THREAD_CHECK) != 0;
355     }
356 
EnableIdleGC()357     bool EnableIdleGC() const
358     {
359         return false;
360     }
361 
EnableGCTracer()362     bool EnableGCTracer() const
363     {
364         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_GC_TRACER) != 0;
365     }
366 
EnableGlobalObjectLeakCheck()367     bool EnableGlobalObjectLeakCheck() const
368     {
369         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::GLOBAL_OBJECT_LEAK_CHECK) != 0;
370     }
371 
EnableGlobalPrimitiveLeakCheck()372     bool EnableGlobalPrimitiveLeakCheck() const
373     {
374         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::GLOBAL_PRIMITIVE_LEAK_CHECK) != 0;
375     }
376 
EnableGlobalLeakCheck()377     bool EnableGlobalLeakCheck() const
378     {
379         return EnableGlobalObjectLeakCheck() || EnableGlobalPrimitiveLeakCheck();
380     }
381 
EnableCpuProfilerColdStartMainThread()382     bool EnableCpuProfilerColdStartMainThread() const
383     {
384         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CPU_PROFILER_COLD_START_MAIN_THREAD) != 0;
385     }
386 
EnableCpuProfilerColdStartWorkerThread()387     bool EnableCpuProfilerColdStartWorkerThread() const
388     {
389         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CPU_PROFILER_COLD_START_WORKER_THREAD) != 0;
390     }
391 
EnableCpuProfilerAnyTimeMainThread()392     bool EnableCpuProfilerAnyTimeMainThread() const
393     {
394         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CPU_PROFILER_ANY_TIME_MAIN_THREAD) != 0;
395     }
396 
EnableCpuProfilerAnyTimeWorkerThread()397     bool EnableCpuProfilerAnyTimeWorkerThread() const
398     {
399         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CPU_PROFILER_ANY_TIME_WORKER_THREAD) != 0;
400     }
401 
EnableCpuProfilerVMTag()402     bool EnableCpuProfilerVMTag() const
403     {
404         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_CPU_PROFILER_VM_TAG) != 0;
405     }
406 
IsStartGlobalLeakCheck()407     bool IsStartGlobalLeakCheck() const
408     {
409         return startGlobalLeakCheck_;
410     }
411 
SwitchStartGlobalLeakCheck()412     void SwitchStartGlobalLeakCheck()
413     {
414         startGlobalLeakCheck_ = !startGlobalLeakCheck_;
415     }
416 
EnableSnapshotSerialize()417     bool EnableSnapshotSerialize() const
418     {
419         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_SNAPSHOT_SERIALIZE) != 0;
420     }
421 
EnableSnapshotDeserialize()422     bool EnableSnapshotDeserialize() const
423     {
424         if (WIN_OR_MAC_OR_IOS_PLATFORM) {
425             return false;
426         }
427 
428         return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_SNAPSHOT_DESERIALIZE) != 0;
429     }
430 
DisableReportModuleResolvingFailure()431     void DisableReportModuleResolvingFailure()
432     {
433         reportModuleResolvingFailure_ = false;
434     }
435 
EnableReportModuleResolvingFailure()436     bool EnableReportModuleResolvingFailure() const
437     {
438         return reportModuleResolvingFailure_;
439     }
440 
WasSetMaxNonmovableSpaceCapacity()441     bool WasSetMaxNonmovableSpaceCapacity() const
442     {
443         return WasOptionSet(OPTION_MAX_UNMOVABLE_SPACE);
444     }
445 
MaxNonmovableSpaceCapacity()446     size_t MaxNonmovableSpaceCapacity() const
447     {
448         return maxNonmovableSpaceCapacity_;
449     }
450 
SetMaxNonmovableSpaceCapacity(uint32_t value)451     void SetMaxNonmovableSpaceCapacity(uint32_t value)
452     {
453         maxNonmovableSpaceCapacity_ = value;
454     }
455 
SetEnableAsmInterpreter(bool value)456     void SetEnableAsmInterpreter(bool value)
457     {
458         enableAsmInterpreter_ = value;
459     }
460 
GetEnableAsmInterpreter()461     bool GetEnableAsmInterpreter() const
462     {
463         return enableAsmInterpreter_;
464     }
465 
SetEnableBuiltinsLazy(bool value)466     void SetEnableBuiltinsLazy(bool value)
467     {
468         enableBuiltinsLazy_ = value;
469     }
470 
GetEnableBuiltinsLazy()471     bool GetEnableBuiltinsLazy() const
472     {
473         return enableBuiltinsLazy_;
474     }
475 
SetAsmOpcodeDisableRange(std::string value)476     void SetAsmOpcodeDisableRange(std::string value)
477     {
478         asmOpcodeDisableRange_ = std::move(value);
479     }
480 
ParseAsmInterOption()481     void ParseAsmInterOption()
482     {
483         asmInterParsedOption_.enableAsm = enableAsmInterpreter_;
484         std::string strAsmOpcodeDisableRange = asmOpcodeDisableRange_;
485         if (strAsmOpcodeDisableRange.empty()) {
486             return;
487         }
488 
489         // asm interpreter handle disable range
490         size_t pos = strAsmOpcodeDisableRange.find(",");
491         if (pos != std::string::npos) {
492             std::string strStart = strAsmOpcodeDisableRange.substr(0, pos);
493             std::string strEnd = strAsmOpcodeDisableRange.substr(pos + 1);
494             int start = strStart.empty() ? 0 : std::stoi(strStart);
495             int end = strEnd.empty() ? kungfu::BYTECODE_STUB_END_ID : std::stoi(strEnd);
496             if (start >= 0 && start < kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS &&
497                 end >= 0 && end < kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS &&
498                 start <= end) {
499                 asmInterParsedOption_.handleStart = start;
500                 asmInterParsedOption_.handleEnd = end;
501             }
502         }
503     }
504 
GetAsmInterParsedOption()505     AsmInterParsedOption GetAsmInterParsedOption() const
506     {
507         return asmInterParsedOption_;
508     }
509 
GetCompilerLogOption()510     std::string GetCompilerLogOption() const
511     {
512         return compilerLogOpt_;
513     }
514 
SetCompilerLogOption(std::string value)515     void SetCompilerLogOption(std::string value)
516     {
517         compilerLogOpt_ = std::move(value);
518     }
519 
WasSetCompilerLogOption()520     bool WasSetCompilerLogOption() const
521     {
522         return 1ULL << static_cast<uint64_t>(OPTION_COMPILER_LOG_OPT) & wasSet_ &&
523             GetCompilerLogOption().find("none") == std::string::npos;
524     }
525 
GetMethodsListForLog()526     std::string GetMethodsListForLog() const
527     {
528         return compilerLogMethods_;
529     }
530 
SetMethodsListForLog(std::string value)531     void SetMethodsListForLog(std::string value)
532     {
533         compilerLogMethods_ = std::move(value);
534     }
535 
WasSetMethodsListForLog()536     bool WasSetMethodsListForLog() const
537     {
538         return 1ULL << static_cast<uint64_t>(OPTION_COMPILER_LOG_METHODS) & wasSet_ &&
539             GetCompilerLogOption().find("none") == std::string::npos &&
540             GetCompilerLogOption().find("all") == std::string::npos;
541     }
542 
SetCompilerLogSnapshot(bool value)543     void SetCompilerLogSnapshot(bool value)
544     {
545         compilerLogSnapshot_ = value;
546     }
547 
IsEnableCompilerLogSnapshot()548     bool IsEnableCompilerLogSnapshot() const
549     {
550         return compilerLogSnapshot_;
551     }
552 
WasSetCompilerLogSnapshot()553     bool WasSetCompilerLogSnapshot() const
554     {
555         return WasOptionSet(OPTION_COMPILER_LOG_SNAPSHOT);
556     }
557 
SetCompilerLogTime(bool value)558     void SetCompilerLogTime(bool value)
559     {
560         compilerLogTime_ = value;
561     }
562 
IsEnableCompilerLogTime()563     bool IsEnableCompilerLogTime() const
564     {
565         return compilerLogTime_;
566     }
567 
WasSetCompilerLogTime()568     bool WasSetCompilerLogTime() const
569     {
570         return WasOptionSet(OPTION_COMPILER_LOG_TIME);
571     }
572 
GetSerializerBufferSizeLimit()573     uint64_t GetSerializerBufferSizeLimit() const
574     {
575         return serializerBufferSizeLimit_;
576     }
577 
SetSerializerBufferSizeLimit(uint64_t value)578     void SetSerializerBufferSizeLimit(uint64_t value)
579     {
580         serializerBufferSizeLimit_ = value;
581     }
582 
GetHeapSizeLimit()583     uint32_t GetHeapSizeLimit() const
584     {
585         return heapSizeLimit_;
586     }
587 
SetHeapSizeLimit(uint32_t value)588     void SetHeapSizeLimit(uint32_t value)
589     {
590         heapSizeLimit_ = value;
591     }
592 
WasSetHeapSizeLimit()593     bool WasSetHeapSizeLimit() const
594     {
595         return WasOptionSet(OPTION_HEAP_SIZE_LIMIT);
596     }
597 
SetIsWorker(bool isWorker)598     void SetIsWorker(bool isWorker)
599     {
600         isWorker_ = isWorker;
601     }
602 
IsWorker()603     bool IsWorker() const
604     {
605         return isWorker_;
606     }
607 
EnableIC()608     bool EnableIC() const
609     {
610         return enableIC_;
611     }
612 
SetEnableIC(bool value)613     void SetEnableIC(bool value)
614     {
615         enableIC_ = value;
616     }
617 
WasSetEnableIC()618     bool WasSetEnableIC() const
619     {
620         return WasOptionSet(OPTION_ENABLE_IC);
621     }
622 
GetIcuDataPath()623     std::string GetIcuDataPath() const
624     {
625         return icuDataPath_;
626     }
627 
SetIcuDataPath(std::string value)628     void SetIcuDataPath(std::string value)
629     {
630         icuDataPath_ = std::move(value);
631     }
632 
WasSetIcuDataPath()633     bool WasSetIcuDataPath() const
634     {
635         return WasOptionSet(OPTION_ICU_DATA_PATH);
636     }
637 
IsStartupTime()638     bool IsStartupTime() const
639     {
640         return startupTime_;
641     }
642 
SetStartupTime(bool value)643     void SetStartupTime(bool value)
644     {
645         startupTime_ = value;
646     }
647 
WasSetStartupTime()648     bool WasSetStartupTime() const
649     {
650         return WasOptionSet(OPTION_STARTUP_TIME);
651     }
652 
AssertTypes()653     bool AssertTypes() const
654     {
655         return assertTypes_;
656     }
657 
SetAssertTypes(bool value)658     void SetAssertTypes(bool value)
659     {
660         assertTypes_ = value;
661     }
662 
PrintTypeInfo()663     bool PrintTypeInfo() const
664     {
665         return printTypeInfo_;
666     }
667 
SetPrintTypeInfo(bool value)668     void SetPrintTypeInfo(bool value)
669     {
670         printTypeInfo_ = value;
671     }
672 
SetBuiltinsDTS(const std::string & value)673     void SetBuiltinsDTS(const std::string& value)
674     {
675         builtinsDTS_ = panda::os::file::File::GetExtendedFilePath(value);
676     }
677 
WasSetBuiltinsDTS()678     bool WasSetBuiltinsDTS() const
679     {
680         return WasOptionSet(OPTION_BUILTINS_DTS);
681     }
682 
GetBuiltinsDTS()683     std::string GetBuiltinsDTS() const
684     {
685         return builtinsDTS_;
686     }
687 
SetTraceBc(bool value)688     void SetTraceBc(bool value)
689     {
690         traceBc_ = value;
691     }
692 
IsTraceBC()693     bool IsTraceBC() const
694     {
695         return traceBc_;
696     }
697 
WasSetTraceBc()698     bool WasSetTraceBc() const
699     {
700         return WasOptionSet(OPTION_COMPILER_TRACE_BC);
701     }
702 
GetLogLevel()703     std::string GetLogLevel() const
704     {
705         return logLevel_;
706     }
707 
SetLogLevel(std::string value)708     void SetLogLevel(std::string value)
709     {
710         logLevel_ = std::move(value);
711     }
712 
WasSetLogLevel()713     bool WasSetLogLevel() const
714     {
715         return WasOptionSet(OPTION_LOG_LEVEL);
716     }
717 
GetLogComponents()718     arg_list_t GetLogComponents() const
719     {
720         return logComponents_;
721     }
722 
SetLogComponents(arg_list_t value)723     void SetLogComponents(arg_list_t value)
724     {
725         logComponents_ = std::move(value);
726     }
727 
WasSetLogComponents()728     bool WasSetLogComponents() const
729     {
730         return WasOptionSet(OPTION_LOG_COMPONENTS);
731     }
732 
GetLogDebug()733     arg_list_t GetLogDebug() const
734     {
735         return logDebug_;
736     }
737 
SetLogDebug(arg_list_t value)738     void SetLogDebug(arg_list_t value)
739     {
740         logDebug_ = std::move(value);
741     }
742 
WasSetLogDebug()743     bool WasSetLogDebug() const
744     {
745         return WasOptionSet(OPTION_LOG_DEBUG);
746     }
747 
GetLogInfo()748     arg_list_t GetLogInfo() const
749     {
750         return logInfo_;
751     }
752 
SetLogInfo(arg_list_t value)753     void SetLogInfo(arg_list_t value)
754     {
755         logInfo_ = std::move(value);
756     }
757 
WasSetLogInfo()758     bool WasSetLogInfo() const
759     {
760         return WasOptionSet(OPTION_LOG_INFO);
761     }
762 
GetLogWarning()763     arg_list_t GetLogWarning() const
764     {
765         return logWarning_;
766     }
767 
SetLogWarning(arg_list_t value)768     void SetLogWarning(arg_list_t value)
769     {
770         logWarning_ = std::move(value);
771     }
772 
WasSetLogWarning()773     bool WasSetLogWarning() const
774     {
775         return WasOptionSet(OPTION_LOG_WARNING);
776     }
777 
GetLogError()778     arg_list_t GetLogError() const
779     {
780         return logError_;
781     }
782 
SetLogError(arg_list_t value)783     void SetLogError(arg_list_t value)
784     {
785         logError_ = std::move(value);
786     }
787 
WasSetLogError()788     bool WasSetLogError() const
789     {
790         return WasOptionSet(OPTION_LOG_ERROR);
791     }
792 
GetLogFatal()793     arg_list_t GetLogFatal() const
794     {
795         return logFatal_;
796     }
797 
SetLogFatal(arg_list_t value)798     void SetLogFatal(arg_list_t value)
799     {
800         logFatal_ = std::move(value);
801     }
802 
WasSetLogFatal()803     bool WasSetLogFatal() const
804     {
805         return WasOptionSet(OPTION_LOG_FATAL);
806     }
807 
GetMaxAotMethodSize()808     size_t GetMaxAotMethodSize() const
809     {
810         return maxAotMethodSize_;
811     }
812 
SetMaxAotMethodSize(uint32_t value)813     void SetMaxAotMethodSize(uint32_t value)
814     {
815         maxAotMethodSize_ = value;
816     }
817 
GetTypeThreshold()818     double GetTypeThreshold() const
819     {
820         return typeThreshold_;
821     }
822 
SetTypeThreshold(double threshold)823     void SetTypeThreshold(double threshold)
824     {
825         typeThreshold_ = threshold;
826     }
827 
GetEntryPoint()828     std::string GetEntryPoint() const
829     {
830         return entryPoint_;
831     }
832 
SetEntryPoint(std::string value)833     void SetEntryPoint(std::string value)
834     {
835         entryPoint_ = std::move(value);
836     }
837 
WasSetEntryPoint()838     bool WasSetEntryPoint() const
839     {
840         return WasOptionSet(OPTION_ENTRY_POINT);
841     }
842 
GetMergeAbc()843     bool GetMergeAbc() const
844     {
845         return mergeAbc_;
846     }
847 
SetMergeAbc(bool value)848     void SetMergeAbc(bool value)
849     {
850         mergeAbc_ = value;
851     }
852 
SetEnablePrintExecuteTime(bool value)853     void SetEnablePrintExecuteTime(bool value)
854     {
855         enablePrintExecuteTime_ = value;
856     }
857 
IsEnablePrintExecuteTime()858     bool IsEnablePrintExecuteTime()
859     {
860         return enablePrintExecuteTime_;
861     }
862 
SetEnablePGOProfiler(bool value)863     void SetEnablePGOProfiler(bool value)
864     {
865         enablePGOProfiler_ = value;
866     }
867 
IsEnablePGOProfiler()868     bool IsEnablePGOProfiler() const
869     {
870         return enablePGOProfiler_;
871     }
872 
GetPGOHotnessThreshold()873     uint32_t GetPGOHotnessThreshold() const
874     {
875         return pgoHotnessThreshold_;
876     }
877 
SetPGOHotnessThreshold(uint32_t threshold)878     void SetPGOHotnessThreshold(uint32_t threshold)
879     {
880         pgoHotnessThreshold_ = threshold;
881     }
882 
GetPGOProfilerPath()883     std::string GetPGOProfilerPath() const
884     {
885         return pgoProfilerPath_;
886     }
887 
SetPGOProfilerPath(const std::string & value)888     void SetPGOProfilerPath(const std::string& value)
889     {
890         pgoProfilerPath_ = panda::os::file::File::GetExtendedFilePath(value);
891     }
892 
IsPGOProfilerPathEmpty()893     bool IsPGOProfilerPathEmpty() const
894     {
895         return pgoProfilerPath_.empty();
896     }
897 
SetEnableTypeLowering(bool value)898     void SetEnableTypeLowering(bool value)
899     {
900         enableTypeLowering_ = value;
901     }
902 
IsEnableTypeLowering()903     bool IsEnableTypeLowering() const
904     {
905         return enableTypeLowering_;
906     }
907 
SetEnableEarlyElimination(bool value)908     void SetEnableEarlyElimination(bool value)
909     {
910         enableEarlyElimination_ = value;
911     }
912 
IsEnableEarlyElimination()913     bool IsEnableEarlyElimination() const
914     {
915         return enableEarlyElimination_;
916     }
917 
SetEnableLaterElimination(bool value)918     void SetEnableLaterElimination(bool value)
919     {
920         enableLaterElimination_ = value;
921     }
922 
IsEnableLaterElimination()923     bool IsEnableLaterElimination() const
924     {
925         return enableLaterElimination_;
926     }
927 
SetEnableValueNumbering(bool value)928     void SetEnableValueNumbering(bool value)
929     {
930         enableValueNumbering_ = value;
931     }
932 
IsEnableValueNumbering()933     bool IsEnableValueNumbering() const
934     {
935         return enableValueNumbering_;
936     }
937 
SetEnableOptInlining(bool value)938     void SetEnableOptInlining(bool value)
939     {
940         enableOptInlining_ = value;
941     }
942 
IsEnableOptInlining()943     bool IsEnableOptInlining() const
944     {
945         return enableOptInlining_;
946     }
947 
SetEnableOptPGOType(bool value)948     void SetEnableOptPGOType(bool value)
949     {
950         enableOptPGOType_ = value;
951     }
952 
IsEnableOptPGOType()953     bool IsEnableOptPGOType() const
954     {
955         return enableOptPGOType_;
956     }
957 
SetEnableOptTrackField(bool value)958     void SetEnableOptTrackField(bool value)
959     {
960         enableOptTrackField_ = value;
961     }
962 
IsEnableOptTrackField()963     bool IsEnableOptTrackField() const
964     {
965         return enableOptTrackField_;
966     }
967 
SetEnableGlobalTypeInfer(bool value)968     void SetEnableGlobalTypeInfer(bool value)
969     {
970         enableGlobalTypeInfer_ = value;
971     }
972 
IsEnableGlobalTypeInfer()973     bool IsEnableGlobalTypeInfer() const
974     {
975         return enableGlobalTypeInfer_;
976     }
977 
GetCompilerModuleMethods()978     uint32_t GetCompilerModuleMethods() const
979     {
980         return compilerModuleMethods_;
981     }
982 
SetCompilerModuleMethods(uint32_t compilerModuleMethods)983     void SetCompilerModuleMethods(uint32_t compilerModuleMethods)
984     {
985         compilerModuleMethods_ = compilerModuleMethods;
986     }
987 
WasSet(int opt)988     void WasSet(int opt)
989     {
990         wasSet_ |= 1ULL << static_cast<uint64_t>(opt);
991     }
992 
SetTraceDeopt(bool value)993     void SetTraceDeopt(bool value)
994     {
995         traceDeopt_ = value;
996     }
997 
GetTraceDeopt()998     bool GetTraceDeopt() const
999     {
1000         return traceDeopt_;
1001     }
1002 
SetDeoptThreshold(uint8_t value)1003     void SetDeoptThreshold(uint8_t value)
1004     {
1005         deoptThreshold_ = value;
1006     }
1007 
GetDeoptThreshold()1008     uint32_t GetDeoptThreshold() const
1009     {
1010         return deoptThreshold_;
1011     }
1012 
SetStressDeopt(bool value)1013     void SetStressDeopt(bool value)
1014     {
1015         stressDeopt_ = value;
1016     }
1017 
GetStressDeopt()1018     bool GetStressDeopt() const
1019     {
1020         return stressDeopt_;
1021     }
1022 
SetOptCodeProfiler(bool value)1023     void SetOptCodeProfiler(bool value)
1024     {
1025         optCodeProfiler_ = value;
1026     }
1027 
GetOptCodeProfiler()1028     bool GetOptCodeProfiler() const
1029     {
1030         return optCodeProfiler_;
1031     }
1032 
SetVerifyVTable(bool value)1033     void SetVerifyVTable(bool value)
1034     {
1035         verifyVTable_ = value;
1036     }
1037 
GetVerifyVTable()1038     bool GetVerifyVTable() const
1039     {
1040         return verifyVTable_;
1041     }
1042 
GetCompilerSelectMethods()1043     std::string GetCompilerSelectMethods() const
1044     {
1045         return compilerSelectMethods_;
1046     }
1047 
SetCompilerSelectMethods(std::string value)1048     void SetCompilerSelectMethods(std::string value)
1049     {
1050         compilerSelectMethods_ = std::move(value);
1051     }
1052 
GetCompilerSkipMethods()1053     std::string GetCompilerSkipMethods() const
1054     {
1055         return compilerSkipMethods_;
1056     }
1057 
SetCompilerSkipMethods(std::string value)1058     void SetCompilerSkipMethods(std::string value)
1059     {
1060         compilerSkipMethods_ = std::move(value);
1061     }
1062 
SetTraceInline(bool value)1063     void SetTraceInline(bool value)
1064     {
1065         traceInline_ = value;
1066     }
1067 
GetTraceInline()1068     bool GetTraceInline() const
1069     {
1070         return traceInline_;
1071     }
1072 
SetMaxInlineBytecodes(size_t value)1073     void SetMaxInlineBytecodes(size_t value)
1074     {
1075         maxInlineBytecodes_ = value;
1076     }
1077 
GetMaxInlineBytecodes()1078     size_t GetMaxInlineBytecodes()
1079     {
1080         return maxInlineBytecodes_;
1081     }
1082 
SetTargetCompilerMode(std::string mode)1083     void SetTargetCompilerMode(std::string mode)
1084     {
1085         targetCompilerMode_ = std::move(mode);
1086     }
1087 
GetTargetCompilerMode()1088     std::string GetTargetCompilerMode() const
1089     {
1090         return targetCompilerMode_;
1091     }
1092 
IsTargetCompilerMode()1093     bool IsTargetCompilerMode() const
1094     {
1095         return IsPartialCompilerMode() || IsFullCompilerMode();
1096     }
1097 
IsPartialCompilerMode()1098     bool IsPartialCompilerMode() const
1099     {
1100         return targetCompilerMode_ == "partial";
1101     }
1102 
IsFullCompilerMode()1103     bool IsFullCompilerMode() const
1104     {
1105         return targetCompilerMode_ == "full";
1106     }
1107 
SetHapPath(std::string path)1108     void SetHapPath(std::string path)
1109     {
1110         hapPath_ = std::move(path);
1111     }
1112 
GetHapPath()1113     std::string GetHapPath() const
1114     {
1115         return hapPath_;
1116     }
1117 
SetHapAbcOffset(uint32_t offset)1118     void SetHapAbcOffset(uint32_t offset)
1119     {
1120         hapAbcOffset_ = offset;
1121     }
1122 
GetHapAbcOffset()1123     uint32_t GetHapAbcOffset() const
1124     {
1125         return hapAbcOffset_;
1126     }
1127 
SetHapAbcSize(uint32_t size)1128     void SetHapAbcSize(uint32_t size)
1129     {
1130         hapAbcSize_ = size;
1131     }
1132 
GetHapAbcSize()1133     uint32_t GetHapAbcSize() const
1134     {
1135         return hapAbcSize_;
1136     }
1137 
SetCompilerNoCheck(bool value)1138     void SetCompilerNoCheck(bool value)
1139     {
1140         compilerNoCheck_ = value;
1141     }
1142 
IsCompilerNoCheck()1143     bool IsCompilerNoCheck() const
1144     {
1145         return compilerNoCheck_;
1146     }
1147 
1148     void SetTargetBuiltinsDtsPath();
1149 
1150     void SetOptionsForTargetCompilation();
1151 
SetFastAOTCompileMode(bool value)1152     void SetFastAOTCompileMode(bool value)
1153     {
1154         fastAOTCompileMode_ = value;
1155     }
1156 
GetFastAOTCompileMode()1157     bool GetFastAOTCompileMode() const
1158     {
1159         return fastAOTCompileMode_;
1160     }
1161 
SetEnableOptLoopPeeling(bool value)1162     void SetEnableOptLoopPeeling(bool value)
1163     {
1164         enableOptLoopPeeling_ = value;
1165     }
1166 
IsEnableOptLoopPeeling()1167     bool IsEnableOptLoopPeeling() const
1168     {
1169         return enableOptLoopPeeling_;
1170     }
1171 
1172 private:
StartsWith(const std::string & haystack,const std::string & needle)1173     static bool StartsWith(const std::string &haystack, const std::string &needle)
1174     {
1175         return std::equal(needle.begin(), needle.end(), haystack.begin());
1176     }
1177 
WasOptionSet(int option)1178     bool WasOptionSet(int option) const
1179     {
1180         return ((1ULL << static_cast<uint64_t>(option)) & wasSet_) != 0;
1181     }
1182 
1183     bool ParseBoolParam(bool* argBool);
1184     bool ParseDoubleParam(const std::string &option, double* argDouble);
1185     bool ParseIntParam(const std::string &option, int* argInt);
1186     bool ParseUint32Param(const std::string &option, uint32_t *argUInt32);
1187     bool ParseUint64Param(const std::string &option, uint64_t *argUInt64);
1188     void ParseListArgParam(const std::string &option, arg_list_t *argListStr, std::string delimiter);
1189 
1190     bool enableArkTools_ {true};
1191     std::string stubFile_ {"stub.an"};
1192     bool enableForceGc_ {true};
1193     bool forceFullGc_ {true};
1194     int arkProperties_ = GetDefaultProperties();
1195     std::string arkBundleName_ = {""};
1196     uint32_t gcThreadNum_ {7}; // 7: default thread num
1197     uint32_t longPauseTime_ {40}; // 40: default pause time
1198     std::string aotOutputFile_ {""};
1199     std::string targetTriple_ {TARGET_X64};
1200     uint32_t asmOptLevel_ {3}; // 3: default opt level
1201     uint32_t relocationMode_ {2}; // 2: default relocation mode
1202     uint32_t maxNonmovableSpaceCapacity_ {4_MB};
1203     bool enableAsmInterpreter_ {true};
1204     bool enableBuiltinsLazy_ {true};
1205     std::string asmOpcodeDisableRange_ {""};
1206     AsmInterParsedOption asmInterParsedOption_;
1207     uint64_t serializerBufferSizeLimit_ {2_GB};
1208     uint32_t heapSizeLimit_ {512_MB};
1209     bool enableIC_ {true};
1210     std::string icuDataPath_ {"default"};
1211     bool startupTime_ {false};
1212     std::string compilerLogOpt_ {"none"};
1213     std::string compilerLogMethods_ {"none"};
1214     bool compilerLogSnapshot_ {false};
1215     bool compilerLogTime_ {false};
1216     bool enableRuntimeStat_ {false};
1217     bool assertTypes_ {false};
1218     bool printTypeInfo_ {false};
1219     bool isWorker_ {false};
1220     std::string builtinsDTS_ {""};
1221     bool traceBc_ {false};
1222     std::string logLevel_ {"error"};
1223     arg_list_t logDebug_ {{"all"}};
1224     arg_list_t logInfo_ {{"all"}};
1225     arg_list_t logWarning_ {{"all"}};
1226     arg_list_t logError_ {{"all"}};
1227     arg_list_t logFatal_ {{"all"}};
1228     arg_list_t logComponents_ {{"all"}};
1229     bool enableAOT_ {false};
1230     uint32_t maxAotMethodSize_ {32_KB};
1231     double typeThreshold_ {-1};
1232     std::string entryPoint_ {"_GLOBAL::func_main_0"};
1233     bool mergeAbc_ {false};
1234     bool enableTypeLowering_ {true};
1235     bool enableEarlyElimination_ {true};
1236     bool enableLaterElimination_ {true};
1237     bool enableValueNumbering_ {true};
1238     bool enableOptInlining_ {true};
1239     bool enableOptPGOType_ {true};
1240     bool enableGlobalTypeInfer_ {false};
1241     bool enableOptTrackField_ {true};
1242     uint32_t compilerModuleMethods_ {100};
1243     uint64_t wasSet_ {0};
1244     bool enablePrintExecuteTime_ {false};
1245     bool enablePGOProfiler_ {false};
1246     bool reportModuleResolvingFailure_ {true};
1247     uint32_t pgoHotnessThreshold_ {1};
1248     std::string pgoProfilerPath_ {""};
1249     bool traceDeopt_ {false};
1250     uint8_t deoptThreshold_ {10};
1251     bool stressDeopt_ {false};
1252     bool optCodeProfiler_ {false};
1253     bool startGlobalLeakCheck_ {false};
1254     bool verifyVTable_ {false};
1255     std::string compilerSelectMethods_ {""};
1256     std::string compilerSkipMethods_ {""};
1257     bool traceInline_ {false};
1258     size_t maxInlineBytecodes_ {25};
1259     std::string targetCompilerMode_ {""};
1260     std::string hapPath_ {""};
1261     uint32_t hapAbcOffset_ {0};
1262     uint32_t hapAbcSize_ {0};
1263     bool compilerNoCheck_ {false};
1264     bool fastAOTCompileMode_ {true};
1265     bool enableOptLoopPeeling_ {false};
1266 };
1267 }  // namespace panda::ecmascript
1268 
1269 #endif  // ECMASCRIPT_JS_RUNTIME_OPTIONS_H_
1270