CodeOrigin.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "CodeOrigin.h"
  27. #include "CallFrame.h"
  28. #include "CodeBlock.h"
  29. #include "Executable.h"
  30. #include "Operations.h"
  31. namespace JSC {
  32. unsigned CodeOrigin::inlineDepthForCallFrame(InlineCallFrame* inlineCallFrame)
  33. {
  34. unsigned result = 1;
  35. for (InlineCallFrame* current = inlineCallFrame; current; current = current->caller.inlineCallFrame)
  36. result++;
  37. return result;
  38. }
  39. unsigned CodeOrigin::inlineDepth() const
  40. {
  41. return inlineDepthForCallFrame(inlineCallFrame);
  42. }
  43. Vector<CodeOrigin> CodeOrigin::inlineStack() const
  44. {
  45. Vector<CodeOrigin> result(inlineDepth());
  46. result.last() = *this;
  47. unsigned index = result.size() - 2;
  48. for (InlineCallFrame* current = inlineCallFrame; current; current = current->caller.inlineCallFrame)
  49. result[index--] = current->caller;
  50. RELEASE_ASSERT(!result[0].inlineCallFrame);
  51. return result;
  52. }
  53. void CodeOrigin::dump(PrintStream& out) const
  54. {
  55. Vector<CodeOrigin> stack = inlineStack();
  56. for (unsigned i = 0; i < stack.size(); ++i) {
  57. if (i)
  58. out.print(" --> ");
  59. if (InlineCallFrame* frame = stack[i].inlineCallFrame) {
  60. out.print(frame->briefFunctionInformation(), ":<", RawPointer(frame->executable.get()), "> ");
  61. if (frame->isClosureCall())
  62. out.print("(closure) ");
  63. }
  64. out.print("bc#", stack[i].bytecodeIndex);
  65. }
  66. }
  67. JSFunction* InlineCallFrame::calleeForCallFrame(ExecState* exec) const
  68. {
  69. if (!isClosureCall())
  70. return callee.get();
  71. return jsCast<JSFunction*>((exec + stackOffset)->callee());
  72. }
  73. CodeBlockHash InlineCallFrame::hash() const
  74. {
  75. return executable->hashFor(specializationKind());
  76. }
  77. String InlineCallFrame::inferredName() const
  78. {
  79. return jsCast<FunctionExecutable*>(executable.get())->inferredName().string();
  80. }
  81. CodeBlock* InlineCallFrame::baselineCodeBlock() const
  82. {
  83. return jsCast<FunctionExecutable*>(executable.get())->baselineCodeBlockFor(specializationKind());
  84. }
  85. void InlineCallFrame::dumpBriefFunctionInformation(PrintStream& out) const
  86. {
  87. out.print(inferredName(), "#", hash());
  88. }
  89. void InlineCallFrame::dump(PrintStream& out) const
  90. {
  91. out.print(briefFunctionInformation(), ":<", RawPointer(executable.get()), ", bc#", caller.bytecodeIndex, ", ", specializationKind());
  92. if (callee)
  93. out.print(", known callee: ", JSValue(callee.get()));
  94. else
  95. out.print(", closure call");
  96. out.print(", numArgs+this = ", arguments.size());
  97. out.print(", stack >= r", stackOffset);
  98. out.print(">");
  99. }
  100. } // namespace JSC