InterpreterStackFrame.h 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. 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 _MSC_VER
  7. extern "C" PVOID _ReturnAddress(VOID);
  8. #pragma intrinsic(_ReturnAddress)
  9. #else
  10. #define _ReturnAddress() __builtin_return_address(0)
  11. #endif
  12. class BailOutRecord;
  13. extern "C" void __cdecl _alloca_probe_16();
  14. namespace Js
  15. {
  16. class EHBailoutData;
  17. enum InterpreterStackFrameFlags : UINT16
  18. {
  19. InterpreterStackFrameFlags_None = 0,
  20. InterpreterStackFrameFlags_WithinTryBlock = 1,
  21. InterpreterStackFrameFlags_WithinCatchBlock = 2,
  22. InterpreterStackFrameFlags_WithinFinallyBlock = 4,
  23. InterpreterStackFrameFlags_FromBailOut = 8,
  24. InterpreterStackFrameFlags_ProcessingBailOutFromEHCode = 0x10,
  25. InterpreterStackFrameFlags_All = 0xFFFF,
  26. };
  27. // TODO: (leish)(swb) this is not always stack allocated now
  28. // with ES6 Generator, this can be allocated with recycler
  29. // need to find a good way to set write barrier, or big refactor.
  30. struct InterpreterStackFrame /* Stack allocated, no virtuals */
  31. {
  32. PREVENT_COPY(InterpreterStackFrame)
  33. friend class ::BailOutRecord;
  34. friend class JavascriptGeneratorFunction;
  35. friend class JavascriptGenerator;
  36. class Setup
  37. {
  38. public:
  39. Setup(ScriptFunction * function, Arguments& args, bool bailout = false, bool inlinee = false);
  40. Setup(ScriptFunction * function, Var * inParams, int inSlotsCount);
  41. size_t GetAllocationVarCount() const { return varAllocCount; }
  42. InterpreterStackFrame * AllocateAndInitialize(bool doProfile, bool * releaseAlloc);
  43. #if DBG
  44. InterpreterStackFrame * InitializeAllocation(__in_ecount(varAllocCount) Var * allocation, bool initParams, bool profileParams, Var loopHeaderArray, DWORD_PTR stackAddr, Var invalidStackVar);
  45. #else
  46. InterpreterStackFrame * InitializeAllocation(__in_ecount(varAllocCount) Var * allocation, bool initParams, bool profileParams, Var loopHeaderArray, DWORD_PTR stackAddr);
  47. #endif
  48. uint GetLocalCount() const { return localCount; }
  49. private:
  50. template <class Fn>
  51. void InitializeParams(InterpreterStackFrame * newInstance, Fn callback, Var **pprestDest);
  52. template <class Fn>
  53. void InitializeParamsAndUndef(InterpreterStackFrame * newInstance, Fn callback, Var **pprestDest);
  54. void InitializeRestParam(InterpreterStackFrame * newInstance, Var *dest);
  55. void SetupInternal();
  56. Var * inParams;
  57. ScriptFunction * const function;
  58. FunctionBody * const executeFunction;
  59. void** inlineCaches;
  60. int inSlotsCount;
  61. uint localCount;
  62. uint varAllocCount;
  63. uint inlineCacheCount;
  64. Js::CallFlags callFlags;
  65. bool bailedOut;
  66. bool bailedOutOfInlinee;
  67. };
  68. private:
  69. ByteCodeReader m_reader; // Reader for current function
  70. int m_inSlotsCount; // Count of actual incoming parameters to this function
  71. Js::CallFlags m_callFlags; // CallFlags passed to the current function
  72. Var* m_inParams; // Range of 'in' parameters
  73. Var* m_outParams; // Range of 'out' parameters (offset in m_localSlots)
  74. Var* m_outSp; // Stack pointer for next outparam
  75. Var* m_outSpCached; // Stack pointer for caching previos SP (in order to assist in try..finally)
  76. Var m_arguments; // Dedicated location for this frame's arguments object
  77. StackScriptFunction * stackNestedFunctions;
  78. FrameDisplay * localFrameDisplay;
  79. Var localClosure;
  80. Var paramClosure;
  81. Var *innerScopeArray;
  82. ForInObjectEnumerator * forInObjectEnumerators;
  83. ScriptContext* scriptContext;
  84. ScriptFunction * function;
  85. FunctionBody * m_functionBody;
  86. void** inlineCaches;
  87. void * returnAddress;
  88. void * addressOfReturnAddress; // Tag this frame with stack position, used by (remote) stack walker to test partially initialized interpreter stack frame.
  89. InterpreterStackFrame *previousInterpreterFrame;
  90. Var loopHeaderArray; // Keeps alive any JITted loop bodies while the function is being interpreted
  91. // 'stack address' of the frame, used for recursion detection during stepping.
  92. // For frames created via interpreter path, we use 'this', for frames created by bailout we use stack addr of actual jitted frame
  93. // the interpreter frame is created for.
  94. DWORD_PTR m_stackAddress;
  95. #if ENABLE_PROFILE_INFO
  96. ImplicitCallFlags * savedLoopImplicitCallFlags;
  97. #endif
  98. uint inlineCacheCount;
  99. uint currentLoopNum;
  100. uint currentLoopCounter; // This keeps tracks of how many times the current loop is executed. It's hit only in cases where jitloopbodies are not hit
  101. // such as loops inside try\catch.
  102. UINT16 m_flags; // based on InterpreterStackFrameFlags
  103. bool closureInitDone : 1;
  104. bool isParamScopeDone : 1;
  105. bool shouldCacheSP : 1; // Helps in determining if we need to cache the sp in ProcessTryFinally
  106. #if ENABLE_PROFILE_INFO
  107. bool switchProfileMode : 1;
  108. bool isAutoProfiling : 1;
  109. uint32 switchProfileModeOnLoopEndNumber;
  110. #endif
  111. int16 nestedTryDepth;
  112. int16 nestedCatchDepth;
  113. uint retOffset;
  114. int16 nestedFinallyDepth;
  115. void (InterpreterStackFrame::*opLoopBodyStart)(uint32 loopNumber, LayoutSize layoutSize, bool isFirstIteration);
  116. #if ENABLE_PROFILE_INFO
  117. void (InterpreterStackFrame::*opProfiledLoopBodyStart)(uint32 loopNumber, LayoutSize layoutSize, bool isFirstIteration);
  118. #endif
  119. #if DBG || DBG_DUMP
  120. void * DEBUG_currentByteOffset;
  121. #endif
  122. // Asm.js stack pointer
  123. int* m_localIntSlots;
  124. int64* m_localInt64Slots;
  125. double* m_localDoubleSlots;
  126. float* m_localFloatSlots;
  127. #ifdef ENABLE_WASM
  128. Wasm::WasmSignature* m_signatures;
  129. WebAssemblyMemory * m_wasmMemory;
  130. #endif
  131. _SIMDValue* m_localSimdSlots;
  132. EHBailoutData * ehBailoutData;
  133. // 16-byte aligned
  134. __declspec(align(16)) Var m_localSlots[0]; // Range of locals and temporaries
  135. static const int LocalsThreshold = 32 * 1024; // Number of locals vars we'll allocate on the frame.
  136. // If there are more, we'll use an arena.
  137. #ifndef TEMP_DISABLE_ASMJS
  138. typedef void(InterpreterStackFrame::*ArrFunc)(uint32, RegSlot);
  139. static const ArrFunc StArrFunc[15];
  140. static const ArrFunc LdArrFunc[15];
  141. static const int TypeToSizeMap[15];
  142. #endif
  143. //This class must have an empty ctor (otherwise it will break the code in InterpreterStackFrame::InterpreterThunk
  144. inline InterpreterStackFrame() { }
  145. void ProcessTryFinally(const byte* ip, Js::JumpOffset jumpOffset, Js::RegSlot regException = Js::Constants::NoRegister, Js::RegSlot regOffset = Js::Constants::NoRegister, bool hasYield = false);
  146. public:
  147. void OP_SetOutAsmInt(RegSlot outRegisterID, int val);
  148. void OP_SetOutAsmFlt(RegSlot outRegisterID, float val);
  149. void OP_SetOutAsmDb(RegSlot outRegisterID, double val);
  150. void OP_I_SetOutAsmInt(RegSlot outRegisterID, int val);
  151. void OP_I_SetOutAsmDb(RegSlot outRegisterID, double val);
  152. void OP_I_SetOutAsmFlt(RegSlot outRegisterID, float val);
  153. void OP_I_SetOutAsmLong(RegSlot outRegisterID, int64 val);
  154. void OP_I_SetOutAsmSimd(RegSlot outRegisterID, AsmJsSIMDValue val);
  155. template<int type, bool toJs> //type is int to avoid including Wasm headers
  156. void OP_InvalidWasmTypeConversion(...);
  157. void SetOut(ArgSlot outRegisterID, Var bValue);
  158. void SetOut(ArgSlot_OneByte outRegisterID, Var bValue);
  159. void PushOut(Var aValue);
  160. void PopOut(ArgSlot argCount);
  161. void CacheSp();
  162. void RestoreSp();
  163. FrameDisplay * GetLocalFrameDisplay() const;
  164. FrameDisplay * GetFrameDisplayForNestedFunc() const;
  165. Var InnerScopeFromRegSlot(RegSlot reg) const;
  166. void SetClosureInitDone(bool done) { closureInitDone = done; }
  167. void ValidateRegValue(Var value, bool allowStackVar = false, bool allowStackVarOnDisabledStackNestedFunc = true) const;
  168. int OP_GetMemorySize();
  169. int32 OP_GrowMemory(int32 delta);
  170. void OP_Unreachable();
  171. template <typename T> using AsmJsMathPtr = T(*)(T a, T b);
  172. template <typename T, AsmJsMathPtr<T> func, T MIN> static T OP_DivOverflow(T a, T b, ScriptContext* scriptContext);
  173. template <typename T, AsmJsMathPtr<T> func> static T OP_DivRemCheck(T a, T b, ScriptContext* scriptContext);
  174. void ValidateSetRegValue(Var value, bool allowStackVar = false, bool allowStackVarOnDisabledStackNestedFunc = true) const;
  175. template <typename RegSlotType> Var GetReg(RegSlotType localRegisterID) const;
  176. template <typename RegSlotType> void SetReg(RegSlotType localRegisterID, Var bValue);
  177. template <typename RegSlotType> Var GetRegAllowStackVar(RegSlotType localRegisterID) const;
  178. template <typename RegSlotType> void SetRegAllowStackVar(RegSlotType localRegisterID, Var bValue);
  179. template <typename RegSlotType> int GetRegRawInt( RegSlotType localRegisterID ) const;
  180. template <typename RegSlotType> void SetRegRawInt( RegSlotType localRegisterID, int bValue );
  181. template <typename RegSlotType> int64 GetRegRawInt64( RegSlotType localRegisterID ) const;
  182. template <typename RegSlotType> void SetRegRawInt64( RegSlotType localRegisterID, int64 bValue );
  183. template <typename RegSlotType> double GetRegRawDouble(RegSlotType localRegisterID) const;
  184. template <typename RegSlotType> float GetRegRawFloat(RegSlotType localRegisterID) const;
  185. template <typename RegSlotType> void SetRegRawDouble(RegSlotType localRegisterID, double bValue);
  186. template <typename RegSlotType> void SetRegRawFloat(RegSlotType localRegisterID, float bValue);
  187. template <typename T> T GetRegRaw( RegSlot localRegisterID ) const;
  188. template <typename T> void SetRegRaw( RegSlot localRegisterID, T bValue );
  189. template <typename RegSlotType> AsmJsSIMDValue GetRegRawSimd(RegSlotType localRegisterID) const;
  190. template <typename RegSlotType> void SetRegRawSimd(RegSlotType localRegisterID, AsmJsSIMDValue bValue);
  191. template <class T> void OP_SimdLdArrGeneric(const unaligned T* playout);
  192. template <class T> void OP_SimdLdArrConstIndex(const unaligned T* playout);
  193. template <class T> void OP_SimdStArrGeneric(const unaligned T* playout);
  194. template <class T> void OP_SimdStArrConstIndex(const unaligned T* playout);
  195. template <class T> void OP_SimdInt32x4FromFloat32x4(const unaligned T* playout);
  196. template <class T> void OP_SimdUint32x4FromFloat32x4(const unaligned T* playout);
  197. template <class T> void OP_WasmSimdConst(const unaligned T* playout);
  198. template <class T> void OP_SimdInt16x8(const unaligned T* playout);
  199. template <class T> void OP_SimdInt8x16(const unaligned T* playout);
  200. template <class T> void OP_SimdUint32x4(const unaligned T* playout);
  201. template <class T> void OP_SimdUint16x8(const unaligned T* playout);
  202. template <class T> void OP_SimdUint8x16(const unaligned T* playout);
  203. template <class T> void OP_SimdBool32x4(const unaligned T* playout);
  204. template <class T> void OP_SimdBool16x8(const unaligned T* playout);
  205. template <class T> void OP_SimdBool8x16(const unaligned T* playout);
  206. template <typename RegSlotType>
  207. Var GetRegAllowStackVarEnableOnly(RegSlotType localRegisterID) const;
  208. template <typename RegSlotType>
  209. void SetRegAllowStackVarEnableOnly(RegSlotType localRegisterID, Var bValue);
  210. Var GetNonVarReg(RegSlot localRegisterID) const;
  211. void SetNonVarReg(RegSlot localRegisterID, void * bValue);
  212. ScriptContext* GetScriptContext() const { return scriptContext; }
  213. Var GetRootObject() const;
  214. ScriptFunction* GetJavascriptFunction() const { return function; }
  215. FunctionBody * GetFunctionBody() const { return m_functionBody; }
  216. ByteCodeReader* GetReader() { return &m_reader;}
  217. uint GetCurrentLoopNum() const { return currentLoopNum; }
  218. InterpreterStackFrame* GetPreviousFrame() const {return previousInterpreterFrame;}
  219. void SetPreviousFrame(InterpreterStackFrame *interpreterFrame) {previousInterpreterFrame = interpreterFrame;}
  220. Var GetArgumentsObject() const { return m_arguments; }
  221. void SetArgumentsObject(Var args) { m_arguments = args; }
  222. UINT16 GetFlags() const { return m_flags; }
  223. void OrFlags(UINT16 addTo) { m_flags |= addTo; }
  224. bool IsInCatchOrFinallyBlock();
  225. static bool IsDelayDynamicInterpreterThunk(JavascriptMethod entryPoint);
  226. Var LdEnv() const;
  227. void SetEnv(FrameDisplay *frameDisplay);
  228. Field(Var)* NewScopeSlots(unsigned int size, ScriptContext *scriptContext, Var scope);
  229. Field(Var)* NewScopeSlots();
  230. Var NewScopeObject();
  231. FrameDisplay * NewFrameDisplay(void *argHead, void *argEnv);
  232. Var CreateHeapArguments(ScriptContext* scriptContext);
  233. bool IsCurrentLoopNativeAddr(void * codeAddr) const;
  234. void * GetReturnAddress() { return returnAddress; }
  235. static uint32 GetOffsetOfLocals() { return offsetof(InterpreterStackFrame, m_localSlots); }
  236. static uint32 GetOffsetOfArguments() { return offsetof(InterpreterStackFrame, m_arguments); }
  237. static uint32 GetOffsetOfInParams() { return offsetof(InterpreterStackFrame, m_inParams); }
  238. static uint32 GetOffsetOfInSlotsCount() { return offsetof(InterpreterStackFrame, m_inSlotsCount); }
  239. static uint32 GetOffsetOfStackNestedFunctions() { return offsetof(InterpreterStackFrame, stackNestedFunctions); }
  240. static uint32 GetOffsetOfForInEnumerators() { return offsetof(InterpreterStackFrame, forInObjectEnumerators); }
  241. static uint32 GetStartLocationOffset() { return offsetof(InterpreterStackFrame, m_reader) + ByteCodeReader::GetStartLocationOffset(); }
  242. static uint32 GetCurrentLocationOffset() { return offsetof(InterpreterStackFrame, m_reader) + ByteCodeReader::GetCurrentLocationOffset(); }
  243. bool IsParamScopeDone() const { return isParamScopeDone; }
  244. void SetIsParamScopeDone(bool value) { isParamScopeDone = value; }
  245. static bool IsBrLong(OpCode op, const byte * ip)
  246. {
  247. #ifdef BYTECODE_BRANCH_ISLAND
  248. CompileAssert(Js::OpCodeInfo<Js::OpCode::BrLong>::IsExtendedOpcode);
  249. return (op == OpCode::ExtendedOpcodePrefix) && ((OpCode)(ByteCodeReader::PeekExtOp(ip)) == OpCode::BrLong);
  250. #else
  251. return false;
  252. #endif
  253. }
  254. DWORD_PTR GetStackAddress() const;
  255. void* GetAddressOfReturnAddress() const;
  256. template <typename T>
  257. static T GetAsmJsRetVal(InterpreterStackFrame* instance);
  258. #if _M_IX86
  259. static int GetRetType(JavascriptFunction* func);
  260. static int GetAsmJsArgSize(AsmJsCallStackLayout * stack);
  261. static int GetDynamicRetType(AsmJsCallStackLayout * stack);
  262. static DWORD GetAsmJsReturnValueOffset(AsmJsCallStackLayout * stack);
  263. _NOINLINE static int AsmJsInterpreter(AsmJsCallStackLayout * stack);
  264. #elif _M_X64
  265. template <typename T>
  266. static T AsmJsInterpreter(AsmJsCallStackLayout* layout);
  267. static void * GetAsmJsInterpreterEntryPoint(AsmJsCallStackLayout* stack);
  268. static Var AsmJsDelayDynamicInterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...);
  269. static __m128 AsmJsInterpreterSimdJs(AsmJsCallStackLayout* func);
  270. #endif
  271. #ifdef ASMJS_PLAT
  272. static void InterpreterAsmThunk(AsmJsCallStackLayout* layout);
  273. #endif
  274. #if DYNAMIC_INTERPRETER_THUNK
  275. static Var DelayDynamicInterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...);
  276. _NOINLINE static Var InterpreterThunk(JavascriptCallStackLayout* layout);
  277. #else
  278. _NOINLINE static Var InterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...);
  279. #endif
  280. static Var InterpreterHelper(ScriptFunction* function, ArgumentReader args, void* returnAddress, void* addressOfReturnAddress, const bool isAsmJs = false);
  281. private:
  282. #if DYNAMIC_INTERPRETER_THUNK
  283. static JavascriptMethod EnsureDynamicInterpreterThunk(Js::ScriptFunction * function);
  284. #endif
  285. template<typename OpCodeType, Js::OpCode (ReadOpFunc)(const byte*&), void (TracingFunc)(InterpreterStackFrame*, OpCodeType)>
  286. OpCodeType ReadOp(const byte *& ip);
  287. static void TraceOpCode(InterpreterStackFrame* that, Js::OpCode op);
  288. static void TraceAsmJsOpCode(InterpreterStackFrame* that, Js::OpCodeAsmJs op);
  289. #if ENABLE_TTD
  290. template<typename OpCodeType, Js::OpCode(ReadOpFunc)(const byte*&), void (TracingFunc)(InterpreterStackFrame*, OpCodeType)>
  291. OpCodeType ReadOp_WPreviousStmtTracking(const byte *& ip);
  292. #endif
  293. void* __cdecl operator new(size_t byteSize, void* previousAllocation) throw();
  294. void __cdecl operator delete(void* allocationToFree, void* previousAllocation) throw();
  295. _NOINLINE Var ProcessThunk(void* returnAddress, void* addressOfReturnAddress);
  296. _NOINLINE Var DebugProcessThunk(void* returnAddress, void* addressOfReturnAddress);
  297. void AlignMemoryForAsmJs();
  298. Var Process();
  299. Var ProcessAsmJsModule();
  300. Var ProcessLinkFailedAsmJsModule();
  301. Var ProcessAsmJs();
  302. Var ProcessProfiled();
  303. Var ProcessUnprofiled();
  304. const byte* ProcessProfiledExtendedOpcodePrefix(const byte* ip);
  305. const byte* ProcessUnprofiledExtendedOpcodePrefix(const byte* ip);
  306. const byte* ProcessWithDebuggingExtendedOpcodePrefix(const byte* ip);
  307. const byte* ProcessAsmJsExtendedOpcodePrefix(const byte* ip);
  308. const byte* ProcessProfiledMediumLayoutPrefix(const byte* ip, Var&);
  309. const byte* ProcessUnprofiledMediumLayoutPrefix(const byte* ip, Var&);
  310. const byte* ProcessWithDebuggingMediumLayoutPrefix(const byte* ip, Var&);
  311. const byte* ProcessAsmJsMediumLayoutPrefix(const byte* ip, Var&);
  312. const byte* ProcessProfiledExtendedMediumLayoutPrefix(const byte* ip);
  313. const byte* ProcessUnprofiledExtendedMediumLayoutPrefix(const byte* ip);
  314. const byte* ProcessWithDebuggingExtendedMediumLayoutPrefix(const byte* ip);
  315. const byte* ProcessAsmJsExtendedMediumLayoutPrefix(const byte* ip);
  316. const byte* ProcessProfiledLargeLayoutPrefix(const byte* ip, Var&);
  317. const byte* ProcessUnprofiledLargeLayoutPrefix(const byte* ip, Var&);
  318. const byte* ProcessWithDebuggingLargeLayoutPrefix(const byte* ip, Var&);
  319. const byte* ProcessAsmJsLargeLayoutPrefix(const byte* ip, Var&);
  320. const byte* ProcessProfiledExtendedLargeLayoutPrefix(const byte* ip);
  321. const byte* ProcessUnprofiledExtendedLargeLayoutPrefix(const byte* ip);
  322. const byte* ProcessWithDebuggingExtendedLargeLayoutPrefix(const byte* ip);
  323. const byte* ProcessAsmJsExtendedLargeLayoutPrefix(const byte* ip);
  324. Var ProcessWithDebugging();
  325. Var DebugProcess();
  326. #if ENABLE_TTD
  327. Var ProcessWithDebugging_PreviousStmtTracking();
  328. const byte* ProcessWithDebugging_PreviousStmtTrackingExtendedOpcodePrefix(const byte* ip);
  329. const byte* ProcessWithDebugging_PreviousStmtTrackingMediumLayoutPrefix(const byte* ip, Var&);
  330. const byte* ProcessWithDebugging_PreviousStmtTrackingExtendedMediumLayoutPrefix(const byte* ip);
  331. const byte* ProcessWithDebugging_PreviousStmtTrackingLargeLayoutPrefix(const byte* ip, Var&);
  332. const byte* ProcessWithDebugging_PreviousStmtTrackingExtendedLargeLayoutPrefix(const byte* ip);
  333. #if ENABLE_TTD_DIAGNOSTICS_TRACING
  334. Var ProcessUnprofiled_PreviousStmtTracking();
  335. const byte* ProcessUnprofiled_PreviousStmtTrackingExtendedOpcodePrefix(const byte* ip);
  336. const byte* ProcessUnprofiled_PreviousStmtTrackingMediumLayoutPrefix(const byte* ip, Var&);
  337. const byte* ProcessUnprofiled_PreviousStmtTrackingExtendedMediumLayoutPrefix(const byte* ip);
  338. const byte* ProcessUnprofiled_PreviousStmtTrackingLargeLayoutPrefix(const byte* ip, Var&);
  339. const byte* ProcessUnprofiled_PreviousStmtTrackingExtendedLargeLayoutPrefix(const byte* ip);
  340. #endif
  341. #endif
  342. bool IsInDebugMode() const { return this->GetFunctionBody()->IsInDebugMode(); }
  343. // This will be called for reseting outs when resume from break on error happened
  344. void ResetOut();
  345. Var OP_ArgIn0();
  346. template <class T> void OP_ArgOut_Env(const unaligned T* playout);
  347. template <class T> void OP_ArgOut_A(const unaligned T* playout);
  348. template <class T> void OP_ProfiledArgOut_A(const unaligned T * playout);
  349. #if DBG
  350. template <class T> void OP_ArgOut_ANonVar(const unaligned T* playout);
  351. #endif
  352. FrameDisplay * GetEnvForEvalCode();
  353. BOOL OP_BrFalse_A(Var aValue, ScriptContext* scriptContext);
  354. BOOL OP_BrTrue_A(Var aValue, ScriptContext* scriptContext);
  355. BOOL OP_BrNotNull_A(Var aValue);
  356. BOOL OP_BrUndecl_A(Var aValue);
  357. BOOL OP_BrNotUndecl_A(Var aValue);
  358. BOOL OP_BrOnHasProperty(Var argInstance, uint propertyIdIndex, ScriptContext* scriptContext);
  359. BOOL OP_BrOnNoProperty(Var argInstance, uint propertyIdIndex, ScriptContext* scriptContext);
  360. BOOL OP_BrOnNoEnvProperty(Var envInstance, int32 slotIndex, uint propertyIdIndex, ScriptContext* scriptContext);
  361. BOOL OP_BrOnClassConstructor(Var aValue);
  362. BOOL OP_BrOnBaseConstructorKind(Var aValue);
  363. RecyclableObject * OP_CallGetFunc(Var target);
  364. template <class T> const byte * OP_Br(const unaligned T * playout);
  365. void OP_AsmStartCall(const unaligned OpLayoutStartCall * playout);
  366. void OP_StartCall( const unaligned OpLayoutStartCall * playout );
  367. void OP_StartCall(uint outParamCount);
  368. template <class T> void OP_CallCommon(const unaligned T *playout, RecyclableObject * aFunc, unsigned flags, const Js::AuxArray<uint32> *spreadIndices = nullptr);
  369. void OP_CallAsmInternal( RecyclableObject * function);
  370. template <class T> void OP_I_AsmCall(const unaligned T* playout) { OP_CallAsmInternal((ScriptFunction*)OP_CallGetFunc(GetRegAllowStackVar(playout->Function))); }
  371. template <class T> void OP_CallCommonI(const unaligned T *playout, RecyclableObject * aFunc, unsigned flags);
  372. template <class T> void OP_ProfileCallCommon(const unaligned T *playout, RecyclableObject * aFunc, unsigned flags, ProfileId profileId, InlineCacheIndex inlineCacheIndex = Js::Constants::NoInlineCacheIndex, const Js::AuxArray<uint32> *spreadIndices = nullptr);
  373. template <class T> void OP_ProfileReturnTypeCallCommon(const unaligned T *playout, RecyclableObject * aFunc, unsigned flags, ProfileId profileId, const Js::AuxArray<uint32> *spreadIndices = nullptr);
  374. template <class T> void OP_CallPutCommon(const unaligned T *playout, RecyclableObject * aFunc);
  375. template <class T> void OP_CallPutCommonI(const unaligned T *playout, RecyclableObject * aFunc);
  376. template <class T> void OP_AsmCall(const unaligned T* playout);
  377. template <class T> void OP_CallI(const unaligned T* playout, unsigned flags) { OP_CallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags); }
  378. template <class T> void OP_CallIExtended(const unaligned T* playout, unsigned flags) { OP_CallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  379. template <class T> void OP_CallIExtendedFlags(const unaligned T* playout, unsigned flags) { OP_CallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags | playout->callFlags, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  380. template <class T> void OP_CallIFlags(const unaligned T* playout, unsigned flags) { playout->callFlags == Js::CallFlags::CallFlags_NewTarget ? OP_CallPutCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function))) : OP_CallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags | playout->callFlags); }
  381. template <class T> void OP_ProfiledCallI(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags, playout->profileId); }
  382. template <class T> void OP_ProfiledCallIExtended(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags, playout->profileId, Js::Constants::NoInlineCacheIndex, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  383. template <class T> void OP_ProfiledCallIExtendedFlags(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags | playout->callFlags, playout->profileId, Js::Constants::NoInlineCacheIndex, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  384. template <class T> void OP_ProfiledCallIWithICIndex(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags, playout->profileId, playout->inlineCacheIndex); }
  385. template <class T> void OP_ProfiledCallIExtendedWithICIndex(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags, playout->profileId, playout->inlineCacheIndex, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  386. template <class T> void OP_ProfiledCallIExtendedFlagsWithICIndex(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags | playout->callFlags, playout->profileId, playout->inlineCacheIndex, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  387. template <class T> void OP_ProfiledCallIFlags(const unaligned T* playout, unsigned flags) { playout->callFlags == Js::CallFlags::CallFlags_NewTarget ? OP_CallPutCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function))) : OP_ProfileCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags | playout->callFlags, playout->profileId); }
  388. template <class T> void OP_ProfiledReturnTypeCallI(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileReturnTypeCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags, playout->profileId); }
  389. template <class T> void OP_ProfiledReturnTypeCallIExtended(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileReturnTypeCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags, playout->profileId, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  390. template <class T> void OP_ProfiledReturnTypeCallIExtendedFlags(const unaligned OpLayoutDynamicProfile<T>* playout, unsigned flags) { OP_ProfileReturnTypeCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags | playout->callFlags, playout->profileId, (playout->Options & CallIExtended_SpreadArgs) ? m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody()) : nullptr); }
  391. template <class T> void OP_ProfiledReturnTypeCallIFlags(const unaligned T* playout, unsigned flags) { playout->callFlags == Js::CallFlags::CallFlags_NewTarget ? OP_CallPutCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function))) : OP_ProfileReturnTypeCallCommon(playout, OP_CallGetFunc(GetRegAllowStackVar(playout->Function)), flags | playout->callFlags, playout->profileId); }
  392. // Patching Fastpath Operations
  393. template <class T> void OP_GetRootProperty(unaligned T* playout);
  394. template <class T> void OP_GetRootPropertyForTypeOf(unaligned T* playout);
  395. template <class T> void OP_GetRootProperty_NoFastPath(unaligned T* playout);
  396. template <class T, bool Root, bool Method, bool CallApplyTarget> void ProfiledGetProperty(unaligned T* playout, const Var instance);
  397. template <class T> void OP_ProfiledGetRootProperty(unaligned T* playout);
  398. template <class T> void OP_ProfiledGetRootPropertyForTypeOf(unaligned T* playout);
  399. template <class T> void OP_GetProperty(Var instance, unaligned T* playout);
  400. template <class T> void OP_GetProperty(unaligned T* playout);
  401. template <class T> void OP_GetLocalProperty(unaligned T* playout);
  402. template <class T> void OP_GetSuperProperty(unaligned T* playout);
  403. template <class T> void OP_GetPropertyForTypeOf(unaligned T* playout);
  404. template <class T> void OP_GetProperty_NoFastPath(Var instance, unaligned T* playout);
  405. template <class T> void OP_ProfiledGetProperty(unaligned T* playout);
  406. template <class T> void OP_ProfiledGetLocalProperty(unaligned T* playout);
  407. template <class T> void OP_ProfiledGetSuperProperty(unaligned T* playout);
  408. template <class T> void OP_ProfiledGetPropertyForTypeOf(unaligned T* playout);
  409. template <class T> void OP_ProfiledGetPropertyCallApplyTarget(unaligned T* playout);
  410. template <class T> void OP_GetRootMethodProperty(unaligned T* playout);
  411. template <class T> void OP_GetRootMethodProperty_NoFastPath(unaligned T* playout);
  412. template <class T> void OP_ProfiledGetRootMethodProperty(unaligned T* playout);
  413. template <class T> void OP_GetMethodProperty(unaligned T* playout);
  414. template <class T> void OP_GetLocalMethodProperty(unaligned T* playout);
  415. template <class T> void OP_GetMethodProperty(Var varInstance, unaligned T* playout);
  416. template <class T> void OP_GetMethodProperty_NoFastPath(Var varInstance, unaligned T* playout);
  417. template <class T> void OP_ProfiledGetMethodProperty(unaligned T* playout);
  418. template <class T> void OP_ProfiledGetLocalMethodProperty(unaligned T* playout);
  419. template <typename T> void OP_GetPropertyScoped(const unaligned OpLayoutT_ElementP<T>* playout);
  420. template <typename T> void OP_GetPropertyForTypeOfScoped(const unaligned OpLayoutT_ElementP<T>* playout);
  421. template <typename T> void OP_GetPropertyScoped_NoFastPath(const unaligned OpLayoutT_ElementP<T>* playout);
  422. template <class T> void OP_GetMethodPropertyScoped(unaligned T* playout);
  423. template <class T> void OP_GetMethodPropertyScoped_NoFastPath(unaligned T* playout);
  424. #if ENABLE_PROFILE_INFO
  425. template <class T> void UpdateFldInfoFlagsForGetSetInlineCandidate(unaligned T* playout, FldInfoFlags& fldInfoFlags, CacheType cacheType,
  426. DynamicProfileInfo * dynamicProfileInfo, uint inlineCacheIndex, RecyclableObject * obj);
  427. template <class T> void UpdateFldInfoFlagsForCallApplyInlineCandidate(unaligned T* playout, FldInfoFlags& fldInfoFlags, CacheType cacheType,
  428. DynamicProfileInfo * dynamicProfileInfo, uint inlineCacheIndex, RecyclableObject * obj);
  429. #endif
  430. template <class T> void OP_SetProperty(unaligned T* playout);
  431. template <class T> void OP_SetLocalProperty(unaligned T* playout);
  432. template <class T> void OP_SetSuperProperty(unaligned T* playout);
  433. template <class T> void OP_ProfiledSetProperty(unaligned T* playout);
  434. template <class T> void OP_ProfiledSetLocalProperty(unaligned T* playout);
  435. template <class T> void OP_ProfiledSetSuperProperty(unaligned T* playout);
  436. template <class T> void OP_SetRootProperty(unaligned T* playout);
  437. template <class T> void OP_ProfiledSetRootProperty(unaligned T* playout);
  438. template <class T> void OP_SetPropertyStrict(unaligned T* playout);
  439. template <class T> void OP_ProfiledSetPropertyStrict(unaligned T* playout);
  440. template <class T> void OP_SetRootPropertyStrict(unaligned T* playout);
  441. template <class T> void OP_ProfiledSetRootPropertyStrict(unaligned T* playout);
  442. template <class T> void OP_SetPropertyScoped(unaligned T* playout, PropertyOperationFlags flags = PropertyOperation_None);
  443. template <class T> void OP_SetPropertyScoped_NoFastPath(unaligned T* playout, PropertyOperationFlags flags);
  444. template <class T> void OP_SetPropertyScopedStrict(unaligned T* playout);
  445. template <class T> void OP_ConsoleSetPropertyScoped(unaligned T* playout);
  446. template <class T> void DoSetProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags);
  447. template <class T> void DoSetSuperProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags);
  448. template <class T> void DoSetProperty_NoFastPath(unaligned T* playout, Var instance, PropertyOperationFlags flags);
  449. template <class T> void DoSetSuperProperty_NoFastPath(unaligned T* playout, Var instance, PropertyOperationFlags flags);
  450. template <class T, bool Root> void ProfiledSetProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags);
  451. template <class T, bool Root> void ProfiledSetSuperProperty(unaligned T* playout, Var instance, Var thisInstance, PropertyOperationFlags flags);
  452. template <class T> void OP_InitProperty(unaligned T* playout);
  453. template <class T> void OP_InitLocalProperty(unaligned T* playout);
  454. template <class T> void OP_InitRootProperty(unaligned T* playout);
  455. template <class T> void OP_InitUndeclLetProperty(unaligned T* playout);
  456. template <class T> void OP_InitUndeclLocalLetProperty(unaligned T* playout);
  457. void OP_InitUndeclRootLetProperty(uint propertyIdIndex);
  458. template <class T> void OP_InitUndeclConstProperty(unaligned T* playout);
  459. template <class T> void OP_InitUndeclLocalConstProperty(unaligned T* playout);
  460. void OP_InitUndeclRootConstProperty(uint propertyIdIndex);
  461. template <class T> void OP_InitUndeclConsoleLetProperty(unaligned T* playout);
  462. template <class T> void OP_InitUndeclConsoleConstProperty(unaligned T* playout);
  463. template <class T> void OP_ProfiledInitProperty(unaligned T* playout);
  464. template <class T> void OP_ProfiledInitLocalProperty(unaligned T* playout);
  465. template <class T> void OP_ProfiledInitRootProperty(unaligned T* playout);
  466. template <class T> void OP_ProfiledInitUndeclProperty(unaligned T* playout);
  467. template <class T> void DoInitProperty(unaligned T* playout, Var instance);
  468. template <class T> void DoInitProperty_NoFastPath(unaligned T* playout, Var instance);
  469. template <class T> void ProfiledInitProperty(unaligned T* playout, Var instance);
  470. template <class T> bool TrySetPropertyLocalFastPath(unaligned T* playout, PropertyId pid, Var instance, InlineCache*& inlineCache, PropertyOperationFlags flags = PropertyOperation_None);
  471. template <bool doProfile> Var ProfiledDivide(Var aLeft, Var aRight, ScriptContext* scriptContext, ProfileId profileId);
  472. template <bool doProfile> Var ProfileModulus(Var aLeft, Var aRight, ScriptContext* scriptContext, ProfileId profileId);
  473. template <bool doProfile> Var ProfiledSwitch(Var exp, ProfileId profileId);
  474. // Non-patching Fastpath operations
  475. template <typename T> void OP_GetElementI(const unaligned T* playout);
  476. template <typename T> void OP_ProfiledGetElementI(const unaligned OpLayoutDynamicProfile<T>* playout);
  477. template <typename T> void OP_SetElementI(const unaligned T* playout, PropertyOperationFlags flags = PropertyOperation_None);
  478. template <typename T> void OP_ProfiledSetElementI(const unaligned OpLayoutDynamicProfile<T>* playout, PropertyOperationFlags flags = PropertyOperation_None);
  479. template <typename T> void OP_SetElementIStrict(const unaligned T* playout);
  480. template <typename T> void OP_ProfiledSetElementIStrict(const unaligned OpLayoutDynamicProfile<T>* playout);
  481. template<class T> void OP_LdLen(const unaligned T *const playout);
  482. template<class T> void OP_ProfiledLdLen(const unaligned OpLayoutDynamicProfile<T> *const playout);
  483. Var OP_ProfiledLdThis(Var thisVar, int moduleID, ScriptContext* scriptContext);
  484. Var OP_ProfiledStrictLdThis(Var thisVar, ScriptContext* scriptContext);
  485. template <class T> void OP_SetArrayItemI_CI4(const unaligned T* playout);
  486. template <class T> void OP_SetArrayItemC_CI4(const unaligned T* playout);
  487. template <class T> void OP_SetArraySegmentItem_CI4(const unaligned T* playout);
  488. template <class T> void SetArrayLiteralItem(JavascriptArray *arr, uint32 index, T value);
  489. void OP_SetArraySegmentVars(const unaligned OpLayoutAuxiliary * playout);
  490. template <class T> void OP_NewScArray(const unaligned T * playout);
  491. template <bool Profiled, class T> void ProfiledNewScArray(const unaligned OpLayoutDynamicProfile<T> * playout);
  492. template <class T> void OP_ProfiledNewScArray(const unaligned OpLayoutDynamicProfile<T> * playout) { ProfiledNewScArray<true, T>(playout); }
  493. template <class T> void OP_ProfiledNewScArray_NoProfile(const unaligned OpLayoutDynamicProfile<T> * playout) { ProfiledNewScArray<false, T>(playout); }
  494. void OP_NewScIntArray(const unaligned OpLayoutAuxiliary * playout);
  495. void OP_NewScFltArray(const unaligned OpLayoutAuxiliary * playout);
  496. void OP_ProfiledNewScIntArray(const unaligned OpLayoutDynamicProfile<OpLayoutAuxiliary> * playout);
  497. void OP_ProfiledNewScFltArray(const unaligned OpLayoutDynamicProfile<OpLayoutAuxiliary> * playout);
  498. template <class T> void OP_LdArrayHeadSegment(const unaligned T* playout);
  499. inline Var GetFunctionExpression();
  500. template <class T> inline void OP_LdFunctionExpression(const unaligned T* playout);
  501. template <class T> inline void OP_StFunctionExpression(const unaligned T* playout);
  502. template <class T> inline void OP_StLocalFunctionExpression(const unaligned T* playout);
  503. void OP_StFunctionExpression(Var instance, Var value, PropertyIdIndexType index);
  504. template <class T> inline void OP_LdNewTarget(const unaligned T* playout);
  505. inline Var OP_Ld_A(Var aValue);
  506. inline Var OP_LdLocalObj();
  507. void OP_ChkUndecl(Var aValue);
  508. void OP_ChkNewCallFlag();
  509. void OP_EnsureNoRootProperty(uint propertyIdIndex);
  510. void OP_EnsureNoRootRedeclProperty(uint propertyIdIndex);
  511. void OP_ScopedEnsureNoRedeclProperty(Var aValue, uint propertyIdIndex, Var aValue2);
  512. Var OP_InitUndecl();
  513. void OP_InitUndeclSlot(Var aValue, int32 slot);
  514. template <class T> inline void OP_InitInnerFld(const unaligned T * playout);
  515. template <class T> inline void OP_InitLetFld(const unaligned T * playout);
  516. template <class T> inline void OP_InitLocalLetFld(const unaligned T* playout);
  517. template <class T> inline void OP_InitInnerLetFld(const unaligned T * playout);
  518. template <class T> inline void OP_InitRootLetFld(const unaligned T * playout);
  519. template <class T> inline void OP_InitConstFld(const unaligned T * playout);
  520. template <class T> inline void OP_InitRootConstFld(const unaligned T * playout);
  521. template <class T> inline void DoInitLetFld(const unaligned T * playout, Var instance, PropertyOperationFlags flags = PropertyOperation_None);
  522. template <class T> inline void DoInitConstFld(const unaligned T * playout, Var instance, PropertyOperationFlags flags = PropertyOperation_None);
  523. template <class T> inline void OP_InitClassMember(const unaligned T * playout);
  524. template <class T> inline void OP_InitClassMemberComputedName(const unaligned T * playout);
  525. template <class T> inline void OP_InitClassMemberGet(const unaligned T * playout);
  526. template <class T> inline void OP_InitClassMemberSet(const unaligned T * playout);
  527. template <class T> inline void OP_InitClassMemberGetComputedName(const unaligned T * playout);
  528. template <class T> inline void OP_InitClassMemberSetComputedName(const unaligned T * playout);
  529. template <typename ArrayType, typename RegType = ArrayType> inline void OP_LdArr( uint32 index, RegSlot value );
  530. template <class T> inline void OP_LdArrFunc(const unaligned T* playout);
  531. template <class T> inline void OP_LdArrWasmFunc(const unaligned T* playout);
  532. template <class T> inline void OP_CheckSignature(const unaligned T* playout);
  533. template <class T> inline void OP_ReturnDb(const unaligned T* playout);
  534. template<typename T> T GetArrayViewOverflowVal();
  535. template <typename ArrayType, typename RegType = ArrayType> inline void OP_StArr( uint32 index, RegSlot value );
  536. template <class T> inline Var OP_LdAsmJsSlot(Var instance, const unaligned T* playout );
  537. template <class T, typename T2> inline void OP_StSlotPrimitive(const unaligned T* playout);
  538. template <class T, typename T2> inline void OP_LdSlotPrimitive( const unaligned T* playout );
  539. template <class T> inline void OP_LdArrGeneric ( const unaligned T* playout );
  540. template <class T> inline void OP_LdArrWasm ( const unaligned T* playout );
  541. template <class T> inline void OP_LdArrConstIndex( const unaligned T* playout );
  542. template <class T> inline void OP_StArrGeneric ( const unaligned T* playout );
  543. template <class T> inline void OP_StArrWasm ( const unaligned T* playout );
  544. template <class T> inline void OP_StArrConstIndex( const unaligned T* playout );
  545. inline Var OP_LdSlot(Var instance, int32 slotIndex);
  546. inline Var OP_LdObjSlot(Var instance, int32 slotIndex);
  547. inline Var OP_LdFrameDisplaySlot(Var instance, int32 slotIndex);
  548. template <class T> inline Var OP_LdSlot(Var instance, const unaligned T* playout);
  549. template <class T> inline Var OP_ProfiledLdSlot(Var instance, const unaligned T* playout);
  550. template <class T> inline Var OP_LdInnerSlot(Var instance, const unaligned T* playout);
  551. template <class T> inline Var OP_ProfiledLdInnerSlot(Var instance, const unaligned T* playout);
  552. template <class T> inline Var OP_LdInnerObjSlot(Var instance, const unaligned T* playout);
  553. template <class T> inline Var OP_ProfiledLdInnerObjSlot(Var instance, const unaligned T* playout);
  554. template <class T> inline Var OP_LdEnvSlot(Var instance, const unaligned T* playout);
  555. template <class T> inline Var OP_ProfiledLdEnvSlot(Var instance, const unaligned T* playout);
  556. template <class T> inline Var OP_LdEnvObj(Var instance, const unaligned T* playout);
  557. template <class T> inline Var OP_LdObjSlot(Var instance, const unaligned T* playout);
  558. template <class T> inline Var OP_ProfiledLdObjSlot(Var instance, const unaligned T* playout);
  559. template <class T> inline Var OP_LdEnvObjSlot(Var instance, const unaligned T* playout);
  560. template <class T> inline Var OP_ProfiledLdEnvObjSlot(Var instance, const unaligned T* playout);
  561. template <class T> inline Var OP_LdModuleSlot(Var instance, const unaligned T* playout);
  562. inline void OP_StModuleSlot(Var instance, int32 slotIndex1, int32 slotIndex2, Var value);
  563. inline void OP_StSlot(Var instance, int32 slotIndex, Var value);
  564. inline void OP_StSlotChkUndecl(Var instance, int32 slotIndex, Var value);
  565. inline void OP_StEnvSlot(Var instance, int32 slotIndex1, int32 slotIndex2, Var value);
  566. inline void OP_StEnvSlotChkUndecl(Var instance, int32 slotIndex1, int32 slotIndex2, Var value);
  567. inline void OP_StObjSlot(Var instance, int32 slotIndex, Var value);
  568. inline void OP_StObjSlotChkUndecl(Var instance, int32 slotIndex, Var value);
  569. inline void OP_StEnvObjSlot(Var instance, int32 slotIndex1, int32 slotIndex2, Var value);
  570. inline void OP_StEnvObjSlotChkUndecl(Var instance, int32 slotIndex1, int32 slotIndex2, Var value);
  571. inline void OP_StModuleSlot(Var instance, int32 slotIndex1, int32 slotIndex2);
  572. inline void* OP_LdArgCnt();
  573. template <bool letArgs> Var LdHeapArgumentsImpl(Var argsArray, ScriptContext* scriptContext);
  574. Var OP_LdHeapArguments(ScriptContext* scriptContext);
  575. inline Var OP_LdLetHeapArguments(ScriptContext* scriptContext);
  576. inline Var OP_LdHeapArgsCached(ScriptContext* scriptContext);
  577. inline Var OP_LdLetHeapArgsCached(ScriptContext* scriptContext);
  578. inline Var OP_LdStackArgPtr();
  579. inline Var OP_LdArgumentsFromFrame();
  580. Var OP_NewScObjectSimple();
  581. void OP_NewScObjectLiteral(const unaligned OpLayoutAuxiliary * playout);
  582. void OP_NewScObjectLiteral_LS(const unaligned OpLayoutAuxiliary * playout, RegSlot& target);
  583. void OP_LdPropIds(const unaligned OpLayoutAuxiliary * playout);
  584. template <bool Profile, bool JITLoopBody> void LoopBodyStart(uint32 loopNumber, LayoutSize layoutSize, bool isFirstIteration);
  585. LoopHeader const * DoLoopBodyStart(uint32 loopNumber, LayoutSize layoutSize, const bool doProfileLoopCheck, bool isFirstIteration);
  586. template <bool Profile, bool JITLoopBody> void ProfiledLoopBodyStart(uint32 loopNumber, LayoutSize layoutSize, bool isFirstIteration);
  587. void OP_RecordImplicitCall(uint loopNumber);
  588. template <class T, bool Profiled, bool ICIndex> void OP_NewScObject_Impl(const unaligned T* playout, InlineCacheIndex inlineCacheIndex = Js::Constants::NoInlineCacheIndex, const Js::AuxArray<uint32> *spreadIndices = nullptr);
  589. template <class T, bool Profiled> void OP_NewScObjArray_Impl(const unaligned T* playout, const Js::AuxArray<uint32> *spreadIndices = nullptr);
  590. template <class T> void OP_NewScObject(const unaligned T* playout) { OP_NewScObject_Impl<T, false, false>(playout); }
  591. template <class T> void OP_NewScObjectNoCtorFull(const unaligned T* playout);
  592. template <class T> void OP_NewScObjectSpread(const unaligned T* playout) { OP_NewScObject_Impl<T, false, false>(playout, Js::Constants::NoInlineCacheIndex, m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody())); }
  593. template <class T> void OP_NewScObjArray(const unaligned T* playout) { OP_NewScObjArray_Impl<T, false>(playout); }
  594. template <class T> void OP_NewScObjArraySpread(const unaligned T* playout) { OP_NewScObjArray_Impl<T, false>(playout, m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody())); }
  595. template <class T> void OP_ProfiledNewScObject(const unaligned OpLayoutDynamicProfile<T>* playout) { OP_NewScObject_Impl<T, true, false>(playout); }
  596. template <class T> void OP_ProfiledNewScObjectSpread(const unaligned OpLayoutDynamicProfile<T>* playout) { OP_NewScObject_Impl<T, true, false>(playout, Js::Constants::NoInlineCacheIndex, m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody())); }
  597. template <class T> void OP_ProfiledNewScObjectWithICIndex(const unaligned OpLayoutDynamicProfile<T>* playout) { OP_NewScObject_Impl<T, true, true>(playout, playout->inlineCacheIndex); }
  598. template <class T> void OP_ProfiledNewScObjArray(const unaligned OpLayoutDynamicProfile2<T>* playout) { OP_NewScObjArray_Impl<T, true>(playout); }
  599. template <class T> void OP_ProfiledNewScObjArray_NoProfile(const unaligned OpLayoutDynamicProfile2<T>* playout) { OP_NewScObjArray_Impl<T, false>(playout); }
  600. template <class T> void OP_ProfiledNewScObjArraySpread(const unaligned OpLayoutDynamicProfile2<T>* playout) { OP_NewScObjArray_Impl<T, true>(playout, m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody())); }
  601. template <class T> void OP_ProfiledNewScObjArraySpread_NoProfile(const unaligned OpLayoutDynamicProfile2<T>* playout) { OP_NewScObjArray_Impl<T, true>(playout, m_reader.ReadAuxArray<uint32>(playout->SpreadAuxOffset, this->GetFunctionBody())); }
  602. Var NewScObject_Helper(Var target, ArgSlot ArgCount, const Js::AuxArray<uint32> *spreadIndices = nullptr);
  603. Var ProfiledNewScObject_Helper(Var target, ArgSlot ArgCount, ProfileId profileId, InlineCacheIndex inlineCacheIndex, const Js::AuxArray<uint32> *spreadIndices = nullptr);
  604. template <class T, bool Profiled, bool ICIndex> Var OP_NewScObjectNoArg_Impl(const unaligned T *playout, InlineCacheIndex inlineCacheIndex = Js::Constants::NoInlineCacheIndex);
  605. void OP_NewScObject_A_Impl(const unaligned OpLayoutAuxiliary * playout, RegSlot *target = nullptr);
  606. void OP_NewScObject_A(const unaligned OpLayoutAuxiliary * playout) { return OP_NewScObject_A_Impl(playout); }
  607. void OP_InitCachedFuncs(const unaligned OpLayoutAuxNoReg * playout);
  608. Var OP_GetCachedFunc(Var instance, int32 index);
  609. void OP_CommitScope();
  610. void OP_CommitScopeHelper(const PropertyIdArray *propIds);
  611. void OP_TryCatch(const unaligned OpLayoutBr* playout);
  612. void ProcessCatch();
  613. int ProcessFinally();
  614. void ProcessTryCatchBailout(EHBailoutData * innermostEHBailoutData, uint32 tryNestingDepth);
  615. void OP_TryFinally(const unaligned OpLayoutBr* playout);
  616. void OP_TryFinallyWithYield(const byte* ip, Js::JumpOffset jumpOffset, Js::RegSlot regException, Js::RegSlot regOffset);
  617. void OP_ResumeCatch();
  618. void OP_ResumeFinally(const byte* ip, Js::JumpOffset jumpOffset, RegSlot exceptionRegSlot, RegSlot offsetRegSlot);
  619. inline Var OP_ResumeYield(Var yieldDataVar, RegSlot yieldStarIterator = Js::Constants::NoRegister);
  620. template <typename T> void OP_IsInst(const unaligned T * playout);
  621. template <class T> void OP_InitClass(const unaligned OpLayoutT_Class<T> * playout);
  622. inline Var OP_LdHomeObj(ScriptContext * scriptContext);
  623. inline Var OP_LdFuncObj(ScriptContext * scriptContext);
  624. inline Var OP_ScopedLdHomeObj(ScriptContext * scriptContext);
  625. inline Var OP_ScopedLdFuncObj(ScriptContext * scriptContext);
  626. template <typename T> void OP_LdElementUndefined(const unaligned OpLayoutT_ElementU<T>* playout);
  627. template <typename T> void OP_LdLocalElementUndefined(const unaligned OpLayoutT_ElementRootU<T>* playout);
  628. template <typename T> void OP_LdElementUndefinedScoped(const unaligned OpLayoutT_ElementScopedU<T>* playout);
  629. void OP_SpreadArrayLiteral(const unaligned OpLayoutReg2Aux * playout);
  630. template <LayoutSize layoutSize,bool profiled> const byte * OP_ProfiledLoopStart(const byte *ip);
  631. template <LayoutSize layoutSize,bool profiled> const byte * OP_ProfiledLoopEnd(const byte *ip);
  632. template <LayoutSize layoutSize,bool profiled> const byte * OP_ProfiledLoopBodyStart(const byte *ip);
  633. template <typename T> void OP_ApplyArgs(const unaligned OpLayoutT_Reg5<T> * playout);
  634. template <class T> void OP_EmitTmpRegCount(const unaligned OpLayoutT_Unsigned1<T> * ip);
  635. HeapArgumentsObject * CreateEmptyHeapArgumentsObject(ScriptContext* scriptContext);
  636. void TrySetFrameObjectInHeapArgObj(ScriptContext * scriptContext, bool hasNonSimpleParam, bool isScopeObjRestored);
  637. Var InnerScopeFromIndex(uint32 index) const;
  638. void SetInnerScopeFromIndex(uint32 index, Var scope);
  639. void OP_NewInnerScopeSlots(uint index, uint count, int scopeIndex, ScriptContext *scriptContext, FunctionBody *functionBody);
  640. template <typename T> void OP_CloneInnerScopeSlots(const unaligned OpLayoutT_Unsigned1<T> *playout);
  641. template <typename T> void OP_CloneBlockScope(const unaligned OpLayoutT_Unsigned1<T> *playout);
  642. FrameDisplay * OP_LdFrameDisplay(void *argHead, void *argEnv, ScriptContext *scriptContext);
  643. FrameDisplay * OP_LdFrameDisplaySetLocal(void *argHead, void *argEnv, ScriptContext *scriptContext);
  644. template <bool innerFD> FrameDisplay * OP_LdFrameDisplayNoParent(void *argHead, ScriptContext *scriptContext);
  645. FrameDisplay * OP_LdFuncExprFrameDisplaySetLocal(void *argHead1, void *argHead2, ScriptContext *scriptContext);
  646. FrameDisplay * OP_LdInnerFrameDisplay(void *argHead, void *argEnv, ScriptContext *scriptContext);
  647. FrameDisplay * OP_LdInnerFrameDisplayNoParent(void *argHead, ScriptContext *scriptContext);
  648. template <class T> void OP_NewStackScFunc(const unaligned T * playout);
  649. template <class T> void OP_NewInnerStackScFunc(const unaligned T * playout);
  650. template <class T> void OP_DeleteFld(const unaligned T * playout);
  651. template <class T> void OP_DeleteLocalFld(const unaligned T * playout);
  652. template <class T> void OP_DeleteRootFld(const unaligned T * playout);
  653. template <class T> void OP_DeleteFldStrict(const unaligned T * playout);
  654. template <class T> void OP_DeleteRootFldStrict(const unaligned T * playout);
  655. template <typename T> void OP_ScopedDeleteFld(const unaligned OpLayoutT_ElementScopedC<T> * playout);
  656. template <typename T> void OP_ScopedDeleteFldStrict(const unaligned OpLayoutT_ElementScopedC<T> * playout);
  657. template <class T> void OP_ScopedLdInst(const unaligned T * playout);
  658. template <typename T> void OP_ScopedInitFunc(const unaligned OpLayoutT_ElementScopedC<T> * playout);
  659. template <class T> void OP_ClearAttributes(const unaligned T * playout);
  660. template <class T> void OP_InitGetFld(const unaligned T * playout);
  661. template <class T> void OP_InitSetFld(const unaligned T * playout);
  662. template <class T> void OP_InitSetElemI(const unaligned T * playout);
  663. template <class T> void OP_InitGetElemI(const unaligned T * playout);
  664. template <class T> void OP_InitComputedProperty(const unaligned T * playout);
  665. template <class T> void OP_InitProto(const unaligned T * playout);
  666. void OP_BeginBodyScope();
  667. void OP_InitForInEnumerator(Var object, uint forInLoopLevel);
  668. void OP_InitForInEnumeratorWithCache(Var object, uint forInLoopLevel, ProfileId profileId);
  669. ForInObjectEnumerator * GetForInEnumerator(uint forInLoopLevel);
  670. uint CallLoopBody(JavascriptMethod address);
  671. uint CallAsmJsLoopBody(JavascriptMethod address);
  672. void DoInterruptProbe();
  673. void CheckIfLoopIsHot(uint profiledLoopCounter);
  674. bool CheckAndResetImplicitCall(DisableImplicitFlags prevDisableImplicitFlags,ImplicitCallFlags savedImplicitCallFlags);
  675. class PushPopFrameHelper
  676. {
  677. public:
  678. PushPopFrameHelper(InterpreterStackFrame *interpreterFrame, void *returnAddress, void *addressOfReturnAddress)
  679. : m_threadContext(interpreterFrame->GetScriptContext()->GetThreadContext()), m_interpreterFrame(interpreterFrame), m_isHiddenFrame(false)
  680. {
  681. interpreterFrame->returnAddress = returnAddress; // Ensure these are set before pushing to interpreter frame list
  682. interpreterFrame->addressOfReturnAddress = addressOfReturnAddress;
  683. if (interpreterFrame->GetFunctionBody()->GetIsAsmJsFunction())
  684. {
  685. m_isHiddenFrame = true;
  686. }
  687. else
  688. {
  689. m_threadContext->PushInterpreterFrame(interpreterFrame);
  690. }
  691. }
  692. ~ PushPopFrameHelper()
  693. {
  694. if (!m_isHiddenFrame)
  695. {
  696. Js::InterpreterStackFrame *interpreterFrame = m_threadContext->PopInterpreterFrame();
  697. AssertMsg(interpreterFrame == m_interpreterFrame,
  698. "Interpreter frame chain corrupted?");
  699. }
  700. }
  701. private:
  702. ThreadContext *m_threadContext;
  703. InterpreterStackFrame *m_interpreterFrame;
  704. bool m_isHiddenFrame;
  705. };
  706. inline InlineCache* GetInlineCache(uint cacheIndex)
  707. {
  708. Assert(this->inlineCaches != nullptr);
  709. Assert(cacheIndex < this->inlineCacheCount);
  710. return reinterpret_cast<InlineCache *>(this->inlineCaches[cacheIndex]);
  711. }
  712. inline IsInstInlineCache* GetIsInstInlineCache(uint cacheIndex)
  713. {
  714. return m_functionBody->GetIsInstInlineCache(cacheIndex);
  715. }
  716. inline PropertyId GetPropertyIdFromCacheId(uint cacheIndex)
  717. {
  718. return m_functionBody->GetPropertyIdFromCacheId(cacheIndex);
  719. }
  720. void InitializeStackFunctions(StackScriptFunction * scriptFunctions);
  721. StackScriptFunction * GetStackNestedFunction(uint index);
  722. void SetExecutingStackFunction(ScriptFunction * scriptFunction);
  723. friend class StackScriptFunction;
  724. void InitializeClosures();
  725. void SetLocalFrameDisplay(FrameDisplay *frameDisplay);
  726. Var GetLocalClosure() const;
  727. void SetLocalClosure(Var closure);
  728. Var GetParamClosure() const;
  729. void SetParamClosure(Var closure);
  730. void TrySetRetOffset();
  731. };
  732. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  733. // Used to track how many interpreter stack frames we have on stack.
  734. class InterpreterThunkStackCountTracker
  735. {
  736. public:
  737. InterpreterThunkStackCountTracker() { ++s_count; }
  738. ~InterpreterThunkStackCountTracker() { --s_count; }
  739. static int GetCount() { return s_count; }
  740. private:
  741. THREAD_LOCAL static int s_count;
  742. };
  743. #endif
  744. } // namespace Js