CallLinkStatus.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #include "config.h"
  26. #include "CallLinkStatus.h"
  27. #include "CodeBlock.h"
  28. #include "LLIntCallLinkInfo.h"
  29. #include "Operations.h"
  30. #include <wtf/CommaPrinter.h>
  31. namespace JSC {
  32. CallLinkStatus::CallLinkStatus(JSValue value)
  33. : m_callTarget(value)
  34. , m_executable(0)
  35. , m_structure(0)
  36. , m_couldTakeSlowPath(false)
  37. , m_isProved(false)
  38. {
  39. if (!value || !value.isCell())
  40. return;
  41. m_structure = value.asCell()->structure();
  42. if (!value.asCell()->inherits(&JSFunction::s_info))
  43. return;
  44. m_executable = jsCast<JSFunction*>(value.asCell())->executable();
  45. }
  46. JSFunction* CallLinkStatus::function() const
  47. {
  48. if (!m_callTarget || !m_callTarget.isCell())
  49. return 0;
  50. if (!m_callTarget.asCell()->inherits(&JSFunction::s_info))
  51. return 0;
  52. return jsCast<JSFunction*>(m_callTarget.asCell());
  53. }
  54. InternalFunction* CallLinkStatus::internalFunction() const
  55. {
  56. if (!m_callTarget || !m_callTarget.isCell())
  57. return 0;
  58. if (!m_callTarget.asCell()->inherits(&InternalFunction::s_info))
  59. return 0;
  60. return jsCast<InternalFunction*>(m_callTarget.asCell());
  61. }
  62. Intrinsic CallLinkStatus::intrinsicFor(CodeSpecializationKind kind) const
  63. {
  64. if (!m_executable)
  65. return NoIntrinsic;
  66. return m_executable->intrinsicFor(kind);
  67. }
  68. CallLinkStatus CallLinkStatus::computeFromLLInt(CodeBlock* profiledBlock, unsigned bytecodeIndex)
  69. {
  70. UNUSED_PARAM(profiledBlock);
  71. UNUSED_PARAM(bytecodeIndex);
  72. #if ENABLE(LLINT)
  73. Instruction* instruction = profiledBlock->instructions().begin() + bytecodeIndex;
  74. LLIntCallLinkInfo* callLinkInfo = instruction[4].u.callLinkInfo;
  75. return CallLinkStatus(callLinkInfo->lastSeenCallee.get());
  76. #else
  77. return CallLinkStatus();
  78. #endif
  79. }
  80. CallLinkStatus CallLinkStatus::computeFor(CodeBlock* profiledBlock, unsigned bytecodeIndex)
  81. {
  82. UNUSED_PARAM(profiledBlock);
  83. UNUSED_PARAM(bytecodeIndex);
  84. #if ENABLE(JIT) && ENABLE(VALUE_PROFILER)
  85. if (!profiledBlock->numberOfCallLinkInfos())
  86. return computeFromLLInt(profiledBlock, bytecodeIndex);
  87. if (profiledBlock->couldTakeSlowCase(bytecodeIndex))
  88. return CallLinkStatus::takesSlowPath();
  89. CallLinkInfo& callLinkInfo = profiledBlock->getCallLinkInfo(bytecodeIndex);
  90. if (callLinkInfo.stub)
  91. return CallLinkStatus(callLinkInfo.stub->executable(), callLinkInfo.stub->structure());
  92. JSFunction* target = callLinkInfo.lastSeenCallee.get();
  93. if (!target)
  94. return computeFromLLInt(profiledBlock, bytecodeIndex);
  95. if (callLinkInfo.hasSeenClosure)
  96. return CallLinkStatus(target->executable(), target->structure());
  97. return CallLinkStatus(target);
  98. #else
  99. return CallLinkStatus();
  100. #endif
  101. }
  102. void CallLinkStatus::dump(PrintStream& out) const
  103. {
  104. if (!isSet()) {
  105. out.print("Not Set");
  106. return;
  107. }
  108. CommaPrinter comma;
  109. if (m_isProved)
  110. out.print(comma, "Statically Proved");
  111. if (m_couldTakeSlowPath)
  112. out.print(comma, "Could Take Slow Path");
  113. if (m_callTarget)
  114. out.print(comma, "Known target: ", m_callTarget);
  115. if (m_executable)
  116. out.print(comma, "Executable/CallHash: ", RawPointer(m_executable), "/", m_executable->hashFor(CodeForCall));
  117. if (m_structure)
  118. out.print(comma, "Structure: ", RawPointer(m_structure));
  119. }
  120. } // namespace JSC