InterpreterStackFrame.h 59 KB

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