PolymorphicPutByIdList.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "PolymorphicPutByIdList.h"
  27. #if ENABLE(JIT)
  28. #include "StructureStubInfo.h"
  29. namespace JSC {
  30. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  31. PutByIdAccess PutByIdAccess::fromStructureStubInfo(
  32. StructureStubInfo& stubInfo,
  33. MacroAssemblerCodePtr initialSlowPath)
  34. {
  35. PutByIdAccess result;
  36. switch (stubInfo.accessType) {
  37. case access_put_by_id_replace:
  38. result.m_type = Replace;
  39. result.m_oldStructure.copyFrom(stubInfo.u.putByIdReplace.baseObjectStructure);
  40. result.m_stubRoutine = JITStubRoutine::createSelfManagedRoutine(initialSlowPath);
  41. break;
  42. case access_put_by_id_transition_direct:
  43. case access_put_by_id_transition_normal:
  44. result.m_type = Transition;
  45. result.m_oldStructure.copyFrom(stubInfo.u.putByIdTransition.previousStructure);
  46. result.m_newStructure.copyFrom(stubInfo.u.putByIdTransition.structure);
  47. result.m_chain.copyFrom(stubInfo.u.putByIdTransition.chain);
  48. result.m_stubRoutine = stubInfo.stubRoutine;
  49. break;
  50. default:
  51. RELEASE_ASSERT_NOT_REACHED();
  52. }
  53. return result;
  54. }
  55. bool PutByIdAccess::visitWeak() const
  56. {
  57. switch (m_type) {
  58. case Replace:
  59. if (!Heap::isMarked(m_oldStructure.get()))
  60. return false;
  61. break;
  62. case Transition:
  63. if (!Heap::isMarked(m_oldStructure.get()))
  64. return false;
  65. if (!Heap::isMarked(m_newStructure.get()))
  66. return false;
  67. if (!Heap::isMarked(m_chain.get()))
  68. return false;
  69. break;
  70. default:
  71. RELEASE_ASSERT_NOT_REACHED();
  72. return false;
  73. }
  74. return true;
  75. }
  76. PolymorphicPutByIdList::PolymorphicPutByIdList(
  77. PutKind putKind,
  78. StructureStubInfo& stubInfo,
  79. MacroAssemblerCodePtr initialSlowPath)
  80. : m_kind(putKind)
  81. {
  82. m_list.append(PutByIdAccess::fromStructureStubInfo(stubInfo, initialSlowPath));
  83. }
  84. PolymorphicPutByIdList* PolymorphicPutByIdList::from(
  85. PutKind putKind,
  86. StructureStubInfo& stubInfo,
  87. MacroAssemblerCodePtr initialSlowPath)
  88. {
  89. if (stubInfo.accessType == access_put_by_id_list)
  90. return stubInfo.u.putByIdList.list;
  91. ASSERT(stubInfo.accessType == access_put_by_id_replace
  92. || stubInfo.accessType == access_put_by_id_transition_normal
  93. || stubInfo.accessType == access_put_by_id_transition_direct);
  94. PolymorphicPutByIdList* result =
  95. new PolymorphicPutByIdList(putKind, stubInfo, initialSlowPath);
  96. stubInfo.initPutByIdList(result);
  97. return result;
  98. }
  99. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  100. PolymorphicPutByIdList::~PolymorphicPutByIdList() { }
  101. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  102. bool PolymorphicPutByIdList::isFull() const
  103. {
  104. ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE);
  105. return size() == POLYMORPHIC_LIST_CACHE_SIZE;
  106. }
  107. bool PolymorphicPutByIdList::isAlmostFull() const
  108. {
  109. ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE);
  110. return size() >= POLYMORPHIC_LIST_CACHE_SIZE - 1;
  111. }
  112. void PolymorphicPutByIdList::addAccess(const PutByIdAccess& putByIdAccess)
  113. {
  114. ASSERT(!isFull());
  115. // Make sure that the resizing optimizes for space, not time.
  116. m_list.resize(m_list.size() + 1);
  117. m_list.last() = putByIdAccess;
  118. }
  119. bool PolymorphicPutByIdList::visitWeak() const
  120. {
  121. for (unsigned i = 0; i < size(); ++i) {
  122. if (!at(i).visitWeak())
  123. return false;
  124. }
  125. return true;
  126. }
  127. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  128. } // namespace JSC
  129. #endif // ENABLE(JIT)