PolymorphicPutByIdList.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #ifndef PolymorphicPutByIdList_h
  26. #define PolymorphicPutByIdList_h
  27. #include <wtf/Platform.h>
  28. #if ENABLE(JIT)
  29. #include "CodeOrigin.h"
  30. #include "MacroAssembler.h"
  31. #include "Opcode.h"
  32. #include "PutKind.h"
  33. #include "Structure.h"
  34. #include <wtf/Vector.h>
  35. namespace JSC {
  36. struct StructureStubInfo;
  37. class PutByIdAccess {
  38. public:
  39. enum AccessType {
  40. Invalid,
  41. Transition,
  42. Replace
  43. };
  44. PutByIdAccess()
  45. : m_type(Invalid)
  46. {
  47. }
  48. static PutByIdAccess transition(
  49. VM& vm,
  50. JSCell* owner,
  51. Structure* oldStructure,
  52. Structure* newStructure,
  53. StructureChain* chain,
  54. PassRefPtr<JITStubRoutine> stubRoutine)
  55. {
  56. PutByIdAccess result;
  57. result.m_type = Transition;
  58. result.m_oldStructure.set(vm, owner, oldStructure);
  59. result.m_newStructure.set(vm, owner, newStructure);
  60. result.m_chain.set(vm, owner, chain);
  61. result.m_stubRoutine = stubRoutine;
  62. return result;
  63. }
  64. static PutByIdAccess replace(
  65. VM& vm,
  66. JSCell* owner,
  67. Structure* structure,
  68. PassRefPtr<JITStubRoutine> stubRoutine)
  69. {
  70. PutByIdAccess result;
  71. result.m_type = Replace;
  72. result.m_oldStructure.set(vm, owner, structure);
  73. result.m_stubRoutine = stubRoutine;
  74. return result;
  75. }
  76. static PutByIdAccess fromStructureStubInfo(
  77. StructureStubInfo&,
  78. MacroAssemblerCodePtr initialSlowPath);
  79. bool isSet() const { return m_type != Invalid; }
  80. bool operator!() const { return !isSet(); }
  81. AccessType type() const { return m_type; }
  82. bool isTransition() const { return m_type == Transition; }
  83. bool isReplace() const { return m_type == Replace; }
  84. Structure* oldStructure() const
  85. {
  86. // Using this instead of isSet() to make this assertion robust against the possibility
  87. // of additional access types being added.
  88. ASSERT(isTransition() || isReplace());
  89. return m_oldStructure.get();
  90. }
  91. Structure* structure() const
  92. {
  93. ASSERT(isReplace());
  94. return m_oldStructure.get();
  95. }
  96. Structure* newStructure() const
  97. {
  98. ASSERT(isTransition());
  99. return m_newStructure.get();
  100. }
  101. StructureChain* chain() const
  102. {
  103. ASSERT(isTransition());
  104. return m_chain.get();
  105. }
  106. PassRefPtr<JITStubRoutine> stubRoutine() const
  107. {
  108. ASSERT(isTransition() || isReplace());
  109. return m_stubRoutine;
  110. }
  111. bool visitWeak() const;
  112. private:
  113. AccessType m_type;
  114. WriteBarrier<Structure> m_oldStructure;
  115. WriteBarrier<Structure> m_newStructure;
  116. WriteBarrier<StructureChain> m_chain;
  117. RefPtr<JITStubRoutine> m_stubRoutine;
  118. };
  119. class PolymorphicPutByIdList {
  120. #if ENABLE(DETACHED_JIT)
  121. DETACHED_JIT_MAKE_SHARED_DATA_ALLOCATED;
  122. #else
  123. WTF_MAKE_FAST_ALLOCATED;
  124. #endif
  125. public:
  126. // Initialize from a stub info; this will place one element in the list and it will
  127. // be created by converting the stub info's put by id access information into our
  128. // PutByIdAccess.
  129. PolymorphicPutByIdList(
  130. PutKind,
  131. StructureStubInfo&,
  132. MacroAssemblerCodePtr initialSlowPath);
  133. // Either creates a new polymorphic put list, or returns the one that is already
  134. // in place.
  135. static PolymorphicPutByIdList* from(
  136. PutKind,
  137. StructureStubInfo&,
  138. MacroAssemblerCodePtr initialSlowPath);
  139. ~PolymorphicPutByIdList();
  140. MacroAssemblerCodePtr currentSlowPathTarget() const
  141. {
  142. return m_list.last().stubRoutine()->code().code();
  143. }
  144. void addAccess(const PutByIdAccess&);
  145. bool isEmpty() const { return m_list.isEmpty(); }
  146. unsigned size() const { return m_list.size(); }
  147. bool isFull() const;
  148. bool isAlmostFull() const; // True if adding an element would make isFull() true.
  149. const PutByIdAccess& at(unsigned i) const { return m_list[i]; }
  150. const PutByIdAccess& operator[](unsigned i) const { return m_list[i]; }
  151. PutKind kind() const { return m_kind; }
  152. bool visitWeak() const;
  153. private:
  154. Vector<PutByIdAccess, 2> m_list;
  155. PutKind m_kind;
  156. };
  157. } // namespace JSC
  158. #endif // ENABLE(JIT)
  159. #endif // PolymorphicPutByIdList_h