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.
27 #include "ArrayProfile.h"
29 #include "CodeBlock.h"
30 #include "JSCInlines.h"
31 #include <wtf/CommaPrinter.h>
32 #include <wtf/StringExtras.h>
33 #include <wtf/StringPrintStream.h>
37 void dumpArrayModes(PrintStream
& out
, ArrayModes arrayModes
)
44 if (arrayModes
== ALL_ARRAY_MODES
) {
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");
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");
97 void ArrayProfile::computeUpdatedPrediction(const ConcurrentJITLocker
& locker
, CodeBlock
* codeBlock
)
99 if (!m_lastSeenStructureID
)
102 Structure
* lastSeenStructure
= codeBlock
->heap()->structureIDTable().get(m_lastSeenStructureID
);
103 computeUpdatedPrediction(locker
, codeBlock
, lastSeenStructure
);
104 m_lastSeenStructureID
= 0;
107 void ArrayProfile::computeUpdatedPrediction(const ConcurrentJITLocker
&, CodeBlock
* codeBlock
, Structure
* lastSeenStructure
)
109 m_observedArrayModes
|= arrayModeFromStructure(lastSeenStructure
);
111 if (!m_didPerformFirstRunPruning
112 && hasTwoOrMoreBitsSet(m_observedArrayModes
)) {
113 m_observedArrayModes
= arrayModeFromStructure(lastSeenStructure
);
114 m_didPerformFirstRunPruning
= true;
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;
125 CString
ArrayProfile::briefDescription(const ConcurrentJITLocker
& locker
, CodeBlock
* codeBlock
)
127 computeUpdatedPrediction(locker
, codeBlock
);
128 return briefDescriptionWithoutUpdating(locker
);
131 CString
ArrayProfile::briefDescriptionWithoutUpdating(const ConcurrentJITLocker
&)
133 StringPrintStream out
;
135 bool hasPrinted
= false;
137 if (m_observedArrayModes
) {
140 out
.print(ArrayModesDump(m_observedArrayModes
));
144 if (m_mayStoreToHole
) {
154 out
.print("OutOfBounds");
158 if (m_mayInterceptIndexedAccesses
) {
161 out
.print("Intercept");
165 if (m_usesOriginalArrayStructures
) {
168 out
.print("Original");
172 UNUSED_PARAM(hasPrinted
);
174 return out
.toCString();