/*
- * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
#ifndef ValueProfile_h
#define ValueProfile_h
-#include <wtf/Platform.h>
-
-#if ENABLE(VALUE_PROFILER)
-
+#include "ConcurrentJITLock.h"
#include "Heap.h"
#include "JSArray.h"
#include "SpeculatedType.h"
: m_bytecodeOffset(-1)
, m_prediction(SpecNone)
, m_numberOfSamplesInPrediction(0)
- , m_singletonValueIsTop(false)
{
for (unsigned i = 0; i < totalNumberOfBuckets; ++i)
m_buckets[i] = JSValue::encode(JSValue());
: m_bytecodeOffset(bytecodeOffset)
, m_prediction(SpecNone)
, m_numberOfSamplesInPrediction(0)
- , m_singletonValueIsTop(false)
{
for (unsigned i = 0; i < totalNumberOfBuckets; ++i)
m_buckets[i] = JSValue::encode(JSValue());
return false;
}
- CString briefDescription()
+ CString briefDescription(const ConcurrentJITLocker& locker)
{
- computeUpdatedPrediction();
+ computeUpdatedPrediction(locker);
StringPrintStream out;
-
- if (m_singletonValueIsTop)
- out.print("predicting ", SpeculationDump(m_prediction));
- else if (m_singletonValue)
- out.print("predicting ", m_singletonValue);
-
+ out.print("predicting ", SpeculationDump(m_prediction));
return out.toCString();
}
void dump(PrintStream& out)
{
out.print("samples = ", totalNumberOfSamples(), " prediction = ", SpeculationDump(m_prediction));
- out.printf(", value = ");
- if (m_singletonValueIsTop)
- out.printf("TOP");
- else
- out.print(m_singletonValue);
bool first = true;
for (unsigned i = 0; i < totalNumberOfBuckets; ++i) {
JSValue value = JSValue::decode(m_buckets[i]);
}
}
- // Updates the prediction and returns the new one.
- SpeculatedType computeUpdatedPrediction(OperationInProgress operation = NoOperation)
+ // Updates the prediction and returns the new one. Never call this from any thread
+ // that isn't executing the code.
+ SpeculatedType computeUpdatedPrediction(const ConcurrentJITLocker&)
{
for (unsigned i = 0; i < totalNumberOfBuckets; ++i) {
JSValue value = JSValue::decode(m_buckets[i]);
m_numberOfSamplesInPrediction++;
mergeSpeculation(m_prediction, speculationFromValue(value));
- if (!m_singletonValueIsTop && !!value) {
- if (!m_singletonValue)
- m_singletonValue = value;
- else if (m_singletonValue != value)
- m_singletonValueIsTop = true;
- }
-
m_buckets[i] = JSValue::encode(JSValue());
}
- if (operation == Collection
- && !m_singletonValueIsTop
- && !!m_singletonValue
- && m_singletonValue.isCell()
- && !Heap::isMarked(m_singletonValue.asCell()))
- m_singletonValueIsTop = true;
-
return m_prediction;
}
SpeculatedType m_prediction;
unsigned m_numberOfSamplesInPrediction;
- bool m_singletonValueIsTop;
- JSValue m_singletonValue;
-
EncodedJSValue m_buckets[totalNumberOfBuckets];
};
} // namespace JSC
-#endif // ENABLE(VALUE_PROFILER)
-
#endif // ValueProfile_h