RuntimeConfig.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #ifndef HERMES_PUBLIC_RUNTIMECONFIG_H
  8. #define HERMES_PUBLIC_RUNTIMECONFIG_H
  9. #include "hermes/Public/CrashManager.h"
  10. #include "hermes/Public/CtorConfig.h"
  11. #include "hermes/Public/GCConfig.h"
  12. #include <memory>
  13. #ifdef HERMESVM_SERIALIZE
  14. #include <vector>
  15. namespace llvm {
  16. class MemoryBuffer;
  17. class raw_ostream;
  18. } // namespace llvm
  19. #endif
  20. namespace hermes {
  21. namespace vm {
  22. class PinnedHermesValue;
  23. #ifdef HERMESVM_SERIALIZE
  24. class Serializer;
  25. class Deserializer;
  26. #endif
  27. // Parameters for Runtime initialisation. Check documentation in README.md
  28. // constexpr indicates that the default value is constexpr.
  29. #define RUNTIME_FIELDS_BASE(F) \
  30. /* Parameters to be passed on to the GC. */ \
  31. F(HERMES_NON_CONSTEXPR, vm::GCConfig, GCConfig) \
  32. \
  33. /* Pre-allocated Register Stack */ \
  34. F(constexpr, PinnedHermesValue *, RegisterStack, nullptr) \
  35. \
  36. /* Register Stack Size */ \
  37. F(constexpr, unsigned, MaxNumRegisters, 1024 * 1024) \
  38. \
  39. /* Whether or not the JIT is enabled */ \
  40. F(constexpr, bool, EnableJIT, false) \
  41. \
  42. /* Whether to allow eval and Function ctor */ \
  43. F(constexpr, bool, EnableEval, true) \
  44. \
  45. /* Whether to verify the IR generated by eval and Function ctor */ \
  46. F(constexpr, bool, VerifyEvalIR, false) \
  47. \
  48. /* Support for ES6 Proxy. */ \
  49. F(constexpr, bool, ES6Proxy, false) \
  50. \
  51. /* Support for ES6 Symbol. */ \
  52. F(constexpr, bool, ES6Symbol, true) \
  53. \
  54. /* Trace non-deterministic JS behavior */ \
  55. F(constexpr, bool, TraceEnvironmentInteractions, false) \
  56. \
  57. /* Enable sampling certain statistics. */ \
  58. F(constexpr, bool, EnableSampledStats, false) \
  59. \
  60. /* Whether to enable sampling profiler */ \
  61. F(constexpr, bool, EnableSampleProfiling, false) \
  62. \
  63. /* Whether to randomize stack placement etc. */ \
  64. F(constexpr, bool, RandomizeMemoryLayout, false) \
  65. \
  66. /* Eagerly read bytecode into page cache. */ \
  67. F(constexpr, unsigned, BytecodeWarmupPercent, 0) \
  68. \
  69. /* Signal-based I/O tracking. Slows down execution. If enabled, */ \
  70. /* all bytecode buffers > 64 kB passed to Hermes must be mmap:ed. */ \
  71. F(constexpr, bool, TrackIO, false) \
  72. \
  73. /* Enable contents of HermesInternal */ \
  74. F(constexpr, bool, EnableHermesInternal, true) \
  75. \
  76. /* Enable methods exposed to JS for testing */ \
  77. F(constexpr, bool, EnableHermesInternalTestMethods, false) \
  78. \
  79. /* Allows Function.toString() to return the original source code */ \
  80. /* if available. For this to work code must have been compiled at */ \
  81. /* runtime with CompileFlags::allowFunctionToStringWithRuntimeSource set. */ \
  82. F(constexpr, bool, AllowFunctionToStringWithRuntimeSource, false) \
  83. \
  84. /* An interface for managing crashes. */ \
  85. F(HERMES_NON_CONSTEXPR, \
  86. std::shared_ptr<CrashManager>, \
  87. CrashMgr, \
  88. new NopCrashManager) \
  89. \
  90. /* The flags passed from a VM experiment */ \
  91. F(constexpr, uint32_t, VMExperimentFlags, 0) \
  92. /* RUNTIME_FIELDS END */
  93. #ifdef HERMESVM_SERIALIZE
  94. using ExternalPointersVectorFunction = std::vector<void *>();
  95. #define RUNTIME_FIELDS_SD(F) \
  96. /* Should serialize after initialization */ \
  97. F(HERMES_NON_CONSTEXPR, \
  98. std::shared_ptr<llvm::raw_ostream>, \
  99. SerializeAfterInitFile, \
  100. nullptr) \
  101. /* Should deserialize instead of initialization */ \
  102. F(HERMES_NON_CONSTEXPR, \
  103. std::shared_ptr<llvm::MemoryBuffer>, \
  104. DeserializeFile, \
  105. nullptr) \
  106. /* A function to get pointer values not visible to Runtime. e.g. \
  107. * function pointers defined in ConsoleHost*/ \
  108. F(constexpr, \
  109. ExternalPointersVectorFunction *, \
  110. ExternalPointersVectorCallBack, \
  111. nullptr)
  112. #define RUNTIME_FIELDS(F) \
  113. RUNTIME_FIELDS_BASE(F) \
  114. RUNTIME_FIELDS_SD(F)
  115. #else // ifndef HERMESVM_SERIALIZE
  116. #define RUNTIME_FIELDS(F) RUNTIME_FIELDS_BASE(F)
  117. #endif // HERMESVM_SERIALIZE
  118. _HERMES_CTORCONFIG_STRUCT(RuntimeConfig, RUNTIME_FIELDS, {});
  119. #undef RUNTIME_FIELDS
  120. } // namespace vm
  121. } // namespace hermes
  122. #endif // HERMES_PUBLIC_RUNTIMECONFIG_H