ExecutionCounter.h [plain text]
#pragma once
#include "JSGlobalObject.h"
#include "Options.h"
#include <wtf/PrintStream.h>
namespace JSC {
class CodeBlock;
enum CountingVariant {
CountingForBaseline,
CountingForUpperTiers
};
double applyMemoryUsageHeuristics(int32_t value, CodeBlock*);
int32_t applyMemoryUsageHeuristicsAndConvertToInt(int32_t value, CodeBlock*);
inline int32_t formattedTotalExecutionCount(float value)
{
union {
int32_t i;
float f;
} u;
u.f = value;
return u.i;
}
template<CountingVariant countingVariant>
class ExecutionCounter {
public:
ExecutionCounter();
void forceSlowPathConcurrently(); bool checkIfThresholdCrossedAndSet(CodeBlock*);
bool hasCrossedThreshold() const { return m_counter >= 0; }
void setNewThreshold(int32_t threshold, CodeBlock*);
void deferIndefinitely();
double count() const { return static_cast<double>(m_totalCount) + m_counter; }
void dump(PrintStream&) const;
void setNewThresholdForOSRExit(uint32_t activeThreshold, double memoryUsageAdjustedThreshold)
{
m_activeThreshold = activeThreshold;
m_counter = static_cast<int32_t>(-memoryUsageAdjustedThreshold);
m_totalCount = memoryUsageAdjustedThreshold;
}
static int32_t maximumExecutionCountsBetweenCheckpoints()
{
switch (countingVariant) {
case CountingForBaseline:
return Options::maximumExecutionCountsBetweenCheckpointsForBaseline();
case CountingForUpperTiers:
return Options::maximumExecutionCountsBetweenCheckpointsForUpperTiers();
default:
RELEASE_ASSERT_NOT_REACHED();
return 0;
}
}
template<typename T>
static T clippedThreshold(JSGlobalObject* globalObject, T threshold)
{
int32_t maxThreshold;
if (Options::randomizeExecutionCountsBetweenCheckpoints())
maxThreshold = globalObject->weakRandomInteger() % maximumExecutionCountsBetweenCheckpoints();
else
maxThreshold = maximumExecutionCountsBetweenCheckpoints();
if (threshold > maxThreshold)
threshold = maxThreshold;
return threshold;
}
private:
bool hasCrossedThreshold(CodeBlock*) const;
bool setThreshold(CodeBlock*);
void reset();
public:
int32_t m_counter;
float m_totalCount;
int32_t m_activeThreshold;
};
typedef ExecutionCounter<CountingForBaseline> BaselineExecutionCounter;
typedef ExecutionCounter<CountingForUpperTiers> UpperTierExecutionCounter;
}