darling-JavaScriptCore/jit/PolymorphicCallStubRoutine.h

118 lines
3.4 KiB
C
Raw Permalink Normal View History

2017-08-12 09:48:01 -07:00
/*
2020-08-29 09:27:11 -04:00
* Copyright (C) 2015-2018 Apple Inc. All rights reserved.
2017-08-12 09:48:01 -07:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if ENABLE(JIT)
#include "CallEdge.h"
#include "CallVariant.h"
#include "GCAwareJITStubRoutine.h"
#include <wtf/Noncopyable.h>
2020-08-29 09:27:11 -04:00
#include <wtf/UniqueArray.h>
2017-08-12 09:48:01 -07:00
#include <wtf/Vector.h>
namespace JSC {
class CallLinkInfo;
2020-08-29 09:27:11 -04:00
class PolymorphicCallNode : public PackedRawSentinelNode<PolymorphicCallNode> {
2017-08-12 09:48:01 -07:00
WTF_MAKE_NONCOPYABLE(PolymorphicCallNode);
public:
PolymorphicCallNode(CallLinkInfo* info)
: m_callLinkInfo(info)
{
}
~PolymorphicCallNode();
void unlink(VM&);
2020-08-29 09:27:11 -04:00
bool hasCallLinkInfo(CallLinkInfo* info) { return m_callLinkInfo.get() == info; }
2017-08-12 09:48:01 -07:00
void clearCallLinkInfo();
private:
2020-08-29 09:27:11 -04:00
PackedPtr<CallLinkInfo> m_callLinkInfo;
2017-08-12 09:48:01 -07:00
};
class PolymorphicCallCase {
public:
PolymorphicCallCase()
: m_codeBlock(nullptr)
{
}
PolymorphicCallCase(CallVariant variant, CodeBlock* codeBlock)
: m_variant(variant)
, m_codeBlock(codeBlock)
{
}
CallVariant variant() const { return m_variant; }
CodeBlock* codeBlock() const { return m_codeBlock; }
void dump(PrintStream&) const;
private:
CallVariant m_variant;
CodeBlock* m_codeBlock;
};
class PolymorphicCallStubRoutine final : public GCAwareJITStubRoutine {
2017-08-12 09:48:01 -07:00
public:
PolymorphicCallStubRoutine(
2020-08-29 09:27:11 -04:00
const MacroAssemblerCodeRef<JITStubRoutinePtrTag>&, VM&, const JSCell* owner,
CallFrame* callerFrame, CallLinkInfo&, const Vector<PolymorphicCallCase>&,
2020-08-29 09:27:11 -04:00
UniqueArray<uint32_t>&& fastCounts);
2017-08-12 09:48:01 -07:00
~PolymorphicCallStubRoutine() final;
2017-08-12 09:48:01 -07:00
CallVariantList variants() const;
2020-08-29 09:27:11 -04:00
bool hasEdges() const;
2017-08-12 09:48:01 -07:00
CallEdgeList edges() const;
void clearCallNodesFor(CallLinkInfo*);
template<typename Functor>
void forEachDependentCell(const Functor& functor)
{
for (auto& variant : m_variants)
functor(variant.get());
}
2017-08-12 09:48:01 -07:00
bool visitWeak(VM&) final;
2017-08-12 09:48:01 -07:00
private:
void markRequiredObjectsInternal(SlotVisitor&) final;
2017-08-12 09:48:01 -07:00
Vector<WriteBarrier<JSCell>, 2> m_variants;
2020-08-29 09:27:11 -04:00
UniqueArray<uint32_t> m_fastCounts;
2017-08-12 09:48:01 -07:00
Bag<PolymorphicCallNode> m_callNodes;
};
} // namespace JSC
#endif // ENABLE(JIT)