PutByIdStatus.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 PutByIdStatus_h
  26. #define PutByIdStatus_h
  27. #include "PropertyOffset.h"
  28. #include <wtf/NotFound.h>
  29. namespace JSC {
  30. class CodeBlock;
  31. class Identifier;
  32. class VM;
  33. class JSGlobalObject;
  34. class Structure;
  35. class StructureChain;
  36. class PutByIdStatus {
  37. public:
  38. enum State {
  39. // It's uncached so we have no information.
  40. NoInformation,
  41. // It's cached as a direct store into an object property for cases where the object
  42. // already has the property.
  43. SimpleReplace,
  44. // It's cached as a transition from one structure that lacks the property to one that
  45. // includes the property, and a direct store to this new property.
  46. SimpleTransition,
  47. // It's known to often take slow path.
  48. TakesSlowPath
  49. };
  50. PutByIdStatus()
  51. : m_state(NoInformation)
  52. , m_oldStructure(0)
  53. , m_newStructure(0)
  54. , m_structureChain(0)
  55. , m_offset(invalidOffset)
  56. {
  57. }
  58. explicit PutByIdStatus(State state)
  59. : m_state(state)
  60. , m_oldStructure(0)
  61. , m_newStructure(0)
  62. , m_structureChain(0)
  63. , m_offset(invalidOffset)
  64. {
  65. ASSERT(m_state == NoInformation || m_state == TakesSlowPath);
  66. }
  67. PutByIdStatus(
  68. State state,
  69. Structure* oldStructure,
  70. Structure* newStructure,
  71. StructureChain* structureChain,
  72. PropertyOffset offset)
  73. : m_state(state)
  74. , m_oldStructure(oldStructure)
  75. , m_newStructure(newStructure)
  76. , m_structureChain(structureChain)
  77. , m_offset(offset)
  78. {
  79. ASSERT((m_state == NoInformation || m_state == TakesSlowPath) == !m_oldStructure);
  80. ASSERT((m_state != SimpleTransition) == !m_newStructure);
  81. ASSERT((m_state != SimpleTransition) == !m_structureChain);
  82. ASSERT((m_state == NoInformation || m_state == TakesSlowPath) == (m_offset == invalidOffset));
  83. }
  84. static PutByIdStatus computeFor(CodeBlock*, unsigned bytecodeIndex, Identifier&);
  85. static PutByIdStatus computeFor(VM&, JSGlobalObject*, Structure*, Identifier&, bool isDirect);
  86. State state() const { return m_state; }
  87. bool isSet() const { return m_state != NoInformation; }
  88. bool operator!() const { return m_state == NoInformation; }
  89. bool isSimpleReplace() const { return m_state == SimpleReplace; }
  90. bool isSimpleTransition() const { return m_state == SimpleTransition; }
  91. bool takesSlowPath() const { return m_state == TakesSlowPath; }
  92. Structure* oldStructure() const { return m_oldStructure; }
  93. Structure* newStructure() const { return m_newStructure; }
  94. StructureChain* structureChain() const { return m_structureChain; }
  95. PropertyOffset offset() const { return m_offset; }
  96. private:
  97. static PutByIdStatus computeFromLLInt(CodeBlock*, unsigned bytecodeIndex, Identifier&);
  98. State m_state;
  99. Structure* m_oldStructure;
  100. Structure* m_newStructure;
  101. StructureChain* m_structureChain;
  102. PropertyOffset m_offset;
  103. };
  104. } // namespace JSC
  105. #endif // PutByIdStatus_h