2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "PolymorphicCallStubRoutine.h"
31 #include "CallLinkInfo.h"
32 #include "CodeBlock.h"
33 #include "JSCInlines.h"
34 #include "LinkBuffer.h"
38 PolymorphicCallNode::~PolymorphicCallNode()
44 void PolymorphicCallNode::unlink(RepatchBuffer
& repatchBuffer
)
47 if (Options::showDisassembly())
48 dataLog("Unlinking polymorphic call at ", m_callLinkInfo
->callReturnLocation(), ", ", m_callLinkInfo
->codeOrigin(), "\n");
50 m_callLinkInfo
->unlink(repatchBuffer
);
57 void PolymorphicCallNode::clearCallLinkInfo()
59 if (Options::showDisassembly())
60 dataLog("Clearing call link info for polymorphic call at ", m_callLinkInfo
->callReturnLocation(), ", ", m_callLinkInfo
->codeOrigin(), "\n");
62 m_callLinkInfo
= nullptr;
65 void PolymorphicCallCase::dump(PrintStream
& out
) const
67 out
.print("<variant = ", m_variant
, ", codeBlock = ", pointerDump(m_codeBlock
), ">");
70 PolymorphicCallStubRoutine::PolymorphicCallStubRoutine(
71 const MacroAssemblerCodeRef
& codeRef
, VM
& vm
, const JSCell
* owner
, ExecState
* callerFrame
,
72 CallLinkInfo
& info
, const Vector
<PolymorphicCallCase
>& cases
,
73 std::unique_ptr
<uint32_t[]> fastCounts
)
74 : GCAwareJITStubRoutine(codeRef
, vm
)
75 , m_fastCounts(WTF::move(fastCounts
))
77 for (PolymorphicCallCase callCase
: cases
) {
78 m_variants
.append(WriteBarrier
<JSCell
>(vm
, owner
, callCase
.variant().rawCalleeCell()));
79 if (shouldShowDisassemblyFor(callerFrame
->codeBlock()))
80 dataLog("Linking polymorphic call in ", *callerFrame
->codeBlock(), " at ", callerFrame
->codeOrigin(), " to ", callCase
.variant(), ", codeBlock = ", pointerDump(callCase
.codeBlock()), "\n");
81 if (CodeBlock
* codeBlock
= callCase
.codeBlock())
82 codeBlock
->linkIncomingPolymorphicCall(callerFrame
, m_callNodes
.add(&info
));
84 m_variants
.shrinkToFit();
85 WTF::storeStoreFence();
88 PolymorphicCallStubRoutine::~PolymorphicCallStubRoutine() { }
90 CallVariantList
PolymorphicCallStubRoutine::variants() const
92 CallVariantList result
;
93 for (size_t i
= 0; i
< m_variants
.size(); ++i
)
94 result
.append(CallVariant(m_variants
[i
].get()));
98 CallEdgeList
PolymorphicCallStubRoutine::edges() const
100 // We wouldn't have these if this was an FTL stub routine. We shouldn't be asking for profiling
102 RELEASE_ASSERT(m_fastCounts
);
105 for (size_t i
= 0; i
< m_variants
.size(); ++i
)
106 result
.append(CallEdge(CallVariant(m_variants
[i
].get()), m_fastCounts
[i
]));
110 void PolymorphicCallStubRoutine::clearCallNodesFor(CallLinkInfo
* info
)
112 for (Bag
<PolymorphicCallNode
>::iterator iter
= m_callNodes
.begin(); !!iter
; ++iter
) {
113 PolymorphicCallNode
& node
= **iter
;
114 // All nodes should point to info, but okay to be a little paranoid.
115 if (node
.hasCallLinkInfo(info
))
116 node
.clearCallLinkInfo();
120 bool PolymorphicCallStubRoutine::visitWeak(RepatchBuffer
&)
122 for (auto& variant
: m_variants
) {
123 if (!Heap::isMarked(variant
.get()))
129 void PolymorphicCallStubRoutine::markRequiredObjectsInternal(SlotVisitor
& visitor
)
131 for (auto& variant
: m_variants
)
132 visitor
.append(&variant
);
137 #endif // ENABLE(JIT)