Changeset 95134 in webkit for trunk/Source/JavaScriptCore/bytecode/ValueProfile.h
- Timestamp:
- Sep 14, 2011, 4:00:26 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecode/ValueProfile.h
r95115 r95134 31 31 32 32 #include "JSArray.h" 33 #include "PredictedType.h" 33 34 #include "Structure.h" 34 35 #include "WriteBarrier.h" … … 45 46 46 47 ValueProfile(int bytecodeOffset) 47 : bytecodeOffset(bytecodeOffset) 48 : m_bytecodeOffset(bytecodeOffset) 49 , m_prediction(PredictNone) 50 , m_numberOfSamplesInPrediction(0) 48 51 { 49 52 for (unsigned i = 0; i < numberOfBuckets; ++i) 50 buckets[i] = JSValue::encode(JSValue());53 m_buckets[i] = JSValue::encode(JSValue()); 51 54 } 52 55 53 56 const ClassInfo* classInfo(unsigned bucket) const 54 57 { 55 if (!! buckets[bucket]) {56 JSValue value = JSValue::decode( buckets[bucket]);58 if (!!m_buckets[bucket]) { 59 JSValue value = JSValue::decode(m_buckets[bucket]); 57 60 if (!value.isCell()) 58 61 return 0; 59 62 return value.asCell()->structure()->classInfo(); 60 63 } 61 return weakBuckets[bucket].getClassInfo();64 return m_weakBuckets[bucket].getClassInfo(); 62 65 } 63 66 … … 66 69 unsigned result = 0; 67 70 for (unsigned i = 0; i < numberOfBuckets; ++i) { 68 if (!!buckets[i] || !!weakBuckets[i]) 69 result++; 70 } 71 return result; 71 if (!!m_buckets[i] || !!m_weakBuckets[i]) 72 result++; 73 } 74 return result; 75 } 76 77 unsigned totalNumberOfSamples() const 78 { 79 return numberOfSamples() + m_numberOfSamplesInPrediction; 80 } 81 82 bool isLive() const 83 { 84 for (unsigned i = 0; i < numberOfBuckets; ++i) { 85 if (!!m_buckets[i] || !!m_weakBuckets[i]) 86 return true; 87 } 88 return false; 72 89 } 73 90 … … 83 100 unsigned result = 0; 84 101 for (unsigned i = 0; i < numberOfBuckets; ++i) { 85 if (!! buckets[i] && JSValue::decode(buckets[i]).isInt32())102 if (!!m_buckets[i] && JSValue::decode(m_buckets[i]).isInt32()) 86 103 result++; 87 104 } … … 93 110 unsigned result = 0; 94 111 for (unsigned i = 0; i < numberOfBuckets; ++i) { 95 if (!! buckets[i] && JSValue::decode(buckets[i]).isDouble())112 if (!!m_buckets[i] && JSValue::decode(m_buckets[i]).isDouble()) 96 113 result++; 97 114 } … … 154 171 unsigned result = 0; 155 172 for (unsigned i = 0; i < numberOfBuckets; ++i) { 156 if (!! buckets[i] && JSValue::decode(buckets[i]).isBoolean())173 if (!!m_buckets[i] && JSValue::decode(m_buckets[i]).isBoolean()) 157 174 result++; 158 175 } … … 209 226 { 210 227 fprintf(out, 211 "samples = %u, int32 = %u (%u), double = %u (%u), cell = %u (%u), object = %u (%u), final object = %u (%u), array = %u (%u), string = %u (%u), boolean = %u (%u) ",228 "samples = %u, int32 = %u (%u), double = %u (%u), cell = %u (%u), object = %u (%u), final object = %u (%u), array = %u (%u), string = %u (%u), boolean = %u (%u), prediction = %s, samples in prediction = %u", 212 229 numberOfSamples(), 213 230 probabilityOfInt32(), numberOfInt32s(), … … 218 235 probabilityOfArray(), numberOfArrays(), 219 236 probabilityOfString(), numberOfStrings(), 220 probabilityOfBoolean(), numberOfBooleans()); 237 probabilityOfBoolean(), numberOfBooleans(), 238 predictionToString(m_prediction), m_numberOfSamplesInPrediction); 221 239 bool first = true; 222 240 for (unsigned i = 0; i < numberOfBuckets; ++i) { 223 if (!! buckets[i] || !!weakBuckets[i]) {241 if (!!m_buckets[i] || !!m_weakBuckets[i]) { 224 242 if (first) { 225 243 fprintf(out, ": "); … … 229 247 } 230 248 231 if (!! buckets[i])232 fprintf(out, "%s", JSValue::decode( buckets[i]).description());249 if (!!m_buckets[i]) 250 fprintf(out, "%s", JSValue::decode(m_buckets[i]).description()); 233 251 234 if (!! weakBuckets[i])252 if (!!m_weakBuckets[i]) 235 253 fprintf(out, "DeadCell"); 236 254 } … … 258 276 // incrementing the number of samples, which the caller is responsible for 259 277 // doing. 260 static void computeStatistics(const ClassInfo* classInfo, Statistics& statistics) 261 { 262 statistics.cells++; 263 264 if (classInfo == &JSFinalObject::s_info) { 265 statistics.finalObjects++; 266 statistics.objects++; 267 return; 268 } 269 270 if (classInfo == &JSArray::s_info) { 271 statistics.arrays++; 272 statistics.objects++; 273 return; 274 } 275 276 if (classInfo == &JSString::s_info) { 277 statistics.strings++; 278 return; 279 } 280 281 if (classInfo->isSubClassOf(&JSObject::s_info)) 282 statistics.objects++; 283 } 278 static void computeStatistics(const ClassInfo*, Statistics&); 284 279 285 280 // Optimized method for getting all counts at once. 286 void computeStatistics(Statistics& statistics) const 287 { 288 for (unsigned i = 0; i < numberOfBuckets; ++i) { 289 if (!buckets[i]) { 290 WeakBucket weakBucket = weakBuckets[i]; 291 if (!!weakBucket) { 292 statistics.samples++; 293 computeStatistics(weakBucket.getClassInfo(), statistics); 294 } 295 296 continue; 297 } 298 299 statistics.samples++; 300 301 JSValue value = JSValue::decode(buckets[i]); 302 if (value.isInt32()) 303 statistics.int32s++; 304 else if (value.isDouble()) 305 statistics.doubles++; 306 else if (value.isCell()) 307 computeStatistics(value.asCell()->structure()->classInfo(), statistics); 308 else if (value.isBoolean()) 309 statistics.booleans++; 310 } 311 } 312 313 int bytecodeOffset; // -1 for prologue 314 EncodedJSValue buckets[numberOfBuckets]; 281 void computeStatistics(Statistics&) const; 282 283 // Updates the prediction and returns the new one. 284 PredictedType computeUpdatedPrediction(); 285 286 int m_bytecodeOffset; // -1 for prologue 287 288 PredictedType m_prediction; 289 unsigned m_numberOfSamplesInPrediction; 290 291 EncodedJSValue m_buckets[numberOfBuckets]; 315 292 316 293 class WeakBucket { … … 376 353 }; 377 354 378 WeakBucket weakBuckets[numberOfBuckets]; // this is not covered by a write barrier because it is only set from GC355 WeakBucket m_weakBuckets[numberOfBuckets]; // this is not covered by a write barrier because it is only set from GC 379 356 }; 380 357 381 358 inline int getValueProfileBytecodeOffset(ValueProfile* valueProfile) 382 359 { 383 return valueProfile-> bytecodeOffset;360 return valueProfile->m_bytecodeOffset; 384 361 } 385 362 #endif
Note:
See TracChangeset
for help on using the changeset viewer.