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 PANDA_RUNTIME_INCLUDE_RUNTIME_OPTIONS_H_ 17 #define PANDA_RUNTIME_INCLUDE_RUNTIME_OPTIONS_H_ 18 19 #include "generated/runtime_options_gen.h" 20 #include "utils/logger.h" 21 22 namespace panda { 23 class JSNApi; 24 25 namespace test { 26 class GetJniNameTest; 27 class MethodTest; 28 class CompilerThreadPoolTest; 29 class MockThreadPoolTest; 30 class ObjectHeaderTest; 31 class ThreadTest; 32 class ClassLinkerTest; 33 class InterpreterToCompiledCodeBridgeTest; 34 class CompiledCodeToInterpreterBridgeTest; 35 class DynCompiledCodeToInterpreterBridgeTest; 36 class JNITest; 37 class CFrameTest; 38 class StackWalkerTest; 39 class PandaRunner; 40 class CompilerQueueTest; 41 class DynObjectsTest; 42 class JSObjectTest; 43 class JSFunctionTest; 44 class BuiltinsTest; 45 class NameDictionaryTest; 46 class JSSymbolTest; 47 class NativePointerTest; 48 class JSTaggedValueTest; 49 class LexicalEnvTest; 50 class GlobalEnvTest; 51 class EcmaIntrinsicsTest; 52 class BuiltinsNumberTest; 53 class JSArrayTest; 54 class BuiltinsObjectTest; 55 class BuiltinsBooleanTest; 56 class BuiltinsErrorsTest; 57 class BuiltinsStringTest; 58 class JSDateTest; 59 class BuiltinsDateTest; 60 class BuiltinsSymbolTest; 61 class BuiltinsRegExpTest; 62 class BuiltinsFunctionTest; 63 class BuiltinsProxyTest; 64 class BuiltinsReflectTest; 65 class BuiltinsErrorTest; 66 class LinkedHashTableTest; 67 class BuiltinsSetTest; 68 class BuiltinsMapTest; 69 class BuiltinsWeakMapTest; 70 class BuiltinsWeakSetTest; 71 class BuiltinsMathTest; 72 class BuiltinsJsonTest; 73 class BuiltinsIteratorTest; 74 class JSSetTest; 75 class JSMapTest; 76 class JSProxyTest; 77 class JSPrimitiveRefTest; 78 class BuiltinsArrayTest; 79 class BuiltinsTypedArrayTest; 80 class ObjectFactoryTest; 81 class HistogramTest; 82 class JSHandleTest; 83 class JSForinIteratorTest; 84 class JSTaggedQueueTest; 85 class EcmaDumpTest; 86 class JSIteratorTest; 87 class BuiltinsArrayBufferTest; 88 class InlineCacheTest; 89 class WeakRefStwGCTest; 90 class WeakRefGenGCTest; 91 class DynBufferTest; 92 class RegExpTest; 93 class JSPromiseTest; 94 class BuiltinsDataViewTest; 95 class SepareteJSVMTest; 96 class HProfTest; 97 class HeapTrackerTest; 98 class DebuggerTypesTest; 99 class DebuggerEventsTest; 100 class DebuggerCommandsTest; 101 class SnapShotTest; 102 class JSVerificationTest; 103 class LargeObjectTest; 104 class GlueRegsTest; 105 } // namespace test 106 107 namespace coretypes::test { 108 class ArrayTest; 109 class ClassTest; 110 class StringTest; 111 } // namespace coretypes::test 112 113 namespace mem { 114 class FreeListAllocatorTest; 115 class VerificationTest; 116 class RegionAllocatorTest; 117 class HybridObjectAllocatorTest; 118 class PygoteSpaceAllocatorGenTest; 119 class PygoteSpaceAllocatorStwTest; 120 } // namespace mem 121 122 namespace mem::test { 123 class StringTableTest; 124 class FileMemoryProfileTest; 125 class MemStatsTest; 126 class MemLeakTest; 127 class MemStatsGCTest; 128 class MemStatsAdditionalInfoTest; 129 class PandaSmartPointersTest; 130 class InternalAllocatorTest; 131 class CardTableTest; 132 class MultithreadedInternStringTableTest; 133 class RemSetTest; 134 } // namespace mem::test 135 136 namespace mem::test { 137 class ReferenceStorageTest; 138 } // namespace mem::test 139 140 namespace concurrency::test { 141 class MonitorTest; 142 class AttachThreadTest; 143 } // namespace concurrency::test 144 145 namespace interpreter::test { 146 class InterpreterTest; 147 } // namespace interpreter::test 148 149 namespace debugger::test { 150 class DebuggerTest; 151 } // namespace debugger::test 152 153 namespace verifier::test { 154 class VerifierTest; 155 } // namespace verifier::test 156 157 namespace time::test { 158 class TimeTest; 159 } // namespace time::test 160 161 /** 162 * \brief Class represents runtime options 163 * 164 * It extends Options that represents public options (that described in options.yaml) and 165 * adds some private options related to runtime initialization that cannot be controlled 166 * via command line tools. Now they are used in unit tests to create minimal runtime for 167 * testing. 168 * 169 * To control private options from any class/function we need to make it friend for this class. 170 */ 171 class RuntimeOptions : public Options { 172 public: Options(exe_path)173 explicit RuntimeOptions(const std::string &exe_path = "") : Options(exe_path) {} 174 ~RuntimeOptions() = default; 175 DEFAULT_COPY_SEMANTIC(RuntimeOptions); 176 DEFAULT_MOVE_SEMANTIC(RuntimeOptions); 177 ShouldLoadBootPandaFiles()178 bool ShouldLoadBootPandaFiles() const 179 { 180 return should_load_boot_panda_files_; 181 } 182 ShouldInitializeIntrinsics()183 bool ShouldInitializeIntrinsics() const 184 { 185 return should_initialize_intrinsics_; 186 } 187 GetMobileLog()188 void *GetMobileLog() 189 { 190 return mlog_buf_print_ptr_; 191 } 192 GetFingerprint()193 std::string GetFingerprint() 194 { 195 return fingerPrint_; 196 } 197 SetFingerprint(const std::string & in)198 void SetFingerprint(const std::string &in) 199 { 200 fingerPrint_.assign(in); 201 } 202 SetUnwindStack(void * in)203 void SetUnwindStack(void *in) 204 { 205 unwindstack_ = reinterpret_cast<char *>(in); 206 } 207 GetUnwindStack()208 void *GetUnwindStack() 209 { 210 return unwindstack_; 211 } 212 SetCrashConnect(void * in)213 void SetCrashConnect(void *in) 214 { 215 crash_connect_ = reinterpret_cast<char *>(in); 216 } 217 GetCrashConnect()218 void *GetCrashConnect() 219 { 220 return crash_connect_; 221 } 222 SetMobileLog(void * mlog_buf_print_ptr)223 void SetMobileLog(void *mlog_buf_print_ptr) 224 { 225 mlog_buf_print_ptr_ = mlog_buf_print_ptr; 226 Logger::SetMobileLogPrintEntryPointByPtr(mlog_buf_print_ptr); 227 } 228 SetForSnapShotStart()229 void SetForSnapShotStart() 230 { 231 should_load_boot_panda_files_ = false; 232 should_initialize_intrinsics_ = false; 233 } 234 SetShouldLoadBootPandaFiles(bool value)235 void SetShouldLoadBootPandaFiles(bool value) 236 { 237 should_load_boot_panda_files_ = value; 238 } 239 SetShouldInitializeIntrinsics(bool value)240 void SetShouldInitializeIntrinsics(bool value) 241 { 242 should_initialize_intrinsics_ = value; 243 } 244 UseMallocForInternalAllocations()245 bool UseMallocForInternalAllocations() const 246 { 247 bool use_malloc = false; 248 auto option = GetInternalAllocatorType(); 249 if (option == "default") { 250 #ifdef NDEBUG 251 use_malloc = true; 252 #else 253 use_malloc = false; 254 #endif 255 } else if (option == "malloc") { 256 use_malloc = true; 257 } else if (option == "panda_allocators") { 258 use_malloc = false; 259 } else { 260 UNREACHABLE(); 261 } 262 return use_malloc; 263 } 264 265 private: 266 bool should_load_boot_panda_files_ {true}; 267 bool should_initialize_intrinsics_ {true}; 268 void *mlog_buf_print_ptr_ {nullptr}; 269 std::string fingerPrint_ {"unknown"}; 270 void *unwindstack_ {nullptr}; 271 void *crash_connect_ {nullptr}; 272 273 friend class panda::JSNApi; 274 friend class coretypes::test::ArrayTest; 275 friend class coretypes::test::ClassTest; 276 friend class coretypes::test::StringTest; 277 friend class mem::test::StringTableTest; 278 friend class mem::test::MultithreadedInternStringTableTest; 279 friend class mem::FreeListAllocatorTest; 280 friend class mem::RegionAllocatorTest; 281 friend class mem::HybridObjectAllocatorTest; 282 friend class mem::PygoteSpaceAllocatorGenTest; 283 friend class mem::PygoteSpaceAllocatorStwTest; 284 friend class concurrency::test::MonitorTest; 285 friend class concurrency::test::AttachThreadTest; 286 friend class test::MethodTest; 287 friend class test::CompilerThreadPoolTest; 288 friend class test::MockThreadPoolTest; 289 friend class test::ThreadTest; 290 friend class test::ObjectHeaderTest; 291 friend class test::ClassLinkerTest; 292 friend class test::CompilerQueueTest; 293 friend class test::GetJniNameTest; 294 friend class mem::test::FileMemoryProfileTest; 295 friend class mem::test::ReferenceStorageTest; 296 friend class mem::test::MemStatsTest; 297 friend class mem::test::MemLeakTest; 298 friend class mem::test::MemStatsGCTest; 299 friend class mem::test::MemStatsAdditionalInfoTest; 300 friend class mem::test::RemSetTest; 301 friend class interpreter::test::InterpreterTest; 302 friend class mem::test::PandaSmartPointersTest; 303 friend class test::InterpreterToCompiledCodeBridgeTest; 304 friend class test::CompiledCodeToInterpreterBridgeTest; 305 friend class test::DynCompiledCodeToInterpreterBridgeTest; 306 friend class test::JNITest; 307 friend class panda::test::CFrameTest; 308 friend class panda::test::StackWalkerTest; 309 friend class test::ClassLinkerTest; 310 friend class debugger::test::DebuggerTest; 311 friend class panda::test::PandaRunner; 312 friend class verifier::test::VerifierTest; 313 friend class panda::Logger; 314 friend class panda::test::DynObjectsTest; 315 friend class panda::test::JSObjectTest; 316 friend class panda::test::JSFunctionTest; 317 friend class panda::test::BuiltinsTest; 318 friend class panda::test::NativePointerTest; 319 friend class panda::test::JSSymbolTest; 320 friend class panda::test::NameDictionaryTest; 321 friend class panda::test::JSTaggedValueTest; 322 friend class panda::test::LexicalEnvTest; 323 friend class panda::test::GlobalEnvTest; 324 friend class panda::test::EcmaIntrinsicsTest; 325 friend class panda::test::BuiltinsNumberTest; 326 friend class panda::test::BuiltinsObjectTest; 327 friend class panda::test::JSArrayTest; 328 friend class panda::test::BuiltinsBooleanTest; 329 friend class time::test::TimeTest; 330 friend class panda::test::BuiltinsErrorsTest; 331 friend class panda::test::BuiltinsStringTest; 332 friend class panda::test::JSDateTest; 333 friend class panda::test::BuiltinsDateTest; 334 friend class panda::test::BuiltinsSymbolTest; 335 friend class panda::test::BuiltinsRegExpTest; 336 friend class panda::test::BuiltinsFunctionTest; 337 friend class panda::test::BuiltinsProxyTest; 338 friend class panda::test::BuiltinsReflectTest; 339 friend class panda::test::BuiltinsErrorTest; 340 friend class panda::test::LinkedHashTableTest; 341 friend class panda::test::BuiltinsSetTest; 342 friend class panda::test::BuiltinsMapTest; 343 friend class panda::test::BuiltinsWeakMapTest; 344 friend class panda::test::BuiltinsWeakSetTest; 345 friend class panda::test::BuiltinsMathTest; 346 friend class panda::test::BuiltinsJsonTest; 347 friend class panda::test::BuiltinsIteratorTest; 348 friend class panda::test::JSSetTest; 349 friend class panda::test::JSMapTest; 350 friend class panda::test::JSProxyTest; 351 friend class panda::test::JSPrimitiveRefTest; 352 friend class panda::test::BuiltinsArrayTest; 353 friend class panda::test::BuiltinsTypedArrayTest; 354 friend class panda::test::ObjectFactoryTest; 355 friend class panda::test::HistogramTest; 356 friend class panda::mem::VerificationTest; 357 friend class panda::test::JSHandleTest; 358 friend class panda::test::JSForinIteratorTest; 359 friend class panda::test::JSTaggedQueueTest; 360 friend class panda::test::EcmaDumpTest; 361 friend class panda::test::JSIteratorTest; 362 friend class panda::test::BuiltinsArrayBufferTest; 363 friend class panda::test::InlineCacheTest; 364 friend class panda::test::WeakRefStwGCTest; 365 friend class panda::test::WeakRefGenGCTest; 366 friend class mem::test::InternalAllocatorTest; 367 friend class panda::test::DynBufferTest; 368 friend class panda::test::RegExpTest; 369 friend class panda::test::JSPromiseTest; 370 friend class panda::test::BuiltinsDataViewTest; 371 friend class panda::test::SepareteJSVMTest; 372 friend class panda::test::HProfTest; 373 friend class panda::test::HeapTrackerTest; 374 friend class panda::test::DebuggerTypesTest; 375 friend class panda::test::DebuggerEventsTest; 376 friend class panda::test::DebuggerCommandsTest; 377 friend class panda::test::SnapShotTest; 378 friend class panda::mem::test::CardTableTest; 379 friend class panda::test::JSVerificationTest; 380 friend class panda::test::LargeObjectTest; 381 friend class panda::test::GlueRegsTest; 382 }; 383 384 } // namespace panda 385 386 #endif // PANDA_RUNTIME_INCLUDE_RUNTIME_OPTIONS_H_ 387