source: webkit/trunk/Source/JavaScriptCore/jit/GCAwareJITStubRoutine.h

Last change on this file was 286769, checked in by [email protected], 3 years ago

[JSC] Introduce BaselineCallLinkInfo and OptimizingCallLinkInfo to shrink sizeof(BaselineCallLinkInfo)
https://bugs.webkit.org/show_bug.cgi?id=233985

Reviewed by Mark Lam.

This patch introduces BaselineCallLinkInfo and OptimizingCallLinkInfo to shrink sizeof(BaselineCallLinkInfo).
BaselineCallLinkInfo is included in metadata, and allocated for LLInt and Baseline. So shrinking it can make
metadata small for LLInt and Baseline, which exists for all live functions.

We also reorder OpIteratorOpen::Metadata and OpIteratorNext::Metadata to shrink sizes.

sizeof(BaselineCallLinkInfo) becomes 88, while the old sizeof(CallLinkInfo) was 120.

  • bytecode/AccessCase.cpp:

(JSC::AccessCase::generateImpl):

  • bytecode/BytecodeList.rb:
  • bytecode/CallLinkInfo.cpp:

(JSC::CallLinkInfo::setMonomorphicCallee):
(JSC::CallLinkInfo::emitFastPathImpl):
(JSC::OptimizingCallLinkInfo::emitFastPath):
(JSC::OptimizingCallLinkInfo::emitTailCallFastPath):
(JSC::OptimizingCallLinkInfo::emitSlowPath):
(JSC::CallLinkInfo::emitDataICSlowPath):
(JSC::OptimizingCallLinkInfo::slowPathStart):
(JSC::OptimizingCallLinkInfo::fastPathStart):
(JSC::OptimizingCallLinkInfo::emitDirectFastPath):
(JSC::OptimizingCallLinkInfo::emitDirectTailCallFastPath):
(JSC::OptimizingCallLinkInfo::initializeDirectCall):
(JSC::OptimizingCallLinkInfo::setDirectCallTarget):
(JSC::BaselineCallLinkInfo::initialize):
(JSC::CallLinkInfo::slowPathStart): Deleted.
(JSC::CallLinkInfo::fastPathStart): Deleted.
(JSC::CallLinkInfo::emitFastPath): Deleted.
(JSC::CallLinkInfo::emitTailCallFastPath): Deleted.
(JSC::CallLinkInfo::emitSlowPath): Deleted.
(JSC::CallLinkInfo::initializeDataIC): Deleted.
(JSC::CallLinkInfo::emitDirectFastPath): Deleted.
(JSC::CallLinkInfo::emitDirectTailCallFastPath): Deleted.
(JSC::CallLinkInfo::initializeDirectCall): Deleted.
(JSC::CallLinkInfo::setDirectCallTarget): Deleted.

  • bytecode/CallLinkInfo.h:

(JSC::CallLinkInfo::type const):
(JSC::CallLinkInfo::CallLinkInfo):
(JSC::CallLinkInfo::calleeGPR const):
(JSC::CallLinkInfo::callLinkInfoGPR const):
(JSC::CallLinkInfo::setCallLinkInfoGPR):
(JSC::CallLinkInfo::setUpCall): Deleted.
(JSC::CallLinkInfo::setCodeLocations): Deleted.
(JSC::CallLinkInfo::calleeGPR): Deleted.

  • bytecode/CallLinkStatus.cpp:

(JSC::CallLinkStatus::computeFor):

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::finishCreation):
(JSC::CodeBlock::setupWithUnlinkedBaselineCode):
(JSC::CodeBlock::finalizeUnconditionally):
(JSC::CodeBlock::getICStatusMap):
(JSC::CodeBlock::jettison):

  • bytecode/GetterSetterAccessCase.h:
  • bytecode/PolymorphicAccess.h:
  • bytecode/Repatch.cpp:

(JSC::revertCall):
(JSC::linkDirectCall):

  • bytecode/Repatch.h:
  • dfg/DFGCommonData.h:

(JSC::DFG::CommonData::addCallLinkInfo):

  • dfg/DFGJITCompiler.cpp:

(JSC::DFG::JITCompiler::link):

  • dfg/DFGJITCompiler.h:

(JSC::DFG::JITCompiler::addJSCall):
(JSC::DFG::JITCompiler::addJSDirectCall):
(JSC::DFG::JITCompiler::JSCallRecord::JSCallRecord):
(JSC::DFG::JITCompiler::JSDirectCallRecord::JSDirectCallRecord):

  • dfg/DFGOperations.cpp:

(JSC::DFG::JSC_DEFINE_JIT_OPERATION):

  • dfg/DFGOperations.h:
  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::emitCall):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::emitCall):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):

  • jit/CallFrameShuffleData.cpp:

(JSC::CallFrameShuffleData::createForBaselineOrLLIntTailCall):

  • jit/GCAwareJITStubRoutine.cpp:

(JSC::MarkingGCAwareJITStubRoutine::MarkingGCAwareJITStubRoutine):
(JSC::GCAwareJITStubRoutineWithExceptionHandler::GCAwareJITStubRoutineWithExceptionHandler):
(JSC::createICJITStubRoutine):

  • jit/GCAwareJITStubRoutine.h:
  • jit/JITCall.cpp:

(JSC::JIT::compileCallEvalSlowCase):
(JSC::JIT::compileTailCall):
(JSC::JIT::compileOpCall):
(): Deleted.

  • wasm/js/JSWebAssemblyCodeBlock.h:
  • wasm/js/WasmToJS.cpp:

(JSC::Wasm::wasmToJS):

  • wasm/js/WasmToJS.h:
File size: 7.3 KB
Line 
1/*
2 * Copyright (C) 2012-2021 Apple Inc. All rights reserved.
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#pragma once
27
28#if ENABLE(JIT)
29
30#include "JITStubRoutine.h"
31#include "JSObject.h"
32#include "WriteBarrier.h"
33#include <wtf/FixedVector.h>
34#include <wtf/Hasher.h>
35#include <wtf/Vector.h>
36
37namespace JSC {
38namespace DFG {
39class CodeOriginPool;
40}
41
42class AccessCase;
43class CallLinkInfo;
44class JITStubRoutineSet;
45class OptimizingCallLinkInfo;
46
47// Use this stub routine if you know that your code might be on stack when
48// either GC or other kinds of stub deletion happen. Basicaly, if your stub
49// routine makes calls (either to JS code or to C++ code) then you should
50// assume that it's possible for that JS or C++ code to do something that
51// causes the system to try to delete your routine. Using this routine type
52// ensures that the actual deletion is delayed until the GC proves that the
53// routine is no longer running. You can also subclass this routine if you
54// want to mark additional objects during GC in those cases where the
55// routine is known to be executing, or if you want to force this routine to
56// keep other routines alive (for example due to the use of a slow-path
57// list which does not get reclaimed all at once).
58class GCAwareJITStubRoutine : public JITStubRoutine {
59public:
60 GCAwareJITStubRoutine(const MacroAssemblerCodeRef<JITStubRoutinePtrTag>&);
61 ~GCAwareJITStubRoutine() override;
62
63 static Ref<JITStubRoutine> create(VM& vm, const MacroAssemblerCodeRef<JITStubRoutinePtrTag>& code)
64 {
65 auto stub = adoptRef(*new GCAwareJITStubRoutine(code));
66 stub->makeGCAware(vm);
67 return stub;
68 }
69
70 template<typename Visitor>
71 void markRequiredObjects(Visitor& visitor)
72 {
73 markRequiredObjectsInternal(visitor);
74 }
75
76 void deleteFromGC();
77
78 void makeGCAware(VM&);
79
80protected:
81 void observeZeroRefCount() override;
82
83 virtual void markRequiredObjectsInternal(AbstractSlotVisitor&) { }
84 virtual void markRequiredObjectsInternal(SlotVisitor&) { }
85
86private:
87 friend class JITStubRoutineSet;
88
89 bool m_mayBeExecuting { false };
90 bool m_isJettisoned { false };
91 bool m_isGCAware { false };
92};
93
94class PolymorphicAccessJITStubRoutine : public GCAwareJITStubRoutine {
95public:
96 using Base = GCAwareJITStubRoutine;
97
98 PolymorphicAccessJITStubRoutine(const MacroAssemblerCodeRef<JITStubRoutinePtrTag>&, VM&, FixedVector<RefPtr<AccessCase>>&&, FixedVector<StructureID>&&);
99
100 const FixedVector<RefPtr<AccessCase>>& cases() const { return m_cases; }
101 const FixedVector<StructureID>& weakStructures() const { return m_weakStructures; }
102
103 unsigned hash() const
104 {
105 if (!m_hash)
106 m_hash = computeHash(m_cases, m_weakStructures);
107 return m_hash;
108 }
109
110 static unsigned computeHash(const FixedVector<RefPtr<AccessCase>>&, const FixedVector<StructureID>&);
111
112protected:
113 void observeZeroRefCount() override;
114
115private:
116 VM& m_vm;
117 FixedVector<RefPtr<AccessCase>> m_cases;
118 FixedVector<StructureID> m_weakStructures;
119};
120
121// Use this if you want to mark one additional object during GC if your stub
122// routine is known to be executing.
123class MarkingGCAwareJITStubRoutine : public PolymorphicAccessJITStubRoutine {
124public:
125 using Base = PolymorphicAccessJITStubRoutine;
126
127 MarkingGCAwareJITStubRoutine(
128 const MacroAssemblerCodeRef<JITStubRoutinePtrTag>&, VM&, FixedVector<RefPtr<AccessCase>>&&, FixedVector<StructureID>&&, const JSCell* owner, const Vector<JSCell*>&, Bag<OptimizingCallLinkInfo>&&);
129 ~MarkingGCAwareJITStubRoutine() override;
130
131protected:
132 template<typename Visitor> void markRequiredObjectsInternalImpl(Visitor&);
133 void markRequiredObjectsInternal(AbstractSlotVisitor&) final;
134 void markRequiredObjectsInternal(SlotVisitor&) final;
135
136private:
137 FixedVector<WriteBarrier<JSCell>> m_cells;
138 Bag<OptimizingCallLinkInfo> m_callLinkInfos;
139};
140
141
142// The stub has exception handlers in it. So it clears itself from exception
143// handling table when it dies. It also frees space in CodeOrigin table
144// for new exception handlers to use the same DisposableCallSiteIndex.
145class GCAwareJITStubRoutineWithExceptionHandler final : public MarkingGCAwareJITStubRoutine {
146public:
147 using Base = MarkingGCAwareJITStubRoutine;
148
149 GCAwareJITStubRoutineWithExceptionHandler(const MacroAssemblerCodeRef<JITStubRoutinePtrTag>&, VM&, FixedVector<RefPtr<AccessCase>>&&, FixedVector<StructureID>&&, const JSCell* owner, const Vector<JSCell*>&, Bag<OptimizingCallLinkInfo>&&, CodeBlock*, DisposableCallSiteIndex);
150 ~GCAwareJITStubRoutineWithExceptionHandler() final;
151
152 void aboutToDie() final;
153 void observeZeroRefCount() final;
154
155private:
156 CodeBlock* m_codeBlockWithExceptionHandler;
157#if ENABLE(DFG_JIT)
158 RefPtr<DFG::CodeOriginPool> m_codeOriginPool;
159#endif
160 DisposableCallSiteIndex m_exceptionHandlerCallSiteIndex;
161};
162
163// Helper for easily creating a GC-aware JIT stub routine. For the varargs,
164// pass zero or more JSCell*'s. This will either create a JITStubRoutine, a
165// GCAwareJITStubRoutine, or an ObjectMarkingGCAwareJITStubRoutine as
166// appropriate. Generally you only need to pass pointers that will be used
167// after the first call to C++ or JS.
168//
169// Ref<PolymorphicAccessJITStubRoutine> createICJITStubRoutine(
170// const MacroAssemblerCodeRef<JITStubRoutinePtrTag>& code,
171// VM& vm,
172// FixedVector<RefPtr<AccessCase>>&& cases,
173// const JSCell* owner,
174// bool makesCalls,
175// ...);
176//
177// Note that we don't actually use C-style varargs because that leads to
178// strange type-related problems. For example it would preclude us from using
179// our custom of passing '0' as NULL pointer. Besides, when I did try to write
180// this function using varargs, I ended up with more code than this simple
181// way.
182
183Ref<PolymorphicAccessJITStubRoutine> createICJITStubRoutine(
184 const MacroAssemblerCodeRef<JITStubRoutinePtrTag>&, FixedVector<RefPtr<AccessCase>>&& cases, FixedVector<StructureID>&& weakStructures, VM&, const JSCell* owner, bool makesCalls,
185 const Vector<JSCell*>&, Bag<OptimizingCallLinkInfo>&& callLinkInfos,
186 CodeBlock* codeBlockForExceptionHandlers, DisposableCallSiteIndex exceptionHandlingCallSiteIndex);
187
188} // namespace JSC
189
190#endif // ENABLE(JIT)
Note: See TracBrowser for help on using the repository browser.