fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | f7240e0 | 2016-12-16 02:16:19 +0000 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Apple Inc. All rights reserved. |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +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 "PolymorphicCallStubRoutine.h" |
| 28 | |
| 29 | #if ENABLE(JIT) |
| 30 | |
| 31 | #include "CallLinkInfo.h" |
| 32 | #include "CodeBlock.h" |
jfbastien@apple.com | c6594e5 | 2017-02-22 01:16:42 +0000 | [diff] [blame] | 33 | #include "FullCodeOrigin.h" |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 34 | #include "JSCInlines.h" |
| 35 | #include "LinkBuffer.h" |
| 36 | |
| 37 | namespace JSC { |
| 38 | |
| 39 | PolymorphicCallNode::~PolymorphicCallNode() |
| 40 | { |
| 41 | if (isOnList()) |
| 42 | remove(); |
| 43 | } |
| 44 | |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 45 | void PolymorphicCallNode::unlink(VM& vm) |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 46 | { |
msaboff@apple.com | 6c3c71c | 2015-06-01 23:35:02 +0000 | [diff] [blame] | 47 | if (m_callLinkInfo) { |
mark.lam@apple.com | ee3c410 | 2015-10-14 18:57:07 +0000 | [diff] [blame] | 48 | if (Options::dumpDisassembly()) |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 49 | dataLog("Unlinking polymorphic call at ", m_callLinkInfo->callReturnLocation(), ", ", m_callLinkInfo->codeOrigin(), "\n"); |
msaboff@apple.com | 6c3c71c | 2015-06-01 23:35:02 +0000 | [diff] [blame] | 50 | |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 51 | m_callLinkInfo->unlink(vm); |
msaboff@apple.com | 6c3c71c | 2015-06-01 23:35:02 +0000 | [diff] [blame] | 52 | } |
| 53 | |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 54 | if (isOnList()) |
| 55 | remove(); |
| 56 | } |
| 57 | |
msaboff@apple.com | 6c3c71c | 2015-06-01 23:35:02 +0000 | [diff] [blame] | 58 | void PolymorphicCallNode::clearCallLinkInfo() |
| 59 | { |
mark.lam@apple.com | ee3c410 | 2015-10-14 18:57:07 +0000 | [diff] [blame] | 60 | if (Options::dumpDisassembly()) |
msaboff@apple.com | 203a56e | 2015-06-24 22:37:30 +0000 | [diff] [blame] | 61 | dataLog("Clearing call link info for polymorphic call at ", m_callLinkInfo->callReturnLocation(), ", ", m_callLinkInfo->codeOrigin(), "\n"); |
msaboff@apple.com | 6c3c71c | 2015-06-01 23:35:02 +0000 | [diff] [blame] | 62 | |
| 63 | m_callLinkInfo = nullptr; |
| 64 | } |
| 65 | |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 66 | void PolymorphicCallCase::dump(PrintStream& out) const |
| 67 | { |
| 68 | out.print("<variant = ", m_variant, ", codeBlock = ", pointerDump(m_codeBlock), ">"); |
| 69 | } |
| 70 | |
| 71 | PolymorphicCallStubRoutine::PolymorphicCallStubRoutine( |
| 72 | const MacroAssemblerCodeRef& codeRef, VM& vm, const JSCell* owner, ExecState* callerFrame, |
| 73 | CallLinkInfo& info, const Vector<PolymorphicCallCase>& cases, |
utatane.tea@gmail.com | 1d211e1 | 2018-03-06 07:25:14 +0000 | [diff] [blame^] | 74 | UniqueArray<uint32_t>&& fastCounts) |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 75 | : GCAwareJITStubRoutine(codeRef, vm) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 76 | , m_fastCounts(WTFMove(fastCounts)) |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 77 | { |
| 78 | for (PolymorphicCallCase callCase : cases) { |
| 79 | m_variants.append(WriteBarrier<JSCell>(vm, owner, callCase.variant().rawCalleeCell())); |
mark.lam@apple.com | ee3c410 | 2015-10-14 18:57:07 +0000 | [diff] [blame] | 80 | if (shouldDumpDisassemblyFor(callerFrame->codeBlock())) |
jfbastien@apple.com | c6594e5 | 2017-02-22 01:16:42 +0000 | [diff] [blame] | 81 | dataLog("Linking polymorphic call in ", FullCodeOrigin(callerFrame->codeBlock(), callerFrame->codeOrigin()), " to ", callCase.variant(), ", codeBlock = ", pointerDump(callCase.codeBlock()), "\n"); |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 82 | if (CodeBlock* codeBlock = callCase.codeBlock()) |
| 83 | codeBlock->linkIncomingPolymorphicCall(callerFrame, m_callNodes.add(&info)); |
| 84 | } |
| 85 | m_variants.shrinkToFit(); |
| 86 | WTF::storeStoreFence(); |
| 87 | } |
| 88 | |
| 89 | PolymorphicCallStubRoutine::~PolymorphicCallStubRoutine() { } |
| 90 | |
| 91 | CallVariantList PolymorphicCallStubRoutine::variants() const |
| 92 | { |
| 93 | CallVariantList result; |
| 94 | for (size_t i = 0; i < m_variants.size(); ++i) |
| 95 | result.append(CallVariant(m_variants[i].get())); |
| 96 | return result; |
| 97 | } |
| 98 | |
| 99 | CallEdgeList PolymorphicCallStubRoutine::edges() const |
| 100 | { |
| 101 | // We wouldn't have these if this was an FTL stub routine. We shouldn't be asking for profiling |
| 102 | // from the FTL. |
| 103 | RELEASE_ASSERT(m_fastCounts); |
| 104 | |
| 105 | CallEdgeList result; |
| 106 | for (size_t i = 0; i < m_variants.size(); ++i) |
| 107 | result.append(CallEdge(CallVariant(m_variants[i].get()), m_fastCounts[i])); |
| 108 | return result; |
| 109 | } |
| 110 | |
msaboff@apple.com | 6c3c71c | 2015-06-01 23:35:02 +0000 | [diff] [blame] | 111 | void PolymorphicCallStubRoutine::clearCallNodesFor(CallLinkInfo* info) |
| 112 | { |
| 113 | for (Bag<PolymorphicCallNode>::iterator iter = m_callNodes.begin(); !!iter; ++iter) { |
| 114 | PolymorphicCallNode& node = **iter; |
| 115 | // All nodes should point to info, but okay to be a little paranoid. |
| 116 | if (node.hasCallLinkInfo(info)) |
| 117 | node.clearCallLinkInfo(); |
| 118 | } |
| 119 | } |
| 120 | |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 121 | bool PolymorphicCallStubRoutine::visitWeak(VM&) |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 122 | { |
| 123 | for (auto& variant : m_variants) { |
| 124 | if (!Heap::isMarked(variant.get())) |
| 125 | return false; |
| 126 | } |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | void PolymorphicCallStubRoutine::markRequiredObjectsInternal(SlotVisitor& visitor) |
| 131 | { |
| 132 | for (auto& variant : m_variants) |
fpizlo@apple.com | f7240e0 | 2016-12-16 02:16:19 +0000 | [diff] [blame] | 133 | visitor.append(variant); |
fpizlo@apple.com | 8a5fd18 | 2015-02-02 18:38:08 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | } // namespace JSC |
| 137 | |
| 138 | #endif // ENABLE(JIT) |