FunctionCodeGenRuntimeData.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. namespace Js
  7. {
  8. // - Data generated for jitting and runtime purposes. Data grows as different versions of the function body are jitted.
  9. // - Recycler-allocated, lifetime is from when a code gen work item is added to the jit queue, to when the function body
  10. // becomes collectible
  11. class FunctionCodeGenRuntimeData sealed
  12. {
  13. private:
  14. Field(FunctionBody *const) functionBody;
  15. // These cloned inline caches are guaranteed to be kept alive for the life of the function body. They may be shared
  16. // by different versions of the same function body that have been or will be jitted. Cached data is not guaranteed to be
  17. // stable while jitting.
  18. Field(InlineCachePointerArray<InlineCache>) clonedInlineCaches;
  19. // There will be a non-null entry for each profiled call site where a function is to be inlined or has previously been
  20. // inlined
  21. Field(Field(FunctionCodeGenRuntimeData *)*) inlinees;
  22. // There will be a non-null entry for each call site where a getter setter is to be inlined or has previously been
  23. // inlined
  24. Field(Field(FunctionCodeGenRuntimeData *)*) ldFldInlinees;
  25. // There will be a non-null entry for each call site where a function is passed in as an argument
  26. Field(Field(FunctionCodeGenRuntimeData *)*) callbackInlinees;
  27. Field(FunctionCodeGenRuntimeData *) next;
  28. public:
  29. FunctionCodeGenRuntimeData(FunctionBody *const functionBody);
  30. void SetupRuntimeDataChain(FunctionCodeGenRuntimeData *nextRuntimeData) { this->next = nextRuntimeData; }
  31. public:
  32. FunctionBody *GetFunctionBody() const;
  33. FunctionCodeGenRuntimeData *GetNext() const { return next; };
  34. Field(FunctionCodeGenRuntimeData*)* GetInlinees() const { return inlinees; }
  35. Field(FunctionCodeGenRuntimeData*)* GetLdFldInlinees() const { return ldFldInlinees; }
  36. Field(FunctionCodeGenRuntimeData*)* GetCallbackInlinees() const { return callbackInlinees; }
  37. const FunctionCodeGenRuntimeData *GetForTarget(FunctionBody *targetFuncBody) const;
  38. const InlineCachePointerArray<InlineCache> *ClonedInlineCaches() const;
  39. InlineCachePointerArray<InlineCache> *ClonedInlineCaches();
  40. const FunctionCodeGenRuntimeData *GetInlinee(const ProfileId profiledCallSiteId) const;
  41. const FunctionCodeGenRuntimeData *GetInlineeForTargetInlinee(const ProfileId profiledCallSiteId, FunctionBody *inlineeFuncBody) const;
  42. FunctionCodeGenRuntimeData * EnsureInlineeCommon(
  43. Recycler *const recycler,
  44. const ProfileId profiledCallSiteId,
  45. FunctionBody *const inlinee,
  46. Field(Field(FunctionCodeGenRuntimeData *)*) & codeGenRuntimeData);
  47. FunctionCodeGenRuntimeData *EnsureInlinee(
  48. Recycler *const recycler,
  49. const ProfileId profiledCallSiteId,
  50. FunctionBody *const inlinee);
  51. void SetupRecursiveInlineeChain(
  52. Recycler *const recycler,
  53. const ProfileId profiledCallSiteId,
  54. FunctionBody *const inlinee);
  55. const FunctionCodeGenRuntimeData *GetLdFldInlinee(const InlineCacheIndex inlineCacheIndex) const;
  56. FunctionCodeGenRuntimeData *EnsureLdFldInlinee(
  57. Recycler *const recycler,
  58. const InlineCacheIndex inlineCacheIndex,
  59. FunctionBody *const inlinee);
  60. const FunctionCodeGenRuntimeData * GetCallbackInlinee(const ProfileId profiledCallSiteId) const;
  61. FunctionCodeGenRuntimeData * EnsureCallbackInlinee(
  62. Recycler *const recycler,
  63. const ProfileId profiledCallSiteId,
  64. FunctionBody *const inlinee);
  65. // This function walks all the chained jittimedata and returns the one which match the functionInfo.
  66. // This can return null, if the functionInfo doesn't match.
  67. const FunctionCodeGenRuntimeData *GetRuntimeDataFromFunctionInfo(FunctionInfo *polyFunctionInfo) const;
  68. template<class Fn>
  69. void MapInlineCaches(Fn fn) const
  70. {
  71. this->clonedInlineCaches.Map(fn, this->functionBody->GetInlineCacheCount());
  72. for (ProfileId iInlinee = 0; iInlinee < this->functionBody->GetProfiledCallSiteCount(); iInlinee++)
  73. {
  74. const FunctionCodeGenRuntimeData* runtimeData = this->GetInlinee(iInlinee);
  75. while (runtimeData)
  76. {
  77. if (functionBody == runtimeData->GetFunctionBody())
  78. {
  79. break;
  80. }
  81. // Map for chained ones as well.
  82. runtimeData->MapInlineCaches(fn);
  83. runtimeData = runtimeData->next;
  84. }
  85. }
  86. }
  87. PREVENT_COPY(FunctionCodeGenRuntimeData)
  88. };
  89. }