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 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 = 1 << 13, 46 ENABLE_CPU_PROFILER_VM_TAG = 1 << 14, 47 }; 48 49 // asm interpreter control parsed option 50 struct AsmInterParsedOption { 51 int handleStart {-1}; 52 int handleEnd {-1}; 53 bool enableAsm {false}; 54 }; 55 56 extern const std::string PUBLIC_API COMMON_HELP_HEAD_MSG; 57 extern const std::string PUBLIC_API STUB_HELP_HEAD_MSG; 58 extern const std::string PUBLIC_API HELP_OPTION_MSG; 59 extern const std::string PUBLIC_API HELP_TAIL_MSG; 60 61 enum CommandValues { 62 OPTION_DEFAULT, 63 OPTION_ENABLE_ARK_TOOLS, 64 OPTION_STUB_FILE, 65 OPTION_ENABLE_FORCE_GC, 66 OPTION_FORCE_FULL_GC, 67 OPTION_ARK_PROPERTIES, 68 OPTION_ARK_BUNDLENAME, 69 OPTION_GC_THREADNUM, 70 OPTION_LONG_PAUSE_TIME, 71 OPTION_AOT_FILE, 72 OPTION_TARGET_TRIPLE, 73 OPTION_ASM_OPT_LEVEL, 74 OPTION_RELOCATION_MODE, 75 OPTION_MAX_NONMOVABLE_SPACE_CAPACITY, 76 OPTION_ENABLE_ASM_INTERPRETER, 77 OPTION_ASM_OPCODE_DISABLE_RANGE, 78 OPTION_SERIALIZER_BUFFER_SIZE_LIMIT, 79 OPTION_HEAP_SIZE_LIMIT, 80 OPTION_ENABLE_IC, 81 OPTION_SNAPSHOT_FILE, 82 OPTION_FRAMEWORK_ABC_FILE, 83 OPTION_ICU_DATA_PATH, 84 OPTION_STARTUP_TIME, 85 OPTION_COMPILER_LOG_OPT, 86 OPTION_COMPILER_LOG_METHODS, 87 OPTION_ENABLE_RUNTIME_STAT, 88 OPTION_ASSERT_TYPES, 89 OPTION_PRINT_ANY_TYPES, 90 OPTION_COMPILER_LOG_SNAPSHOT, 91 OPTION_COMPILER_LOG_TIME, 92 OPTION_IS_WORKER, 93 OPTION_BUILTINS_DTS, 94 OPTION_TRACE_BC, 95 OPTION_TRACE_DEOPT, 96 OPTION_DEOPT_THRESHOLD, 97 OPTION_OPT_CODE_PROFILER, 98 OPTION_LOG_LEVEL, 99 OPTION_LOG_DEBUG, 100 OPTION_LOG_INFO, 101 OPTION_LOG_WARNING, 102 OPTION_LOG_ERROR, 103 OPTION_LOG_FATAL, 104 OPTION_LOG_COMPONENTS, 105 OPTION_MAX_AOTMETHODSIZE, 106 OPTION_ENTRY_POINT, 107 OPTION_MERGE_ABC, 108 OPTION_ENABLE_TYPE_LOWERING, 109 OPTION_HELP, 110 OPTION_PGO_PROFILER_PATH, 111 OPTION_PGO_HOTNESS_THRESHOLD, 112 OPTION_ENABLE_PGO_PROFILER, 113 OPTION_OPTIONS, 114 OPTION_PRINT_EXECUTE_TIME 115 }; 116 117 class PUBLIC_API JSRuntimeOptions { 118 public: JSRuntimeOptions()119 explicit JSRuntimeOptions() {} 120 ~JSRuntimeOptions() = default; 121 DEFAULT_COPY_SEMANTIC(JSRuntimeOptions); 122 DEFAULT_MOVE_SEMANTIC(JSRuntimeOptions); 123 124 bool ParseCommand(const int argc, const char **argv); 125 bool SetDefaultValue(char* argv); 126 EnableArkTools()127 bool EnableArkTools() const 128 { 129 return (enableArkTools_) || 130 ((static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_ARKTOOLS) != 0); 131 } 132 SetEnableArkTools(bool value)133 void SetEnableArkTools(bool value) { 134 enableArkTools_ = value; 135 } 136 WasSetEnableArkTools()137 bool WasSetEnableArkTools() const 138 { 139 return WasOptionSet(OPTION_ENABLE_ARK_TOOLS); 140 } 141 IsEnableRuntimeStat()142 bool IsEnableRuntimeStat() const 143 { 144 return enableRuntimeStat_; 145 } 146 SetEnableRuntimeStat(bool value)147 void SetEnableRuntimeStat(bool value) 148 { 149 enableRuntimeStat_ = value; 150 } 151 WasSetEnableRuntimeStat()152 bool WasSetEnableRuntimeStat() const 153 { 154 return WasOptionSet(OPTION_ENABLE_RUNTIME_STAT); 155 } 156 GetStubFile()157 std::string GetStubFile() const 158 { 159 return stubFile_; 160 } 161 SetStubFile(std::string value)162 void SetStubFile(std::string value) 163 { 164 stubFile_ = std::move(value); 165 } 166 WasStubFileSet()167 bool WasStubFileSet() const 168 { 169 return WasOptionSet(OPTION_STUB_FILE); 170 } 171 SetEnableAOT(bool value)172 void SetEnableAOT(bool value) 173 { 174 enableAOT_ = value; 175 } 176 GetEnableAOT()177 bool GetEnableAOT() const 178 { 179 return enableAOT_; 180 } 181 GetAOTOutputFile()182 std::string GetAOTOutputFile() const 183 { 184 return aotOutputFile_; 185 } 186 SetAOTOutputFile(const std::string & value)187 void SetAOTOutputFile(const std::string& value) 188 { 189 aotOutputFile_ = panda::os::file::File::GetExtendedFilePath(value); 190 } 191 WasAOTOutputFileSet()192 bool WasAOTOutputFileSet() const 193 { 194 return WasOptionSet(OPTION_AOT_FILE); 195 } 196 GetTargetTriple()197 std::string GetTargetTriple() const 198 { 199 return targetTriple_; 200 } 201 SetTargetTriple(std::string value)202 void SetTargetTriple(std::string value) 203 { 204 targetTriple_ = std::move(value); 205 } 206 GetOptLevel()207 size_t GetOptLevel() const 208 { 209 return asmOptLevel_; 210 } 211 SetOptLevel(size_t value)212 void SetOptLevel(size_t value) 213 { 214 asmOptLevel_ = value; 215 } 216 GetRelocMode()217 size_t GetRelocMode() const 218 { 219 return relocationMode_; 220 } 221 SetRelocMode(size_t value)222 void SetRelocMode(size_t value) 223 { 224 relocationMode_ = value; 225 } 226 EnableForceGC()227 bool EnableForceGC() const 228 { 229 return enableForceGc_; 230 } 231 SetEnableForceGC(bool value)232 void SetEnableForceGC(bool value) 233 { 234 enableForceGc_ = value; 235 } 236 ForceFullGC()237 bool ForceFullGC() const 238 { 239 return forceFullGc_; 240 } 241 SetForceFullGC(bool value)242 void SetForceFullGC(bool value) 243 { 244 forceFullGc_ = value; 245 } 246 SetGcThreadNum(size_t num)247 void SetGcThreadNum(size_t num) 248 { 249 gcThreadNum_ = num; 250 } 251 GetGcThreadNum()252 size_t GetGcThreadNum() const 253 { 254 return gcThreadNum_; 255 } 256 SetLongPauseTime(size_t time)257 void SetLongPauseTime(size_t time) 258 { 259 longPauseTime_ = time; 260 } 261 GetLongPauseTime()262 size_t GetLongPauseTime() const 263 { 264 return longPauseTime_; 265 } 266 SetArkProperties(int prop)267 void SetArkProperties(int prop) 268 { 269 if (prop != ArkProperties::DEFAULT) { 270 arkProperties_ = prop; 271 } 272 } 273 SetArkBundleName(std::string bundleName)274 void SetArkBundleName(std::string bundleName) 275 { 276 if (bundleName != "") { 277 arkBundleName_ = bundleName; 278 } 279 } 280 GetDefaultProperties()281 int GetDefaultProperties() 282 { 283 return ArkProperties::PARALLEL_GC | ArkProperties::CONCURRENT_MARK | ArkProperties::CONCURRENT_SWEEP 284 | ArkProperties::ENABLE_ARKTOOLS | ArkProperties::ENABLE_IDLE_GC; 285 } 286 GetArkProperties()287 int GetArkProperties() 288 { 289 return arkProperties_; 290 } 291 GetArkBundleName()292 std::string GetArkBundleName() const 293 { 294 return arkBundleName_; 295 } 296 EnableOptionalLog()297 bool EnableOptionalLog() const 298 { 299 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::OPTIONAL_LOG) != 0; 300 } 301 EnableGCStatsPrint()302 bool EnableGCStatsPrint() const 303 { 304 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::GC_STATS_PRINT) != 0; 305 } 306 EnableParallelGC()307 bool EnableParallelGC() const 308 { 309 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::PARALLEL_GC) != 0; 310 } 311 EnableConcurrentMark()312 bool EnableConcurrentMark() const 313 { 314 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CONCURRENT_MARK) != 0; 315 } 316 EnableExceptionBacktrace()317 bool EnableExceptionBacktrace() const 318 { 319 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::EXCEPTION_BACKTRACE) != 0; 320 } 321 EnableConcurrentSweep()322 bool EnableConcurrentSweep() const 323 { 324 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CONCURRENT_SWEEP) != 0; 325 } 326 EnableThreadCheck()327 bool EnableThreadCheck() const 328 { 329 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::THREAD_CHECK) != 0; 330 } 331 EnableIdleGC()332 bool EnableIdleGC() const 333 { 334 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_IDLE_GC) != 0; 335 } 336 EnableGlobalObjectLeakCheck()337 bool EnableGlobalObjectLeakCheck() const 338 { 339 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::GLOBAL_OBJECT_LEAK_CHECK) != 0; 340 } 341 EnableGlobalPrimitiveLeakCheck()342 bool EnableGlobalPrimitiveLeakCheck() const 343 { 344 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::GLOBAL_PRIMITIVE_LEAK_CHECK) != 0; 345 } 346 EnableGlobalLeakCheck()347 bool EnableGlobalLeakCheck() const 348 { 349 return EnableGlobalObjectLeakCheck() || EnableGlobalPrimitiveLeakCheck(); 350 } 351 EnableCpuProfiler()352 bool EnableCpuProfiler() const 353 { 354 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::CPU_PROFILER) != 0; 355 } 356 EnableCpuProfilerVMTag()357 bool EnableCpuProfilerVMTag() const 358 { 359 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_CPU_PROFILER_VM_TAG) != 0; 360 } 361 IsStartGlobalLeakCheck()362 bool IsStartGlobalLeakCheck() const 363 { 364 return startGlobalLeakCheck_; 365 } 366 SwitchStartGlobalLeakCheck()367 void SwitchStartGlobalLeakCheck() 368 { 369 startGlobalLeakCheck_ = !startGlobalLeakCheck_; 370 } 371 EnableSnapshotSerialize()372 bool EnableSnapshotSerialize() const 373 { 374 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_SNAPSHOT_SERIALIZE) != 0; 375 } 376 EnableSnapshotDeserialize()377 bool EnableSnapshotDeserialize() const 378 { 379 if (WIN_OR_MAC_OR_IOS_PLATFORM) { 380 return false; 381 } 382 383 return (static_cast<uint32_t>(arkProperties_) & ArkProperties::ENABLE_SNAPSHOT_DESERIALIZE) != 0; 384 } 385 WasSetMaxNonmovableSpaceCapacity()386 bool WasSetMaxNonmovableSpaceCapacity() const 387 { 388 return WasOptionSet(OPTION_MAX_NONMOVABLE_SPACE_CAPACITY); 389 } 390 MaxNonmovableSpaceCapacity()391 size_t MaxNonmovableSpaceCapacity() const 392 { 393 return maxNonmovableSpaceCapacity_; 394 } 395 SetMaxNonmovableSpaceCapacity(uint32_t value)396 void SetMaxNonmovableSpaceCapacity(uint32_t value) 397 { 398 maxNonmovableSpaceCapacity_ = value; 399 } 400 SetEnableAsmInterpreter(bool value)401 void SetEnableAsmInterpreter(bool value) 402 { 403 enableAsmInterpreter_ = value; 404 } 405 GetEnableAsmInterpreter()406 bool GetEnableAsmInterpreter() const 407 { 408 return enableAsmInterpreter_; 409 } 410 SetAsmOpcodeDisableRange(std::string value)411 void SetAsmOpcodeDisableRange(std::string value) 412 { 413 asmOpcodeDisableRange_ = std::move(value); 414 } 415 ParseAsmInterOption()416 void ParseAsmInterOption() 417 { 418 asmInterParsedOption_.enableAsm = enableAsmInterpreter_; 419 std::string strAsmOpcodeDisableRange = asmOpcodeDisableRange_; 420 if (strAsmOpcodeDisableRange.empty()) { 421 return; 422 } 423 424 // asm interpreter handle disable range 425 size_t pos = strAsmOpcodeDisableRange.find(","); 426 if (pos != std::string::npos) { 427 std::string strStart = strAsmOpcodeDisableRange.substr(0, pos); 428 std::string strEnd = strAsmOpcodeDisableRange.substr(pos + 1); 429 int start = strStart.empty() ? 0 : std::stoi(strStart); 430 int end = strEnd.empty() ? kungfu::BYTECODE_STUB_END_ID : std::stoi(strEnd); 431 if (start >= 0 && start < kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS 432 && end >= 0 && end < kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS 433 && start <= end) { 434 asmInterParsedOption_.handleStart = start; 435 asmInterParsedOption_.handleEnd = end; 436 } 437 } 438 } 439 GetAsmInterParsedOption()440 AsmInterParsedOption GetAsmInterParsedOption() const 441 { 442 return asmInterParsedOption_; 443 } 444 GetCompilerLogOption()445 std::string GetCompilerLogOption() const 446 { 447 return compilerLogOpt_; 448 } 449 SetCompilerLogOption(std::string value)450 void SetCompilerLogOption(std::string value) 451 { 452 compilerLogOpt_ = std::move(value); 453 } 454 WasSetCompilerLogOption()455 bool WasSetCompilerLogOption() const 456 { 457 return 1ULL << static_cast<uint64_t>(OPTION_COMPILER_LOG_OPT) & wasSet_ && 458 GetCompilerLogOption().find("none") == std::string::npos; 459 } 460 GetMethodsListForLog()461 std::string GetMethodsListForLog() const 462 { 463 return compilerLogMethods_; 464 } 465 SetMethodsListForLog(std::string value)466 void SetMethodsListForLog(std::string value) 467 { 468 compilerLogMethods_ = std::move(value); 469 } 470 WasSetMethodsListForLog()471 bool WasSetMethodsListForLog() const 472 { 473 return 1ULL << static_cast<uint64_t>(OPTION_COMPILER_LOG_METHODS) & wasSet_ && 474 GetCompilerLogOption().find("none") == std::string::npos && 475 GetCompilerLogOption().find("all") == std::string::npos; 476 } 477 SetCompilerLogSnapshot(bool value)478 void SetCompilerLogSnapshot(bool value) 479 { 480 compilerLogSnapshot_ = value; 481 } 482 IsEnableCompilerLogSnapshot()483 bool IsEnableCompilerLogSnapshot() const 484 { 485 return compilerLogSnapshot_; 486 } 487 WasSetCompilerLogSnapshot()488 bool WasSetCompilerLogSnapshot() const 489 { 490 return WasOptionSet(OPTION_COMPILER_LOG_SNAPSHOT); 491 } 492 SetCompilerLogTime(bool value)493 void SetCompilerLogTime(bool value) 494 { 495 compilerLogTime_ = value; 496 } 497 IsEnableCompilerLogTime()498 bool IsEnableCompilerLogTime() const 499 { 500 return compilerLogTime_; 501 } 502 WasSetCompilerLogTime()503 bool WasSetCompilerLogTime() const 504 { 505 return WasOptionSet(OPTION_COMPILER_LOG_TIME); 506 } 507 GetSerializerBufferSizeLimit()508 uint64_t GetSerializerBufferSizeLimit() const 509 { 510 return serializerBufferSizeLimit_; 511 } 512 SetSerializerBufferSizeLimit(uint64_t value)513 void SetSerializerBufferSizeLimit(uint64_t value) 514 { 515 serializerBufferSizeLimit_ = value; 516 } 517 GetHeapSizeLimit()518 uint32_t GetHeapSizeLimit() const 519 { 520 return heapSizeLimit_; 521 } 522 SetHeapSizeLimit(uint32_t value)523 void SetHeapSizeLimit(uint32_t value) 524 { 525 heapSizeLimit_ = value; 526 } 527 WasSetHeapSizeLimit()528 bool WasSetHeapSizeLimit() const 529 { 530 return WasOptionSet(OPTION_HEAP_SIZE_LIMIT); 531 } 532 SetIsWorker(bool isWorker)533 void SetIsWorker(bool isWorker) 534 { 535 isWorker_ = isWorker; 536 } 537 IsWorker()538 bool IsWorker() const 539 { 540 return isWorker_; 541 } 542 EnableIC()543 bool EnableIC() const 544 { 545 return enableIC_; 546 } 547 SetEnableIC(bool value)548 void SetEnableIC(bool value) 549 { 550 enableIC_ = value; 551 } 552 WasSetEnableIC()553 bool WasSetEnableIC() const 554 { 555 return WasOptionSet(OPTION_ENABLE_IC); 556 } 557 GetSnapshotFile()558 std::string GetSnapshotFile() const 559 { 560 return snapshotFile_; 561 } 562 SetSnapshotFile(std::string value)563 void SetSnapshotFile(std::string value) 564 { 565 snapshotFile_ = std::move(value); 566 } 567 WasSetSnapshotFile()568 bool WasSetSnapshotFile() const 569 { 570 return WasOptionSet(OPTION_SNAPSHOT_FILE); 571 } 572 GetFrameworkAbcFile()573 std::string GetFrameworkAbcFile() const 574 { 575 return frameworkAbcFile_; 576 } 577 SetFrameworkAbcFile(std::string value)578 void SetFrameworkAbcFile(std::string value) 579 { 580 frameworkAbcFile_ = std::move(value); 581 } 582 WasSetFrameworkAbcFile()583 bool WasSetFrameworkAbcFile() const 584 { 585 return WasOptionSet(OPTION_FRAMEWORK_ABC_FILE); 586 } 587 GetIcuDataPath()588 std::string GetIcuDataPath() const 589 { 590 return icuDataPath_; 591 } 592 SetIcuDataPath(std::string value)593 void SetIcuDataPath(std::string value) 594 { 595 icuDataPath_ = std::move(value); 596 } 597 WasSetIcuDataPath()598 bool WasSetIcuDataPath() const 599 { 600 return WasOptionSet(OPTION_ICU_DATA_PATH); 601 } 602 IsStartupTime()603 bool IsStartupTime() const 604 { 605 return startupTime_; 606 } 607 SetStartupTime(bool value)608 void SetStartupTime(bool value) 609 { 610 startupTime_ = value; 611 } 612 WasSetStartupTime()613 bool WasSetStartupTime() const 614 { 615 return WasOptionSet(OPTION_STARTUP_TIME); 616 } 617 AssertTypes()618 bool AssertTypes() const 619 { 620 return assertTypes_; 621 } 622 SetAssertTypes(bool value)623 void SetAssertTypes(bool value) 624 { 625 assertTypes_ = value; 626 } 627 PrintAnyTypes()628 bool PrintAnyTypes() const 629 { 630 return printAnyTypes_; 631 } 632 SetPrintAnyTypes(bool value)633 void SetPrintAnyTypes(bool value) 634 { 635 printAnyTypes_ = value; 636 } 637 SetBuiltinsDTS(const std::string & value)638 void SetBuiltinsDTS(const std::string& value) 639 { 640 builtinsDTS_ = panda::os::file::File::GetExtendedFilePath(value); 641 } 642 WasSetBuiltinsDTS()643 bool WasSetBuiltinsDTS() const 644 { 645 return WasOptionSet(OPTION_BUILTINS_DTS); 646 } 647 GetBuiltinsDTS()648 std::string GetBuiltinsDTS() const 649 { 650 return builtinsDTS_; 651 } 652 SetTraceBc(bool value)653 void SetTraceBc(bool value) 654 { 655 traceBc_ = value; 656 } 657 IsTraceBC()658 bool IsTraceBC() const 659 { 660 return traceBc_; 661 } 662 WasSetTraceBc()663 bool WasSetTraceBc() const 664 { 665 return WasOptionSet(OPTION_TRACE_BC); 666 } 667 668 GetLogLevel()669 std::string GetLogLevel() const 670 { 671 return logLevel_; 672 } 673 SetLogLevel(std::string value)674 void SetLogLevel(std::string value) 675 { 676 logLevel_ = std::move(value); 677 } 678 WasSetLogLevel()679 bool WasSetLogLevel() const 680 { 681 return WasOptionSet(OPTION_LOG_LEVEL); 682 } 683 GetLogComponents()684 arg_list_t GetLogComponents() const 685 { 686 return logComponents_; 687 } 688 SetLogComponents(arg_list_t value)689 void SetLogComponents(arg_list_t value) 690 { 691 logComponents_ = std::move(value); 692 } 693 WasSetLogComponents()694 bool WasSetLogComponents() const 695 { 696 return WasOptionSet(OPTION_LOG_COMPONENTS); 697 } 698 GetLogDebug()699 arg_list_t GetLogDebug() const 700 { 701 return logDebug_; 702 } 703 SetLogDebug(arg_list_t value)704 void SetLogDebug(arg_list_t value) 705 { 706 logDebug_ = std::move(value); 707 } 708 WasSetLogDebug()709 bool WasSetLogDebug() const 710 { 711 return WasOptionSet(OPTION_LOG_DEBUG); 712 } 713 GetLogInfo()714 arg_list_t GetLogInfo() const 715 { 716 return logInfo_; 717 } 718 SetLogInfo(arg_list_t value)719 void SetLogInfo(arg_list_t value) 720 { 721 logInfo_ = std::move(value); 722 } 723 WasSetLogInfo()724 bool WasSetLogInfo() const 725 { 726 return WasOptionSet(OPTION_LOG_INFO); 727 } 728 GetLogWarning()729 arg_list_t GetLogWarning() const 730 { 731 return logWarning_; 732 } 733 SetLogWarning(arg_list_t value)734 void SetLogWarning(arg_list_t value) 735 { 736 logWarning_ = std::move(value); 737 } 738 WasSetLogWarning()739 bool WasSetLogWarning() const 740 { 741 return WasOptionSet(OPTION_LOG_WARNING); 742 } 743 GetLogError()744 arg_list_t GetLogError() const 745 { 746 return logError_; 747 } 748 SetLogError(arg_list_t value)749 void SetLogError(arg_list_t value) 750 { 751 logError_ = std::move(value); 752 } 753 WasSetLogError()754 bool WasSetLogError() const 755 { 756 return WasOptionSet(OPTION_LOG_ERROR); 757 } 758 GetLogFatal()759 arg_list_t GetLogFatal() const 760 { 761 return logFatal_; 762 } 763 SetLogFatal(arg_list_t value)764 void SetLogFatal(arg_list_t value) 765 { 766 logFatal_ = std::move(value); 767 } 768 WasSetLogFatal()769 bool WasSetLogFatal() const 770 { 771 return WasOptionSet(OPTION_LOG_FATAL); 772 } 773 GetMaxAotMethodSize()774 size_t GetMaxAotMethodSize() const 775 { 776 return maxAotMethodSize_; 777 } 778 SetMaxAotMethodSize(uint32_t value)779 void SetMaxAotMethodSize(uint32_t value) 780 { 781 maxAotMethodSize_ = value; 782 } 783 GetEntryPoint()784 std::string GetEntryPoint() const 785 { 786 return entryPoint_; 787 } 788 SetEntryPoint(std::string value)789 void SetEntryPoint(std::string value) 790 { 791 entryPoint_ = std::move(value); 792 } 793 WasSetEntryPoint()794 bool WasSetEntryPoint() const 795 { 796 return WasOptionSet(OPTION_ENTRY_POINT); 797 } 798 GetMergeAbc()799 bool GetMergeAbc() const 800 { 801 return mergeAbc_; 802 } 803 SetMergeAbc(bool value)804 void SetMergeAbc(bool value) 805 { 806 mergeAbc_ = value; 807 } 808 SetEnablePrintExecuteTime(bool value)809 void SetEnablePrintExecuteTime(bool value) 810 { 811 enablePrintExecuteTime_ = value; 812 } 813 IsEnablePrintExecuteTime()814 bool IsEnablePrintExecuteTime() 815 { 816 return enablePrintExecuteTime_; 817 } 818 SetEnablePGOProfiler(bool value)819 void SetEnablePGOProfiler(bool value) 820 { 821 enablePGOProfiler_ = value; 822 } 823 IsEnablePGOProfiler()824 bool IsEnablePGOProfiler() const 825 { 826 return enablePGOProfiler_; 827 } 828 GetPGOHotnessThreshold()829 uint32_t GetPGOHotnessThreshold() const 830 { 831 return pgoHotnessThreshold_; 832 } 833 SetPGOHotnessThreshold(uint32_t threshold)834 void SetPGOHotnessThreshold(uint32_t threshold) 835 { 836 pgoHotnessThreshold_ = threshold; 837 } 838 GetPGOProfilerPath()839 std::string GetPGOProfilerPath() const 840 { 841 return pgoProfilerPath_; 842 } 843 SetPGOProfilerPath(const std::string & value)844 void SetPGOProfilerPath(const std::string& value) 845 { 846 pgoProfilerPath_ = panda::os::file::File::GetExtendedFilePath(value); 847 } 848 SetEnableTypeLowering(bool value)849 void SetEnableTypeLowering(bool value) 850 { 851 enableTypeLowering_ = value; 852 } 853 IsEnableTypeLowering()854 bool IsEnableTypeLowering() const 855 { 856 return enableTypeLowering_; 857 } 858 WasSet(int opt)859 void WasSet(int opt) 860 { 861 wasSet_ |= 1ULL << static_cast<uint64_t>(opt); 862 } 863 SetTraceDeopt(bool value)864 void SetTraceDeopt(bool value) 865 { 866 traceDeopt_= value; 867 } 868 GetTraceDeopt()869 bool GetTraceDeopt() const 870 { 871 return traceDeopt_; 872 } 873 SetDeoptThreshold(uint8_t value)874 void SetDeoptThreshold(uint8_t value) 875 { 876 deoptThreshold_ = value; 877 } 878 GetDeoptThreshold()879 uint32_t GetDeoptThreshold() const 880 { 881 return deoptThreshold_; 882 } 883 SetOptCodeProfiler(bool value)884 void SetOptCodeProfiler(bool value) 885 { 886 optCodeProfiler_ = value; 887 } 888 GetOptCodeProfiler()889 bool GetOptCodeProfiler() const 890 { 891 return optCodeProfiler_; 892 } 893 private: StartsWith(const std::string & haystack,const std::string & needle)894 static bool StartsWith(const std::string &haystack, const std::string &needle) 895 { 896 return std::equal(needle.begin(), needle.end(), haystack.begin()); 897 } 898 WasOptionSet(int option)899 bool WasOptionSet(int option) const 900 { 901 return ((1ULL << static_cast<uint64_t>(option)) & wasSet_) != 0; 902 } 903 904 bool ParseBoolParam(bool* argBool); 905 bool ParseIntParam(const std::string &option, int* argInt); 906 bool ParseUint32Param(const std::string &option, uint32_t *argUInt32); 907 bool ParseUint64Param(const std::string &option, uint64_t *argUInt64); 908 void ParseListArgParam(const std::string &option, arg_list_t *argListStr, std::string delimiter); 909 910 bool enableArkTools_ {true}; 911 std::string stubFile_ {"stub.an"}; 912 bool enableForceGc_ {true}; 913 bool forceFullGc_ {true}; 914 int arkProperties_ = GetDefaultProperties(); 915 std::string arkBundleName_ = {""}; 916 uint32_t gcThreadNum_ {7}; // 7: default thread num 917 uint32_t longPauseTime_ {40}; // 40: default pause time 918 std::string aotOutputFile_ {""}; 919 std::string targetTriple_ {"x86_64-unknown-linux-gnu"}; 920 uint32_t asmOptLevel_ {3}; // 3: default opt level 921 uint32_t relocationMode_ {2}; // 2: default relocation mode 922 uint32_t maxNonmovableSpaceCapacity_ {4_MB}; 923 bool enableAsmInterpreter_ {true}; 924 std::string asmOpcodeDisableRange_ {""}; 925 AsmInterParsedOption asmInterParsedOption_; 926 uint64_t serializerBufferSizeLimit_ {2_GB}; 927 uint32_t heapSizeLimit_ {512_MB}; 928 bool enableIC_ {true}; 929 std::string snapshotFile_ {"/system/etc/snapshot"}; 930 std::string frameworkAbcFile_ {"strip.native.min.abc"}; 931 std::string icuDataPath_ {"default"}; 932 bool startupTime_ {false}; 933 std::string compilerLogOpt_ {"none"}; 934 std::string compilerLogMethods_ {"none"}; 935 bool compilerLogSnapshot_ {false}; 936 bool compilerLogTime_ {false}; 937 bool enableRuntimeStat_ {false}; 938 bool assertTypes_ {false}; 939 bool printAnyTypes_ {false}; 940 bool isWorker_ {false}; 941 std::string builtinsDTS_ {""}; 942 bool traceBc_ {false}; 943 std::string logLevel_ {"error"}; 944 arg_list_t logDebug_ {{"all"}}; 945 arg_list_t logInfo_ {{"all"}}; 946 arg_list_t logWarning_ {{"all"}}; 947 arg_list_t logError_ {{"all"}}; 948 arg_list_t logFatal_ {{"all"}}; 949 arg_list_t logComponents_ {{"all"}}; 950 bool enableAOT_ {false}; 951 uint32_t maxAotMethodSize_ {32_KB}; 952 std::string entryPoint_ {"_GLOBAL::func_main_0"}; 953 bool mergeAbc_ {false}; 954 bool enableTypeLowering_ {true}; 955 uint64_t wasSet_ {0}; 956 bool enablePrintExecuteTime_ {false}; 957 bool enablePGOProfiler_ {false}; 958 uint32_t pgoHotnessThreshold_ {2}; 959 std::string pgoProfilerPath_ {""}; 960 bool traceDeopt_ {false}; 961 uint8_t deoptThreshold_ {10}; 962 bool optCodeProfiler_ {false}; 963 bool startGlobalLeakCheck_ {false}; 964 }; 965 } // namespace panda::ecmascript 966 967 #endif // ECMASCRIPT_JS_RUNTIME_OPTIONS_H_ 968