NativeEntryPointData.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #if ENABLE_NATIVE_CODEGEN
  7. class NativeCodeData;
  8. namespace Js
  9. {
  10. class FunctionBody;
  11. };
  12. typedef JsUtil::List<NativeOffsetInlineeFramePair, HeapAllocator> InlineeFrameMap;
  13. typedef JsUtil::List<LazyBailOutRecord, HeapAllocator> BailOutRecordMap;
  14. class JitTransferData;
  15. class NativeEntryPointData
  16. {
  17. public:
  18. NativeEntryPointData();
  19. JitTransferData* EnsureJitTransferData(Recycler* recycler);
  20. JitTransferData* GetJitTransferData() { return this->jitTransferData; }
  21. void FreeJitTransferData();
  22. void RecordNativeCode(Js::JavascriptMethod thunkAddress, Js::JavascriptMethod nativeAddress, ptrdiff_t codeSize, void * validationCookie);
  23. Js::JavascriptMethod GetNativeAddress() { return this->nativeAddress; }
  24. Js::JavascriptMethod GetThunkAddress() { return this->thunkAddress; }
  25. ptrdiff_t GetCodeSize() { return this->codeSize; }
  26. void SetTJNativeAddress(Js::JavascriptMethod nativeAddress, void * validationCookie);
  27. void SetTJCodeSize(ptrdiff_t codeSize);
  28. void AddWeakFuncRef(RecyclerWeakReference<Js::FunctionBody> *weakFuncRef, Recycler *recycler);
  29. Js::EntryPointPolymorphicInlineCacheInfo * EnsurePolymorphicInlineCacheInfo(Recycler * recycler, Js::FunctionBody * functionBody);
  30. Js::EntryPointPolymorphicInlineCacheInfo * GetPolymorphicInlineCacheInfo() { return polymorphicInlineCacheInfo; }
  31. void RegisterConstructorCache(Js::ConstructorCache* constructorCache, Recycler* recycler);
  32. #if DBG
  33. uint GetConstructorCacheCount() const { return this->constructorCaches != nullptr ? this->constructorCaches->Count() : 0; }
  34. #endif
  35. void PinTypeRefs(Recycler * recycler, size_t count, void ** typeRefs);
  36. Js::PropertyGuard* RegisterSharedPropertyGuard(Js::PropertyId propertyId, Js::ScriptContext* scriptContext);
  37. Js::PropertyId* GetSharedPropertyGuards(Recycler * recycler, _Out_ unsigned int& count);
  38. bool TryGetSharedPropertyGuard(Js::PropertyId propertyId, Js::PropertyGuard*& guard);
  39. Js::EquivalentTypeCache * EnsureEquivalentTypeCache(int guardCount, Js::ScriptContext * scriptContext, Js::EntryPointInfo * entryPointInfo);
  40. bool ClearEquivalentTypeCaches(Recycler * recycler);
  41. Field(Js::FakePropertyGuardWeakReference*) * EnsurePropertyGuardWeakRefs(int guardCount, Recycler * recycler);
  42. Js::SmallSpanSequence * GetNativeThrowSpanSequence() { return this->nativeThrowSpanSequence; }
  43. void SetNativeThrowSpanSequence(Js::SmallSpanSequence * seq) { this->nativeThrowSpanSequence = seq; }
  44. uint GetFrameHeight() { return frameHeight; }
  45. void SetFrameHeight(uint frameHeight) { this->frameHeight = frameHeight; }
  46. uint32 GetPendingPolymorphicCacheState() const { return this->pendingPolymorphicCacheState; }
  47. void SetPendingPolymorphicCacheState(uint32 state) { this->pendingPolymorphicCacheState = state; }
  48. BYTE GetPendingInlinerVersion() const { return this->pendingInlinerVersion; }
  49. void SetPendingInlinerVersion(BYTE version) { this->pendingInlinerVersion = version; }
  50. Js::ImplicitCallFlags GetPendingImplicitCallFlags() const { return this->pendingImplicitCallFlags; }
  51. void SetPendingImplicitCallFlags(Js::ImplicitCallFlags flags) { this->pendingImplicitCallFlags = flags; }
  52. void Cleanup(Js::ScriptContext * scriptContext, bool isShutdown, bool reset);
  53. void ClearTypeRefsAndGuards(Js::ScriptContext * scriptContext);
  54. #if PDATA_ENABLED
  55. XDataAllocation* GetXDataInfo() { return this->xdataInfo; }
  56. void SetXDataInfo(XDataAllocation* xdataInfo) { this->xdataInfo = xdataInfo; }
  57. #endif
  58. private:
  59. void RegisterEquivalentTypeCaches(Js::ScriptContext * scriptContext, Js::EntryPointInfo * entryPointInfo);
  60. void UnregisterEquivalentTypeCaches(Js::ScriptContext * scriptContext);
  61. void FreePropertyGuards();
  62. void FreeNativeCode(Js::ScriptContext * scriptContext, bool isShutdown);
  63. #if PDATA_ENABLED
  64. void CleanupXDataInfo();
  65. #endif
  66. FieldNoBarrier(Js::JavascriptMethod) nativeAddress;
  67. FieldNoBarrier(Js::JavascriptMethod) thunkAddress;
  68. Field(ptrdiff_t) codeSize;
  69. Field(void*) validationCookie;
  70. // This field holds any recycler allocated references that must be kept alive until
  71. // we install the entry point. It is freed at that point, so anything that must survive
  72. // until the EntryPointInfo itself goes away, must be copied somewhere else.
  73. Field(JitTransferData*) jitTransferData;
  74. typedef JsUtil::BaseHashSet<RecyclerWeakReference<Js::FunctionBody>*, Recycler, PowerOf2SizePolicy> WeakFuncRefSet;
  75. Field(WeakFuncRefSet *) weakFuncRefSet;
  76. // Need to keep strong references to the guards here so they don't get collected while the entry point is alive.
  77. typedef JsUtil::BaseDictionary<Js::PropertyId, Js::PropertyGuard*, Recycler, PowerOf2SizePolicy> SharedPropertyGuardDictionary;
  78. Field(SharedPropertyGuardDictionary*) sharedPropertyGuards;
  79. typedef SListCounted<Js::ConstructorCache*, Recycler> ConstructorCacheList;
  80. Field(ConstructorCacheList*) constructorCaches;
  81. Field(Js::EntryPointPolymorphicInlineCacheInfo *) polymorphicInlineCacheInfo;
  82. // If we pin types this array contains strong references to types, otherwise it holds weak references.
  83. Field(Field(void*)*) runtimeTypeRefs;
  84. // This array holds fake weak references to type property guards. We need it to zero out the weak references when the
  85. // entry point is finalized and the guards are about to be freed. Otherwise, if one of the guards was to be invalidated
  86. // from the thread context, we would AV trying to access freed memory. Note that the guards themselves are allocated by
  87. // NativeCodeData::Allocator and are kept alive by the data field. The weak references are recycler allocated, and so
  88. // the array must be recycler allocated also, so that the recycler doesn't collect the weak references.
  89. Field(Field(Js::FakePropertyGuardWeakReference*)*) propertyGuardWeakRefs;
  90. Field(Js::EquivalentTypeCache*) equivalentTypeCaches;
  91. Field(Js::EntryPointInfo **) registeredEquivalentTypeCacheRef;
  92. FieldNoBarrier(Js::SmallSpanSequence *) nativeThrowSpanSequence;
  93. #if PDATA_ENABLED
  94. Field(XDataAllocation *) xdataInfo;
  95. #endif
  96. Field(int) propertyGuardCount;
  97. Field(int) equivalentTypeCacheCount;
  98. Field(uint) frameHeight;
  99. // TODO: these only applies to FunctionEntryPointInfo
  100. Field(BYTE) pendingInlinerVersion;
  101. Field(Js::ImplicitCallFlags) pendingImplicitCallFlags;
  102. Field(uint32) pendingPolymorphicCacheState;
  103. #if DBG_DUMP || defined(VTUNE_PROFILING)
  104. public:
  105. // NativeOffsetMap is public for DBG_DUMP, private for VTUNE_PROFILING
  106. struct NativeOffsetMap
  107. {
  108. uint32 statementIndex;
  109. regex::Interval nativeOffsetSpan;
  110. };
  111. typedef JsUtil::List<NativeOffsetMap, HeapAllocator> NativeOffsetMapListType;
  112. NativeOffsetMapListType& GetNativeOffsetMaps() { return nativeOffsetMaps; }
  113. private:
  114. Field(NativeOffsetMapListType) nativeOffsetMaps;
  115. #endif
  116. };
  117. class InProcNativeEntryPointData : public NativeEntryPointData
  118. {
  119. public:
  120. InProcNativeEntryPointData();
  121. void SetNativeCodeData(NativeCodeData * nativeCodeData);
  122. InlineeFrameMap * GetInlineeFrameMap();
  123. void RecordInlineeFrameMap(JsUtil::List<NativeOffsetInlineeFramePair, ArenaAllocator>* tempInlineeFrameMap);
  124. BailOutRecordMap * GetBailOutRecordMap();
  125. void RecordBailOutMap(JsUtil::List<LazyBailOutRecord, ArenaAllocator>* bailoutMap);
  126. #if !FLOATVAR
  127. void SetNumberChunks(CodeGenNumberChunk* chunks)
  128. {
  129. numberChunks = chunks;
  130. }
  131. #endif
  132. void OnCleanup();
  133. private:
  134. FieldNoBarrier(NativeCodeData *) nativeCodeData;
  135. FieldNoBarrier(InlineeFrameMap*) inlineeFrameMap;
  136. FieldNoBarrier(BailOutRecordMap*) bailoutRecordMap;
  137. #if !FLOATVAR
  138. Field(CodeGenNumberChunk*) numberChunks;
  139. #endif
  140. };
  141. class OOPNativeEntryPointData : public NativeEntryPointData
  142. {
  143. public:
  144. OOPNativeEntryPointData();
  145. static uint32 GetOffsetOfNativeDataBuffer();
  146. static void DeleteNativeDataBuffer(char * naitveDataBuffer);
  147. char* GetNativeDataBuffer();
  148. char** GetNativeDataBufferRef();
  149. void SetNativeDataBuffer(char *);
  150. uint GetInlineeFrameOffsetArrayOffset();
  151. uint GetInlineeFrameOffsetArrayCount();
  152. void RecordInlineeFrameOffsetsInfo(unsigned int offsetsArrayOffset, unsigned int offsetsArrayCount);
  153. #if !FLOATVAR
  154. void ProcessNumberPageSegments(Js::ScriptContext * scriptContext);
  155. void SetNumberPageSegment(XProcNumberPageSegment * segments)
  156. {
  157. Assert(numberPageSegments == nullptr);
  158. numberPageSegments = segments;
  159. }
  160. #endif
  161. void OnCleanup();
  162. private:
  163. Field(uint) inlineeFrameOffsetArrayOffset;
  164. Field(uint) inlineeFrameOffsetArrayCount;
  165. FieldNoBarrier(char *) nativeDataBuffer;
  166. #if !FLOATVAR
  167. Field(Field(Js::JavascriptNumber*)*) numberArray;
  168. Field(XProcNumberPageSegment*) numberPageSegments;
  169. #endif
  170. };
  171. #endif