]>
Commit | Line | Data |
---|---|---|
93a37866 | 1 | /* |
81345200 | 2 | * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. |
93a37866 A |
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 "ArrayProfile.h" | |
28 | ||
29 | #include "CodeBlock.h" | |
81345200 A |
30 | #include "JSCInlines.h" |
31 | #include <wtf/CommaPrinter.h> | |
93a37866 A |
32 | #include <wtf/StringExtras.h> |
33 | #include <wtf/StringPrintStream.h> | |
34 | ||
35 | namespace JSC { | |
36 | ||
37 | void dumpArrayModes(PrintStream& out, ArrayModes arrayModes) | |
38 | { | |
39 | if (!arrayModes) { | |
81345200 | 40 | out.print("<empty>"); |
93a37866 A |
41 | return; |
42 | } | |
43 | ||
44 | if (arrayModes == ALL_ARRAY_MODES) { | |
45 | out.print("TOP"); | |
46 | return; | |
47 | } | |
48 | ||
81345200 | 49 | CommaPrinter comma("|"); |
93a37866 | 50 | if (arrayModes & asArrayModes(NonArray)) |
81345200 | 51 | out.print(comma, "NonArray"); |
93a37866 | 52 | if (arrayModes & asArrayModes(NonArrayWithInt32)) |
81345200 | 53 | out.print(comma, "NonArrayWithInt32"); |
93a37866 | 54 | if (arrayModes & asArrayModes(NonArrayWithDouble)) |
81345200 | 55 | out.print(comma, "NonArrayWithDouble"); |
93a37866 | 56 | if (arrayModes & asArrayModes(NonArrayWithContiguous)) |
81345200 | 57 | out.print(comma, "NonArrayWithContiguous"); |
93a37866 | 58 | if (arrayModes & asArrayModes(NonArrayWithArrayStorage)) |
81345200 | 59 | out.print(comma, "NonArrayWithArrayStorage"); |
93a37866 | 60 | if (arrayModes & asArrayModes(NonArrayWithSlowPutArrayStorage)) |
81345200 | 61 | out.print(comma, "NonArrayWithSlowPutArrayStorage"); |
93a37866 | 62 | if (arrayModes & asArrayModes(ArrayClass)) |
81345200 | 63 | out.print(comma, "ArrayClass"); |
93a37866 | 64 | if (arrayModes & asArrayModes(ArrayWithUndecided)) |
81345200 | 65 | out.print(comma, "ArrayWithUndecided"); |
93a37866 | 66 | if (arrayModes & asArrayModes(ArrayWithInt32)) |
81345200 | 67 | out.print(comma, "ArrayWithInt32"); |
93a37866 | 68 | if (arrayModes & asArrayModes(ArrayWithDouble)) |
81345200 | 69 | out.print(comma, "ArrayWithDouble"); |
93a37866 | 70 | if (arrayModes & asArrayModes(ArrayWithContiguous)) |
81345200 | 71 | out.print(comma, "ArrayWithContiguous"); |
93a37866 | 72 | if (arrayModes & asArrayModes(ArrayWithArrayStorage)) |
81345200 | 73 | out.print(comma, "ArrayWithArrayStorage"); |
93a37866 | 74 | if (arrayModes & asArrayModes(ArrayWithSlowPutArrayStorage)) |
81345200 | 75 | out.print(comma, "ArrayWithSlowPutArrayStorage"); |
ed1e77d3 A |
76 | |
77 | if (arrayModes & Int8ArrayMode) | |
78 | out.print(comma, "Int8ArrayMode"); | |
79 | if (arrayModes & Int16ArrayMode) | |
80 | out.print(comma, "Int16ArrayMode"); | |
81 | if (arrayModes & Int32ArrayMode) | |
82 | out.print(comma, "Int32ArrayMode"); | |
83 | if (arrayModes & Uint8ArrayMode) | |
84 | out.print(comma, "Uint8ArrayMode"); | |
85 | if (arrayModes & Uint8ClampedArrayMode) | |
86 | out.print(comma, "Uint8ClampedArrayMode"); | |
87 | if (arrayModes & Uint16ArrayMode) | |
88 | out.print(comma, "Uint16ArrayMode"); | |
89 | if (arrayModes & Uint32ArrayMode) | |
90 | out.print(comma, "Uint32ArrayMode"); | |
91 | if (arrayModes & Float32ArrayMode) | |
92 | out.print(comma, "Float32ArrayMode"); | |
93 | if (arrayModes & Float64ArrayMode) | |
94 | out.print(comma, "Float64ArrayMode"); | |
93a37866 A |
95 | } |
96 | ||
ed1e77d3 | 97 | void ArrayProfile::computeUpdatedPrediction(const ConcurrentJITLocker& locker, CodeBlock* codeBlock) |
93a37866 | 98 | { |
81345200 A |
99 | if (!m_lastSeenStructureID) |
100 | return; | |
93a37866 | 101 | |
81345200 | 102 | Structure* lastSeenStructure = codeBlock->heap()->structureIDTable().get(m_lastSeenStructureID); |
ed1e77d3 A |
103 | computeUpdatedPrediction(locker, codeBlock, lastSeenStructure); |
104 | m_lastSeenStructureID = 0; | |
105 | } | |
106 | ||
107 | void ArrayProfile::computeUpdatedPrediction(const ConcurrentJITLocker&, CodeBlock* codeBlock, Structure* lastSeenStructure) | |
108 | { | |
81345200 | 109 | m_observedArrayModes |= arrayModeFromStructure(lastSeenStructure); |
93a37866 | 110 | |
81345200 A |
111 | if (!m_didPerformFirstRunPruning |
112 | && hasTwoOrMoreBitsSet(m_observedArrayModes)) { | |
113 | m_observedArrayModes = arrayModeFromStructure(lastSeenStructure); | |
114 | m_didPerformFirstRunPruning = true; | |
93a37866 A |
115 | } |
116 | ||
81345200 A |
117 | m_mayInterceptIndexedAccesses |= |
118 | lastSeenStructure->typeInfo().interceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero(); | |
119 | JSGlobalObject* globalObject = codeBlock->globalObject(); | |
120 | if (!globalObject->isOriginalArrayStructure(lastSeenStructure) | |
121 | && !globalObject->isOriginalTypedArrayStructure(lastSeenStructure)) | |
122 | m_usesOriginalArrayStructures = false; | |
93a37866 A |
123 | } |
124 | ||
81345200 A |
125 | CString ArrayProfile::briefDescription(const ConcurrentJITLocker& locker, CodeBlock* codeBlock) |
126 | { | |
127 | computeUpdatedPrediction(locker, codeBlock); | |
128 | return briefDescriptionWithoutUpdating(locker); | |
129 | } | |
130 | ||
131 | CString ArrayProfile::briefDescriptionWithoutUpdating(const ConcurrentJITLocker&) | |
93a37866 | 132 | { |
93a37866 A |
133 | StringPrintStream out; |
134 | ||
135 | bool hasPrinted = false; | |
136 | ||
137 | if (m_observedArrayModes) { | |
138 | if (hasPrinted) | |
139 | out.print(", "); | |
140 | out.print(ArrayModesDump(m_observedArrayModes)); | |
141 | hasPrinted = true; | |
142 | } | |
143 | ||
93a37866 A |
144 | if (m_mayStoreToHole) { |
145 | if (hasPrinted) | |
146 | out.print(", "); | |
147 | out.print("Hole"); | |
148 | hasPrinted = true; | |
149 | } | |
150 | ||
151 | if (m_outOfBounds) { | |
152 | if (hasPrinted) | |
153 | out.print(", "); | |
154 | out.print("OutOfBounds"); | |
155 | hasPrinted = true; | |
156 | } | |
157 | ||
158 | if (m_mayInterceptIndexedAccesses) { | |
159 | if (hasPrinted) | |
160 | out.print(", "); | |
161 | out.print("Intercept"); | |
162 | hasPrinted = true; | |
163 | } | |
164 | ||
165 | if (m_usesOriginalArrayStructures) { | |
166 | if (hasPrinted) | |
167 | out.print(", "); | |
168 | out.print("Original"); | |
169 | hasPrinted = true; | |
170 | } | |
171 | ||
172 | UNUSED_PARAM(hasPrinted); | |
173 | ||
174 | return out.toCString(); | |
175 | } | |
176 | ||
177 | } // namespace JSC | |
178 |