Commit 08941c01 authored by rmcilroy@chromium.org's avatar rmcilroy@chromium.org

Refactor FrameAndConstantPoolScope and ConstantPoolUnavailableScope to be architecture independent

Move the FrameAndConstantPoolScope and ConstantPoolUnavailableScope out of the arm architecture directory to enable them to be used on all architectures.

R=rmcilroy@chromium.org

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

Patch from André Baixo <baixo@google.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24565 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 403dc885
......@@ -472,7 +472,6 @@ Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size)
first_const_pool_32_use_ = -1;
first_const_pool_64_use_ = -1;
last_bound_pos_ = 0;
constant_pool_available_ = !FLAG_enable_ool_constant_pool;
ClearRecordedAstId();
}
......@@ -1056,7 +1055,8 @@ bool Operand::must_output_reloc_info(const Assembler* assembler) const {
static bool use_mov_immediate_load(const Operand& x,
const Assembler* assembler) {
if (assembler != NULL && !assembler->is_constant_pool_available()) {
if (FLAG_enable_ool_constant_pool && assembler != NULL &&
!assembler->is_ool_constant_pool_available()) {
return true;
} else if (CpuFeatures::IsSupported(MOVW_MOVT_IMMEDIATE_LOADS) &&
(assembler == NULL || !assembler->predictable_code_size())) {
......@@ -1137,7 +1137,7 @@ void Assembler::move_32_bit_immediate(Register rd,
mov(rd, target, LeaveCC, cond);
}
} else {
DCHECK(is_constant_pool_available());
DCHECK(!FLAG_enable_ool_constant_pool || is_ool_constant_pool_available());
ConstantPoolArray::LayoutSection section = ConstantPoolAddEntry(rinfo);
if (section == ConstantPoolArray::EXTENDED_SECTION) {
DCHECK(FLAG_enable_ool_constant_pool);
......@@ -2492,7 +2492,7 @@ void Assembler::vmov(const DwVfpRegister dst,
int vd, d;
dst.split_code(&vd, &d);
emit(al | 0x1D*B23 | d*B22 | 0x3*B20 | vd*B12 | 0x5*B9 | B8 | enc);
} else if (FLAG_enable_vldr_imm && is_constant_pool_available()) {
} else if (FLAG_enable_vldr_imm && is_ool_constant_pool_available()) {
// TODO(jfb) Temporarily turned off until we have constant blinding or
// some equivalent mitigation: an attacker can otherwise control
// generated data which also happens to be executable, a Very Bad
......
......@@ -1488,8 +1488,6 @@ class Assembler : public AssemblerBase {
// Generate the constant pool for the generated code.
void PopulateConstantPool(ConstantPoolArray* constant_pool);
bool is_constant_pool_available() const { return constant_pool_available_; }
bool use_extended_constant_pool() const {
return constant_pool_builder_.current_section() ==
ConstantPoolArray::EXTENDED_SECTION;
......@@ -1549,10 +1547,6 @@ class Assembler : public AssemblerBase {
(pc_offset() < no_const_pool_before_);
}
void set_constant_pool_available(bool available) {
constant_pool_available_ = available;
}
private:
int next_buffer_check_; // pc offset of next buffer check
......@@ -1615,10 +1609,6 @@ class Assembler : public AssemblerBase {
// The bound position, before this we cannot do instruction elimination.
int last_bound_pos_;
// Indicates whether the constant pool can be accessed, which is only possible
// if the pp register points to the current code object's constant pool.
bool constant_pool_available_;
// Code emission
inline void CheckBuffer();
void GrowBuffer();
......@@ -1654,9 +1644,6 @@ class Assembler : public AssemblerBase {
friend class RelocInfo;
friend class CodePatcher;
friend class BlockConstPoolScope;
friend class FrameAndConstantPoolScope;
friend class ConstantPoolUnavailableScope;
PositionsRecorder positions_recorder_;
friend class PositionsRecorder;
friend class EnsureSpace;
......
......@@ -967,7 +967,7 @@ void MacroAssembler::StubPrologue() {
add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
if (FLAG_enable_ool_constant_pool) {
LoadConstantPoolPointerRegister();
set_constant_pool_available(true);
set_ool_constant_pool_available(true);
}
}
......@@ -992,16 +992,16 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
}
if (FLAG_enable_ool_constant_pool) {
LoadConstantPoolPointerRegister();
set_constant_pool_available(true);
set_ool_constant_pool_available(true);
}
}
void MacroAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool) {
bool load_constant_pool_pointer_reg) {
// r0-r3: preserved
PushFixedFrame();
if (FLAG_enable_ool_constant_pool && load_constant_pool) {
if (FLAG_enable_ool_constant_pool && load_constant_pool_pointer_reg) {
LoadConstantPoolPointerRegister();
}
mov(ip, Operand(Smi::FromInt(type)));
......
......@@ -1401,7 +1401,8 @@ class MacroAssembler: public Assembler {
}
// Activation support.
void EnterFrame(StackFrame::Type type, bool load_constant_pool = false);
void EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg = false);
// Returns the pc offset at which the frame ends.
int LeaveFrame(StackFrame::Type type);
......@@ -1530,71 +1531,6 @@ class CodePatcher {
};
class FrameAndConstantPoolScope {
public:
FrameAndConstantPoolScope(MacroAssembler* masm, StackFrame::Type type)
: masm_(masm),
type_(type),
old_has_frame_(masm->has_frame()),
old_constant_pool_available_(masm->is_constant_pool_available()) {
// We only want to enable constant pool access for non-manual frame scopes
// to ensure the constant pool pointer is valid throughout the scope.
DCHECK(type_ != StackFrame::MANUAL && type_ != StackFrame::NONE);
masm->set_has_frame(true);
masm->set_constant_pool_available(true);
masm->EnterFrame(type, !old_constant_pool_available_);
}
~FrameAndConstantPoolScope() {
masm_->LeaveFrame(type_);
masm_->set_has_frame(old_has_frame_);
masm_->set_constant_pool_available(old_constant_pool_available_);
}
// Normally we generate the leave-frame code when this object goes
// out of scope. Sometimes we may need to generate the code somewhere else
// in addition. Calling this will achieve that, but the object stays in
// scope, the MacroAssembler is still marked as being in a frame scope, and
// the code will be generated again when it goes out of scope.
void GenerateLeaveFrame() {
DCHECK(type_ != StackFrame::MANUAL && type_ != StackFrame::NONE);
masm_->LeaveFrame(type_);
}
private:
MacroAssembler* masm_;
StackFrame::Type type_;
bool old_has_frame_;
bool old_constant_pool_available_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FrameAndConstantPoolScope);
};
// Class for scoping the the unavailability of constant pool access.
class ConstantPoolUnavailableScope {
public:
explicit ConstantPoolUnavailableScope(MacroAssembler* masm)
: masm_(masm),
old_constant_pool_available_(masm->is_constant_pool_available()) {
if (FLAG_enable_ool_constant_pool) {
masm_->set_constant_pool_available(false);
}
}
~ConstantPoolUnavailableScope() {
if (FLAG_enable_ool_constant_pool) {
masm_->set_constant_pool_available(old_constant_pool_available_);
}
}
private:
MacroAssembler* masm_;
int old_constant_pool_available_;
DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolUnavailableScope);
};
// -----------------------------------------------------------------------------
// Static helper functions.
......
......@@ -3064,6 +3064,13 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
}
void MacroAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
// Out-of-line constant pool not implemented on arm64.
UNREACHABLE();
}
void MacroAssembler::EnterFrame(StackFrame::Type type) {
DCHECK(jssp.Is(StackPointer()));
UseScratchRegisterScope temps(this);
......
......@@ -1627,6 +1627,7 @@ class MacroAssembler : public Assembler {
// Activation support.
void EnterFrame(StackFrame::Type type);
void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
void LeaveFrame(StackFrame::Type type);
// Returns map with validated enum cache in object register.
......
......@@ -131,7 +131,8 @@ AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size)
emit_debug_code_(FLAG_debug_code),
predictable_code_size_(false),
// We may use the assembler without an isolate.
serializer_enabled_(isolate && isolate->serializer_enabled()) {
serializer_enabled_(isolate && isolate->serializer_enabled()),
ool_constant_pool_available_(false) {
if (FLAG_mask_constants_with_cookie && isolate != NULL) {
jit_cookie_ = isolate->random_number_generator()->NextInt();
}
......
......@@ -79,6 +79,16 @@ class AssemblerBase: public Malloced {
return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0;
}
bool is_ool_constant_pool_available() const {
if (FLAG_enable_ool_constant_pool) {
return ool_constant_pool_available_;
} else {
// Out-of-line constant pool not supported on this architecture.
UNREACHABLE();
return false;
}
}
// Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
// cross-snapshotting.
static void QuietNaN(HeapObject* nan) { }
......@@ -98,6 +108,15 @@ class AssemblerBase: public Malloced {
int buffer_size_;
bool own_buffer_;
void set_ool_constant_pool_available(bool available) {
if (FLAG_enable_ool_constant_pool) {
ool_constant_pool_available_ = available;
} else {
// Out-of-line constant pool not supported on this architecture.
UNREACHABLE();
}
}
// The program counter, which points into the buffer above and moves forward.
byte* pc_;
......@@ -108,6 +127,14 @@ class AssemblerBase: public Malloced {
bool emit_debug_code_;
bool predictable_code_size_;
bool serializer_enabled_;
// Indicates whether the constant pool can be accessed, which is only possible
// if the pp register points to the current code object's constant pool.
bool ool_constant_pool_available_;
// Constant pool.
friend class FrameAndConstantPoolScope;
friend class ConstantPoolUnavailableScope;
};
......
......@@ -901,7 +901,7 @@ DEFINE_INT(dump_allocations_digest_at_alloc, 0,
#undef FLAG
#define FLAG FLAG_READONLY
// assembler-arm.h
// assembler.h
DEFINE_BOOL(enable_ool_constant_pool, V8_OOL_CONSTANT_POOL,
"enable use of out-of-line constant pools (ARM only)")
......
......@@ -896,6 +896,13 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
}
void MacroAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
// Out-of-line constant pool not implemented on ia32.
UNREACHABLE();
}
void MacroAssembler::EnterFrame(StackFrame::Type type) {
push(ebp);
mov(ebp, esp);
......
......@@ -941,6 +941,7 @@ class MacroAssembler: public Assembler {
// Activation support.
void EnterFrame(StackFrame::Type type);
void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
void LeaveFrame(StackFrame::Type type);
// Expects object in eax and returns map with validated enum cache
......
......@@ -124,6 +124,74 @@ class FrameScope {
bool old_has_frame_;
};
class FrameAndConstantPoolScope {
public:
FrameAndConstantPoolScope(MacroAssembler* masm, StackFrame::Type type)
: masm_(masm),
type_(type),
old_has_frame_(masm->has_frame()),
old_constant_pool_available_(FLAG_enable_ool_constant_pool &&
masm->is_ool_constant_pool_available()) {
masm->set_has_frame(true);
if (FLAG_enable_ool_constant_pool) {
masm->set_ool_constant_pool_available(true);
}
if (type_ != StackFrame::MANUAL && type_ != StackFrame::NONE) {
masm->EnterFrame(type, !old_constant_pool_available_);
}
}
~FrameAndConstantPoolScope() {
masm_->LeaveFrame(type_);
masm_->set_has_frame(old_has_frame_);
if (FLAG_enable_ool_constant_pool) {
masm_->set_ool_constant_pool_available(old_constant_pool_available_);
}
}
// Normally we generate the leave-frame code when this object goes
// out of scope. Sometimes we may need to generate the code somewhere else
// in addition. Calling this will achieve that, but the object stays in
// scope, the MacroAssembler is still marked as being in a frame scope, and
// the code will be generated again when it goes out of scope.
void GenerateLeaveFrame() {
DCHECK(type_ != StackFrame::MANUAL && type_ != StackFrame::NONE);
masm_->LeaveFrame(type_);
}
private:
MacroAssembler* masm_;
StackFrame::Type type_;
bool old_has_frame_;
bool old_constant_pool_available_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FrameAndConstantPoolScope);
};
// Class for scoping the the unavailability of constant pool access.
class ConstantPoolUnavailableScope {
public:
explicit ConstantPoolUnavailableScope(MacroAssembler* masm)
: masm_(masm),
old_constant_pool_available_(FLAG_enable_ool_constant_pool &&
masm->is_ool_constant_pool_available()) {
if (FLAG_enable_ool_constant_pool) {
masm_->set_ool_constant_pool_available(false);
}
}
~ConstantPoolUnavailableScope() {
if (FLAG_enable_ool_constant_pool) {
masm_->set_ool_constant_pool_available(old_constant_pool_available_);
}
}
private:
MacroAssembler* masm_;
int old_constant_pool_available_;
DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolUnavailableScope);
};
class AllowExternalCallThatCantCauseGC: public FrameScope {
public:
......
......@@ -5006,6 +5006,13 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
}
void MacroAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
// Out-of-line constant pool not implemented on mips.
UNREACHABLE();
}
void MacroAssembler::EnterFrame(StackFrame::Type type) {
addiu(sp, sp, -5 * kPointerSize);
li(t8, Operand(Smi::FromInt(type)));
......
......@@ -1563,6 +1563,7 @@ const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
// Activation support.
void EnterFrame(StackFrame::Type type);
void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
void LeaveFrame(StackFrame::Type type);
// Patch the relocated value (lui/ori pair).
......
......@@ -4779,6 +4779,13 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
}
void MacroAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
// Out-of-line constant pool not implemented on mips64.
UNREACHABLE();
}
void MacroAssembler::EnterFrame(StackFrame::Type type) {
daddiu(sp, sp, -5 * kPointerSize);
li(t8, Operand(Smi::FromInt(type)));
......
......@@ -1617,6 +1617,7 @@ const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
// Activation support.
void EnterFrame(StackFrame::Type type);
void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
void LeaveFrame(StackFrame::Type type);
// Patch the relocated value (lui/ori pair).
......
......@@ -3984,6 +3984,13 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
}
void MacroAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
// Out-of-line constant pool not implemented on x64.
UNREACHABLE();
}
void MacroAssembler::EnterFrame(StackFrame::Type type) {
pushq(rbp);
movp(rbp, rsp);
......
......@@ -1438,6 +1438,7 @@ class MacroAssembler: public Assembler {
// Activation support.
void EnterFrame(StackFrame::Type type);
void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
void LeaveFrame(StackFrame::Type type);
// Expects object in rax and returns map with validated enum cache
......
......@@ -860,6 +860,13 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
}
void MacroAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
// Out-of-line constant pool not implemented on x87.
UNREACHABLE();
}
void MacroAssembler::EnterFrame(StackFrame::Type type) {
push(ebp);
mov(ebp, esp);
......
......@@ -906,6 +906,7 @@ class MacroAssembler: public Assembler {
// Activation support.
void EnterFrame(StackFrame::Type type);
void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
void LeaveFrame(StackFrame::Type type);
// Expects object in eax and returns map with validated enum cache
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment