JitTransferData.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "Backend.h"
  6. #include "JitTransferData.h"
  7. using namespace Js;
  8. void JitTransferData::AddJitTimeTypeRef(void* typeRef, Recycler* recycler)
  9. {
  10. Assert(typeRef != nullptr);
  11. EnsureJitTimeTypeRefs(recycler);
  12. this->jitTimeTypeRefs->AddNew(typeRef);
  13. }
  14. void JitTransferData::EnsureJitTimeTypeRefs(Recycler* recycler)
  15. {
  16. if (this->jitTimeTypeRefs == nullptr)
  17. {
  18. this->jitTimeTypeRefs = RecyclerNew(recycler, TypeRefSet, recycler);
  19. }
  20. }
  21. void JitTransferData::RecordTypeGuards(int typeGuardCount, TypeGuardTransferEntry* typeGuardTransferRecord, size_t typeGuardTransferPlusSize)
  22. {
  23. this->propertyGuardCount = typeGuardCount;
  24. this->propertyGuardsByPropertyId = typeGuardTransferRecord;
  25. this->propertyGuardsByPropertyIdPlusSize = typeGuardTransferPlusSize;
  26. }
  27. void JitTransferData::RecordCtorCacheGuards(CtorCacheGuardTransferEntry* ctorCacheTransferRecord, size_t ctorCacheTransferPlusSize)
  28. {
  29. this->ctorCacheGuardsByPropertyId = ctorCacheTransferRecord;
  30. this->ctorCacheGuardsByPropertyIdPlusSize = ctorCacheTransferPlusSize;
  31. }
  32. void JitTransferData::Cleanup()
  33. {
  34. // This dictionary is recycler allocated so it doesn't need to be explicitly freed.
  35. this->jitTimeTypeRefs = nullptr;
  36. if (this->lazyBailoutProperties != nullptr)
  37. {
  38. HeapDeleteArray(this->lazyBailoutPropertyCount, this->lazyBailoutProperties);
  39. this->lazyBailoutProperties = nullptr;
  40. }
  41. // All structures below are heap allocated and need to be freed explicitly.
  42. if (this->runtimeTypeRefs != nullptr)
  43. {
  44. if (this->runtimeTypeRefs->isOOPJIT)
  45. {
  46. midl_user_free(this->runtimeTypeRefs);
  47. }
  48. else
  49. {
  50. HeapDeletePlus(offsetof(PinnedTypeRefsIDL, typeRefs) + sizeof(void*)*this->runtimeTypeRefs->count - sizeof(PinnedTypeRefsIDL),
  51. PointerValue(this->runtimeTypeRefs));
  52. }
  53. this->runtimeTypeRefs = nullptr;
  54. }
  55. if (this->propertyGuardsByPropertyId != nullptr)
  56. {
  57. HeapDeletePlus(this->propertyGuardsByPropertyIdPlusSize, this->propertyGuardsByPropertyId);
  58. this->propertyGuardsByPropertyId = nullptr;
  59. }
  60. this->propertyGuardCount = 0;
  61. this->propertyGuardsByPropertyIdPlusSize = 0;
  62. if (this->ctorCacheGuardsByPropertyId != nullptr)
  63. {
  64. HeapDeletePlus(this->ctorCacheGuardsByPropertyIdPlusSize, this->ctorCacheGuardsByPropertyId);
  65. this->ctorCacheGuardsByPropertyId = nullptr;
  66. }
  67. this->ctorCacheGuardsByPropertyIdPlusSize = 0;
  68. if (this->equivalentTypeGuards != nullptr)
  69. {
  70. HeapDeleteArray(this->equivalentTypeGuardCount, this->equivalentTypeGuards);
  71. this->equivalentTypeGuards = nullptr;
  72. }
  73. this->equivalentTypeGuardCount = 0;
  74. if (this->jitTransferRawData != nullptr)
  75. {
  76. HeapDelete(this->jitTransferRawData);
  77. this->jitTransferRawData = nullptr;
  78. }
  79. if (this->equivalentTypeGuardOffsets)
  80. {
  81. midl_user_free(this->equivalentTypeGuardOffsets);
  82. }
  83. if (this->typeGuardTransferData.entries != nullptr)
  84. {
  85. auto next = &this->typeGuardTransferData.entries;
  86. while (*next)
  87. {
  88. auto current = (*next);
  89. *next = (*next)->next;
  90. midl_user_free(current);
  91. }
  92. }
  93. if (this->ctorCacheTransferData.entries != nullptr)
  94. {
  95. CtorCacheTransferEntryIDL ** entries = this->ctorCacheTransferData.entries;
  96. for (uint i = 0; i < this->ctorCacheTransferData.ctorCachesCount; ++i)
  97. {
  98. midl_user_free(entries[i]);
  99. }
  100. midl_user_free(entries);
  101. }
  102. }