summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp')
-rw-r--r--Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp79
1 files changed, 23 insertions, 56 deletions
diff --git a/Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp b/Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
index 8d5018b6c..8e0b77cfc 100644
--- a/Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
+++ b/Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -24,18 +24,14 @@
*/
#include "config.h"
-#include "ExecutableAllocator.h"
-#include "JSCInlines.h"
+#include "ExecutableAllocator.h"
#if ENABLE(EXECUTABLE_ALLOCATOR_FIXED)
#include "CodeProfiling.h"
-#include "ExecutableAllocationFuzz.h"
#include <errno.h>
-#if !PLATFORM(WIN)
#include <unistd.h>
-#endif
#include <wtf/MetaAllocator.h>
#include <wtf/PageReservation.h>
#include <wtf/VMTags.h>
@@ -48,6 +44,11 @@
#include <stdio.h>
#endif
+#if !PLATFORM(IOS) && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+// MADV_FREE_REUSABLE does not work for JIT memory on older OSes so use MADV_FREE in that case.
+#define WTF_USE_MADV_FREE_FOR_JIT_MEMORY 1
+#endif
+
using namespace WTF;
namespace JSC {
@@ -60,15 +61,12 @@ public:
FixedVMPoolExecutableAllocator()
: MetaAllocator(jitAllocationGranule) // round up all allocations to 32 bytes
{
- size_t reservationSize;
- if (Options::jitMemoryReservationSize())
- reservationSize = Options::jitMemoryReservationSize();
- else
- reservationSize = fixedExecutableMemoryPoolSize;
- reservationSize = roundUpToMultipleOf(pageSize(), reservationSize);
- m_reservation = PageReservation::reserveWithGuardPages(reservationSize, OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
+ m_reservation = PageReservation::reserveWithGuardPages(fixedExecutableMemoryPoolSize, OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
+#if !ENABLE(LLINT)
+ RELEASE_ASSERT(m_reservation);
+#endif
if (m_reservation) {
- ASSERT(m_reservation.size() == reservationSize);
+ ASSERT(m_reservation.size() == fixedExecutableMemoryPoolSize);
addFreshFreeSpace(m_reservation.base(), m_reservation.size());
startOfFixedExecutableMemoryPool = reinterpret_cast<uintptr_t>(m_reservation.base());
@@ -154,59 +152,28 @@ double ExecutableAllocator::memoryPressureMultiplier(size_t addedMemoryUsage)
MetaAllocator::Statistics statistics = allocator->currentStatistics();
ASSERT(statistics.bytesAllocated <= statistics.bytesReserved);
size_t bytesAllocated = statistics.bytesAllocated + addedMemoryUsage;
- size_t bytesAvailable = static_cast<size_t>(
- statistics.bytesReserved * (1 - executablePoolReservationFraction));
- if (bytesAllocated >= bytesAvailable)
- bytesAllocated = bytesAvailable;
+ if (bytesAllocated >= statistics.bytesReserved)
+ bytesAllocated = statistics.bytesReserved;
double result = 1.0;
- size_t divisor = bytesAvailable - bytesAllocated;
+ size_t divisor = statistics.bytesReserved - bytesAllocated;
if (divisor)
- result = static_cast<double>(bytesAvailable) / divisor;
+ result = static_cast<double>(statistics.bytesReserved) / divisor;
if (result < 1.0)
result = 1.0;
return result;
}
-RefPtr<ExecutableMemoryHandle> ExecutableAllocator::allocate(VM&, size_t sizeInBytes, void* ownerUID, JITCompilationEffort effort)
+PassRefPtr<ExecutableMemoryHandle> ExecutableAllocator::allocate(VM& vm, size_t sizeInBytes, void* ownerUID, JITCompilationEffort effort)
{
- if (effort != JITCompilationCanFail && Options::reportMustSucceedExecutableAllocations()) {
- dataLog("Allocating ", sizeInBytes, " bytes of executable memory with JITCompilationMustSucceed.\n");
- WTFReportBacktrace();
- }
-
- if (effort == JITCompilationCanFail
- && doExecutableAllocationFuzzingIfEnabled() == PretendToFailExecutableAllocation)
- return nullptr;
-
- if (effort == JITCompilationCanFail) {
- // Don't allow allocations if we are down to reserve.
- MetaAllocator::Statistics statistics = allocator->currentStatistics();
- size_t bytesAllocated = statistics.bytesAllocated + sizeInBytes;
- size_t bytesAvailable = static_cast<size_t>(
- statistics.bytesReserved * (1 - executablePoolReservationFraction));
- if (bytesAllocated > bytesAvailable)
- return nullptr;
- }
-
RefPtr<ExecutableMemoryHandle> result = allocator->allocate(sizeInBytes, ownerUID);
if (!result) {
- if (effort != JITCompilationCanFail) {
- dataLog("Ran out of executable memory while allocating ", sizeInBytes, " bytes.\n");
- CRASH();
- }
- return nullptr;
+ if (effort == JITCompilationCanFail)
+ return result;
+ releaseExecutableMemory(vm);
+ result = allocator->allocate(sizeInBytes, ownerUID);
+ RELEASE_ASSERT(result);
}
- return result;
-}
-
-bool ExecutableAllocator::isValidExecutableMemory(const LockHolder& locker, void* address)
-{
- return allocator->isInAllocatedMemory(locker, address);
-}
-
-Lock& ExecutableAllocator::getLock() const
-{
- return allocator->getLock();
+ return result.release();
}
size_t ExecutableAllocator::committedByteCount()