~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/bytecode/ArrayProfile.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 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
#ifndef ArrayProfile_h
 
27
#define ArrayProfile_h
 
28
 
 
29
#include "JSArray.h"
 
30
#include "Structure.h"
 
31
#include <wtf/HashMap.h>
 
32
#include <wtf/SegmentedVector.h>
 
33
 
 
34
namespace JSC {
 
35
 
 
36
class CodeBlock;
 
37
class LLIntOffsetsExtractor;
 
38
 
 
39
// This is a bitfield where each bit represents an IndexingType that we have seen.
 
40
// There are 32 indexing types, so an unsigned is enough.
 
41
typedef unsigned ArrayModes;
 
42
 
 
43
#define asArrayModes(type) \
 
44
    (static_cast<unsigned>(1) << static_cast<unsigned>(type))
 
45
 
 
46
#define ALL_NON_ARRAY_ARRAY_MODES                       \
 
47
    (asArrayModes(NonArray)                             \
 
48
    | asArrayModes(NonArrayWithInt32)                   \
 
49
    | asArrayModes(NonArrayWithDouble)                  \
 
50
    | asArrayModes(NonArrayWithContiguous)              \
 
51
    | asArrayModes(NonArrayWithArrayStorage)            \
 
52
    | asArrayModes(NonArrayWithSlowPutArrayStorage))
 
53
 
 
54
#define ALL_ARRAY_ARRAY_MODES                           \
 
55
    (asArrayModes(ArrayClass)                           \
 
56
    | asArrayModes(ArrayWithUndecided)                  \
 
57
    | asArrayModes(ArrayWithInt32)                      \
 
58
    | asArrayModes(ArrayWithDouble)                     \
 
59
    | asArrayModes(ArrayWithContiguous)                 \
 
60
    | asArrayModes(ArrayWithArrayStorage)               \
 
61
    | asArrayModes(ArrayWithSlowPutArrayStorage))
 
62
 
 
63
#define ALL_ARRAY_MODES (ALL_NON_ARRAY_ARRAY_MODES | ALL_ARRAY_ARRAY_MODES)
 
64
 
 
65
inline ArrayModes arrayModeFromStructure(Structure* structure)
 
66
{
 
67
    return asArrayModes(structure->indexingType());
 
68
}
 
69
 
 
70
const char* arrayModesToString(ArrayModes);
 
71
 
 
72
inline bool mergeArrayModes(ArrayModes& left, ArrayModes right)
 
73
{
 
74
    ArrayModes newModes = left | right;
 
75
    if (newModes == left)
 
76
        return false;
 
77
    left = newModes;
 
78
    return true;
 
79
}
 
80
 
 
81
// Checks if proven is a subset of expected.
 
82
inline bool arrayModesAlreadyChecked(ArrayModes proven, ArrayModes expected)
 
83
{
 
84
    return (expected | proven) == expected;
 
85
}
 
86
 
 
87
inline bool arrayModesInclude(ArrayModes arrayModes, IndexingType shape)
 
88
{
 
89
    return !!(arrayModes & (asArrayModes(NonArray | shape) | asArrayModes(ArrayClass | shape)));
 
90
}
 
91
 
 
92
inline bool shouldUseSlowPutArrayStorage(ArrayModes arrayModes)
 
93
{
 
94
    return arrayModesInclude(arrayModes, SlowPutArrayStorageShape);
 
95
}
 
96
 
 
97
inline bool shouldUseFastArrayStorage(ArrayModes arrayModes)
 
98
{
 
99
    return arrayModesInclude(arrayModes, ArrayStorageShape);
 
100
}
 
101
 
 
102
inline bool shouldUseContiguous(ArrayModes arrayModes)
 
103
{
 
104
    return arrayModesInclude(arrayModes, ContiguousShape);
 
105
}
 
106
 
 
107
inline bool shouldUseDouble(ArrayModes arrayModes)
 
108
{
 
109
    return arrayModesInclude(arrayModes, DoubleShape);
 
110
}
 
111
 
 
112
inline bool shouldUseInt32(ArrayModes arrayModes)
 
113
{
 
114
    return arrayModesInclude(arrayModes, Int32Shape);
 
115
}
 
116
 
 
117
class ArrayProfile {
 
118
public:
 
119
    ArrayProfile()
 
120
        : m_bytecodeOffset(std::numeric_limits<unsigned>::max())
 
121
        , m_lastSeenStructure(0)
 
122
        , m_expectedStructure(0)
 
123
        , m_structureIsPolymorphic(false)
 
124
        , m_mayStoreToHole(false)
 
125
        , m_mayInterceptIndexedAccesses(false)
 
126
        , m_usesOriginalArrayStructures(true)
 
127
        , m_observedArrayModes(0)
 
128
    {
 
129
    }
 
130
    
 
131
    ArrayProfile(unsigned bytecodeOffset)
 
132
        : m_bytecodeOffset(bytecodeOffset)
 
133
        , m_lastSeenStructure(0)
 
134
        , m_expectedStructure(0)
 
135
        , m_structureIsPolymorphic(false)
 
136
        , m_mayStoreToHole(false)
 
137
        , m_mayInterceptIndexedAccesses(false)
 
138
        , m_usesOriginalArrayStructures(true)
 
139
        , m_observedArrayModes(0)
 
140
    {
 
141
    }
 
142
    
 
143
    unsigned bytecodeOffset() const { return m_bytecodeOffset; }
 
144
    
 
145
    Structure** addressOfLastSeenStructure() { return &m_lastSeenStructure; }
 
146
    ArrayModes* addressOfArrayModes() { return &m_observedArrayModes; }
 
147
    bool* addressOfMayStoreToHole() { return &m_mayStoreToHole; }
 
148
    
 
149
    void observeStructure(Structure* structure)
 
150
    {
 
151
        m_lastSeenStructure = structure;
 
152
    }
 
153
    
 
154
    void computeUpdatedPrediction(CodeBlock*, OperationInProgress = NoOperation);
 
155
    
 
156
    Structure* expectedStructure() const { return m_expectedStructure; }
 
157
    bool structureIsPolymorphic() const
 
158
    {
 
159
        return m_structureIsPolymorphic;
 
160
    }
 
161
    bool hasDefiniteStructure() const
 
162
    {
 
163
        return !structureIsPolymorphic() && m_expectedStructure;
 
164
    }
 
165
    ArrayModes observedArrayModes() const { return m_observedArrayModes; }
 
166
    ArrayModes updatedObservedArrayModes() const; // Computes the observed array modes without updating the profile.
 
167
    bool mayInterceptIndexedAccesses() const { return m_mayInterceptIndexedAccesses; }
 
168
    
 
169
    bool mayStoreToHole() const { return m_mayStoreToHole; }
 
170
    
 
171
    bool usesOriginalArrayStructures() const { return m_usesOriginalArrayStructures; }
 
172
    
 
173
private:
 
174
    friend class LLIntOffsetsExtractor;
 
175
    
 
176
    unsigned m_bytecodeOffset;
 
177
    Structure* m_lastSeenStructure;
 
178
    Structure* m_expectedStructure;
 
179
    bool m_structureIsPolymorphic;
 
180
    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.
 
181
    bool m_mayInterceptIndexedAccesses;
 
182
    bool m_usesOriginalArrayStructures;
 
183
    ArrayModes m_observedArrayModes;
 
184
};
 
185
 
 
186
typedef SegmentedVector<ArrayProfile, 4, 0> ArrayProfileVector;
 
187
 
 
188
} // namespace JSC
 
189
 
 
190
#endif // ArrayProfile_h
 
191