Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Assembler changes for enabling GrowHeap in Wasm
Browse files Browse the repository at this point in the history
 - New RelocInfo mode WASM_MEMORY_REFERENCE as a marker for wasm code objects that need to be relocated on a heap change
 - RelocInfo mode recorded for immediates that use the memory buffer as base
 - Tests to verify address patching works

BUG=

Review URL: https://codereview.chromium.org/1759873002

Cr-Commit-Position: refs/heads/master@{#34831}
  • Loading branch information
dtig authored and Commit bot committed Mar 16, 2016
1 parent 689980f commit cc815b6
Show file tree
Hide file tree
Showing 19 changed files with 483 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/arm/assembler-arm-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Address RelocInfo::target_address() {
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
Expand Down Expand Up @@ -114,6 +118,18 @@ void RelocInfo::set_target_address(Address target,
}
}

void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_));
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Assembler::set_target_address_at(isolate_, pc_, host_, updated_reference,
icache_flush_mode);
}

Object* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Expand Down
16 changes: 16 additions & 0 deletions src/arm64/assembler-arm64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ void RelocInfo::set_target_address(Address target,
}
}

void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_));
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Assembler::set_target_address_at(isolate_, pc_, host_, updated_reference,
icache_flush_mode);
}

inline int CPURegister::code() const {
DCHECK(IsValid());
Expand Down Expand Up @@ -693,6 +705,10 @@ Address RelocInfo::target_address() {
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
Expand Down
3 changes: 2 additions & 1 deletion src/arm64/assembler-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ bool ConstPool::CanBeShared(RelocInfo::Mode mode) {
DCHECK(mode != RelocInfo::NONE32);

return RelocInfo::IsNone(mode) ||
(!assm_->serializer_enabled() && (mode >= RelocInfo::CELL));
(!assm_->serializer_enabled() &&
(mode >= RelocInfo::FIRST_SHAREABLE_RELOC_MODE));
}


Expand Down
3 changes: 3 additions & 0 deletions src/assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,8 @@ const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
return "code age sequence";
case GENERATOR_CONTINUATION:
return "generator continuation";
case WASM_MEMORY_REFERENCE:
return "wasm memory reference";
case NUMBER_OF_MODES:
case PC_JUMP:
UNREACHABLE();
Expand Down Expand Up @@ -935,6 +937,7 @@ void RelocInfo::Verify(Isolate* isolate) {
case DEBUG_BREAK_SLOT_AT_RETURN:
case DEBUG_BREAK_SLOT_AT_CALL:
case GENERATOR_CONTINUATION:
case WASM_MEMORY_REFERENCE:
case NONE32:
case NONE64:
break;
Expand Down
12 changes: 11 additions & 1 deletion src/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ class RelocInfo {
DEBUGGER_STATEMENT, // Code target for the debugger statement.
EMBEDDED_OBJECT,
CELL,
// To relocate pointers into the wasm memory embedded in wasm code
WASM_MEMORY_REFERENCE,

// Everything after runtime_entry (inclusive) is not GC'ed.
RUNTIME_ENTRY,
Expand Down Expand Up @@ -427,7 +429,8 @@ class RelocInfo {
FIRST_REAL_RELOC_MODE = CODE_TARGET,
LAST_REAL_RELOC_MODE = VENEER_POOL,
LAST_CODE_ENUM = DEBUGGER_STATEMENT,
LAST_GCED_ENUM = CELL,
LAST_GCED_ENUM = WASM_MEMORY_REFERENCE,
FIRST_SHAREABLE_RELOC_MODE = CELL,
};

STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt);
Expand Down Expand Up @@ -511,6 +514,9 @@ class RelocInfo {
static inline bool IsGeneratorContinuation(Mode mode) {
return mode == GENERATOR_CONTINUATION;
}
static inline bool IsWasmMemoryReference(Mode mode) {
return mode == WASM_MEMORY_REFERENCE;
}
static inline int ModeMask(Mode mode) { return 1 << mode; }

// Accessors
Expand Down Expand Up @@ -571,6 +577,10 @@ class RelocInfo {
ICacheFlushMode icache_flush_mode =
FLUSH_ICACHE_IF_NEEDED));

INLINE(Address wasm_memory_reference());
INLINE(void update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode = SKIP_ICACHE_FLUSH));
// Returns the address of the constant pool entry where the target address
// is held. This should only be called if IsInConstantPool returns true.
INLINE(Address constant_pool_entry_address());
Expand Down
22 changes: 22 additions & 0 deletions src/ia32/assembler-ia32-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ Address RelocInfo::target_address() {
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Memory::Address_at(pc_);
}

Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
Expand Down Expand Up @@ -115,6 +119,20 @@ void RelocInfo::set_target_address(Address target,
}
}

void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_));
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Memory::Address_at(pc_) = updated_reference;
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate_, pc_, sizeof(int32_t));
}
}

Object* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Expand Down Expand Up @@ -321,6 +339,10 @@ Immediate::Immediate(int x) {
rmode_ = RelocInfo::NONE32;
}

Immediate::Immediate(Address x, RelocInfo::Mode rmode) {
x_ = reinterpret_cast<int32_t>(x);
rmode_ = rmode;
}

Immediate::Immediate(const ExternalReference& ext) {
x_ = reinterpret_cast<int32_t>(ext.address());
Expand Down
1 change: 1 addition & 0 deletions src/ia32/assembler-ia32.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Immediate BASE_EMBEDDED {
inline explicit Immediate(Handle<Object> handle);
inline explicit Immediate(Smi* value);
inline explicit Immediate(Address addr);
inline explicit Immediate(Address x, RelocInfo::Mode rmode);

static Immediate CodeRelativeOffset(Label* label) {
return Immediate(label);
Expand Down
16 changes: 16 additions & 0 deletions src/mips/assembler-mips-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Address RelocInfo::target_address() {
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) ||
Expand Down Expand Up @@ -152,6 +156,18 @@ void RelocInfo::set_target_address(Address target,
}
}

void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_));
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Assembler::set_target_address_at(isolate_, pc_, host_, updated_reference,
icache_flush_mode);
}

Address Assembler::target_address_from_return_address(Address pc) {
return pc - kCallTargetAddressOffset;
Expand Down
16 changes: 16 additions & 0 deletions src/mips64/assembler-mips64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Address RelocInfo::target_address() {
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) ||
Expand Down Expand Up @@ -154,6 +158,18 @@ void RelocInfo::set_target_address(Address target,
}
}

void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_));
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Assembler::set_target_address_at(isolate_, pc_, host_, updated_reference,
icache_flush_mode);
}

Address Assembler::target_address_from_return_address(Address pc) {
return pc - kCallTargetAddressOffset;
Expand Down
18 changes: 18 additions & 0 deletions src/x64/assembler-x64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ Address RelocInfo::target_address() {
return Assembler::target_address_at(pc_, host_);
}

Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Memory::Address_at(pc_);
}

Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
Expand Down Expand Up @@ -364,6 +368,20 @@ void RelocInfo::set_target_address(Address target,
}
}

void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_));
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Memory::Address_at(pc_) = updated_reference;
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate_, pc_, sizeof(int64_t));
}
}

Object* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Expand Down
11 changes: 6 additions & 5 deletions src/x64/assembler-x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1469,17 +1469,18 @@ void Assembler::movp(Register dst, void* value, RelocInfo::Mode rmode) {
emitp(value, rmode);
}


void Assembler::movq(Register dst, int64_t value) {
void Assembler::movq(Register dst, int64_t value, RelocInfo::Mode rmode) {
EnsureSpace ensure_space(this);
emit_rex_64(dst);
emit(0xB8 | dst.low_bits());
if (!RelocInfo::IsNone(rmode)) {
RecordRelocInfo(rmode, value);
}
emitq(value);
}


void Assembler::movq(Register dst, uint64_t value) {
movq(dst, static_cast<int64_t>(value));
void Assembler::movq(Register dst, uint64_t value, RelocInfo::Mode rmode) {
movq(dst, static_cast<int64_t>(value), rmode);
}


Expand Down
6 changes: 4 additions & 2 deletions src/x64/assembler-x64.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,10 @@ class Assembler : public AssemblerBase {
void movp(Register dst, void* ptr, RelocInfo::Mode rmode);

// Loads a 64-bit immediate into a register.
void movq(Register dst, int64_t value);
void movq(Register dst, uint64_t value);
void movq(Register dst, int64_t value,
RelocInfo::Mode rmode = RelocInfo::NONE64);
void movq(Register dst, uint64_t value,
RelocInfo::Mode rmode = RelocInfo::NONE64);

void movsxbl(Register dst, Register src);
void movsxbl(Register dst, const Operand& src);
Expand Down
8 changes: 8 additions & 0 deletions src/x64/macro-assembler-x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,14 @@ void MacroAssembler::Set(Register dst, int64_t x) {
}
}

void MacroAssembler::Set(Register dst, int64_t x, RelocInfo::Mode rmode) {
if (rmode == RelocInfo::WASM_MEMORY_REFERENCE) {
DCHECK(x != 0);
movq(dst, x, rmode);
} else {
DCHECK(RelocInfo::IsNone(rmode));
}
}

void MacroAssembler::Set(const Operand& dst, intptr_t x) {
if (kPointerSize == kInt64Size) {
Expand Down
1 change: 1 addition & 0 deletions src/x64/macro-assembler-x64.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ class MacroAssembler: public Assembler {

// Load a register with a long value as efficiently as possible.
void Set(Register dst, int64_t x);
void Set(Register dst, int64_t x, RelocInfo::Mode rmode);
void Set(const Operand& dst, intptr_t x);

void Cvtss2sd(XMMRegister dst, XMMRegister src);
Expand Down
12 changes: 8 additions & 4 deletions test/cctest/cctest.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
'test-code-stubs-ia32.cc',
'test-disasm-ia32.cc',
'test-macro-assembler-ia32.cc',
'test-log-stack-tracer.cc'
'test-log-stack-tracer.cc',
'test-run-wasm-relocation-ia32.cc'
],
}],
['v8_target_arch=="x64"', {
Expand All @@ -212,7 +213,8 @@
'test-code-stubs-x64.cc',
'test-disasm-x64.cc',
'test-macro-assembler-x64.cc',
'test-log-stack-tracer.cc'
'test-log-stack-tracer.cc',
'test-run-wasm-relocation-x64.cc'
],
}],
['v8_target_arch=="arm"', {
Expand All @@ -221,7 +223,8 @@
'test-code-stubs.cc',
'test-code-stubs-arm.cc',
'test-disasm-arm.cc',
'test-macro-assembler-arm.cc'
'test-macro-assembler-arm.cc',
'test-run-wasm-relocation-arm.cc'
],
}],
['v8_target_arch=="arm64"', {
Expand All @@ -233,7 +236,8 @@
'test-disasm-arm64.cc',
'test-fuzz-arm64.cc',
'test-javascript-arm64.cc',
'test-js-arm64-variables.cc'
'test-js-arm64-variables.cc',
'test-run-wasm-relocation-arm64.cc'
],
}],
['v8_target_arch=="s390"', {
Expand Down
Loading

0 comments on commit cc815b6

Please sign in to comment.