CallLinkStatus.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2012, 2013 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 CallLinkStatus_h
  26. #define CallLinkStatus_h
  27. #include "CodeSpecializationKind.h"
  28. #include "Intrinsic.h"
  29. #include "JSCJSValue.h"
  30. namespace JSC {
  31. class CodeBlock;
  32. class ExecutableBase;
  33. class InternalFunction;
  34. class JSFunction;
  35. class Structure;
  36. class CallLinkStatus {
  37. public:
  38. CallLinkStatus()
  39. : m_executable(0)
  40. , m_structure(0)
  41. , m_couldTakeSlowPath(false)
  42. , m_isProved(false)
  43. {
  44. }
  45. static CallLinkStatus takesSlowPath()
  46. {
  47. CallLinkStatus result;
  48. result.m_couldTakeSlowPath = true;
  49. return result;
  50. }
  51. explicit CallLinkStatus(JSValue);
  52. CallLinkStatus(ExecutableBase* executable, Structure* structure)
  53. : m_executable(executable)
  54. , m_structure(structure)
  55. , m_couldTakeSlowPath(false)
  56. , m_isProved(false)
  57. {
  58. ASSERT(!!executable == !!structure);
  59. }
  60. CallLinkStatus& setIsProved(bool isProved)
  61. {
  62. m_isProved = isProved;
  63. return *this;
  64. }
  65. static CallLinkStatus computeFor(CodeBlock*, unsigned bytecodeIndex);
  66. CallLinkStatus& setHasBadFunctionExitSite(bool didHaveExitSite)
  67. {
  68. ASSERT(!m_isProved);
  69. if (didHaveExitSite) {
  70. // Turn this into a closure call.
  71. m_callTarget = JSValue();
  72. }
  73. return *this;
  74. }
  75. CallLinkStatus& setHasBadCacheExitSite(bool didHaveExitSite)
  76. {
  77. ASSERT(!m_isProved);
  78. if (didHaveExitSite)
  79. *this = takesSlowPath();
  80. return *this;
  81. }
  82. CallLinkStatus& setHasBadExecutableExitSite(bool didHaveExitSite)
  83. {
  84. ASSERT(!m_isProved);
  85. if (didHaveExitSite)
  86. *this = takesSlowPath();
  87. return *this;
  88. }
  89. bool isSet() const { return m_callTarget || m_executable || m_couldTakeSlowPath; }
  90. bool operator!() const { return !isSet(); }
  91. bool couldTakeSlowPath() const { return m_couldTakeSlowPath; }
  92. bool isClosureCall() const { return m_executable && !m_callTarget; }
  93. JSValue callTarget() const { return m_callTarget; }
  94. JSFunction* function() const;
  95. InternalFunction* internalFunction() const;
  96. Intrinsic intrinsicFor(CodeSpecializationKind) const;
  97. ExecutableBase* executable() const { return m_executable; }
  98. Structure* structure() const { return m_structure; }
  99. bool isProved() const { return m_isProved; }
  100. bool canOptimize() const { return (m_callTarget || m_executable) && !m_couldTakeSlowPath; }
  101. void dump(PrintStream&) const;
  102. private:
  103. static CallLinkStatus computeFromLLInt(CodeBlock*, unsigned bytecodeIndex);
  104. JSValue m_callTarget;
  105. ExecutableBase* m_executable;
  106. Structure* m_structure;
  107. bool m_couldTakeSlowPath;
  108. bool m_isProved;
  109. };
  110. } // namespace JSC
  111. #endif // CallLinkStatus_h