summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/jit
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/jit')
-rw-r--r--JavaScriptCore/jit/ExecutableAllocator.cpp9
-rw-r--r--JavaScriptCore/jit/ExecutableAllocator.h13
-rw-r--r--JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp37
-rw-r--r--JavaScriptCore/jit/JITOpcodes.cpp12
-rw-r--r--JavaScriptCore/jit/JITOpcodes32_64.cpp20
-rw-r--r--JavaScriptCore/jit/JITStubs.cpp20
6 files changed, 54 insertions, 57 deletions
diff --git a/JavaScriptCore/jit/ExecutableAllocator.cpp b/JavaScriptCore/jit/ExecutableAllocator.cpp
index 8742eda..4530b38 100644
--- a/JavaScriptCore/jit/ExecutableAllocator.cpp
+++ b/JavaScriptCore/jit/ExecutableAllocator.cpp
@@ -45,13 +45,13 @@ void ExecutableAllocator::intializePageSize()
// for moving memory model limitation
ExecutableAllocator::pageSize = 256 * 1024;
#else
- ExecutableAllocator::pageSize = PageAllocation::pageSize();
+ ExecutableAllocator::pageSize = WTF::pageSize();
#endif
}
ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t size)
{
- PageAllocation allocation = PageAllocation::allocate(size, PageAllocation::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
+ PageAllocation allocation = PageAllocation::allocate(size, OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
if (!allocation)
CRASH();
return allocation;
@@ -67,6 +67,11 @@ bool ExecutableAllocator::isValid() const
return true;
}
+bool ExecutableAllocator::underMemoryPressure()
+{
+ return false;
+}
+
size_t ExecutableAllocator::committedByteCount()
{
return 0;
diff --git a/JavaScriptCore/jit/ExecutableAllocator.h b/JavaScriptCore/jit/ExecutableAllocator.h
index f362605..4580a67 100644
--- a/JavaScriptCore/jit/ExecutableAllocator.h
+++ b/JavaScriptCore/jit/ExecutableAllocator.h
@@ -137,9 +137,11 @@ public:
return poolAllocate(n);
}
- void returnLastBytes(size_t count)
+ void tryShrink(void* allocation, size_t oldSize, size_t newSize)
{
- m_freePtr -= count;
+ if (static_cast<char*>(allocation) + oldSize != m_freePtr)
+ return;
+ m_freePtr = static_cast<char*>(allocation) + roundUpAllocationSize(newSize, sizeof(void*));
}
~ExecutablePool()
@@ -182,7 +184,9 @@ public:
}
bool isValid() const;
-
+
+ static bool underMemoryPressure();
+
PassRefPtr<ExecutablePool> poolForSize(size_t n)
{
// Try to fit in the existing small allocator
@@ -253,8 +257,7 @@ public:
#elif CPU(ARM_THUMB2) && OS(IOS)
static void cacheFlush(void* code, size_t size)
{
- sys_dcache_flush(code, size);
- sys_icache_invalidate(code, size);
+ sys_cache_control(kCacheFunctionPrepareForExecution, code, size);
}
#elif CPU(ARM_THUMB2) && OS(LINUX)
static void cacheFlush(void* code, size_t size)
diff --git a/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp b/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
index 15247c2..e280b2d 100644
--- a/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
+++ b/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
@@ -48,9 +48,6 @@
#define COALESCE_LIMIT (4u * 1024u * 1024u) // 4Mb
#endif
-// ASLR currently only works on darwin (due to arc4random) & 64-bit (due to address space size).
-#define VM_POOL_ASLR (OS(DARWIN) && CPU(X86_64))
-
using namespace WTF;
namespace JSC {
@@ -136,8 +133,7 @@ class FixedVMPoolAllocator
void reuse(void* position, size_t size)
{
- bool okay = m_allocation.commit(position, size);
- ASSERT_UNUSED(okay, okay);
+ m_allocation.commit(position, size);
addToCommittedByteCount(static_cast<long>(size));
}
@@ -282,24 +278,7 @@ public:
: m_commonSize(commonSize)
, m_countFreedSinceLastCoalesce(0)
{
- // Cook up an address to allocate at, using the following recipe:
- // 17 bits of zero, stay in userspace kids.
- // 26 bits of randomness for ASLR.
- // 21 bits of zero, at least stay aligned within one level of the pagetables.
- //
- // But! - as a temporary workaround for some plugin problems (rdar://problem/6812854),
- // for now instead of 2^26 bits of ASLR lets stick with 25 bits of randomization plus
- // 2^24, which should put up somewhere in the middle of userspace (in the address range
- // 0x200000000000 .. 0x5fffffffffff).
-#if VM_POOL_ASLR
- intptr_t randomLocation = 0;
- randomLocation = arc4random() & ((1 << 25) - 1);
- randomLocation += (1 << 24);
- randomLocation <<= 21;
- m_allocation = PageReservation::reserveAt(reinterpret_cast<void*>(randomLocation), false, totalHeapSize, PageAllocation::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
-#else
- m_allocation = PageReservation::reserve(totalHeapSize, PageAllocation::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
-#endif
+ m_allocation = PageReservation::reserve(totalHeapSize, OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
if (!!m_allocation)
m_freeList.insert(new FreeListEntry(m_allocation.base(), m_allocation.size()));
@@ -452,7 +431,8 @@ void ExecutableAllocator::intializePageSize()
}
static FixedVMPoolAllocator* allocator = 0;
-
+static size_t allocatedCount = 0;
+
bool ExecutableAllocator::isValid() const
{
SpinLockHolder lock_holder(&spinlock);
@@ -461,10 +441,18 @@ bool ExecutableAllocator::isValid() const
return allocator->isValid();
}
+bool ExecutableAllocator::underMemoryPressure()
+{
+ // Technically we should take the spin lock here, but we don't care if we get stale data.
+ // This is only really a heuristic anyway.
+ return allocatedCount > (VM_POOL_SIZE / 2);
+}
+
ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t size)
{
SpinLockHolder lock_holder(&spinlock);
ASSERT(allocator);
+ allocatedCount += size;
return allocator->alloc(size);
}
@@ -472,6 +460,7 @@ void ExecutablePool::systemRelease(ExecutablePool::Allocation& allocation)
{
SpinLockHolder lock_holder(&spinlock);
ASSERT(allocator);
+ allocatedCount -= allocation.size();
allocator->free(allocation);
}
diff --git a/JavaScriptCore/jit/JITOpcodes.cpp b/JavaScriptCore/jit/JITOpcodes.cpp
index 66285ae..972b879 100644
--- a/JavaScriptCore/jit/JITOpcodes.cpp
+++ b/JavaScriptCore/jit/JITOpcodes.cpp
@@ -806,7 +806,7 @@ void JIT::emit_op_eq(Instruction* currentInstruction)
{
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
- set32(Equal, regT1, regT0, regT0);
+ set32Compare32(Equal, regT1, regT0, regT0);
emitTagAsBoolImmediate(regT0);
emitPutVirtualRegister(currentInstruction[1].u.operand);
}
@@ -854,7 +854,7 @@ void JIT::emit_op_neq(Instruction* currentInstruction)
{
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
- set32(NotEqual, regT1, regT0, regT0);
+ set32Compare32(NotEqual, regT1, regT0, regT0);
emitTagAsBoolImmediate(regT0);
emitPutVirtualRegister(currentInstruction[1].u.operand);
@@ -1026,9 +1026,9 @@ void JIT::compileOpStrictEq(Instruction* currentInstruction, CompileOpStrictEqTy
addSlowCase(emitJumpIfImmediateNumber(regT2));
if (type == OpStrictEq)
- set32(Equal, regT1, regT0, regT0);
+ set32Compare32(Equal, regT1, regT0, regT0);
else
- set32(NotEqual, regT1, regT0, regT0);
+ set32Compare32(NotEqual, regT1, regT0, regT0);
emitTagAsBoolImmediate(regT0);
emitPutVirtualRegister(dst);
@@ -1177,7 +1177,7 @@ void JIT::emit_op_eq_null(Instruction* currentInstruction)
Jump isImmediate = emitJumpIfNotJSCell(regT0);
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
- setTest8(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0);
+ set32Test8(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0);
Jump wasNotImmediate = jump();
@@ -1202,7 +1202,7 @@ void JIT::emit_op_neq_null(Instruction* currentInstruction)
Jump isImmediate = emitJumpIfNotJSCell(regT0);
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
- setTest8(Zero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0);
+ set32Test8(Zero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0);
Jump wasNotImmediate = jump();
diff --git a/JavaScriptCore/jit/JITOpcodes32_64.cpp b/JavaScriptCore/jit/JITOpcodes32_64.cpp
index a2bb159..4ad974c 100644
--- a/JavaScriptCore/jit/JITOpcodes32_64.cpp
+++ b/JavaScriptCore/jit/JITOpcodes32_64.cpp
@@ -1018,7 +1018,7 @@ void JIT::emit_op_eq(Instruction* currentInstruction)
addSlowCase(branch32(Equal, regT1, Imm32(JSValue::CellTag)));
addSlowCase(branch32(Below, regT1, Imm32(JSValue::LowestTag)));
- set8(Equal, regT0, regT2, regT0);
+ set8Compare32(Equal, regT0, regT2, regT0);
or32(Imm32(JSValue::FalseTag), regT0);
emitStoreBool(dst, regT0);
@@ -1070,7 +1070,7 @@ void JIT::emit_op_neq(Instruction* currentInstruction)
addSlowCase(branch32(Equal, regT1, Imm32(JSValue::CellTag)));
addSlowCase(branch32(Below, regT1, Imm32(JSValue::LowestTag)));
- set8(NotEqual, regT0, regT2, regT0);
+ set8Compare32(NotEqual, regT0, regT2, regT0);
or32(Imm32(JSValue::FalseTag), regT0);
emitStoreBool(dst, regT0);
@@ -1127,9 +1127,9 @@ void JIT::compileOpStrictEq(Instruction* currentInstruction, CompileOpStrictEqTy
addSlowCase(branch32(AboveOrEqual, regT2, Imm32(JSValue::CellTag)));
if (type == OpStrictEq)
- set8(Equal, regT0, regT1, regT0);
+ set8Compare32(Equal, regT0, regT1, regT0);
else
- set8(NotEqual, regT0, regT1, regT0);
+ set8Compare32(NotEqual, regT0, regT1, regT0);
or32(Imm32(JSValue::FalseTag), regT0);
@@ -1185,14 +1185,14 @@ void JIT::emit_op_eq_null(Instruction* currentInstruction)
Jump isImmediate = branch32(NotEqual, regT1, Imm32(JSValue::CellTag));
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT1);
- setTest8(NonZero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT1);
+ set32Test8(NonZero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT1);
Jump wasNotImmediate = jump();
isImmediate.link(this);
- set8(Equal, regT1, Imm32(JSValue::NullTag), regT2);
- set8(Equal, regT1, Imm32(JSValue::UndefinedTag), regT1);
+ set8Compare32(Equal, regT1, Imm32(JSValue::NullTag), regT2);
+ set8Compare32(Equal, regT1, Imm32(JSValue::UndefinedTag), regT1);
or32(regT2, regT1);
wasNotImmediate.link(this);
@@ -1211,14 +1211,14 @@ void JIT::emit_op_neq_null(Instruction* currentInstruction)
Jump isImmediate = branch32(NotEqual, regT1, Imm32(JSValue::CellTag));
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT1);
- setTest8(Zero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT1);
+ set32Test8(Zero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT1);
Jump wasNotImmediate = jump();
isImmediate.link(this);
- set8(NotEqual, regT1, Imm32(JSValue::NullTag), regT2);
- set8(NotEqual, regT1, Imm32(JSValue::UndefinedTag), regT1);
+ set8Compare32(NotEqual, regT1, Imm32(JSValue::NullTag), regT2);
+ set8Compare32(NotEqual, regT1, Imm32(JSValue::UndefinedTag), regT1);
and32(regT2, regT1);
wasNotImmediate.link(this);
diff --git a/JavaScriptCore/jit/JITStubs.cpp b/JavaScriptCore/jit/JITStubs.cpp
index 097d55b..0959a6e 100644
--- a/JavaScriptCore/jit/JITStubs.cpp
+++ b/JavaScriptCore/jit/JITStubs.cpp
@@ -546,7 +546,7 @@ extern "C" {
#endif // USE(JSVALUE32_64)
#if CPU(MIPS)
-asm volatile(
+asm (
".text" "\n"
".align 2" "\n"
".set noreorder" "\n"
@@ -585,7 +585,7 @@ SYMBOL_STRING(ctiTrampoline) ":" "\n"
".end " SYMBOL_STRING(ctiTrampoline) "\n"
);
-asm volatile(
+asm (
".text" "\n"
".align 2" "\n"
".set noreorder" "\n"
@@ -616,7 +616,7 @@ SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
".end " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
);
-asm volatile(
+asm (
".text" "\n"
".align 2" "\n"
".set noreorder" "\n"
@@ -639,7 +639,7 @@ SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
#if COMPILER(GCC) && CPU(ARM_THUMB2)
-asm volatile(
+asm (
".text" "\n"
".align 2" "\n"
".globl " SYMBOL_STRING(ctiTrampoline) "\n"
@@ -666,7 +666,7 @@ SYMBOL_STRING(ctiTrampoline) ":" "\n"
"bx lr" "\n"
);
-asm volatile(
+asm (
".text" "\n"
".align 2" "\n"
".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
@@ -684,7 +684,7 @@ SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
"bx lr" "\n"
);
-asm volatile(
+asm (
".text" "\n"
".align 2" "\n"
".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
@@ -702,7 +702,7 @@ SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
#elif COMPILER(GCC) && CPU(ARM_TRADITIONAL)
-asm volatile(
+asm (
".globl " SYMBOL_STRING(ctiTrampoline) "\n"
HIDE_SYMBOL(ctiTrampoline) "\n"
SYMBOL_STRING(ctiTrampoline) ":" "\n"
@@ -720,7 +720,7 @@ SYMBOL_STRING(ctiTrampoline) ":" "\n"
"mov pc, lr" "\n"
);
-asm volatile(
+asm (
".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
@@ -1108,7 +1108,7 @@ static ExceptionHandler jitThrow(JSGlobalData* globalData, CallFrame* callFrame,
extern "C" { \
rtype JITStubThunked_##op(STUB_ARGS_DECLARATION); \
}; \
- asm volatile( \
+ asm ( \
".text" "\n" \
".align 2" "\n" \
".set noreorder" "\n" \
@@ -1138,7 +1138,7 @@ static ExceptionHandler jitThrow(JSGlobalData* globalData, CallFrame* callFrame,
extern "C" { \
rtype JITStubThunked_##op(STUB_ARGS_DECLARATION); \
}; \
- asm volatile( \
+ asm ( \
".text" "\n" \
".align 2" "\n" \
".set noreorder" "\n" \