Commit e1fde266 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

Make explicit that RelocInfo's target_object is always a HeapObject.

BUG=v8:6048

Change-Id: Iecca35fa73d036ca6043712e3b14bf449ff2e457
Reviewed-on: https://chromium-review.googlesource.com/449734
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43633}
parent 8150cb2c
......@@ -98,32 +98,28 @@ int RelocInfo::target_address_size() {
return kPointerSize;
}
Object* RelocInfo::target_object() {
HeapObject* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
return HeapObject::cast(
reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_)));
}
Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Handle<Object>(reinterpret_cast<Object**>(
Assembler::target_address_at(pc_, host_)));
return Handle<HeapObject>(
reinterpret_cast<HeapObject**>(Assembler::target_address_at(pc_, host_)));
}
void RelocInfo::set_target_object(Object* target,
void RelocInfo::set_target_object(HeapObject* target,
WriteBarrierMode write_barrier_mode,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Assembler::set_target_address_at(isolate_, pc_, host_,
reinterpret_cast<Address>(target),
icache_flush_mode);
if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
host() != NULL &&
target->IsHeapObject()) {
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
host(), this, HeapObject::cast(target));
if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
target);
host()->GetHeap()->RecordWriteIntoCode(host(), this, target);
}
}
......@@ -187,10 +183,9 @@ void RelocInfo::set_target_cell(Cell* cell,
}
}
Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
Handle<Code> RelocInfo::code_age_stub_handle(Assembler* origin) {
UNREACHABLE(); // This should never be reached on Arm.
return Handle<Object>();
return Handle<Code>();
}
......
......@@ -691,32 +691,28 @@ Address RelocInfo::constant_pool_entry_address() {
return Assembler::target_pointer_address_at(pc_);
}
Object* RelocInfo::target_object() {
HeapObject* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
return HeapObject::cast(
reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_)));
}
Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Handle<Object>(reinterpret_cast<Object**>(
Assembler::target_address_at(pc_, host_)));
return Handle<HeapObject>(
reinterpret_cast<HeapObject**>(Assembler::target_address_at(pc_, host_)));
}
void RelocInfo::set_target_object(Object* target,
void RelocInfo::set_target_object(HeapObject* target,
WriteBarrierMode write_barrier_mode,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Assembler::set_target_address_at(isolate_, pc_, host_,
reinterpret_cast<Address>(target),
icache_flush_mode);
if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
host() != NULL &&
target->IsHeapObject()) {
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
host(), this, HeapObject::cast(target));
if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
target);
host()->GetHeap()->RecordWriteIntoCode(host(), this, target);
}
}
......@@ -779,10 +775,9 @@ void RelocInfo::set_target_cell(Cell* cell,
static const int kNoCodeAgeSequenceLength = 5 * kInstructionSize;
static const int kCodeAgeStubEntryOffset = 3 * kInstructionSize;
Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
Handle<Code> RelocInfo::code_age_stub_handle(Assembler* origin) {
UNREACHABLE(); // This should never be reached on ARM64.
return Handle<Object>();
return Handle<Code>();
}
......
......@@ -525,10 +525,10 @@ class RelocInfo {
// this relocation applies to;
// can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
INLINE(Address target_address());
INLINE(Object* target_object());
INLINE(Handle<Object> target_object_handle(Assembler* origin));
INLINE(HeapObject* target_object());
INLINE(Handle<HeapObject> target_object_handle(Assembler* origin));
INLINE(void set_target_object(
Object* target,
HeapObject* target,
WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED));
INLINE(Address target_runtime_entry(Assembler* origin));
......@@ -541,7 +541,7 @@ class RelocInfo {
INLINE(void set_target_cell(
Cell* cell, WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED));
INLINE(Handle<Object> code_age_stub_handle(Assembler* origin));
INLINE(Handle<Code> code_age_stub_handle(Assembler* origin));
INLINE(Code* code_age_stub());
INLINE(void set_code_age_stub(
Code* stub, ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED));
......
......@@ -16,7 +16,7 @@ class Object;
class FindAndReplacePattern {
public:
FindAndReplacePattern() : count_(0) {}
void Add(Handle<Map> map_to_find, Handle<Object> obj_to_replace) {
void Add(Handle<Map> map_to_find, Handle<HeapObject> obj_to_replace) {
DCHECK(count_ < kMaxCount);
find_[count_] = map_to_find;
replace_[count_] = obj_to_replace;
......@@ -27,7 +27,7 @@ class FindAndReplacePattern {
static const int kMaxCount = 4;
int count_;
Handle<Map> find_[kMaxCount];
Handle<Object> replace_[kMaxCount];
Handle<HeapObject> replace_[kMaxCount];
friend class Code;
};
......
......@@ -315,11 +315,11 @@ class UpdateTypedSlotHelper {
static SlotCallbackResult UpdateEmbeddedPointer(RelocInfo* rinfo,
Callback callback) {
DCHECK(rinfo->rmode() == RelocInfo::EMBEDDED_OBJECT);
Object* target = rinfo->target_object();
Object* old_target = target;
SlotCallbackResult result = callback(&target);
if (target != old_target) {
rinfo->set_target_object(target);
HeapObject* old_target = rinfo->target_object();
Object* new_target = old_target;
SlotCallbackResult result = callback(&new_target);
if (new_target != old_target) {
rinfo->set_target_object(HeapObject::cast(new_target));
}
return result;
}
......
......@@ -101,20 +101,17 @@ int RelocInfo::target_address_size() {
return Assembler::kSpecialTargetSize;
}
Object* RelocInfo::target_object() {
HeapObject* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Memory::Object_at(pc_);
return HeapObject::cast(Memory::Object_at(pc_));
}
Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Memory::Object_Handle_at(pc_);
return Handle<HeapObject>::cast(Memory::Object_Handle_at(pc_));
}
void RelocInfo::set_target_object(Object* target,
void RelocInfo::set_target_object(HeapObject* target,
WriteBarrierMode write_barrier_mode,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
......@@ -122,12 +119,10 @@ void RelocInfo::set_target_object(Object* target,
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate_, pc_, sizeof(Address));
}
if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
host() != NULL &&
target->IsHeapObject()) {
if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
host()->GetHeap()->RecordWriteIntoCode(host(), this, target);
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
host(), this, HeapObject::cast(target));
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
target);
}
}
......@@ -195,11 +190,10 @@ void RelocInfo::set_target_cell(Cell* cell,
}
}
Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
Handle<Code> RelocInfo::code_age_stub_handle(Assembler* origin) {
DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
DCHECK(*pc_ == kCallOpcode);
return Memory::Object_Handle_at(pc_ + 1);
return Handle<Code>::cast(Memory::Object_Handle_at(pc_ + 1));
}
......
......@@ -197,30 +197,26 @@ void Assembler::deserialization_set_target_internal_reference_at(
}
}
Object* RelocInfo::target_object() {
HeapObject* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
return HeapObject::cast(
reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_)));
}
Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Handle<Object>(reinterpret_cast<Object**>(
Assembler::target_address_at(pc_, host_)));
return Handle<HeapObject>(
reinterpret_cast<HeapObject**>(Assembler::target_address_at(pc_, host_)));
}
void RelocInfo::set_target_object(Object* target,
void RelocInfo::set_target_object(HeapObject* target,
WriteBarrierMode write_barrier_mode,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Assembler::set_target_address_at(isolate_, pc_, host_,
reinterpret_cast<Address>(target),
icache_flush_mode);
if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
host() != NULL &&
target->IsHeapObject()) {
if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
host(), this, HeapObject::cast(target));
host()->GetHeap()->RecordWriteIntoCode(host(), this, target);
......@@ -305,10 +301,9 @@ void RelocInfo::set_target_cell(Cell* cell,
static const int kNoCodeAgeSequenceLength = 7 * Assembler::kInstrSize;
Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
Handle<Code> RelocInfo::code_age_stub_handle(Assembler* origin) {
UNREACHABLE(); // This should never be reached on Arm.
return Handle<Object>();
return Handle<Code>();
}
......
......@@ -185,21 +185,19 @@ void Assembler::deserialization_set_target_internal_reference_at(
}
}
Object* RelocInfo::target_object() {
HeapObject* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
return HeapObject::cast(
reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_)));
}
Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Handle<Object>(reinterpret_cast<Object**>(
Assembler::target_address_at(pc_, host_)));
return Handle<HeapObject>(
reinterpret_cast<HeapObject**>(Assembler::target_address_at(pc_, host_)));
}
void RelocInfo::set_target_object(Object* target,
void RelocInfo::set_target_object(HeapObject* target,
WriteBarrierMode write_barrier_mode,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
......@@ -287,10 +285,9 @@ void RelocInfo::set_target_cell(Cell* cell,
static const int kNoCodeAgeSequenceLength = 9 * Assembler::kInstrSize;
Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
Handle<Code> RelocInfo::code_age_stub_handle(Assembler* origin) {
UNREACHABLE(); // This should never be reached on Arm.
return Handle<Object>();
return Handle<Code>();
}
......
......@@ -13812,7 +13812,7 @@ void Code::InvalidateRelocation() {
void Code::InvalidateEmbeddedObjects() {
Object* undefined = GetHeap()->undefined_value();
HeapObject* undefined = GetHeap()->undefined_value();
Cell* undefined_cell = GetHeap()->undefined_cell();
int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::CELL);
......@@ -13866,7 +13866,7 @@ void Code::CopyFrom(const CodeDesc& desc) {
for (RelocIterator it(this, mode_mask); !it.done(); it.next()) {
RelocInfo::Mode mode = it.rinfo()->rmode();
if (mode == RelocInfo::EMBEDDED_OBJECT) {
Handle<Object> p = it.rinfo()->target_object_handle(origin);
Handle<HeapObject> p = it.rinfo()->target_object_handle(origin);
it.rinfo()->set_target_object(*p, UPDATE_WRITE_BARRIER,
SKIP_ICACHE_FLUSH);
} else if (mode == RelocInfo::CELL) {
......@@ -13940,16 +13940,14 @@ void Code::FindAndReplace(const FindAndReplacePattern& pattern) {
int current_pattern = 0;
for (RelocIterator it(this, mask); !it.done(); it.next()) {
RelocInfo* info = it.rinfo();
Object* object = info->target_object();
if (object->IsHeapObject()) {
if (object->IsWeakCell()) {
object = HeapObject::cast(WeakCell::cast(object)->value());
}
Map* map = HeapObject::cast(object)->map();
if (map == *pattern.find_[current_pattern]) {
info->set_target_object(*pattern.replace_[current_pattern]);
if (++current_pattern == pattern.count_) return;
}
HeapObject* object = info->target_object();
if (object->IsWeakCell()) {
object = HeapObject::cast(WeakCell::cast(object)->value());
}
Map* map = object->map();
if (map == *pattern.find_[current_pattern]) {
info->set_target_object(*pattern.replace_[current_pattern]);
if (++current_pattern == pattern.count_) return;
}
}
UNREACHABLE();
......
......@@ -239,7 +239,8 @@ bool CodeSpecialization::ApplyToWasmCode(Code* code,
Object* old = it.rinfo()->target_object();
Handle<Object>* new_obj = objects_to_relocate.Find(old);
if (new_obj) {
it.rinfo()->set_target_object(**new_obj, UPDATE_WRITE_BARRIER,
it.rinfo()->set_target_object(HeapObject::cast(**new_obj),
UPDATE_WRITE_BARRIER,
icache_flush_mode);
changed = true;
}
......
......@@ -313,7 +313,7 @@ void Assembler::deserialization_set_special_target_at(
set_target_address_at(isolate, instruction_payload, code, target);
}
Handle<Object> Assembler::code_target_object_handle_at(Address pc) {
Handle<Code> Assembler::code_target_object_handle_at(Address pc) {
return code_targets_[Memory::int32_at(pc)];
}
......@@ -369,17 +369,15 @@ int RelocInfo::target_address_size() {
}
}
Object* RelocInfo::target_object() {
HeapObject* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Memory::Object_at(pc_);
return HeapObject::cast(Memory::Object_at(pc_));
}
Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
if (rmode_ == EMBEDDED_OBJECT) {
return Memory::Object_Handle_at(pc_);
return Handle<HeapObject>::cast(Memory::Object_Handle_at(pc_));
} else {
return origin->code_target_object_handle_at(pc_);
}
......@@ -403,8 +401,7 @@ Address RelocInfo::target_internal_reference_address() {
return reinterpret_cast<Address>(pc_);
}
void RelocInfo::set_target_object(Object* target,
void RelocInfo::set_target_object(HeapObject* target,
WriteBarrierMode write_barrier_mode,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
......@@ -412,11 +409,9 @@ void RelocInfo::set_target_object(Object* target,
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate_, pc_, sizeof(Address));
}
if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
host() != NULL &&
target->IsHeapObject()) {
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
host(), this, HeapObject::cast(target));
if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
target);
host()->GetHeap()->RecordWriteIntoCode(host(), this, target);
}
}
......@@ -481,8 +476,7 @@ void RelocInfo::WipeOut() {
}
}
Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
Handle<Code> RelocInfo::code_age_stub_handle(Assembler* origin) {
DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
DCHECK(*pc_ == kCallOpcode);
return origin->code_target_object_handle_at(pc_ + 1);
......
......@@ -535,7 +535,7 @@ class Assembler : public AssemblerBase {
}
}
inline Handle<Object> code_target_object_handle_at(Address pc);
inline Handle<Code> code_target_object_handle_at(Address pc);
inline Address runtime_entry_at(Address pc);
// Number of bytes taken up by the branch target in the code.
static const int kSpecialTargetSize = 4; // Use 32-bit displacement.
......
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