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 | #include "config.h" |
27 | #include "FTLAbstractHeapRepository.h" |
28 | |
29 | #if ENABLE(FTL_JIT) |
30 | |
31 | #include "B3CCallValue.h" |
32 | #include "B3FenceValue.h" |
33 | #include "B3MemoryValue.h" |
34 | #include "B3PatchpointValue.h" |
35 | #include "B3ValueInlines.h" |
36 | #include "DirectArguments.h" |
37 | #include "FTLState.h" |
38 | #include "GetterSetter.h" |
39 | #include "JSPropertyNameEnumerator.h" |
40 | #include "JSScope.h" |
41 | #include "JSCInlines.h" |
42 | #include "RegExpObject.h" |
43 | #include "ScopedArguments.h" |
44 | #include "ScopedArgumentsTable.h" |
45 | #include "ShadowChicken.h" |
46 | |
47 | namespace JSC { namespace FTL { |
48 | |
49 | AbstractHeapRepository::AbstractHeapRepository() |
50 | : root(nullptr, "jscRoot" ) |
51 | |
52 | #define ABSTRACT_HEAP_INITIALIZATION(name) , name(&root, #name) |
53 | FOR_EACH_ABSTRACT_HEAP(ABSTRACT_HEAP_INITIALIZATION) |
54 | #undef ABSTRACT_HEAP_INITIALIZATION |
55 | |
56 | #define ABSTRACT_FIELD_INITIALIZATION(name, offset) , name(&root, #name, offset) |
57 | FOR_EACH_ABSTRACT_FIELD(ABSTRACT_FIELD_INITIALIZATION) |
58 | #undef ABSTRACT_FIELD_INITIALIZATION |
59 | |
60 | , JSCell_freeListNext(JSCell_header) |
61 | , ArrayStorage_publicLength(Butterfly_publicLength) |
62 | , ArrayStorage_vectorLength(Butterfly_vectorLength) |
63 | |
64 | #define INDEXED_ABSTRACT_HEAP_INITIALIZATION(name, offset, size) , name(&root, #name, offset, size) |
65 | FOR_EACH_INDEXED_ABSTRACT_HEAP(INDEXED_ABSTRACT_HEAP_INITIALIZATION) |
66 | #undef INDEXED_ABSTRACT_HEAP_INITIALIZATION |
67 | |
68 | #define NUMBERED_ABSTRACT_HEAP_INITIALIZATION(name) , name(&root, #name) |
69 | FOR_EACH_NUMBERED_ABSTRACT_HEAP(NUMBERED_ABSTRACT_HEAP_INITIALIZATION) |
70 | #undef NUMBERED_ABSTRACT_HEAP_INITIALIZATION |
71 | |
72 | , JSString_value(JSRopeString_fiber0) |
73 | |
74 | , absolute(&root, "absolute" ) |
75 | { |
76 | // Make sure that our explicit assumptions about the StructureIDBlob match reality. |
77 | RELEASE_ASSERT(!(JSCell_indexingTypeAndMisc.offset() & (sizeof(int32_t) - 1))); |
78 | RELEASE_ASSERT(JSCell_indexingTypeAndMisc.offset() + 1 == JSCell_typeInfoType.offset()); |
79 | RELEASE_ASSERT(JSCell_indexingTypeAndMisc.offset() + 2 == JSCell_typeInfoFlags.offset()); |
80 | RELEASE_ASSERT(JSCell_indexingTypeAndMisc.offset() + 3 == JSCell_cellState.offset()); |
81 | |
82 | JSCell_structureID.changeParent(&JSCell_header); |
83 | JSCell_usefulBytes.changeParent(&JSCell_header); |
84 | JSCell_indexingTypeAndMisc.changeParent(&JSCell_usefulBytes); |
85 | JSCell_typeInfoType.changeParent(&JSCell_usefulBytes); |
86 | JSCell_typeInfoFlags.changeParent(&JSCell_usefulBytes); |
87 | JSCell_cellState.changeParent(&JSCell_usefulBytes); |
88 | JSRopeString_flags.changeParent(&JSRopeString_fiber0); |
89 | JSRopeString_length.changeParent(&JSRopeString_fiber1); |
90 | |
91 | RELEASE_ASSERT(!JSCell_freeListNext.offset()); |
92 | } |
93 | |
94 | AbstractHeapRepository::~AbstractHeapRepository() |
95 | { |
96 | } |
97 | |
98 | void AbstractHeapRepository::decorateMemory(const AbstractHeap* heap, B3::Value* value) |
99 | { |
100 | m_heapForMemory.append(HeapForValue(heap, value)); |
101 | } |
102 | |
103 | void AbstractHeapRepository::decorateCCallRead(const AbstractHeap* heap, B3::Value* value) |
104 | { |
105 | m_heapForCCallRead.append(HeapForValue(heap, value)); |
106 | } |
107 | |
108 | void AbstractHeapRepository::decorateCCallWrite(const AbstractHeap* heap, B3::Value* value) |
109 | { |
110 | m_heapForCCallWrite.append(HeapForValue(heap, value)); |
111 | } |
112 | |
113 | void AbstractHeapRepository::decoratePatchpointRead(const AbstractHeap* heap, B3::Value* value) |
114 | { |
115 | m_heapForPatchpointRead.append(HeapForValue(heap, value)); |
116 | } |
117 | |
118 | void AbstractHeapRepository::decoratePatchpointWrite(const AbstractHeap* heap, B3::Value* value) |
119 | { |
120 | m_heapForPatchpointWrite.append(HeapForValue(heap, value)); |
121 | } |
122 | |
123 | void AbstractHeapRepository::decorateFenceRead(const AbstractHeap* heap, B3::Value* value) |
124 | { |
125 | m_heapForFenceRead.append(HeapForValue(heap, value)); |
126 | } |
127 | |
128 | void AbstractHeapRepository::decorateFenceWrite(const AbstractHeap* heap, B3::Value* value) |
129 | { |
130 | m_heapForFenceWrite.append(HeapForValue(heap, value)); |
131 | } |
132 | |
133 | void AbstractHeapRepository::decorateFencedAccess(const AbstractHeap* heap, B3::Value* value) |
134 | { |
135 | m_heapForFencedAccess.append(HeapForValue(heap, value)); |
136 | } |
137 | |
138 | void AbstractHeapRepository::computeRangesAndDecorateInstructions() |
139 | { |
140 | using namespace B3; |
141 | root.compute(); |
142 | |
143 | if (verboseCompilationEnabled()) { |
144 | dataLog("Abstract Heap Repository:\n" ); |
145 | root.deepDump(WTF::dataFile()); |
146 | } |
147 | |
148 | auto rangeFor = [&] (const AbstractHeap* heap) -> HeapRange { |
149 | if (heap) |
150 | return heap->range(); |
151 | return HeapRange(); |
152 | }; |
153 | |
154 | for (HeapForValue entry : m_heapForMemory) |
155 | entry.value->as<MemoryValue>()->setRange(rangeFor(entry.heap)); |
156 | for (HeapForValue entry : m_heapForCCallRead) |
157 | entry.value->as<CCallValue>()->effects.reads = rangeFor(entry.heap); |
158 | for (HeapForValue entry : m_heapForCCallWrite) |
159 | entry.value->as<CCallValue>()->effects.writes = rangeFor(entry.heap); |
160 | for (HeapForValue entry : m_heapForPatchpointRead) |
161 | entry.value->as<PatchpointValue>()->effects.reads = rangeFor(entry.heap); |
162 | for (HeapForValue entry : m_heapForPatchpointWrite) |
163 | entry.value->as<PatchpointValue>()->effects.writes = rangeFor(entry.heap); |
164 | for (HeapForValue entry : m_heapForFenceRead) |
165 | entry.value->as<FenceValue>()->read = rangeFor(entry.heap); |
166 | for (HeapForValue entry : m_heapForFenceWrite) |
167 | entry.value->as<FenceValue>()->write = rangeFor(entry.heap); |
168 | for (HeapForValue entry : m_heapForFencedAccess) |
169 | entry.value->as<MemoryValue>()->setFenceRange(rangeFor(entry.heap)); |
170 | } |
171 | |
172 | } } // namespace JSC::FTL |
173 | |
174 | #endif // ENABLE(FTL_JIT) |
175 | |
176 | |