Constants.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #ifdef TARGET_64
  7. # define WIN64_STACK_FACTOR 3
  8. #else
  9. # define WIN64_STACK_FACTOR 1
  10. #endif
  11. namespace Js
  12. {
  13. class Constants
  14. {
  15. public:
  16. // Id of the NoContextSourceContextInfo
  17. static const uint NoSourceContext = (uint)-1;
  18. // Variable indicating no source context cookie was passed in by the host- indicates Dynamic Script
  19. static const uint JsBuiltInSourceContextId = (uint)-2;
  20. static const DWORD_PTR JsBuiltInSourceContext = (DWORD_PTR)-2;
  21. static const DWORD_PTR NoHostSourceContext = (DWORD_PTR)-1;
  22. static const DWORD_PTR FunctionBodyUnavailable = (DWORD_PTR)NULL; // Not a valid Var
  23. static const LocalFunctionId NoFunctionId = (LocalFunctionId)-1;
  24. static const uint NoStatementIndex = (uint)-1;
  25. static const uint NoByteCodeOffset = (uint)-1;
  26. static const PropertyId NoProperty = -1;
  27. static const RegSlot NoRegister = (RegSlot)-1;
  28. static const RegSlot OneByteRegister = (RegSlot_OneByte)-1;
  29. static const int32 InvalidOffset = -1;
  30. static const unsigned int PropertyGroupSize = 512;
  31. static const unsigned int PropertyGroupMask = PropertyGroupSize-1;
  32. static const unsigned int PropertyGroupShift = 9;
  33. static const unsigned int MaxPropertyGroups = 128;
  34. static const PropertyIndex FieldsChunkSize = 4;
  35. static const PropertyIndex NoSlot = (PropertyIndex)-1;
  36. static const PropertyIndex PropertyIndexMax = 0xFFFE;
  37. static const BigPropertyIndex NoBigSlot = (BigPropertyIndex)-1;
  38. static const int IntMaxValue = 2147483647;
  39. static const int Int31MinValue = -1073741824; //0xC0000000
  40. static const int Int31MaxValue = ~Int31MinValue;
  41. static const unsigned int UShortMaxValue = 0xFFFF;
  42. static const uint InvalidSourceIndex = (uint)-1;
  43. static const ProfileId NoProfileId = (ProfileId)-1;
  44. static const int InvalidByteCodeOffset = -1;
  45. static const InlineCacheIndex NoInlineCacheIndex = (InlineCacheIndex)-1;
  46. static const uint UninitializedValue = (uint)-1;
  47. static const ArgSlot InvalidArgSlot = (ArgSlot)-1;
  48. static const uint32 InvalidSymID = (uint32)-1;
  49. static const size_t InvalidSignature = (size_t)-1;
  50. // We add extra args during bytecode phase, so account for those and few extra slots for padding.
  51. static const uint16 MaxAllowedArgs = UShortMaxValue - 6;
  52. static const uint64 ExponentMask;
  53. static const uint64 MantissaMask;
  54. static const int ReservedTypeIds = 2048;
  55. // 1 MEM_RESERVE page at the bottom of the stack
  56. // 1 PAGE_GUARD | PAGE_READWRITE page that serves as the guard page
  57. static const unsigned NumGuardPages = 2;
  58. // We need to keep some buffer to run our stack overflow
  59. // handling code which throws an exception
  60. static const unsigned StackOverflowHandlingBufferPages = 10;
  61. // Minimum stack required to JIT-compile a function
  62. static const unsigned MinStackJITCompile = 16 * 0x400 * WIN64_STACK_FACTOR; // 16 KB
  63. // Maximum number of arguments allowed on an inlinee function for constant argument inlining
  64. // It is set to 13 to ensure optimum size of callSiteInfo
  65. static const unsigned MaximumArgumentCountForConstantArgumentInlining = 13;
  66. //Invalid loop unrolling factor used for memory operations (memset/ memcopy)
  67. static const byte InvalidLoopUnrollFactor = 0x7F;
  68. // Minimum stack required to be able to execute a JITted Javascript function.
  69. static const unsigned MinStackJIT = 0x930 * WIN64_STACK_FACTOR;
  70. // Maximum stack space allowed to avoid generating ProbeCurrentStack
  71. static const unsigned MaxStackSizeForNoProbe = 0x64;
  72. #if (defined(_M_ARM32_OR_ARM64) || defined(_M_AMD64))
  73. #if DBG
  74. static const unsigned MinStackInterpreter = 0x4000; // 16 KB
  75. #else
  76. // Minimum stack required to be able to enter the interpreter.
  77. static const unsigned MinStackInterpreter = 0x2000; // 8 KB
  78. #endif
  79. #else
  80. #if DBG
  81. static const unsigned MinStackInterpreter = 0x1000; // 4 KB
  82. #else
  83. // Minimum stack required to be able to enter the interpreter.
  84. static const unsigned MinStackInterpreter = 0xC00; // 3 KB
  85. #endif
  86. #endif
  87. // Minimum stack required by the byte code compiler.
  88. static const unsigned MinStackCompile = 0x400 * WIN64_STACK_FACTOR; // 1 KB
  89. static const unsigned MinStackByteCodeVisitor = 0xC00 * WIN64_STACK_FACTOR; // 3 KB
  90. static const unsigned MinStackRegex = 8 * 0x400 * WIN64_STACK_FACTOR; // 8 KB
  91. static const unsigned MinStackRuntime = 32 * 0x0400 * WIN64_STACK_FACTOR;
  92. static const unsigned MinStackCallout = 32 * 0x0400 * WIN64_STACK_FACTOR;
  93. static const unsigned MinStackParseOneTerm = 0x100 * WIN64_STACK_FACTOR;
  94. // MinStackDefault is the minimum amount of stack space required to
  95. // call RaiseException to report a stack overflow.
  96. static const unsigned MinStackDefault = 1 * 0x0400 * WIN64_STACK_FACTOR;
  97. static const unsigned ExtraStack = 2 * 0x0400 * WIN64_STACK_FACTOR;
  98. #if TARGET_32
  99. static const unsigned MaxThreadJITCodeHeapSize = 28 * 1024 * 1024;
  100. static const unsigned MaxProcessJITCodeHeapSize = 55 * 1024 * 1024;
  101. #elif TARGET_64
  102. // larger address space means we can keep this higher on 64 bit architectures
  103. static const unsigned MaxThreadJITCodeHeapSize = 800 * 1024 * 1024;
  104. static const unsigned MaxProcessJITCodeHeapSize = 1024 * 1024 * 1024;
  105. #endif
  106. static const unsigned MinStackJitEHBailout = MinStackInterpreter + MinStackDefault;
  107. static const size_t StackLimitForScriptInterrupt;
  108. // Arguments object created on the fly is 1 slot before the frame
  109. static const int ArgumentLocationOnFrame = 1;
  110. static const int StackNestedFuncList = 2;
  111. static const int StackFrameDisplay = 3;
  112. static const int StackScopeSlots = 4;
  113. #if _M_IX86 || _M_AMD64
  114. static const int StackNestedFuncListWithNoArg = 1;
  115. static const int StackFrameDisplayWithNoArg = 2;
  116. static const int StackScopeSlotsWithNoArg = 3;
  117. #endif
  118. static const DWORD NonWebWorkerContextId = 0;
  119. // Inlinee constants shared between the backend and the stack walker.
  120. static const uint InlineeMetaArgIndex_Argc = 0;
  121. static const uint InlineeMetaArgIndex_FunctionObject = 1;
  122. static const uint InlineeMetaArgIndex_ArgumentsObject = 2;
  123. static const uint InlineeMetaArgIndex_Argv = 3;
  124. static const uint InlineeMetaArgCount = 3;
  125. static const char16 AnonymousFunction[];
  126. static const char16 AnonymousCode[];
  127. static const char16 Anonymous[]; // Used in the function created due to new Function
  128. static const char16 Empty[];
  129. static const char16 FunctionCode[];
  130. static const char16 GlobalCode[];
  131. static const char16 EvalCode[];
  132. static const char16 GlobalFunction[];
  133. static const char16 UnknownScriptCode[];
  134. static const char16 StringReplace[];
  135. static const char16 StringMatch[];
  136. static const charcount_t AnonymousFunctionLength = _countof(_u("Anonymous function")) - 1;
  137. static const charcount_t AnonymousLength = _countof(_u("anonymous")) - 1;
  138. static const charcount_t AnonymousClassLength = _countof(_u("Anonymous class")) - 1;
  139. static const charcount_t FunctionCodeLength = _countof(_u("Function code")) - 1;
  140. static const charcount_t GlobalFunctionLength = _countof(_u("glo")) - 1;
  141. static const charcount_t GlobalCodeLength = _countof(_u("Global code")) - 1;
  142. static const charcount_t EvalCodeLength = _countof(_u("eval code")) - 1;
  143. static const charcount_t UnknownScriptCodeLength = _countof(_u("Unknown script code")) - 1;
  144. static const charcount_t NullStringLength = _countof(_u("Null")) - 1;
  145. static const charcount_t TrueStringLength = _countof(_u("True")) - 1;
  146. static const charcount_t FalseStringLength = _countof(_u("False")) - 1;
  147. };
  148. extern const FrameDisplay NullFrameDisplay;
  149. extern const FrameDisplay StrictNullFrameDisplay;
  150. }