Skip to content
Permalink
Browse files
Restructure LinkBuffer to allow for alternate allocation strategies
https://bugs.webkit.org/show_bug.cgi?id=123071

Reviewed by Oliver Hunt.

The idea is to eventually allow a LinkBuffer to place the code into an already
allocated region of memory.  That region of memory could be the nop-slide left behind
by a llvm.webkit.patchpoint.

* assembler/ARM64Assembler.h:
(JSC::ARM64Assembler::buffer):
* assembler/AssemblerBuffer.h:
* assembler/LinkBuffer.cpp:
(JSC::LinkBuffer::copyCompactAndLinkCode):
(JSC::LinkBuffer::linkCode):
(JSC::LinkBuffer::allocate):
(JSC::LinkBuffer::shrink):
* assembler/LinkBuffer.h:
(JSC::LinkBuffer::LinkBuffer):
(JSC::LinkBuffer::didFailToAllocate):
* assembler/X86Assembler.h:
(JSC::X86Assembler::buffer):
(JSC::X86Assembler::X86InstructionFormatter::memoryModRM):



Canonical link: https://commits.webkit.org/141151@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157690 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pizlonator committed Oct 20, 2013
1 parent 14cb452 commit 4f727d300bbd1c635ff1aa9f33941c9a3c403939
Showing 6 changed files with 60 additions and 40 deletions.
@@ -1,3 +1,29 @@
2013-10-19 Filip Pizlo <fpizlo@apple.com>

Restructure LinkBuffer to allow for alternate allocation strategies
https://bugs.webkit.org/show_bug.cgi?id=123071

Reviewed by Oliver Hunt.

The idea is to eventually allow a LinkBuffer to place the code into an already
allocated region of memory. That region of memory could be the nop-slide left behind
by a llvm.webkit.patchpoint.

* assembler/ARM64Assembler.h:
(JSC::ARM64Assembler::buffer):
* assembler/AssemblerBuffer.h:
* assembler/LinkBuffer.cpp:
(JSC::LinkBuffer::copyCompactAndLinkCode):
(JSC::LinkBuffer::linkCode):
(JSC::LinkBuffer::allocate):
(JSC::LinkBuffer::shrink):
* assembler/LinkBuffer.h:
(JSC::LinkBuffer::LinkBuffer):
(JSC::LinkBuffer::didFailToAllocate):
* assembler/X86Assembler.h:
(JSC::X86Assembler::buffer):
(JSC::X86Assembler::X86InstructionFormatter::memoryModRM):

2013-10-19 Alexey Proskuryakov <ap@apple.com>

Some includes in JSC seem to use an incorrect style
@@ -453,6 +453,8 @@ class ARM64Assembler {
, m_indexOfTailOfLastWatchpoint(INT_MIN)
{
}

AssemblerBuffer& buffer() { return m_buffer; }

// (HS, LO, HI, LS) -> (AE, B, A, BE)
// (VS, VC) -> (O, NO)
@@ -130,23 +130,6 @@ namespace JSC {
return AssemblerLabel(m_index);
}

PassRefPtr<ExecutableMemoryHandle> executableCopy(VM& vm, void* ownerUID, JITCompilationEffort effort)
{
if (!m_index)
return 0;

RefPtr<ExecutableMemoryHandle> result = vm.executableAllocator.allocate(vm, m_index, ownerUID, effort);

if (!result)
return 0;

ExecutableAllocator::makeWritable(result->start(), result->sizeInBytes());

memcpy(result->start(), m_buffer, m_index);

return result.release();
}

unsigned debugOffset() { return m_index; }

protected:
@@ -64,12 +64,7 @@ template <typename InstructionType>
void LinkBuffer::copyCompactAndLinkCode(void* ownerUID, JITCompilationEffort effort)
{
m_initialSize = m_assembler->m_assembler.codeSize();
m_executableMemory = m_vm->executableAllocator.allocate(*m_vm, m_initialSize, ownerUID, effort);
if (!m_executableMemory)
return;
m_code = (uint8_t*)m_executableMemory->start();
ASSERT(m_code);
ExecutableAllocator::makeWritable(m_code, m_initialSize);
allocate(m_initialSize, ownerUID, effort);
uint8_t* inData = (uint8_t*)m_assembler->unlinkedCode();
uint8_t* outData = reinterpret_cast<uint8_t*>(m_code);
int readPtr = 0;
@@ -125,8 +120,7 @@ void LinkBuffer::copyCompactAndLinkCode(void* ownerUID, JITCompilationEffort eff
}

jumpsToLink.clear();
m_size = writePtr + m_initialSize - readPtr;
m_executableMemory->shrink(m_size);
shrink(writePtr + m_initialSize - readPtr);

#if DUMP_LINK_STATISTICS
dumpLinkStatistics(m_code, m_initialSize, m_size);
@@ -142,19 +136,36 @@ void LinkBuffer::linkCode(void* ownerUID, JITCompilationEffort effort)
{
ASSERT(!m_code);
#if !ENABLE(BRANCH_COMPACTION)
m_executableMemory = m_assembler->m_assembler.executableCopy(*m_vm, ownerUID, effort);
if (!m_executableMemory)
AssemblerBuffer& buffer = m_assembler->m_assembler.buffer();
allocate(buffer.codeSize(), ownerUID, effort);
if (!m_didAllocate)
return;
m_code = m_executableMemory->start();
m_size = m_assembler->m_assembler.codeSize();
ASSERT(m_code);
memcpy(m_code, buffer.data(), buffer.codeSize());
#elif CPU(ARM_THUMB2)
copyCompactAndLinkCode<uint16_t>(ownerUID, effort);
#elif CPU(ARM64)
copyCompactAndLinkCode<uint32_t>(ownerUID, effort);
#endif
}

void LinkBuffer::allocate(size_t initialSize, void* ownerUID, JITCompilationEffort effort)
{
m_executableMemory = m_vm->executableAllocator.allocate(*m_vm, initialSize, ownerUID, effort);
if (!m_executableMemory)
return;
ExecutableAllocator::makeWritable(m_executableMemory->start(), m_executableMemory->sizeInBytes());
m_code = m_executableMemory->start();
m_size = initialSize;
m_didAllocate = true;
}

void LinkBuffer::shrink(size_t newSize)
{
m_size = newSize;
m_executableMemory->shrink(m_size);
}

void LinkBuffer::performFinalization()
{
#ifndef NDEBUG
@@ -83,6 +83,7 @@ class LinkBuffer {
#if ENABLE(BRANCH_COMPACTION)
, m_initialSize(0)
#endif
, m_didAllocate(false)
, m_code(0)
, m_assembler(masm)
, m_vm(&vm)
@@ -99,7 +100,7 @@ class LinkBuffer {

bool didFailToAllocate() const
{
return !m_executableMemory;
return !m_didAllocate;
}

bool isValid() const
@@ -241,6 +242,9 @@ class LinkBuffer {
{
return m_code;
}

void allocate(size_t initialSize, void* ownerUID, JITCompilationEffort);
void shrink(size_t newSize);

void linkCode(void* ownerUID, JITCompilationEffort);
#if ENABLE(BRANCH_COMPACTION)
@@ -263,6 +267,7 @@ class LinkBuffer {
#if ENABLE(BRANCH_COMPACTION)
size_t m_initialSize;
#endif
bool m_didAllocate;
void* m_code;
MacroAssembler* m_assembler;
VM* m_vm;
@@ -333,6 +333,8 @@ class X86Assembler {
, m_indexOfTailOfLastWatchpoint(INT_MIN)
{
}

AssemblerBuffer& buffer() { return m_formatter.m_buffer; }

// Stack operations:

@@ -2122,11 +2124,6 @@ class X86Assembler {
return b.m_offset - a.m_offset;
}

PassRefPtr<ExecutableMemoryHandle> executableCopy(VM& vm, void* ownerUID, JITCompilationEffort effort)
{
return m_formatter.executableCopy(vm, ownerUID, effort);
}

unsigned debugOffset() { return m_formatter.debugOffset(); }

void nop()
@@ -2480,11 +2477,6 @@ class X86Assembler {
bool isAligned(int alignment) const { return m_buffer.isAligned(alignment); }
void* data() const { return m_buffer.data(); }

PassRefPtr<ExecutableMemoryHandle> executableCopy(VM& vm, void* ownerUID, JITCompilationEffort effort)
{
return m_buffer.executableCopy(vm, ownerUID, effort);
}

unsigned debugOffset() { return m_buffer.debugOffset(); }

private:
@@ -2658,6 +2650,7 @@ class X86Assembler {
}
#endif

public:
AssemblerBuffer m_buffer;
} m_formatter;
int m_indexOfLastWatchpoint;

0 comments on commit 4f727d3

Please sign in to comment.