JITTimeConstructorCache.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. CompileAssert(sizeof(JITTimeConstructorCache) == sizeof(JITTimeConstructorCacheIDL));
  7. JITTimeConstructorCache::JITTimeConstructorCache(const Js::JavascriptFunction* constructor, Js::ConstructorCache* runtimeCache)
  8. {
  9. Assert(constructor != nullptr);
  10. Assert(runtimeCache != nullptr);
  11. m_data.runtimeCacheAddr = runtimeCache;
  12. m_data.runtimeCacheGuardAddr = const_cast<void*>(runtimeCache->GetAddressOfGuardValue());
  13. m_data.slotCount = runtimeCache->content.slotCount;
  14. m_data.inlineSlotCount = runtimeCache->content.inlineSlotCount;
  15. m_data.skipNewScObject = runtimeCache->content.skipDefaultNewObject;
  16. m_data.ctorHasNoExplicitReturnValue = runtimeCache->content.ctorHasNoExplicitReturnValue;
  17. m_data.typeIsFinal = runtimeCache->content.typeIsFinal;
  18. m_data.isUsed = false;
  19. m_data.guardedPropOps = 0;
  20. if (runtimeCache->IsNormal())
  21. {
  22. JITType::BuildFromJsType(runtimeCache->content.type, (JITType*)&m_data.type);
  23. }
  24. }
  25. JITTimeConstructorCache::JITTimeConstructorCache(const JITTimeConstructorCache* other)
  26. {
  27. Assert(other != nullptr);
  28. Assert(other->GetRuntimeCacheAddr() != 0);
  29. m_data.runtimeCacheAddr = reinterpret_cast<void*>(other->GetRuntimeCacheAddr());
  30. m_data.runtimeCacheGuardAddr = reinterpret_cast<void*>(other->GetRuntimeCacheGuardAddr());
  31. m_data.type = *(TypeIDL*)PointerValue(other->GetType().t);
  32. m_data.slotCount = other->GetSlotCount();
  33. m_data.inlineSlotCount = other->GetInlineSlotCount();
  34. m_data.skipNewScObject = other->SkipNewScObject();
  35. m_data.ctorHasNoExplicitReturnValue = other->CtorHasNoExplicitReturnValue();
  36. m_data.typeIsFinal = other->IsTypeFinal();
  37. m_data.isUsed = false;
  38. m_data.guardedPropOps = 0; // REVIEW: OOP JIT should we copy these when cloning?
  39. }
  40. JITTimeConstructorCache*
  41. JITTimeConstructorCache::Clone(JitArenaAllocator* allocator) const
  42. {
  43. JITTimeConstructorCache* clone = Anew(allocator, JITTimeConstructorCache, this);
  44. return clone;
  45. }
  46. BVSparse<JitArenaAllocator>*
  47. JITTimeConstructorCache::GetGuardedPropOps() const
  48. {
  49. return (BVSparse<JitArenaAllocator>*)(m_data.guardedPropOps & ~(intptr_t)1);
  50. }
  51. void
  52. JITTimeConstructorCache::EnsureGuardedPropOps(JitArenaAllocator* allocator)
  53. {
  54. if (GetGuardedPropOps() == nullptr)
  55. {
  56. m_data.guardedPropOps = (intptr_t)Anew(allocator, BVSparse<JitArenaAllocator>, allocator);
  57. m_data.guardedPropOps |= 1; // tag it to prevent false positive after the arena address reuse in recycler
  58. }
  59. }
  60. void
  61. JITTimeConstructorCache::SetGuardedPropOp(uint propOpId)
  62. {
  63. Assert(GetGuardedPropOps() != nullptr);
  64. GetGuardedPropOps()->Set(propOpId);
  65. }
  66. void
  67. JITTimeConstructorCache::AddGuardedPropOps(const BVSparse<JitArenaAllocator>* propOps)
  68. {
  69. Assert(GetGuardedPropOps() != nullptr);
  70. GetGuardedPropOps()->Or(propOps);
  71. }
  72. intptr_t
  73. JITTimeConstructorCache::GetRuntimeCacheAddr() const
  74. {
  75. return reinterpret_cast<intptr_t>(PointerValue(m_data.runtimeCacheAddr));
  76. }
  77. intptr_t
  78. JITTimeConstructorCache::GetRuntimeCacheGuardAddr() const
  79. {
  80. return reinterpret_cast<intptr_t>(PointerValue(m_data.runtimeCacheGuardAddr));
  81. }
  82. JITTypeHolder
  83. JITTimeConstructorCache::GetType() const
  84. {
  85. return JITTypeHolder((JITType*)&m_data.type);
  86. }
  87. int
  88. JITTimeConstructorCache::GetSlotCount() const
  89. {
  90. return m_data.slotCount;
  91. }
  92. int16
  93. JITTimeConstructorCache::GetInlineSlotCount() const
  94. {
  95. return m_data.inlineSlotCount;
  96. }
  97. bool
  98. JITTimeConstructorCache::SkipNewScObject() const
  99. {
  100. return m_data.skipNewScObject != FALSE;
  101. }
  102. bool
  103. JITTimeConstructorCache::CtorHasNoExplicitReturnValue() const
  104. {
  105. return m_data.ctorHasNoExplicitReturnValue != FALSE;
  106. }
  107. bool
  108. JITTimeConstructorCache::IsTypeFinal() const
  109. {
  110. return m_data.typeIsFinal != FALSE;
  111. }
  112. bool
  113. JITTimeConstructorCache::IsUsed() const
  114. {
  115. return m_data.isUsed != FALSE;
  116. }
  117. // TODO: OOP JIT, does this need to flow back?
  118. void
  119. JITTimeConstructorCache::SetUsed(bool val)
  120. {
  121. m_data.isUsed = val;
  122. }
  123. JITTimeConstructorCacheIDL *
  124. JITTimeConstructorCache::GetData()
  125. {
  126. return &m_data;
  127. }