fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 2 | * Copyright (C) 2012-2015 Apple Inc. All rights reserved. |
fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +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 "CallLinkStatus.h" |
| 28 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 29 | #include "CallLinkInfo.h" |
fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +0000 | [diff] [blame] | 30 | #include "CodeBlock.h" |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 31 | #include "DFGJITCode.h" |
ggaren@apple.com | 21cd702 | 2015-08-18 18:28:54 +0000 | [diff] [blame] | 32 | #include "InlineCallFrame.h" |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 33 | #include "LLIntCallLinkInfo.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 34 | #include "JSCInlines.h" |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 35 | #include <wtf/CommaPrinter.h> |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 36 | #include <wtf/ListDump.h> |
fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +0000 | [diff] [blame] | 37 | |
| 38 | namespace JSC { |
| 39 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 40 | static const bool verbose = false; |
| 41 | |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 42 | CallLinkStatus::CallLinkStatus(JSValue value) |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 43 | : m_couldTakeSlowPath(false) |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 44 | , m_isProved(false) |
| 45 | { |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 46 | if (!value || !value.isCell()) { |
| 47 | m_couldTakeSlowPath = true; |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 48 | return; |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 49 | } |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 50 | |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 51 | m_variants.append(CallVariant(value.asCell())); |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 52 | } |
| 53 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 54 | CallLinkStatus CallLinkStatus::computeFromLLInt(const ConcurrentJITLocker& locker, CodeBlock* profiledBlock, unsigned bytecodeIndex) |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 55 | { |
| 56 | UNUSED_PARAM(profiledBlock); |
| 57 | UNUSED_PARAM(bytecodeIndex); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 58 | #if ENABLE(DFG_JIT) |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 59 | if (profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadCell))) { |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 60 | // We could force this to be a closure call, but instead we'll just assume that it |
| 61 | // takes slow path. |
| 62 | return takesSlowPath(); |
| 63 | } |
| 64 | #else |
| 65 | UNUSED_PARAM(locker); |
| 66 | #endif |
| 67 | |
| 68 | VM& vm = *profiledBlock->vm(); |
| 69 | |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 70 | Instruction* instruction = profiledBlock->instructions().begin() + bytecodeIndex; |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 71 | OpcodeID op = vm.interpreter->getOpcodeID(instruction[0].u.opcode); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 72 | if (op != op_call && op != op_construct && op != op_tail_call) |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 73 | return CallLinkStatus(); |
| 74 | |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 75 | LLIntCallLinkInfo* callLinkInfo = instruction[5].u.callLinkInfo; |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 76 | |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 77 | return CallLinkStatus(callLinkInfo->lastSeenCallee.get()); |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 78 | } |
| 79 | |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 80 | CallLinkStatus CallLinkStatus::computeFor( |
| 81 | CodeBlock* profiledBlock, unsigned bytecodeIndex, const CallLinkInfoMap& map) |
fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +0000 | [diff] [blame] | 82 | { |
oliver@apple.com | d205666 | 2013-07-25 04:00:37 +0000 | [diff] [blame] | 83 | ConcurrentJITLocker locker(profiledBlock->m_lock); |
oliver@apple.com | 0c1b13e | 2013-07-25 03:58:43 +0000 | [diff] [blame] | 84 | |
fpizlo@apple.com | 246741b | 2012-01-22 09:11:49 +0000 | [diff] [blame] | 85 | UNUSED_PARAM(profiledBlock); |
| 86 | UNUSED_PARAM(bytecodeIndex); |
fpizlo@apple.com | f7100b6 | 2014-03-24 17:29:51 +0000 | [diff] [blame] | 87 | UNUSED_PARAM(map); |
commit-queue@webkit.org | e975487 | 2014-02-15 08:30:54 +0000 | [diff] [blame] | 88 | #if ENABLE(DFG_JIT) |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 89 | ExitSiteData exitSiteData = computeExitSiteData(locker, profiledBlock, bytecodeIndex); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 90 | |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 91 | CallLinkInfo* callLinkInfo = map.get(CodeOrigin(bytecodeIndex)); |
fpizlo@apple.com | dc983c4 | 2015-01-28 05:48:59 +0000 | [diff] [blame] | 92 | if (!callLinkInfo) { |
| 93 | if (exitSiteData.m_takesSlowPath) |
| 94 | return takesSlowPath(); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 95 | return computeFromLLInt(locker, profiledBlock, bytecodeIndex); |
fpizlo@apple.com | dc983c4 | 2015-01-28 05:48:59 +0000 | [diff] [blame] | 96 | } |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 97 | |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 98 | return computeFor(locker, profiledBlock, *callLinkInfo, exitSiteData); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 99 | #else |
| 100 | return CallLinkStatus(); |
| 101 | #endif |
| 102 | } |
| 103 | |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 104 | CallLinkStatus::ExitSiteData CallLinkStatus::computeExitSiteData( |
fpizlo@apple.com | c1f69d7 | 2015-06-02 05:39:11 +0000 | [diff] [blame] | 105 | const ConcurrentJITLocker& locker, CodeBlock* profiledBlock, unsigned bytecodeIndex) |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 106 | { |
| 107 | ExitSiteData exitSiteData; |
| 108 | |
| 109 | #if ENABLE(DFG_JIT) |
| 110 | exitSiteData.m_takesSlowPath = |
fpizlo@apple.com | c1f69d7 | 2015-06-02 05:39:11 +0000 | [diff] [blame] | 111 | profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadType)) |
| 112 | || profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadExecutable)); |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 113 | exitSiteData.m_badFunction = |
fpizlo@apple.com | c1f69d7 | 2015-06-02 05:39:11 +0000 | [diff] [blame] | 114 | profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadCell)); |
fpizlo@apple.com | 0d24eb3 | 2014-07-22 21:30:48 +0000 | [diff] [blame] | 115 | #else |
| 116 | UNUSED_PARAM(locker); |
| 117 | UNUSED_PARAM(profiledBlock); |
| 118 | UNUSED_PARAM(bytecodeIndex); |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | return exitSiteData; |
| 122 | } |
| 123 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 124 | #if ENABLE(JIT) |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 125 | CallLinkStatus CallLinkStatus::computeFor( |
| 126 | const ConcurrentJITLocker& locker, CodeBlock* profiledBlock, CallLinkInfo& callLinkInfo) |
| 127 | { |
| 128 | // We don't really need this, but anytime we have to debug this code, it becomes indispensable. |
| 129 | UNUSED_PARAM(profiledBlock); |
| 130 | |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 131 | CallLinkStatus result = computeFromCallLinkInfo(locker, callLinkInfo); |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 132 | result.m_maxNumArguments = callLinkInfo.maxNumArguments(); |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 133 | return result; |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | CallLinkStatus CallLinkStatus::computeFromCallLinkInfo( |
| 137 | const ConcurrentJITLocker&, CallLinkInfo& callLinkInfo) |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 138 | { |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 139 | if (callLinkInfo.clearedByGC()) |
fpizlo@apple.com | 23bc584 | 2015-06-03 20:08:01 +0000 | [diff] [blame] | 140 | return takesSlowPath(); |
| 141 | |
fpizlo@apple.com | 2bcd60f | 2014-05-01 15:48:05 +0000 | [diff] [blame] | 142 | // Note that despite requiring that the locker is held, this code is racy with respect |
| 143 | // to the CallLinkInfo: it may get cleared while this code runs! This is because |
| 144 | // CallLinkInfo::unlink() may be called from a different CodeBlock than the one that owns |
| 145 | // the CallLinkInfo and currently we save space by not having CallLinkInfos know who owns |
| 146 | // them. So, there is no way for either the caller of CallLinkInfo::unlock() or unlock() |
| 147 | // itself to figure out which lock to lock. |
| 148 | // |
| 149 | // Fortunately, that doesn't matter. The only things we ask of CallLinkInfo - the slow |
| 150 | // path count, the stub, and the target - can all be asked racily. Stubs and targets can |
| 151 | // only be deleted at next GC, so if we load a non-null one, then it must contain data |
| 152 | // that is still marginally valid (i.e. the pointers ain't stale). This kind of raciness |
| 153 | // is probably OK for now. |
| 154 | |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 155 | // PolymorphicCallStubRoutine is a GCAwareJITStubRoutine, so if non-null, it will stay alive |
| 156 | // until next GC even if the CallLinkInfo is concurrently cleared. Also, the variants list is |
| 157 | // never mutated after the PolymorphicCallStubRoutine is instantiated. We have some conservative |
| 158 | // fencing in place to make sure that we see the variants list after construction. |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 159 | if (PolymorphicCallStubRoutine* stub = callLinkInfo.stub()) { |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 160 | WTF::loadLoadFence(); |
| 161 | |
| 162 | CallEdgeList edges = stub->edges(); |
| 163 | |
| 164 | // Now that we've loaded the edges list, there are no further concurrency concerns. We will |
| 165 | // just manipulate and prune this list to our liking - mostly removing entries that are too |
| 166 | // infrequent and ensuring that it's sorted in descending order of frequency. |
| 167 | |
| 168 | RELEASE_ASSERT(edges.size()); |
| 169 | |
| 170 | std::sort( |
| 171 | edges.begin(), edges.end(), |
| 172 | [] (CallEdge a, CallEdge b) { |
| 173 | return a.count() > b.count(); |
| 174 | }); |
| 175 | RELEASE_ASSERT(edges.first().count() >= edges.last().count()); |
| 176 | |
| 177 | double totalCallsToKnown = 0; |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 178 | double totalCallsToUnknown = callLinkInfo.slowPathCount(); |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 179 | CallVariantList variants; |
| 180 | for (size_t i = 0; i < edges.size(); ++i) { |
| 181 | CallEdge edge = edges[i]; |
| 182 | // If the call is at the tail of the distribution, then we don't optimize it and we |
| 183 | // treat it as if it was a call to something unknown. We define the tail as being either |
| 184 | // a call that doesn't belong to the N most frequent callees (N = |
| 185 | // maxPolymorphicCallVariantsForInlining) or that has a total call count that is too |
| 186 | // small. |
| 187 | if (i >= Options::maxPolymorphicCallVariantsForInlining() |
| 188 | || edge.count() < Options::frequentCallThreshold()) |
| 189 | totalCallsToUnknown += edge.count(); |
| 190 | else { |
| 191 | totalCallsToKnown += edge.count(); |
| 192 | variants.append(edge.callee()); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // Bail if we didn't find any calls that qualified. |
| 197 | RELEASE_ASSERT(!!totalCallsToKnown == !!variants.size()); |
| 198 | if (variants.isEmpty()) |
| 199 | return takesSlowPath(); |
| 200 | |
| 201 | // We require that the distribution of callees is skewed towards a handful of common ones. |
| 202 | if (totalCallsToKnown / totalCallsToUnknown < Options::minimumCallToKnownRate()) |
| 203 | return takesSlowPath(); |
| 204 | |
| 205 | RELEASE_ASSERT(totalCallsToKnown); |
| 206 | RELEASE_ASSERT(variants.size()); |
| 207 | |
| 208 | CallLinkStatus result; |
| 209 | result.m_variants = variants; |
| 210 | result.m_couldTakeSlowPath = !!totalCallsToUnknown; |
| 211 | return result; |
| 212 | } |
| 213 | |
fpizlo@apple.com | 481b5f1 | 2015-06-02 02:59:39 +0000 | [diff] [blame] | 214 | CallLinkStatus result; |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 215 | |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 216 | if (JSFunction* target = callLinkInfo.lastSeenCallee()) { |
fpizlo@apple.com | 481b5f1 | 2015-06-02 02:59:39 +0000 | [diff] [blame] | 217 | CallVariant variant(target); |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 218 | if (callLinkInfo.hasSeenClosure()) |
fpizlo@apple.com | 481b5f1 | 2015-06-02 02:59:39 +0000 | [diff] [blame] | 219 | variant = variant.despecifiedClosure(); |
| 220 | result.m_variants.append(variant); |
| 221 | } |
fpizlo@apple.com | 806b582 | 2013-01-08 01:23:38 +0000 | [diff] [blame] | 222 | |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 223 | result.m_couldTakeSlowPath = !!callLinkInfo.slowPathCount(); |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 224 | |
fpizlo@apple.com | 481b5f1 | 2015-06-02 02:59:39 +0000 | [diff] [blame] | 225 | return result; |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 226 | } |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 227 | |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 228 | CallLinkStatus CallLinkStatus::computeFor( |
| 229 | const ConcurrentJITLocker& locker, CodeBlock* profiledBlock, CallLinkInfo& callLinkInfo, |
| 230 | ExitSiteData exitSiteData) |
| 231 | { |
| 232 | CallLinkStatus result = computeFor(locker, profiledBlock, callLinkInfo); |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 233 | if (exitSiteData.m_badFunction) |
| 234 | result.makeClosureCall(); |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 235 | if (exitSiteData.m_takesSlowPath) |
| 236 | result.m_couldTakeSlowPath = true; |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 237 | |
| 238 | return result; |
| 239 | } |
fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +0000 | [diff] [blame] | 240 | #endif |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 241 | |
| 242 | void CallLinkStatus::computeDFGStatuses( |
| 243 | CodeBlock* dfgCodeBlock, CallLinkStatus::ContextMap& map) |
| 244 | { |
| 245 | #if ENABLE(DFG_JIT) |
| 246 | RELEASE_ASSERT(dfgCodeBlock->jitType() == JITCode::DFGJIT); |
| 247 | CodeBlock* baselineCodeBlock = dfgCodeBlock->alternative(); |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 248 | for (auto iter = dfgCodeBlock->callLinkInfosBegin(); !!iter; ++iter) { |
| 249 | CallLinkInfo& info = **iter; |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 250 | CodeOrigin codeOrigin = info.codeOrigin(); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 251 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 252 | // Check if we had already previously made a terrible mistake in the FTL for this |
| 253 | // code origin. Note that this is approximate because we could have a monovariant |
| 254 | // inline in the FTL that ended up failing. We should fix that at some point by |
| 255 | // having data structures to track the context of frequent exits. This is currently |
| 256 | // challenging because it would require creating a CodeOrigin-based database in |
| 257 | // baseline CodeBlocks, but those CodeBlocks don't really have a place to put the |
| 258 | // InlineCallFrames. |
| 259 | CodeBlock* currentBaseline = |
| 260 | baselineCodeBlockForOriginAndBaselineCodeBlock(codeOrigin, baselineCodeBlock); |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 261 | ExitSiteData exitSiteData; |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 262 | { |
| 263 | ConcurrentJITLocker locker(currentBaseline->m_lock); |
fpizlo@apple.com | 4c6b8ad | 2014-07-22 21:08:50 +0000 | [diff] [blame] | 264 | exitSiteData = computeExitSiteData( |
fpizlo@apple.com | c1f69d7 | 2015-06-02 05:39:11 +0000 | [diff] [blame] | 265 | locker, currentBaseline, codeOrigin.bytecodeIndex); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | { |
| 269 | ConcurrentJITLocker locker(dfgCodeBlock->m_lock); |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 270 | map.add(info.codeOrigin(), computeFor(locker, dfgCodeBlock, info, exitSiteData)); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | #else |
| 274 | UNUSED_PARAM(dfgCodeBlock); |
| 275 | #endif // ENABLE(DFG_JIT) |
| 276 | |
| 277 | if (verbose) { |
| 278 | dataLog("Context map:\n"); |
| 279 | ContextMap::iterator iter = map.begin(); |
| 280 | ContextMap::iterator end = map.end(); |
| 281 | for (; iter != end; ++iter) { |
| 282 | dataLog(" ", iter->key, ":\n"); |
| 283 | dataLog(" ", iter->value, "\n"); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | CallLinkStatus CallLinkStatus::computeFor( |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 289 | CodeBlock* profiledBlock, CodeOrigin codeOrigin, |
| 290 | const CallLinkInfoMap& baselineMap, const CallLinkStatus::ContextMap& dfgMap) |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 291 | { |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 292 | auto iter = dfgMap.find(codeOrigin); |
| 293 | if (iter != dfgMap.end()) |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 294 | return iter->value; |
| 295 | |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 296 | return computeFor(profiledBlock, codeOrigin.bytecodeIndex, baselineMap); |
fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +0000 | [diff] [blame] | 297 | } |
| 298 | |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 299 | void CallLinkStatus::setProvenConstantCallee(CallVariant variant) |
| 300 | { |
| 301 | m_variants = CallVariantList{ variant }; |
| 302 | m_couldTakeSlowPath = false; |
| 303 | m_isProved = true; |
| 304 | } |
| 305 | |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 306 | bool CallLinkStatus::isClosureCall() const |
| 307 | { |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 308 | for (unsigned i = m_variants.size(); i--;) { |
| 309 | if (m_variants[i].isClosureCall()) |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 310 | return true; |
| 311 | } |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | void CallLinkStatus::makeClosureCall() |
| 316 | { |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 317 | m_variants = despecifiedVariantList(m_variants); |
fpizlo@apple.com | 29abafe | 2014-08-28 19:09:48 +0000 | [diff] [blame] | 318 | } |
| 319 | |
fpizlo@apple.com | 5e2296a | 2013-01-07 02:24:58 +0000 | [diff] [blame] | 320 | void CallLinkStatus::dump(PrintStream& out) const |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 321 | { |
| 322 | if (!isSet()) { |
| 323 | out.print("Not Set"); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | CommaPrinter comma; |
| 328 | |
| 329 | if (m_isProved) |
| 330 | out.print(comma, "Statically Proved"); |
| 331 | |
| 332 | if (m_couldTakeSlowPath) |
| 333 | out.print(comma, "Could Take Slow Path"); |
| 334 | |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 335 | if (!m_variants.isEmpty()) |
| 336 | out.print(comma, listDump(m_variants)); |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 337 | |
| 338 | if (m_maxNumArguments) |
| 339 | out.print(comma, "maxNumArguments = ", m_maxNumArguments); |
fpizlo@apple.com | 6bd6145 | 2013-01-03 22:04:39 +0000 | [diff] [blame] | 340 | } |
| 341 | |
fpizlo@apple.com | 1f8917f | 2012-01-22 01:36:23 +0000 | [diff] [blame] | 342 | } // namespace JSC |
| 343 | |