FullGCActivityCallback.cpp [plain text]
#include "config.h"
#include "FullGCActivityCallback.h"
#include "VM.h"
namespace JSC {
#if USE(CF) || USE(GLIB)
#if !PLATFORM(IOS)
const double pagingTimeOut = 0.1; #endif
FullGCActivityCallback::FullGCActivityCallback(Heap* heap)
: GCActivityCallback(heap)
{
}
void FullGCActivityCallback::doCollection()
{
Heap& heap = m_vm->heap;
m_didSyncGCRecently = false;
#if !PLATFORM(IOS)
double startTime = WTF::monotonicallyIncreasingTime();
if (heap.isPagedOut(startTime + pagingTimeOut)) {
cancel();
heap.increaseLastFullGCLength(pagingTimeOut);
return;
}
#endif
heap.collectAsync(CollectionScope::Full);
}
double FullGCActivityCallback::lastGCLength()
{
return m_vm->heap.lastFullGCLength();
}
double FullGCActivityCallback::deathRate()
{
Heap* heap = &m_vm->heap;
size_t sizeBefore = heap->sizeBeforeLastFullCollection();
size_t sizeAfter = heap->sizeAfterLastFullCollection();
if (!sizeBefore)
return 1.0;
if (sizeAfter > sizeBefore) {
return 0;
}
return static_cast<double>(sizeBefore - sizeAfter) / static_cast<double>(sizeBefore);
}
double FullGCActivityCallback::gcTimeSlice(size_t bytes)
{
return std::min((static_cast<double>(bytes) / MB) * Options::percentCPUPerMBForFullTimer(), Options::collectionTimerMaxPercentCPU());
}
#else
FullGCActivityCallback::FullGCActivityCallback(Heap* heap)
: GCActivityCallback(heap)
{
}
void FullGCActivityCallback::doCollection()
{
}
double FullGCActivityCallback::lastGCLength()
{
return 0;
}
double FullGCActivityCallback::deathRate()
{
return 0;
}
double FullGCActivityCallback::gcTimeSlice(size_t)
{
return 0;
}
#endif // USE(CF) || USE(GLIB)
}