]> git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/ArrayProfile.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / bytecode / ArrayProfile.cpp
1 /*
2 * Copyright (C) 2012, 2013 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 "ArrayProfile.h"
28
29 #include "CodeBlock.h"
30 #include "JSCInlines.h"
31 #include <wtf/CommaPrinter.h>
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) {
40 out.print("<empty>");
41 return;
42 }
43
44 if (arrayModes == ALL_ARRAY_MODES) {
45 out.print("TOP");
46 return;
47 }
48
49 CommaPrinter comma("|");
50 if (arrayModes & asArrayModes(NonArray))
51 out.print(comma, "NonArray");
52 if (arrayModes & asArrayModes(NonArrayWithInt32))
53 out.print(comma, "NonArrayWithInt32");
54 if (arrayModes & asArrayModes(NonArrayWithDouble))
55 out.print(comma, "NonArrayWithDouble");
56 if (arrayModes & asArrayModes(NonArrayWithContiguous))
57 out.print(comma, "NonArrayWithContiguous");
58 if (arrayModes & asArrayModes(NonArrayWithArrayStorage))
59 out.print(comma, "NonArrayWithArrayStorage");
60 if (arrayModes & asArrayModes(NonArrayWithSlowPutArrayStorage))
61 out.print(comma, "NonArrayWithSlowPutArrayStorage");
62 if (arrayModes & asArrayModes(ArrayClass))
63 out.print(comma, "ArrayClass");
64 if (arrayModes & asArrayModes(ArrayWithUndecided))
65 out.print(comma, "ArrayWithUndecided");
66 if (arrayModes & asArrayModes(ArrayWithInt32))
67 out.print(comma, "ArrayWithInt32");
68 if (arrayModes & asArrayModes(ArrayWithDouble))
69 out.print(comma, "ArrayWithDouble");
70 if (arrayModes & asArrayModes(ArrayWithContiguous))
71 out.print(comma, "ArrayWithContiguous");
72 if (arrayModes & asArrayModes(ArrayWithArrayStorage))
73 out.print(comma, "ArrayWithArrayStorage");
74 if (arrayModes & asArrayModes(ArrayWithSlowPutArrayStorage))
75 out.print(comma, "ArrayWithSlowPutArrayStorage");
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");
95 }
96
97 void ArrayProfile::computeUpdatedPrediction(const ConcurrentJITLocker& locker, CodeBlock* codeBlock)
98 {
99 if (!m_lastSeenStructureID)
100 return;
101
102 Structure* lastSeenStructure = codeBlock->heap()->structureIDTable().get(m_lastSeenStructureID);
103 computeUpdatedPrediction(locker, codeBlock, lastSeenStructure);
104 m_lastSeenStructureID = 0;
105 }
106
107 void ArrayProfile::computeUpdatedPrediction(const ConcurrentJITLocker&, CodeBlock* codeBlock, Structure* lastSeenStructure)
108 {
109 m_observedArrayModes |= arrayModeFromStructure(lastSeenStructure);
110
111 if (!m_didPerformFirstRunPruning
112 && hasTwoOrMoreBitsSet(m_observedArrayModes)) {
113 m_observedArrayModes = arrayModeFromStructure(lastSeenStructure);
114 m_didPerformFirstRunPruning = true;
115 }
116
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;
123 }
124
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&)
132 {
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
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