2 * Copyright (C) 2011 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
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "ValueProfile.h"
34 #if ENABLE(VALUE_PROFILER)
35 void ValueProfile::computeStatistics(const ClassInfo* classInfo, Statistics& statistics)
39 if (classInfo == &JSFinalObject::s_info) {
40 statistics.finalObjects++;
45 if (classInfo == &JSArray::s_info) {
51 if (classInfo == &JSString::s_info) {
56 if (classInfo->isSubClassOf(&JSObject::s_info))
60 void ValueProfile::computeStatistics(Statistics& statistics) const
62 for (unsigned i = 0; i < numberOfBuckets; ++i) {
64 WeakBucket weakBucket = m_weakBuckets[i];
67 computeStatistics(weakBucket.getClassInfo(), statistics);
75 JSValue value = JSValue::decode(m_buckets[i]);
78 else if (value.isDouble())
80 else if (value.isCell())
81 computeStatistics(value.asCell()->structure()->classInfo(), statistics);
82 else if (value.isBoolean())
83 statistics.booleans++;
87 PredictedType ValueProfile::computeUpdatedPrediction()
89 ValueProfile::Statistics statistics;
90 computeStatistics(statistics);
92 PredictedType prediction;
94 if (!statistics.samples)
95 prediction = PredictNone;
96 else if (statistics.int32s == statistics.samples)
97 prediction = StrongPredictionTag | PredictInt32;
98 else if (statistics.doubles == statistics.samples)
99 prediction = StrongPredictionTag | PredictDouble;
100 else if (statistics.int32s + statistics.doubles == statistics.samples)
101 prediction = StrongPredictionTag | PredictNumber;
102 else if (statistics.arrays == statistics.samples)
103 prediction = StrongPredictionTag | PredictArray;
104 else if (statistics.finalObjects == statistics.samples)
105 prediction = StrongPredictionTag | PredictFinalObject;
106 else if (statistics.strings == statistics.samples)
107 prediction = StrongPredictionTag | PredictString;
108 else if (statistics.objects == statistics.samples)
109 prediction = StrongPredictionTag | PredictObjectOther;
110 else if (statistics.cells == statistics.samples)
111 prediction = StrongPredictionTag | PredictCellOther;
112 else if (statistics.booleans == statistics.samples)
113 prediction = StrongPredictionTag | PredictBoolean;
115 prediction = StrongPredictionTag | PredictOther;
117 m_numberOfSamplesInPrediction += statistics.samples;
118 mergePrediction(m_prediction, prediction);
119 for (unsigned i = 0; i < numberOfBuckets; ++i) {
120 m_buckets[i] = JSValue::encode(JSValue());
121 m_weakBuckets[i] = WeakBucket();
125 #endif // ENABLE(VALUE_PROFILER)