CommonDefines.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. /*****************************************************************************************************
  7. * This file contains defines that switch feature on or off, or configuration a feature at build time
  8. *****************************************************************************************************/
  9. #include "TargetVer.h"
  10. #include "Warnings.h"
  11. #include "ChakraCoreVersion.h"
  12. //----------------------------------------------------------------------------------------------------
  13. // Default debug/fretest/release flags values
  14. // - Set the default values of debug/fretest/release flags if it is not set by the command line
  15. //----------------------------------------------------------------------------------------------------
  16. #ifndef DBG_DUMP
  17. #define DBG_DUMP 0
  18. #endif
  19. #ifdef _DEBUG
  20. #ifdef DEBUG
  21. #undef DEBUG
  22. #endif
  23. #define DEBUG 1
  24. #endif
  25. // if test hook is enabled, debug config options are enabled too
  26. #ifdef ENABLE_TEST_HOOKS
  27. #ifndef ENABLE_DEBUG_CONFIG_OPTIONS
  28. #define ENABLE_DEBUG_CONFIG_OPTIONS 1
  29. #endif
  30. #endif
  31. // ENABLE_DEBUG_CONFIG_OPTIONS is enabled in debug build when DBG or DBG_DUMP is defined
  32. // It is enabled in fretest build (jscript9test.dll and jc.exe) in the build script
  33. #if DBG || DBG_DUMP
  34. #ifndef ENABLE_DEBUG_CONFIG_OPTIONS
  35. #define ENABLE_DEBUG_CONFIG_OPTIONS 1
  36. #endif
  37. // Flag to control availability of other flags to control regex debugging, tracing, profiling, etc. This is separate from
  38. // ENABLE_DEBUG_CONFIG_OPTIONS because enabling this flag may affect performance significantly, even with default values for
  39. // the regex flags this flag would make available.
  40. #ifndef ENABLE_REGEX_CONFIG_OPTIONS
  41. #define ENABLE_REGEX_CONFIG_OPTIONS 1
  42. #endif
  43. #endif
  44. // TODO: consider removing before RTM: keep for CHK/FRETEST but remove from FRE.
  45. // This will cause terminate process on AV/Assert rather that letting PDM (F12/debugger scenarios) eat exceptions.
  46. // At least for now, enable this even in FRE builds. See ReportError.h.
  47. #define ENABLE_DEBUG_API_WRAPPER 1
  48. //----------------------------------------------------------------------------------------------------
  49. // Define Architectures' aliases for Simplicity
  50. //----------------------------------------------------------------------------------------------------
  51. #if defined(_M_ARM) || defined(_M_ARM64)
  52. #define _M_ARM32_OR_ARM64 1
  53. #endif
  54. #if defined(_M_IX86) || defined(_M_ARM)
  55. #define TARGET_32 1
  56. #endif
  57. #if defined(_M_X64) || defined(_M_ARM64)
  58. #define TARGET_64 1
  59. #endif
  60. #ifndef DECLSPEC_CHPE_GUEST
  61. // For CHPE build aka Arm64.x86
  62. // https://osgwiki.com/wiki/ARM64_CHPE
  63. // On ChakraCore alone we do not support this
  64. // so we define to nothing to avoid build breaks
  65. #define DECLSPEC_CHPE_GUEST
  66. #endif
  67. // Memory Protections
  68. #ifdef _CONTROL_FLOW_GUARD
  69. #define PAGE_EXECUTE_RO_TARGETS_INVALID (PAGE_EXECUTE_READ | PAGE_TARGETS_INVALID)
  70. #else
  71. #define PAGE_EXECUTE_RO_TARGETS_INVALID (PAGE_EXECUTE_READ)
  72. #endif
  73. //----------------------------------------------------------------------------------------------------
  74. // Enabled features
  75. //----------------------------------------------------------------------------------------------------
  76. // NOTE: Disabling these might not work and are not fully supported and maintained
  77. // Even if it builds, it may not work properly. Disable at your own risk
  78. // Config options
  79. #define CONFIG_PARSE_CONFIG_FILE 1
  80. #ifdef _WIN32
  81. #define CONFIG_CONSOLE_AVAILABLE 1
  82. #define CONFIG_RICH_TRACE_FORMAT 1
  83. #else
  84. #define CONFIG_CONSOLE_AVAILABLE 0
  85. #define CONFIG_RICH_TRACE_FORMAT 0
  86. #endif
  87. // ByteCode
  88. #define VARIABLE_INT_ENCODING 1 // Byte code serialization variable size int field encoding
  89. #define BYTECODE_BRANCH_ISLAND // Byte code short branch and branch island
  90. #if defined(_WIN32) || defined(HAS_REAL_ICU)
  91. #define ENABLE_UNICODE_API 1 // Enable use of Unicode-related APIs
  92. #endif
  93. // Language features
  94. #if !defined(CHAKRACORE_LITE) && (defined(_WIN32) || defined(INTL_ICU))
  95. #define ENABLE_INTL_OBJECT // Intl support
  96. #define ENABLE_JS_BUILTINS // Built In functions support
  97. #endif
  98. //#define INTL_ICU 1 // NOTE: uncomment this to allow the IDE to see INTL_ICU blocks
  99. #ifdef INTL_ICU
  100. #ifdef DBG
  101. //#define INTL_ICU_DEBUG 1 // NOTE: uncomment this to display INTL_ICU-specific debug output
  102. #endif
  103. //#define INTL_ICU_ALLOW_HYBRID 1 // NOTE: uncomment this line to test INTL_ICU SxS with INTL_WINGLOB while INTL_ICU is in-development
  104. #endif
  105. #if defined(_WIN32) && (!defined(INTL_ICU) || (defined(INTL_ICU) && defined(INTL_ICU_ALLOW_HYBRID)))
  106. #define INTL_WINGLOB 1
  107. #endif
  108. #define ENABLE_ES6_CHAR_CLASSIFIER // ES6 Unicode character classifier support
  109. // Type system features
  110. #define PERSISTENT_INLINE_CACHES // *** TODO: Won't build if disabled currently
  111. #if !DISABLE_JIT
  112. #define ENABLE_FIXED_FIELDS 1 // Turn on fixed fields if JIT is enabled
  113. #endif
  114. #if ENABLE_FIXED_FIELDS
  115. #define SUPPORT_FIXED_FIELDS_ON_PATH_TYPES
  116. #endif
  117. // xplat-todo: revisit these features
  118. #ifdef _WIN32
  119. // dep: TIME_ZONE_INFORMATION, DaylightTimeHelper, Windows.Globalization
  120. #define ENABLE_GLOBALIZATION
  121. // #ifndef __clang__
  122. // xplat-todo: change DISABLE_SEH to ENABLE_SEH and move here
  123. // #define ENABLE_SIMDJS
  124. // #endif
  125. #define ENABLE_CUSTOM_ENTROPY
  126. #endif
  127. // dep: IDebugDocumentContext
  128. #if !BUILD_WITHOUT_SCRIPT_DEBUG
  129. #define ENABLE_SCRIPT_DEBUGGING
  130. #endif
  131. // GC features
  132. #define BUCKETIZE_MEDIUM_ALLOCATIONS 1 // *** TODO: Won't build if disabled currently
  133. #define SMALLBLOCK_MEDIUM_ALLOC 1 // *** TODO: Won't build if disabled currently
  134. #define LARGEHEAPBLOCK_ENCODING 1 // Large heap block metadata encoding
  135. #ifndef CHAKRACORE_LITE
  136. #define IDLE_DECOMMIT_ENABLED 1 // Idle Decommit
  137. #endif
  138. #if defined(NTBUILD) || defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  139. #define RECYCLER_PAGE_HEAP // PageHeap support, on by default, off in ChakraCore release build
  140. #endif
  141. #ifndef ENABLE_VALGRIND
  142. #define ENABLE_CONCURRENT_GC 1
  143. #ifdef _WIN32
  144. #define ENABLE_ALLOCATIONS_DURING_CONCURRENT_SWEEP 1 // Needs ENABLE_CONCURRENT_GC to be enabled for this to be enabled.
  145. #else
  146. #define ENABLE_ALLOCATIONS_DURING_CONCURRENT_SWEEP 0 // Needs ENABLE_CONCURRENT_GC to be enabled for this to be enabled.
  147. #endif
  148. #else
  149. #define ENABLE_CONCURRENT_GC 0
  150. #define ENABLE_ALLOCATIONS_DURING_CONCURRENT_SWEEP 0 // Needs ENABLE_CONCURRENT_GC to be enabled for this to be enabled.
  151. #endif
  152. #ifdef _WIN32
  153. #define SYSINFO_IMAGE_BASE_AVAILABLE 1
  154. #define SUPPORT_WIN32_SLIST 1
  155. #ifndef CHAKRACORE_LITE
  156. #define ENABLE_JS_ETW // ETW support
  157. #endif
  158. #else
  159. #define SYSINFO_IMAGE_BASE_AVAILABLE 0
  160. #define SUPPORT_WIN32_SLIST 0
  161. #endif
  162. #ifdef CHAKRACORE_LITE
  163. #define USE_VPM_TABLE 0
  164. #else
  165. #define USE_VPM_TABLE 1
  166. #endif
  167. // xplat-todo: fix up vpm.64b.h generation to generate correctly
  168. // templatized code
  169. #if defined(_MSC_VER) && !defined(__clang__)
  170. #define USE_STATIC_VPM 1 // Disable to force generation at runtime
  171. #else
  172. #define USE_STATIC_VPM 0
  173. #endif
  174. #if ENABLE_CONCURRENT_GC
  175. // Write-barrier refers to a software write barrier implementation using a card table.
  176. // Write watch refers to a hardware backed write-watch feature supported by the Windows memory manager.
  177. // Both are used for detecting changes to memory for concurrent and partial GC.
  178. // RECYCLER_WRITE_BARRIER controls the former, RECYCLER_WRITE_WATCH controls the latter.
  179. // GLOBAL_ENABLE_WRITE_BARRIER controls the smart pointer wrapper at compile time, every Field annotation on the
  180. // recycler allocated class will take effect if GLOBAL_ENABLE_WRITE_BARRIER is 1, otherwise only the class declared
  181. // with FieldWithBarrier annotations use the WriteBarrierPtr<>, see WriteBarrierMacros.h and RecyclerPointers.h for detail
  182. #define RECYCLER_WRITE_BARRIER // Write Barrier support
  183. #ifdef _WIN32
  184. #define RECYCLER_WRITE_WATCH // Support hardware write watch
  185. #endif
  186. #ifdef RECYCLER_WRITE_BARRIER
  187. #if !GLOBAL_ENABLE_WRITE_BARRIER
  188. #ifdef _WIN32
  189. #define GLOBAL_ENABLE_WRITE_BARRIER 0
  190. #else
  191. #define GLOBAL_ENABLE_WRITE_BARRIER 1
  192. #endif
  193. #endif
  194. #endif
  195. #define ENABLE_PARTIAL_GC 1
  196. #define ENABLE_BACKGROUND_PAGE_ZEROING 1
  197. #define ENABLE_BACKGROUND_PAGE_FREEING 1
  198. #define ENABLE_RECYCLER_TYPE_TRACKING 1
  199. #else
  200. #define ENABLE_PARTIAL_GC 0
  201. #define ENABLE_BACKGROUND_PAGE_ZEROING 0
  202. #define ENABLE_BACKGROUND_PAGE_FREEING 0
  203. #define ENABLE_RECYCLER_TYPE_TRACKING 0
  204. #endif
  205. #if ENABLE_BACKGROUND_PAGE_ZEROING && !ENABLE_BACKGROUND_PAGE_FREEING
  206. #error "Background page zeroing can't be turned on if freeing pages in the background is disabled"
  207. #endif
  208. #if defined(_WIN32) && !GLOBAL_ENABLE_WRITE_BARRIER
  209. #define RECYCLER_VISITED_HOST
  210. #endif
  211. // JIT features
  212. #if DISABLE_JIT
  213. #define ENABLE_NATIVE_CODEGEN 0
  214. #define ENABLE_PROFILE_INFO 0
  215. #define ENABLE_BACKGROUND_JOB_PROCESSOR 0
  216. #define ENABLE_BACKGROUND_PARSING 0 // Disable background parsing in this mode
  217. // We need to decouple the Jobs infrastructure out of
  218. // Backend to make background parsing work with JIT disabled
  219. #define DYNAMIC_INTERPRETER_THUNK 0
  220. #define DISABLE_DYNAMIC_PROFILE_DEFER_PARSE
  221. #define ENABLE_COPYONACCESS_ARRAY 0
  222. #else
  223. // By default, enable the JIT
  224. #define ENABLE_NATIVE_CODEGEN 1
  225. #define ENABLE_PROFILE_INFO 1
  226. #define ENABLE_BACKGROUND_JOB_PROCESSOR 1
  227. #define ENABLE_COPYONACCESS_ARRAY 1
  228. #ifndef DYNAMIC_INTERPRETER_THUNK
  229. #if defined(TARGET_32) || defined(TARGET_64)
  230. #define DYNAMIC_INTERPRETER_THUNK 1
  231. #else
  232. #define DYNAMIC_INTERPRETER_THUNK 0
  233. #endif
  234. #endif
  235. // Only enable background parser in debug build.
  236. #ifdef DBG
  237. #define ENABLE_BACKGROUND_PARSING 1
  238. #endif
  239. #if ENABLE_DEBUG_CONFIG_OPTIONS
  240. #define ALLOW_JIT_REPRO
  241. #endif
  242. #endif
  243. #if ENABLE_NATIVE_CODEGEN
  244. #ifdef _WIN32
  245. #define ENABLE_OOP_NATIVE_CODEGEN 1 // Out of process JIT
  246. #endif
  247. // ToDo (SaAgarwa): Disable VirtualTypedArray on ARM64 till we make sure it works correctly
  248. #if defined(_WIN32) && defined(TARGET_64) && !defined(_M_ARM64)
  249. #define ENABLE_FAST_ARRAYBUFFER 1
  250. #endif
  251. #endif
  252. // Other features
  253. // #define CHAKRA_CORE_DOWN_COMPAT 1
  254. // todo:: Enable vectorcall on NTBUILD. OS#13609380
  255. #if defined(_WIN32) && !defined(NTBUILD) && defined(_M_IX86)
  256. #define VECTORCALL __vectorcall
  257. #else
  258. #define VECTORCALL
  259. #endif
  260. #if defined(ENABLE_DEBUG_CONFIG_OPTIONS) || defined(CHAKRA_CORE_DOWN_COMPAT)
  261. #define DELAYLOAD_SET_CFG_TARGET 1
  262. #endif
  263. #ifndef PERFMAP_SIGNAL
  264. #define PERFMAP_SIGNAL SIGUSR2
  265. #endif
  266. #ifndef NTBUILD
  267. #define DELAYLOAD_SECTIONAPI 1
  268. #define DELAYLOAD_UNLOCKMEMORY 1
  269. #endif
  270. #ifdef NTBUILD
  271. #define ENABLE_PROJECTION
  272. #define ENABLE_FOUNDATION_OBJECT
  273. #define ENABLE_EXPERIMENTAL_FLAGS
  274. #define ENABLE_WININET_PROFILE_DATA_CACHE
  275. #define ENABLE_BASIC_TELEMETRY
  276. #define ENABLE_DOM_FAST_PATH
  277. #define EDIT_AND_CONTINUE
  278. #define ENABLE_JIT_CLAMP
  279. #define ENABLE_SCRIPT_PROFILING
  280. #endif
  281. // Telemetry flags
  282. #ifdef ENABLE_BASIC_TELEMETRY
  283. #define ENABLE_DIRECTCALL_TELEMETRY
  284. #endif
  285. // Telemetry features (non-DEBUG related)
  286. #ifdef ENABLE_BASIC_TELEMETRY
  287. // These defines can be "overridden" in other headers (e.g. ESBuiltInsTelemetryProvider.h) in case a specific telemetry provider wants to change an option for performance.
  288. #define TELEMETRY_OPCODE_OFFSET_ENABLED true // If the BytecodeOffset and FunctionId are logged.
  289. #define TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId) true // Any filter to apply on a per propertyId basis in the opcode handler for GetProperty/TypeofProperty/GetMethodProperty/etc.
  290. #define TELEMETRY_OPCODE_GET_PROPERTY_VALUES true // If no telemetry providers need the values of properties then this option skips getting the value in the TypeofProperty opcode handler.
  291. // #define TELEMETRY_PROFILED // If telemetry should capture "Profiled*" operations
  292. // #define TELEMETRY_CACHEHIT // If telemetry should capture data that was gotten with a Cache Hit
  293. // #define TELEMETRY_JSO // If telemetry should capture JavascriptOperators (expensive, as it happens during JITed code too, not just interpreted mode)
  294. #define TELEMETRY_AddToCache // If telemetry should capture property-gets only when the propertyId is added to the cache (generally this means only the first usage of any feature is logged)
  295. // #define TELEMETRY_INTERPRETER // If telemetry should capture more interpreter events compared to just TELEMETRY_AddToCache
  296. #define TELEMETRY_TRACELOGGING // Telemetry output using TraceLogging
  297. // #define TELEMETRY_OUTPUTPRINT // Telemetry output using Output::Print
  298. // Enable/disable specific telemetry providers:
  299. #define TELEMETRY_ESB // Telemetry of ECMAScript Built-Ins usage or detection.
  300. // #define TELEMETRY_ARRAY_USAGE // Telemetry of Array usage statistics
  301. #define TELEMETRY_DateParse // Telemetry of `Date.parse`
  302. #ifdef TELEMETRY_ESB
  303. // Because ESB telemetry is in-production and has major performance implications, this redefines some of the #defines above to disable non-critical functionality to get more performance.
  304. #undef TELEMETRY_OPCODE_OFFSET_ENABLED // Disable the FunctionId+Offset tracker.
  305. #define TELEMETRY_OPCODE_OFFSET_ENABLED false
  306. #undef TELEMETRY_PROPERTY_OPCODE_FILTER // Redefine the Property Opcode filter to ignore non-built-in properties.
  307. #define TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId) (propertyId < Js::PropertyIds::_countJSOnlyProperty)
  308. #undef TELEMETRY_OPCODE_GET_PROPERTY_VALUES
  309. #define TELEMETRY_OPCODE_GET_PROPERTY_VALUES false
  310. //#define TELEMETRY_ESB_GetConstructorPropertyPolyfillDetection // Whether telemetry will inspect the `.constructor` property of every Object instance to determine if it's a polyfill of a known ES built-in.
  311. #endif
  312. #define REJIT_STATS
  313. #else
  314. #define TELEMETRY_OPCODE_OFFSET_ENABLED false
  315. #define TELEMETRY_OPCODE_FILTER(propertyId) false
  316. #endif
  317. #if ENABLE_DEBUG_CONFIG_OPTIONS
  318. #define ENABLE_DIRECTCALL_TELEMETRY_STATS
  319. #endif
  320. //----------------------------------------------------------------------------------------------------
  321. // Debug and fretest features
  322. //----------------------------------------------------------------------------------------------------
  323. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  324. #define BAILOUT_INJECTION
  325. #if ENABLE_PROFILE_INFO
  326. #define DYNAMIC_PROFILE_STORAGE
  327. #define DYNAMIC_PROFILE_MUTATOR
  328. #endif
  329. #define RUNTIME_DATA_COLLECTION
  330. #define SECURITY_TESTING
  331. // xplat-todo: Temporarily disable profile output on non-Win32 builds
  332. #ifdef _WIN32
  333. #define PROFILE_EXEC
  334. #endif
  335. #define BGJIT_STATS
  336. #define REJIT_STATS
  337. #define PERF_HINT
  338. #define POLY_INLINE_CACHE_SIZE_STATS
  339. #define JS_PROFILE_DATA_INTERFACE 1
  340. #define EXCEPTION_RECOVERY 1
  341. #define RECYCLER_TEST_SUPPORT
  342. #define ARENA_ALLOCATOR_FREE_LIST_SIZE
  343. // TODO (t-doilij) combine IR_VIEWER and ENABLE_IR_VIEWER
  344. #if 0
  345. #if ENABLE_NATIVE_CODEGEN
  346. #define IR_VIEWER
  347. #define ENABLE_IR_VIEWER
  348. #define ENABLE_IR_VIEWER_DBG_DUMP // TODO (t-doilij) disable this before check-in
  349. #endif
  350. #endif
  351. #ifdef ENABLE_JS_ETW
  352. #define TEST_ETW_EVENTS
  353. #endif
  354. // VTUNE profiling requires ETW trace
  355. #if defined(_M_IX86) || defined(_M_X64)
  356. #define VTUNE_PROFILING
  357. #endif
  358. #ifdef NTBUILD
  359. #define PERF_COUNTERS
  360. #define ENABLE_MUTATION_BREAKPOINT
  361. #endif
  362. #ifdef _CONTROL_FLOW_GUARD
  363. #define CONTROL_FLOW_GUARD_LOGGER
  364. #endif
  365. #ifndef ENABLE_TEST_HOOKS
  366. #define ENABLE_TEST_HOOKS
  367. #endif
  368. #endif // ENABLE_DEBUG_CONFIG_OPTIONS
  369. ////////
  370. //Time Travel flags
  371. //Include TTD code in the build when building for Chakra (except NT/Edge) or for debug/test builds
  372. #if defined(ENABLE_SCRIPT_DEBUGGING) && (!defined(NTBUILD) || defined(ENABLE_DEBUG_CONFIG_OPTIONS))
  373. #define ENABLE_TTD 1
  374. #else
  375. #define ENABLE_TTD 0
  376. #endif
  377. #if ENABLE_TTD
  378. #define TTDAssert(C, M) { if(!(C)) TTDAbort_fatal_error(M); }
  379. #else
  380. #define TTDAssert(C, M)
  381. #endif
  382. #if ENABLE_TTD
  383. //A workaround for profile based creation of Native Arrays -- we may or may not want to allow since it differs in record/replay and (currently) asserts in our snap compare
  384. #define TTD_NATIVE_PROFILE_ARRAY_WORK_AROUND 1
  385. //See also -- Disabled fast path on property enumeration, random number generation, disabled new/eval code cache, and others.
  386. // Disabled ActivationObjectEx and others.
  387. //Force debug or notjit mode
  388. #define TTD_FORCE_DEBUG_MODE 0
  389. #define TTD_FORCE_NOJIT_MODE 0
  390. //Enable various sanity checking features and asserts
  391. #if ENABLE_DEBUG_CONFIG_OPTIONS
  392. #define ENABLE_TTD_INTERNAL_DIAGNOSTICS 1
  393. #else
  394. #define ENABLE_TTD_INTERNAL_DIAGNOSTICS 0
  395. #endif
  396. #define TTD_LOG_READER TextFormatReader
  397. #define TTD_LOG_WRITER TextFormatWriter
  398. //For now always use the (lower performance) text format for snapshots for easier debugging etc.
  399. #define TTD_SNAP_READER TextFormatReader
  400. #define TTD_SNAP_WRITER TextFormatWriter
  401. //#if ENABLE_TTD_INTERNAL_DIAGNOSTICS
  402. //#define TTD_SNAP_READER TextFormatReader
  403. //#define TTD_SNAP_WRITER TextFormatWriter
  404. //#else
  405. //#define TTD_SNAP_READER BinaryFormatReader
  406. //#define TTD_SNAP_WRITER BinaryFormatWriter
  407. //#endif
  408. #if ENABLE_TTD_INTERNAL_DIAGNOSTICS
  409. #define ENABLE_SNAPSHOT_COMPARE 1
  410. #define ENABLE_OBJECT_SOURCE_TRACKING 0
  411. #define ENABLE_VALUE_TRACE 0
  412. #define ENABLE_BASIC_TRACE 0
  413. #define ENABLE_FULL_BC_TRACE 0
  414. #define ENABLE_CROSSSITE_TRACE 0
  415. #else
  416. #define ENABLE_SNAPSHOT_COMPARE 0
  417. #define ENABLE_OBJECT_SOURCE_TRACKING 0
  418. #define ENABLE_BASIC_TRACE 0
  419. #define ENABLE_FULL_BC_TRACE 0
  420. #define ENABLE_CROSSSITE_TRACE 0
  421. #endif
  422. #define ENABLE_TTD_DIAGNOSTICS_TRACING (ENABLE_OBJECT_SOURCE_TRACKING || ENABLE_BASIC_TRACE || ENABLE_FULL_BC_TRACE)
  423. //End Time Travel flags
  424. ////////
  425. #endif
  426. //----------------------------------------------------------------------------------------------------
  427. // Debug only features
  428. //----------------------------------------------------------------------------------------------------
  429. #ifdef DEBUG
  430. #define BYTECODE_TESTING
  431. // xplat-todo: revive FaultInjection on non-Win32 platforms
  432. // currently depends on io.h
  433. #ifdef _WIN32
  434. #define FAULT_INJECTION
  435. #endif
  436. #define RECYCLER_NO_PAGE_REUSE
  437. #ifdef NTBUILD
  438. #define INTERNAL_MEM_PROTECT_HEAP_ALLOC
  439. #define INTERNAL_MEM_PROTECT_HEAP_CMDLINE
  440. #endif
  441. #endif
  442. #ifdef DBG
  443. #define VALIDATE_ARRAY
  444. // xplat-todo: Do we need dump generation for non-Win32 platforms?
  445. #ifdef _WIN32
  446. #define GENERATE_DUMP
  447. #endif
  448. #endif
  449. #if DBG_DUMP
  450. #undef DBG_EXTRAFIELD // make sure we don't extra fields in free build.
  451. #define TRACK_DISPATCH
  452. #define BGJIT_STATS
  453. #define REJIT_STATS
  454. #define POLY_INLINE_CACHE_SIZE_STATS
  455. #define INLINE_CACHE_STATS
  456. #define FIELD_ACCESS_STATS
  457. #define MISSING_PROPERTY_STATS
  458. #define EXCEPTION_RECOVERY 1
  459. #define EXCEPTION_CHECK // Check exception handling.
  460. #ifdef _WIN32
  461. #define PROFILE_EXEC
  462. #endif
  463. #if !(defined(__clang__) && defined(_M_IX86))
  464. // todo: implement this for clang x86
  465. #define PROFILE_MEM
  466. #endif
  467. #define PROFILE_TYPES
  468. #define PROFILE_EVALMAP
  469. #define PROFILE_OBJECT_LITERALS
  470. #define PROFILE_BAILOUT_RECORD_MEMORY
  471. #define MEMSPECT_TRACKING
  472. #define PROFILE_RECYCLER_ALLOC
  473. // Needs to compile in debug mode
  474. // Just needs strings converted
  475. #define PROFILE_DICTIONARY 1
  476. #define PROFILE_STRINGS
  477. #define RECYCLER_SLOW_CHECK_ENABLED // This can be disabled to speed up the debug build's GC
  478. #define RECYCLER_STRESS
  479. #define RECYCLER_STATS
  480. #define RECYCLER_FINALIZE_CHECK
  481. #define RECYCLER_FREE_MEM_FILL
  482. #define RECYCLER_DUMP_OBJECT_GRAPH
  483. #define RECYCLER_MEMORY_VERIFY
  484. #define RECYCLER_ZERO_MEM_CHECK
  485. #define RECYCLER_TRACE
  486. #define RECYCLER_VERIFY_MARK
  487. #ifdef PERF_COUNTERS
  488. #define RECYCLER_PERF_COUNTERS
  489. #define HEAP_PERF_COUNTERS
  490. #endif // PERF_COUNTERS
  491. #define PAGEALLOCATOR_PROTECT_FREEPAGE
  492. #define ARENA_MEMORY_VERIFY
  493. #define SEPARATE_ARENA
  494. #ifndef _WIN32
  495. #ifdef _X64_OR_ARM64
  496. #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
  497. #define MEMORY_ALLOCATION_ALIGNMENT 16
  498. #else
  499. #define MAX_NATURAL_ALIGNMENT sizeof(DWORD)
  500. #define MEMORY_ALLOCATION_ALIGNMENT 8
  501. #endif
  502. #endif
  503. #define HEAP_TRACK_ALLOC
  504. #define CHECK_MEMORY_LEAK
  505. #define LEAK_REPORT
  506. #define PROJECTION_METADATA_TRACE
  507. #define ERROR_TRACE
  508. #define DEBUGGER_TRACE
  509. #define PROPERTY_RECORD_TRACE
  510. #define ARENA_ALLOCATOR_FREE_LIST_SIZE
  511. #ifdef DBG_EXTRAFIELD
  512. #define HEAP_ENUMERATION_VALIDATION
  513. #endif
  514. #endif // DBG_DUMP
  515. //----------------------------------------------------------------------------------------------------
  516. // Special build features
  517. // - features that can be enabled on private builds for debugging
  518. //----------------------------------------------------------------------------------------------------
  519. #ifdef ENABLE_JS_ETW
  520. // #define ETW_MEMORY_TRACKING // ETW events for internal allocations
  521. #endif
  522. // #define OLD_ITRACKER // Switch to the old IE8 ITracker GUID
  523. // #define LOG_BYTECODE_AST_RATIO // log the ratio between AST size and bytecode generated.
  524. // #define DUMP_FRAGMENTATION_STATS // Display HeapBucket fragmentation stats after sweep
  525. // ----- Fretest or free build special build features (already enabled in debug builds) -----
  526. // #define TRACK_DISPATCH
  527. // #define BGJIT_STATS
  528. // Profile defines that can be enabled in release build
  529. // #define PROFILE_EXEC
  530. // #define PROFILE_MEM
  531. // #define PROFILE_STRINGS
  532. // #define PROFILE_TYPES
  533. // #define PROFILE_OBJECT_LITERALS
  534. // #define PROFILE_RECYCLER_ALLOC
  535. // #define MEMSPECT_TRACKING
  536. // #define HEAP_TRACK_ALLOC
  537. // Recycler defines that can be enabled in release build
  538. // #define RECYCLER_STRESS
  539. // #define RECYCLER_STATS
  540. // #define RECYCLER_FINALIZE_CHECK
  541. // #define RECYCLER_FREE_MEM_FILL
  542. // #define RECYCLER_DUMP_OBJECT_GRAPH
  543. // #define RECYCLER_MEMORY_VERIFY
  544. // #define RECYCLER_TRACE
  545. // #define RECYCLER_VERIFY_MARK
  546. // #ifdef PERF_COUNTERS
  547. // #define RECYCLER_PERF_COUNTERS
  548. // #define HEAP_PERF_COUNTERS
  549. // #endif //PERF_COUNTERS
  550. // Other defines that can be enabled in release build
  551. // #define PAGEALLOCATOR_PROTECT_FREEPAGE
  552. // #define ARENA_MEMORY_VERIFY
  553. // #define SEPARATE_ARENA
  554. // #define LEAK_REPORT
  555. // #define CHECK_MEMORY_LEAK
  556. // #define RECYCLER_MARK_TRACK
  557. // #define INTERNAL_MEM_PROTECT_HEAP_ALLOC
  558. #if defined(ENABLE_JS_ETW) || defined(DUMP_FRAGMENTATION_STATS)
  559. #define ENABLE_MEM_STATS 1
  560. #endif
  561. #define NO_SANITIZE_ADDRESS
  562. #if defined(__has_feature)
  563. #if __has_feature(address_sanitizer)
  564. #undef NO_SANITIZE_ADDRESS
  565. #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address")))
  566. #define NO_SANITIZE_ADDRESS_CHECK
  567. #endif
  568. #endif
  569. //----------------------------------------------------------------------------------------------------
  570. // Disabled features
  571. //----------------------------------------------------------------------------------------------------
  572. //Enable/disable dom properties
  573. #define DOMEnabled 0
  574. //----------------------------------------------------------------------------------------------------
  575. // Platform dependent flags
  576. //----------------------------------------------------------------------------------------------------
  577. #ifndef INT32VAR
  578. #if defined(TARGET_64)
  579. #define INT32VAR 1
  580. #else
  581. #define INT32VAR 0
  582. #endif
  583. #endif
  584. #ifndef FLOATVAR
  585. #if defined(TARGET_64)
  586. #define FLOATVAR 1
  587. #else
  588. #define FLOATVAR 0
  589. #endif
  590. #endif
  591. #ifdef _M_IX86
  592. #define LOWER_SPLIT_INT64 1
  593. #else
  594. #define LOWER_SPLIT_INT64 0
  595. #endif
  596. #if (defined(_M_IX86) || defined(_M_X64)) && !defined(DISABLE_JIT)
  597. #define ASMJS_PLAT
  598. #endif
  599. #if defined(ASMJS_PLAT)
  600. #define ENABLE_WASM
  601. #define ENABLE_WASM_SIMD
  602. #ifdef CAN_BUILD_WABT
  603. #define ENABLE_WABT
  604. #endif
  605. #endif
  606. #if _M_IX86
  607. #define I386_ASM 1
  608. #endif //_M_IX86
  609. #ifndef PDATA_ENABLED
  610. #if defined(_M_ARM32_OR_ARM64) || defined(_M_X64)
  611. #define PDATA_ENABLED 1
  612. #define ALLOC_XDATA (true)
  613. #else
  614. #define PDATA_ENABLED 0
  615. #define ALLOC_XDATA (false)
  616. #endif
  617. #endif
  618. #ifndef _WIN32
  619. #define DISABLE_SEH 1
  620. #endif
  621. //----------------------------------------------------------------------------------------------------
  622. // Dependent flags
  623. // - flags values that are dependent on other flags
  624. //----------------------------------------------------------------------------------------------------
  625. #if !ENABLE_CONCURRENT_GC
  626. #undef IDLE_DECOMMIT_ENABLED // Currently idle decommit can only be enabled if concurrent gc is enabled
  627. #endif
  628. #ifdef BAILOUT_INJECTION
  629. #define ENABLE_PREJIT
  630. #endif
  631. #if defined(ENABLE_DEBUG_CONFIG_OPTIONS)
  632. // Enable Output::Trace
  633. #define ENABLE_TRACE
  634. #endif
  635. #if !(defined(__clang__) && defined(_M_ARM32_OR_ARM64)) // xplat-todo: ARM
  636. #if DBG || defined(CHECK_MEMORY_LEAK) || defined(LEAK_REPORT) || defined(TRACK_DISPATCH) || defined(ENABLE_TRACE) || defined(RECYCLER_PAGE_HEAP)
  637. #define STACK_BACK_TRACE
  638. #endif
  639. #endif
  640. // ENABLE_DEBUG_STACK_BACK_TRACE is for capturing stack back trace for debug only.
  641. // (STACK_BACK_TRACE is enabled on release build, used by RECYCLER_PAGE_HEAP.)
  642. #if ENABLE_DEBUG_CONFIG_OPTIONS && defined(STACK_BACK_TRACE)
  643. #define ENABLE_DEBUG_STACK_BACK_TRACE 1
  644. #endif
  645. #if defined(STACK_BACK_TRACE) || defined(CONTROL_FLOW_GUARD_LOGGER)
  646. #ifdef _WIN32
  647. #define DBGHELP_SYMBOL_MANAGER
  648. #endif
  649. #endif
  650. #if defined(TRACK_DISPATCH) || defined(CHECK_MEMORY_LEAK) || defined(LEAK_REPORT)
  651. #define TRACK_JS_DISPATCH
  652. #endif
  653. // LEAK_REPORT and CHECK_MEMORY_LEAK requires RECYCLER_DUMP_OBJECT_GRAPH
  654. // HEAP_TRACK_ALLOC and RECYCLER_STATS
  655. #if defined(LEAK_REPORT) || defined(CHECK_MEMORY_LEAK)
  656. #define RECYCLER_DUMP_OBJECT_GRAPH
  657. #define HEAP_TRACK_ALLOC
  658. #define RECYCLER_STATS
  659. #endif
  660. // PROFILE_RECYCLER_ALLOC requires PROFILE_MEM
  661. #if defined(PROFILE_RECYCLER_ALLOC) && !defined(PROFILE_MEM)
  662. #define PROFILE_MEM
  663. #endif
  664. // RECYCLER_DUMP_OBJECT_GRAPH is needed when using PROFILE_RECYCLER_ALLOC
  665. #if defined(PROFILE_RECYCLER_ALLOC) && !defined(RECYCLER_DUMP_OBJECT_GRAPH)
  666. #define RECYCLER_DUMP_OBJECT_GRAPH
  667. #endif
  668. #if defined(HEAP_TRACK_ALLOC) || defined(PROFILE_RECYCLER_ALLOC)
  669. #define TRACK_ALLOC
  670. #define TRACE_OBJECT_LIFETIME // track a particular object's lifetime
  671. #endif
  672. #if defined(USED_IN_STATIC_LIB)
  673. #undef FAULT_INJECTION
  674. #undef RECYCLER_DUMP_OBJECT_GRAPH
  675. #undef HEAP_TRACK_ALLOC
  676. #undef RECYCLER_STATS
  677. #undef PERF_COUNTERS
  678. #endif
  679. // Not having the config options enabled trumps all the above logic for these switches
  680. #ifndef ENABLE_DEBUG_CONFIG_OPTIONS
  681. #undef ARENA_MEMORY_VERIFY
  682. #undef RECYCLER_MEMORY_VERIFY
  683. #undef PROFILE_MEM
  684. #undef PROFILE_DICTIONARY
  685. #undef PROFILE_RECYCLER_ALLOC
  686. #undef PROFILE_EXEC
  687. #undef PROFILE_EVALMAP
  688. #undef FAULT_INJECTION
  689. #undef RECYCLER_STRESS
  690. #undef RECYCLER_SLOW_VERIFY
  691. #undef RECYCLER_VERIFY_MARK
  692. #undef RECYCLER_STATS
  693. #undef RECYCLER_FINALIZE_CHECK
  694. #undef RECYCLER_DUMP_OBJECT_GRAPH
  695. #undef DBG_DUMP
  696. #undef BGJIT_STATS
  697. #undef EXCEPTION_RECOVERY
  698. #undef PROFILE_STRINGS
  699. #undef PROFILE_TYPES
  700. #undef PROFILE_OBJECT_LITERALS
  701. #undef SECURITY_TESTING
  702. #undef LEAK_REPORT
  703. #endif
  704. //----------------------------------------------------------------------------------------------------
  705. // Default flags values
  706. // - Set the default values of flags if it is not set by the command line or above
  707. //----------------------------------------------------------------------------------------------------
  708. #ifndef JS_PROFILE_DATA_INTERFACE
  709. #define JS_PROFILE_DATA_INTERFACE 0
  710. #endif
  711. #define JS_REENTRANCY_FAILFAST 1
  712. #if DBG || JS_REENTRANCY_FAILFAST
  713. #define ENABLE_JS_REENTRANCY_CHECK 1
  714. #else
  715. #define ENABLE_JS_REENTRANCY_CHECK 0
  716. #endif
  717. #ifndef PROFILE_DICTIONARY
  718. #define PROFILE_DICTIONARY 0
  719. #endif