summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/bytecode/ExecutionCounter.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/bytecode/ExecutionCounter.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/bytecode/ExecutionCounter.cpp')
-rw-r--r--Source/JavaScriptCore/bytecode/ExecutionCounter.cpp55
1 files changed, 36 insertions, 19 deletions
diff --git a/Source/JavaScriptCore/bytecode/ExecutionCounter.cpp b/Source/JavaScriptCore/bytecode/ExecutionCounter.cpp
index 3a646a86a..237c0e752 100644
--- a/Source/JavaScriptCore/bytecode/ExecutionCounter.cpp
+++ b/Source/JavaScriptCore/bytecode/ExecutionCounter.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2014, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,21 +28,26 @@
#include "CodeBlock.h"
#include "ExecutableAllocator.h"
+#include "JSCInlines.h"
+#include "VMInlines.h"
#include <wtf/StringExtras.h>
namespace JSC {
-ExecutionCounter::ExecutionCounter()
+template<CountingVariant countingVariant>
+ExecutionCounter<countingVariant>::ExecutionCounter()
{
reset();
}
-void ExecutionCounter::forceSlowPathConcurrently()
+template<CountingVariant countingVariant>
+void ExecutionCounter<countingVariant>::forceSlowPathConcurrently()
{
m_counter = 0;
}
-bool ExecutionCounter::checkIfThresholdCrossedAndSet(CodeBlock* codeBlock)
+template<CountingVariant countingVariant>
+bool ExecutionCounter<countingVariant>::checkIfThresholdCrossedAndSet(CodeBlock* codeBlock)
{
if (hasCrossedThreshold(codeBlock))
return true;
@@ -53,26 +58,28 @@ bool ExecutionCounter::checkIfThresholdCrossedAndSet(CodeBlock* codeBlock)
return false;
}
-void ExecutionCounter::setNewThreshold(int32_t threshold, CodeBlock* codeBlock)
+template<CountingVariant countingVariant>
+void ExecutionCounter<countingVariant>::setNewThreshold(int32_t threshold, CodeBlock* codeBlock)
{
reset();
m_activeThreshold = threshold;
setThreshold(codeBlock);
}
-void ExecutionCounter::deferIndefinitely()
+template<CountingVariant countingVariant>
+void ExecutionCounter<countingVariant>::deferIndefinitely()
{
m_totalCount = 0;
m_activeThreshold = std::numeric_limits<int32_t>::max();
m_counter = std::numeric_limits<int32_t>::min();
}
-double ExecutionCounter::applyMemoryUsageHeuristics(int32_t value, CodeBlock* codeBlock)
+double applyMemoryUsageHeuristics(int32_t value, CodeBlock* codeBlock)
{
#if ENABLE(JIT)
double multiplier =
ExecutableAllocator::memoryPressureMultiplier(
- codeBlock->predictedMachineCodeSize());
+ codeBlock->baselineAlternative()->predictedMachineCodeSize());
#else
// This code path will probably not be taken, but if it is, we fake it.
double multiplier = 1.0;
@@ -82,8 +89,7 @@ double ExecutionCounter::applyMemoryUsageHeuristics(int32_t value, CodeBlock* co
return multiplier * value;
}
-int32_t ExecutionCounter::applyMemoryUsageHeuristicsAndConvertToInt(
- int32_t value, CodeBlock* codeBlock)
+int32_t applyMemoryUsageHeuristicsAndConvertToInt(int32_t value, CodeBlock* codeBlock)
{
double doubleResult = applyMemoryUsageHeuristics(value, codeBlock);
@@ -95,7 +101,8 @@ int32_t ExecutionCounter::applyMemoryUsageHeuristicsAndConvertToInt(
return static_cast<int32_t>(doubleResult);
}
-bool ExecutionCounter::hasCrossedThreshold(CodeBlock* codeBlock) const
+template<CountingVariant countingVariant>
+bool ExecutionCounter<countingVariant>::hasCrossedThreshold(CodeBlock* codeBlock) const
{
// This checks if the current count rounded up to the threshold we were targeting.
// For example, if we are using half of available executable memory and have
@@ -117,20 +124,25 @@ bool ExecutionCounter::hasCrossedThreshold(CodeBlock* codeBlock) const
double modifiedThreshold = applyMemoryUsageHeuristics(m_activeThreshold, codeBlock);
- return static_cast<double>(m_totalCount) + m_counter >=
- modifiedThreshold - static_cast<double>(
- std::min(m_activeThreshold, Options::maximumExecutionCountsBetweenCheckpoints())) / 2;
+ double actualCount = static_cast<double>(m_totalCount) + m_counter;
+ double desiredCount = modifiedThreshold - static_cast<double>(
+ std::min(m_activeThreshold, maximumExecutionCountsBetweenCheckpoints())) / 2;
+
+ bool result = actualCount >= desiredCount;
+
+ CODEBLOCK_LOG_EVENT(codeBlock, "thresholdCheck", ("activeThreshold = ", m_activeThreshold, ", modifiedThreshold = ", modifiedThreshold, ", actualCount = ", actualCount, ", desiredCount = ", desiredCount));
+
+ return result;
}
-bool ExecutionCounter::setThreshold(CodeBlock* codeBlock)
+template<CountingVariant countingVariant>
+bool ExecutionCounter<countingVariant>::setThreshold(CodeBlock* codeBlock)
{
if (m_activeThreshold == std::numeric_limits<int32_t>::max()) {
deferIndefinitely();
return false;
}
- ASSERT(!m_activeThreshold || !hasCrossedThreshold(codeBlock));
-
// Compute the true total count.
double trueTotalCount = count();
@@ -159,17 +171,22 @@ bool ExecutionCounter::setThreshold(CodeBlock* codeBlock)
return false;
}
-void ExecutionCounter::reset()
+template<CountingVariant countingVariant>
+void ExecutionCounter<countingVariant>::reset()
{
m_counter = 0;
m_totalCount = 0;
m_activeThreshold = 0;
}
-void ExecutionCounter::dump(PrintStream& out) const
+template<CountingVariant countingVariant>
+void ExecutionCounter<countingVariant>::dump(PrintStream& out) const
{
out.printf("%lf/%lf, %d", count(), static_cast<double>(m_activeThreshold), m_counter);
}
+template class ExecutionCounter<CountingForBaseline>;
+template class ExecutionCounter<CountingForUpperTiers>;
+
} // namespace JSC