2 * Copyright (C) 2012, 2013 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.
26 #ifndef ArrayProfile_h
27 #define ArrayProfile_h
29 #include "ConcurrentJITLock.h"
31 #include "Structure.h"
32 #include <wtf/HashMap.h>
33 #include <wtf/SegmentedVector.h>
38 class LLIntOffsetsExtractor
;
40 // This is a bitfield where each bit represents an IndexingType that we have seen.
41 // There are 32 indexing types, so an unsigned is enough.
42 typedef unsigned ArrayModes
;
44 #define asArrayModes(type) \
45 (static_cast<unsigned>(1) << static_cast<unsigned>(type))
47 #define ALL_NON_ARRAY_ARRAY_MODES \
48 (asArrayModes(NonArray) \
49 | asArrayModes(NonArrayWithInt32) \
50 | asArrayModes(NonArrayWithDouble) \
51 | asArrayModes(NonArrayWithContiguous) \
52 | asArrayModes(NonArrayWithArrayStorage) \
53 | asArrayModes(NonArrayWithSlowPutArrayStorage))
55 #define ALL_ARRAY_ARRAY_MODES \
56 (asArrayModes(ArrayClass) \
57 | asArrayModes(ArrayWithUndecided) \
58 | asArrayModes(ArrayWithInt32) \
59 | asArrayModes(ArrayWithDouble) \
60 | asArrayModes(ArrayWithContiguous) \
61 | asArrayModes(ArrayWithArrayStorage) \
62 | asArrayModes(ArrayWithSlowPutArrayStorage))
64 #define ALL_ARRAY_MODES (ALL_NON_ARRAY_ARRAY_MODES | ALL_ARRAY_ARRAY_MODES)
66 inline ArrayModes
arrayModeFromStructure(Structure
* structure
)
68 return asArrayModes(structure
->indexingType());
71 void dumpArrayModes(PrintStream
&, ArrayModes
);
72 MAKE_PRINT_ADAPTOR(ArrayModesDump
, ArrayModes
, dumpArrayModes
);
74 inline bool mergeArrayModes(ArrayModes
& left
, ArrayModes right
)
76 ArrayModes newModes
= left
| right
;
83 inline bool arrayModesAreClearOrTop(ArrayModes modes
)
85 return !modes
|| modes
== ALL_ARRAY_MODES
;
88 // Checks if proven is a subset of expected.
89 inline bool arrayModesAlreadyChecked(ArrayModes proven
, ArrayModes expected
)
91 return (expected
| proven
) == expected
;
94 inline bool arrayModesInclude(ArrayModes arrayModes
, IndexingType shape
)
96 return !!(arrayModes
& (asArrayModes(NonArray
| shape
) | asArrayModes(ArrayClass
| shape
)));
99 inline bool shouldUseSlowPutArrayStorage(ArrayModes arrayModes
)
101 return arrayModesInclude(arrayModes
, SlowPutArrayStorageShape
);
104 inline bool shouldUseFastArrayStorage(ArrayModes arrayModes
)
106 return arrayModesInclude(arrayModes
, ArrayStorageShape
);
109 inline bool shouldUseContiguous(ArrayModes arrayModes
)
111 return arrayModesInclude(arrayModes
, ContiguousShape
);
114 inline bool shouldUseDouble(ArrayModes arrayModes
)
116 return arrayModesInclude(arrayModes
, DoubleShape
);
119 inline bool shouldUseInt32(ArrayModes arrayModes
)
121 return arrayModesInclude(arrayModes
, Int32Shape
);
124 inline bool hasSeenArray(ArrayModes arrayModes
)
126 return arrayModes
& ALL_ARRAY_ARRAY_MODES
;
129 inline bool hasSeenNonArray(ArrayModes arrayModes
)
131 return arrayModes
& ALL_NON_ARRAY_ARRAY_MODES
;
137 : m_bytecodeOffset(std::numeric_limits
<unsigned>::max())
138 , m_lastSeenStructureID(0)
139 , m_mayStoreToHole(false)
140 , m_outOfBounds(false)
141 , m_mayInterceptIndexedAccesses(false)
142 , m_usesOriginalArrayStructures(true)
143 , m_didPerformFirstRunPruning(false)
144 , m_observedArrayModes(0)
148 ArrayProfile(unsigned bytecodeOffset
)
149 : m_bytecodeOffset(bytecodeOffset
)
150 , m_lastSeenStructureID(0)
151 , m_mayStoreToHole(false)
152 , m_outOfBounds(false)
153 , m_mayInterceptIndexedAccesses(false)
154 , m_usesOriginalArrayStructures(true)
155 , m_didPerformFirstRunPruning(false)
156 , m_observedArrayModes(0)
160 unsigned bytecodeOffset() const { return m_bytecodeOffset
; }
162 StructureID
* addressOfLastSeenStructureID() { return &m_lastSeenStructureID
; }
163 ArrayModes
* addressOfArrayModes() { return &m_observedArrayModes
; }
164 bool* addressOfMayStoreToHole() { return &m_mayStoreToHole
; }
165 bool* addressOfOutOfBounds() { return &m_outOfBounds
; }
167 void observeStructure(Structure
* structure
)
169 m_lastSeenStructureID
= structure
->id();
172 void computeUpdatedPrediction(const ConcurrentJITLocker
&, CodeBlock
*);
174 ArrayModes
observedArrayModes(const ConcurrentJITLocker
&) const { return m_observedArrayModes
; }
175 bool mayInterceptIndexedAccesses(const ConcurrentJITLocker
&) const { return m_mayInterceptIndexedAccesses
; }
177 bool mayStoreToHole(const ConcurrentJITLocker
&) const { return m_mayStoreToHole
; }
178 bool outOfBounds(const ConcurrentJITLocker
&) const { return m_outOfBounds
; }
180 bool usesOriginalArrayStructures(const ConcurrentJITLocker
&) const { return m_usesOriginalArrayStructures
; }
182 CString
briefDescription(const ConcurrentJITLocker
&, CodeBlock
*);
183 CString
briefDescriptionWithoutUpdating(const ConcurrentJITLocker
&);
186 friend class LLIntOffsetsExtractor
;
188 static Structure
* polymorphicStructure() { return static_cast<Structure
*>(reinterpret_cast<void*>(1)); }
190 unsigned m_bytecodeOffset
;
191 StructureID m_lastSeenStructureID
;
192 bool m_mayStoreToHole
; // This flag may become overloaded to indicate other special cases that were encountered during array access, as it depends on indexing type. Since we currently have basically just one indexing type (two variants of ArrayStorage), this flag for now just means exactly what its name implies.
194 bool m_mayInterceptIndexedAccesses
: 1;
195 bool m_usesOriginalArrayStructures
: 1;
196 bool m_didPerformFirstRunPruning
: 1;
197 ArrayModes m_observedArrayModes
;
200 typedef SegmentedVector
<ArrayProfile
, 4, 0> ArrayProfileVector
;
204 #endif // ArrayProfile_h