[JSC] JSCell_freeListNext and JSCell_structureID are considered not overlapping
[WebKit-https.git] / Source / JavaScriptCore / ftl / FTLAbstractHeapRepository.h
1 /*
2  * Copyright (C) 2013-2016 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 #ifndef FTLAbstractHeapRepository_h
27 #define FTLAbstractHeapRepository_h
28
29 #if ENABLE(FTL_JIT)
30
31 #include "B3Value.h"
32 #include "DFGArrayMode.h"
33 #include "FTLAbstractHeap.h"
34 #include "IndexingType.h"
35
36 namespace JSC { namespace FTL {
37
38 #define FOR_EACH_ABSTRACT_HEAP(macro) \
39     macro(typedArrayProperties)
40
41 #define FOR_EACH_ABSTRACT_FIELD(macro) \
42     macro(ArrayBuffer_data, ArrayBuffer::offsetOfData()) \
43     macro(Butterfly_arrayBuffer, Butterfly::offsetOfArrayBuffer()) \
44     macro(Butterfly_publicLength, Butterfly::offsetOfPublicLength()) \
45     macro(Butterfly_vectorLength, Butterfly::offsetOfVectorLength()) \
46     macro(CallFrame_callerFrame, CallFrame::callerFrameOffset()) \
47     macro(DirectArguments_callee, DirectArguments::offsetOfCallee()) \
48     macro(DirectArguments_length, DirectArguments::offsetOfLength()) \
49     macro(DirectArguments_minCapacity, DirectArguments::offsetOfMinCapacity()) \
50     macro(DirectArguments_overrides, DirectArguments::offsetOfOverrides()) \
51     macro(GetterSetter_getter, GetterSetter::offsetOfGetter()) \
52     macro(GetterSetter_setter, GetterSetter::offsetOfSetter()) \
53     macro(JSArrayBufferView_length, JSArrayBufferView::offsetOfLength()) \
54     macro(JSArrayBufferView_mode, JSArrayBufferView::offsetOfMode()) \
55     macro(JSArrayBufferView_vector, JSArrayBufferView::offsetOfVector()) \
56     macro(JSCell_cellState, JSCell::cellStateOffset()) \
57     macro(JSCell_header, 0) \
58     macro(JSCell_indexingType, JSCell::indexingTypeOffset()) \
59     macro(JSCell_structureID, JSCell::structureIDOffset()) \
60     macro(JSCell_typeInfoFlags, JSCell::typeInfoFlagsOffset()) \
61     macro(JSCell_typeInfoType, JSCell::typeInfoTypeOffset()) \
62     macro(JSCell_usefulBytes, JSCell::indexingTypeOffset()) \
63     macro(JSFunction_executable, JSFunction::offsetOfExecutable()) \
64     macro(JSFunction_scope, JSFunction::offsetOfScopeChain()) \
65     macro(JSFunction_rareData, JSFunction::offsetOfRareData()) \
66     macro(JSObject_butterfly, JSObject::butterflyOffset()) \
67     macro(JSPropertyNameEnumerator_cachedInlineCapacity, JSPropertyNameEnumerator::cachedInlineCapacityOffset()) \
68     macro(JSPropertyNameEnumerator_cachedPropertyNamesVector, JSPropertyNameEnumerator::cachedPropertyNamesVectorOffset()) \
69     macro(JSPropertyNameEnumerator_cachedStructureID, JSPropertyNameEnumerator::cachedStructureIDOffset()) \
70     macro(JSPropertyNameEnumerator_endGenericPropertyIndex, JSPropertyNameEnumerator::endGenericPropertyIndexOffset()) \
71     macro(JSPropertyNameEnumerator_endStructurePropertyIndex, JSPropertyNameEnumerator::endStructurePropertyIndexOffset()) \
72     macro(JSPropertyNameEnumerator_indexLength, JSPropertyNameEnumerator::indexedLengthOffset()) \
73     macro(JSScope_next, JSScope::offsetOfNext()) \
74     macro(JSString_flags, JSString::offsetOfFlags()) \
75     macro(JSString_length, JSString::offsetOfLength()) \
76     macro(JSString_value, JSString::offsetOfValue()) \
77     macro(JSSymbolTableObject_symbolTable, JSSymbolTableObject::offsetOfSymbolTable()) \
78     macro(JSWrapperObject_internalValue, JSWrapperObject::internalValueOffset()) \
79     macro(MarkedAllocator_freeListHead, MarkedAllocator::offsetOfFreeListHead()) \
80     macro(ScopedArguments_overrodeThings, ScopedArguments::offsetOfOverrodeThings()) \
81     macro(ScopedArguments_scope, ScopedArguments::offsetOfScope()) \
82     macro(ScopedArguments_table, ScopedArguments::offsetOfTable()) \
83     macro(ScopedArguments_totalLength, ScopedArguments::offsetOfTotalLength()) \
84     macro(ScopedArgumentsTable_arguments, ScopedArgumentsTable::offsetOfArguments()) \
85     macro(ScopedArgumentsTable_length, ScopedArgumentsTable::offsetOfLength()) \
86     macro(StringImpl_data, StringImpl::dataOffset()) \
87     macro(StringImpl_hashAndFlags, StringImpl::flagsOffset()) \
88     macro(Structure_classInfo, Structure::classInfoOffset()) \
89     macro(Structure_globalObject, Structure::globalObjectOffset()) \
90     macro(Structure_prototype, Structure::prototypeOffset()) \
91     macro(Structure_structureID, Structure::structureIDOffset()) \
92     macro(Symbol_privateName, Symbol::offsetOfPrivateName())
93
94 #define FOR_EACH_INDEXED_ABSTRACT_HEAP(macro) \
95     macro(DirectArguments_storage, DirectArguments::storageOffset(), sizeof(EncodedJSValue)) \
96     macro(JSEnvironmentRecord_variables, JSEnvironmentRecord::offsetOfVariables(), sizeof(EncodedJSValue)) \
97     macro(JSPropertyNameEnumerator_cachedPropertyNamesVectorContents, 0, sizeof(WriteBarrier<JSString>)) \
98     macro(JSRopeString_fibers, JSRopeString::offsetOfFibers(), sizeof(WriteBarrier<JSString>)) \
99     macro(MarkedSpace_Subspace_impreciseAllocators, OBJECT_OFFSETOF(MarkedSpace::Subspace, impreciseAllocators), sizeof(MarkedAllocator)) \
100     macro(MarkedSpace_Subspace_preciseAllocators, OBJECT_OFFSETOF(MarkedSpace::Subspace, preciseAllocators), sizeof(MarkedAllocator)) \
101     macro(ScopedArguments_overflowStorage, ScopedArguments::overflowStorageOffset(), sizeof(EncodedJSValue)) \
102     macro(WriteBarrierBuffer_bufferContents, 0, sizeof(JSCell*)) \
103     macro(characters8, 0, sizeof(LChar)) \
104     macro(characters16, 0, sizeof(UChar)) \
105     macro(indexedInt32Properties, 0, sizeof(EncodedJSValue)) \
106     macro(indexedDoubleProperties, 0, sizeof(double)) \
107     macro(indexedContiguousProperties, 0, sizeof(EncodedJSValue)) \
108     macro(indexedArrayStorageProperties, 0, sizeof(EncodedJSValue)) \
109     macro(scopedArgumentsTableArguments, 0, sizeof(int32_t)) \
110     macro(singleCharacterStrings, 0, sizeof(JSString*)) \
111     macro(structureTable, 0, sizeof(Structure*)) \
112     macro(variables, 0, sizeof(Register))
113     
114 #define FOR_EACH_NUMBERED_ABSTRACT_HEAP(macro) \
115     macro(properties)
116     
117 // This class is meant to be cacheable between compilations, but it doesn't have to be.
118 // Doing so saves on creation of nodes. But clearing it will save memory.
119
120 class AbstractHeapRepository {
121     WTF_MAKE_NONCOPYABLE(AbstractHeapRepository);
122 public:
123     AbstractHeapRepository();
124     ~AbstractHeapRepository();
125     
126     AbstractHeap root;
127     
128 #define ABSTRACT_HEAP_DECLARATION(name) AbstractHeap name;
129     FOR_EACH_ABSTRACT_HEAP(ABSTRACT_HEAP_DECLARATION)
130 #undef ABSTRACT_HEAP_DECLARATION
131
132 #define ABSTRACT_FIELD_DECLARATION(name, offset) AbstractHeap name;
133     FOR_EACH_ABSTRACT_FIELD(ABSTRACT_FIELD_DECLARATION)
134 #undef ABSTRACT_FIELD_DECLARATION
135     
136     AbstractHeap& JSCell_freeListNext;
137     
138 #define INDEXED_ABSTRACT_HEAP_DECLARATION(name, offset, size) IndexedAbstractHeap name;
139     FOR_EACH_INDEXED_ABSTRACT_HEAP(INDEXED_ABSTRACT_HEAP_DECLARATION)
140 #undef INDEXED_ABSTRACT_HEAP_DECLARATION
141     
142 #define NUMBERED_ABSTRACT_HEAP_DECLARATION(name) NumberedAbstractHeap name;
143     FOR_EACH_NUMBERED_ABSTRACT_HEAP(NUMBERED_ABSTRACT_HEAP_DECLARATION)
144 #undef NUMBERED_ABSTRACT_HEAP_DECLARATION
145
146     AbsoluteAbstractHeap absolute;
147     
148     IndexedAbstractHeap* forIndexingType(IndexingType indexingType)
149     {
150         switch (indexingType) {
151         case ALL_BLANK_INDEXING_TYPES:
152         case ALL_UNDECIDED_INDEXING_TYPES:
153             return 0;
154             
155         case ALL_INT32_INDEXING_TYPES:
156             return &indexedInt32Properties;
157             
158         case ALL_DOUBLE_INDEXING_TYPES:
159             return &indexedDoubleProperties;
160             
161         case ALL_CONTIGUOUS_INDEXING_TYPES:
162             return &indexedContiguousProperties;
163             
164         case ALL_ARRAY_STORAGE_INDEXING_TYPES:
165             return &indexedArrayStorageProperties;
166             
167         default:
168             RELEASE_ASSERT_NOT_REACHED();
169             return 0;
170         }
171     }
172     
173     IndexedAbstractHeap& forArrayType(DFG::Array::Type type)
174     {
175         switch (type) {
176         case DFG::Array::Int32:
177             return indexedInt32Properties;
178         case DFG::Array::Double:
179             return indexedDoubleProperties;
180         case DFG::Array::Contiguous:
181             return indexedContiguousProperties;
182         case DFG::Array::ArrayStorage:
183         case DFG::Array::SlowPutArrayStorage:
184             return indexedArrayStorageProperties;
185         default:
186             RELEASE_ASSERT_NOT_REACHED();
187             return indexedInt32Properties;
188         }
189     }
190
191     void decorateMemory(const AbstractHeap*, B3::Value*);
192     void decorateCCallRead(const AbstractHeap*, B3::Value*);
193     void decorateCCallWrite(const AbstractHeap*, B3::Value*);
194     void decoratePatchpointRead(const AbstractHeap*, B3::Value*);
195     void decoratePatchpointWrite(const AbstractHeap*, B3::Value*);
196
197     void computeRangesAndDecorateInstructions();
198
199 private:
200
201     struct HeapForValue {
202         HeapForValue()
203         {
204         }
205
206         HeapForValue(const AbstractHeap* heap, B3::Value* value)
207             : heap(heap)
208             , value(value)
209         {
210         }
211         
212         const AbstractHeap* heap { nullptr };
213         B3::Value* value { nullptr };
214     };
215
216     Vector<HeapForValue> m_heapForMemory;
217     Vector<HeapForValue> m_heapForCCallRead;
218     Vector<HeapForValue> m_heapForCCallWrite;
219     Vector<HeapForValue> m_heapForPatchpointRead;
220     Vector<HeapForValue> m_heapForPatchpointWrite;
221 };
222
223 } } // namespace JSC::FTL
224
225 #endif // ENABLE(FTL_JIT)
226
227 #endif // FTLAbstractHeapRepository_h
228