fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 2 | * Copyright (C) 2012-2015 Apple Inc. All rights reserved. |
fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 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 "CodeOrigin.h" |
| 28 | |
fpizlo@apple.com | 608ecbe | 2013-01-08 22:02:04 +0000 | [diff] [blame] | 29 | #include "CallFrame.h" |
fpizlo@apple.com | 4a81fa4 | 2012-12-05 01:26:13 +0000 | [diff] [blame] | 30 | #include "CodeBlock.h" |
ggaren@apple.com | 21cd702 | 2015-08-18 18:28:54 +0000 | [diff] [blame] | 31 | #include "InlineCallFrame.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 32 | #include "JSCInlines.h" |
fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 33 | |
| 34 | namespace JSC { |
| 35 | |
| 36 | unsigned CodeOrigin::inlineDepthForCallFrame(InlineCallFrame* inlineCallFrame) |
| 37 | { |
| 38 | unsigned result = 1; |
msaboff@apple.com | a3dc753 | 2015-09-24 21:42:59 +0000 | [diff] [blame] | 39 | for (InlineCallFrame* current = inlineCallFrame; current; current = current->directCaller.inlineCallFrame) |
fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 40 | result++; |
| 41 | return result; |
| 42 | } |
| 43 | |
| 44 | unsigned CodeOrigin::inlineDepth() const |
| 45 | { |
| 46 | return inlineDepthForCallFrame(inlineCallFrame); |
| 47 | } |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 48 | |
| 49 | bool CodeOrigin::isApproximatelyEqualTo(const CodeOrigin& other) const |
| 50 | { |
| 51 | CodeOrigin a = *this; |
| 52 | CodeOrigin b = other; |
| 53 | |
| 54 | if (!a.isSet()) |
| 55 | return !b.isSet(); |
| 56 | if (!b.isSet()) |
| 57 | return false; |
fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 58 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 59 | if (a.isHashTableDeletedValue()) |
| 60 | return b.isHashTableDeletedValue(); |
| 61 | if (b.isHashTableDeletedValue()) |
| 62 | return false; |
| 63 | |
| 64 | for (;;) { |
| 65 | ASSERT(a.isSet()); |
| 66 | ASSERT(b.isSet()); |
| 67 | |
| 68 | if (a.bytecodeIndex != b.bytecodeIndex) |
| 69 | return false; |
| 70 | |
| 71 | if ((!!a.inlineCallFrame) != (!!b.inlineCallFrame)) |
| 72 | return false; |
| 73 | |
| 74 | if (!a.inlineCallFrame) |
| 75 | return true; |
| 76 | |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 77 | if (a.inlineCallFrame->baselineCodeBlock.get() != b.inlineCallFrame->baselineCodeBlock.get()) |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 78 | return false; |
| 79 | |
msaboff@apple.com | a3dc753 | 2015-09-24 21:42:59 +0000 | [diff] [blame] | 80 | a = a.inlineCallFrame->directCaller; |
| 81 | b = b.inlineCallFrame->directCaller; |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | unsigned CodeOrigin::approximateHash() const |
| 86 | { |
| 87 | if (!isSet()) |
| 88 | return 0; |
| 89 | if (isHashTableDeletedValue()) |
| 90 | return 1; |
| 91 | |
| 92 | unsigned result = 2; |
| 93 | CodeOrigin codeOrigin = *this; |
| 94 | for (;;) { |
| 95 | result += codeOrigin.bytecodeIndex; |
| 96 | |
| 97 | if (!codeOrigin.inlineCallFrame) |
| 98 | return result; |
| 99 | |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 100 | result += WTF::PtrHash<JSCell*>::hash(codeOrigin.inlineCallFrame->baselineCodeBlock.get()); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 101 | |
msaboff@apple.com | a3dc753 | 2015-09-24 21:42:59 +0000 | [diff] [blame] | 102 | codeOrigin = codeOrigin.inlineCallFrame->directCaller; |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 106 | Vector<CodeOrigin> CodeOrigin::inlineStack() const |
| 107 | { |
| 108 | Vector<CodeOrigin> result(inlineDepth()); |
| 109 | result.last() = *this; |
| 110 | unsigned index = result.size() - 2; |
msaboff@apple.com | a3dc753 | 2015-09-24 21:42:59 +0000 | [diff] [blame] | 111 | for (InlineCallFrame* current = inlineCallFrame; current; current = current->directCaller.inlineCallFrame) |
| 112 | result[index--] = current->directCaller; |
oliver@apple.com | 903b0c0 | 2013-01-24 01:40:37 +0000 | [diff] [blame] | 113 | RELEASE_ASSERT(!result[0].inlineCallFrame); |
fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 114 | return result; |
| 115 | } |
| 116 | |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 117 | CodeBlock* CodeOrigin::codeOriginOwner() const |
ggaren@apple.com | 21cd702 | 2015-08-18 18:28:54 +0000 | [diff] [blame] | 118 | { |
| 119 | if (!inlineCallFrame) |
| 120 | return 0; |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 121 | return inlineCallFrame->baselineCodeBlock.get(); |
ggaren@apple.com | 21cd702 | 2015-08-18 18:28:54 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | int CodeOrigin::stackOffset() const |
| 125 | { |
| 126 | if (!inlineCallFrame) |
| 127 | return 0; |
| 128 | |
| 129 | return inlineCallFrame->stackOffset; |
| 130 | } |
| 131 | |
fpizlo@apple.com | 20d4624 | 2012-11-30 21:56:24 +0000 | [diff] [blame] | 132 | void CodeOrigin::dump(PrintStream& out) const |
| 133 | { |
fpizlo@apple.com | 50f0628 | 2013-12-10 05:52:24 +0000 | [diff] [blame] | 134 | if (!isSet()) { |
| 135 | out.print("<none>"); |
| 136 | return; |
| 137 | } |
| 138 | |
fpizlo@apple.com | 20d4624 | 2012-11-30 21:56:24 +0000 | [diff] [blame] | 139 | Vector<CodeOrigin> stack = inlineStack(); |
| 140 | for (unsigned i = 0; i < stack.size(); ++i) { |
| 141 | if (i) |
| 142 | out.print(" --> "); |
| 143 | |
fpizlo@apple.com | 806b582 | 2013-01-08 01:23:38 +0000 | [diff] [blame] | 144 | if (InlineCallFrame* frame = stack[i].inlineCallFrame) { |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 145 | out.print(frame->briefFunctionInformation(), ":<", RawPointer(frame->baselineCodeBlock.get()), "> "); |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 146 | if (frame->isClosureCall) |
fpizlo@apple.com | 806b582 | 2013-01-08 01:23:38 +0000 | [diff] [blame] | 147 | out.print("(closure) "); |
| 148 | } |
fpizlo@apple.com | 20d4624 | 2012-11-30 21:56:24 +0000 | [diff] [blame] | 149 | |
| 150 | out.print("bc#", stack[i].bytecodeIndex); |
| 151 | } |
| 152 | } |
| 153 | |
oliver@apple.com | 237b146 | 2013-07-25 04:05:36 +0000 | [diff] [blame] | 154 | void CodeOrigin::dumpInContext(PrintStream& out, DumpContext*) const |
| 155 | { |
| 156 | dump(out); |
| 157 | } |
| 158 | |
fpizlo@apple.com | 0bfcc38 | 2012-11-30 03:42:29 +0000 | [diff] [blame] | 159 | } // namespace JSC |