| 1 | /* |
| 2 | * Copyright (C) 2012-2015 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 | |
| 26 | #include "config.h" |
| 27 | #include "InlineCallFrame.h" |
| 28 | |
| 29 | #include "CallFrame.h" |
| 30 | #include "CodeBlock.h" |
| 31 | #include "JSCInlines.h" |
| 32 | |
| 33 | namespace JSC { |
| 34 | |
| 35 | JSFunction* InlineCallFrame::calleeConstant() const |
| 36 | { |
| 37 | if (calleeRecovery.isConstant()) |
| 38 | return jsCast<JSFunction*>(calleeRecovery.constant()); |
| 39 | return nullptr; |
| 40 | } |
| 41 | |
| 42 | JSFunction* InlineCallFrame::calleeForCallFrame(ExecState* exec) const |
| 43 | { |
| 44 | return jsCast<JSFunction*>(calleeRecovery.recover(exec)); |
| 45 | } |
| 46 | |
| 47 | CodeBlockHash InlineCallFrame::hash() const |
| 48 | { |
| 49 | return baselineCodeBlock->hash(); |
| 50 | } |
| 51 | |
| 52 | CString InlineCallFrame::hashAsStringIfPossible() const |
| 53 | { |
| 54 | return baselineCodeBlock->hashAsStringIfPossible(); |
| 55 | } |
| 56 | |
| 57 | CString InlineCallFrame::inferredName() const |
| 58 | { |
| 59 | return jsCast<FunctionExecutable*>(baselineCodeBlock->ownerExecutable())->ecmaName().utf8(); |
| 60 | } |
| 61 | |
| 62 | void InlineCallFrame::dumpBriefFunctionInformation(PrintStream& out) const |
| 63 | { |
| 64 | out.print(inferredName(), "#" , hashAsStringIfPossible()); |
| 65 | } |
| 66 | |
| 67 | void InlineCallFrame::dumpInContext(PrintStream& out, DumpContext* context) const |
| 68 | { |
| 69 | out.print(briefFunctionInformation(), ":<" , RawPointer(baselineCodeBlock.get())); |
| 70 | if (isStrictMode()) |
| 71 | out.print(" (StrictMode)" ); |
| 72 | out.print(", bc#" , directCaller.bytecodeIndex(), ", " , static_cast<Kind>(kind)); |
| 73 | if (isClosureCall) |
| 74 | out.print(", closure call" ); |
| 75 | else |
| 76 | out.print(", known callee: " , inContext(calleeRecovery.constant(), context)); |
| 77 | out.print(", numArgs+this = " , argumentCountIncludingThis); |
| 78 | out.print(", numFixup = " , argumentsWithFixup.size() - argumentCountIncludingThis); |
| 79 | out.print(", stackOffset = " , stackOffset); |
| 80 | out.print(" (" , virtualRegisterForLocal(0), " maps to " , virtualRegisterForLocal(0) + stackOffset, ")>" ); |
| 81 | } |
| 82 | |
| 83 | void InlineCallFrame::dump(PrintStream& out) const |
| 84 | { |
| 85 | dumpInContext(out, 0); |
| 86 | } |
| 87 | |
| 88 | } // namespace JSC |
| 89 | |
| 90 | namespace WTF { |
| 91 | |
| 92 | void printInternal(PrintStream& out, JSC::InlineCallFrame::Kind kind) |
| 93 | { |
| 94 | switch (kind) { |
| 95 | case JSC::InlineCallFrame::Call: |
| 96 | out.print("Call" ); |
| 97 | return; |
| 98 | case JSC::InlineCallFrame::Construct: |
| 99 | out.print("Construct" ); |
| 100 | return; |
| 101 | case JSC::InlineCallFrame::TailCall: |
| 102 | out.print("TailCall" ); |
| 103 | return; |
| 104 | case JSC::InlineCallFrame::CallVarargs: |
| 105 | out.print("CallVarargs" ); |
| 106 | return; |
| 107 | case JSC::InlineCallFrame::ConstructVarargs: |
| 108 | out.print("ConstructVarargs" ); |
| 109 | return; |
| 110 | case JSC::InlineCallFrame::TailCallVarargs: |
| 111 | out.print("TailCallVarargs" ); |
| 112 | return; |
| 113 | case JSC::InlineCallFrame::GetterCall: |
| 114 | out.print("GetterCall" ); |
| 115 | return; |
| 116 | case JSC::InlineCallFrame::SetterCall: |
| 117 | out.print("SetterCall" ); |
| 118 | return; |
| 119 | } |
| 120 | RELEASE_ASSERT_NOT_REACHED(); |
| 121 | } |
| 122 | |
| 123 | } // namespace WTF |
| 124 | |
| 125 | |