Skip to content

Commit 9302db4

Browse files
jakobkummerowCommit Bot
authored andcommitted
[ubsan] Port HeapObject to the new design
Merging the temporary HeapObjectPtr back into HeapObject. Bug: v8:3770 Change-Id: I5bcd23ca2f5ba862cf5b52955dca143e531c637b Reviewed-on: https://chromium-review.googlesource.com/c/1386492 Commit-Queue: Jakob Kummerow <[email protected]> Reviewed-by: Clemens Hammacher <[email protected]> Reviewed-by: Ulan Degenbaev <[email protected]> Reviewed-by: Michael Stanton <[email protected]> Reviewed-by: Jakob Gruber <[email protected]> Cr-Commit-Position: refs/heads/master@{#58410}
1 parent 42b4180 commit 9302db4

File tree

211 files changed

+2141
-2489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+2141
-2489
lines changed

include/v8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ class V8_EXPORT HandleScope {
881881
template<class F> friend class Local;
882882

883883
// Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
884-
// a HeapObject* in their shortcuts.
884+
// a HeapObject in their shortcuts.
885885
friend class Object;
886886
friend class Context;
887887
};

src/address-map.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "src/heap/heap.h"
77
#include "src/isolate.h"
88
#include "src/objects-inl.h"
9+
#include "src/objects/heap-object-inl.h"
910

1011
namespace v8 {
1112
namespace internal {
@@ -23,7 +24,7 @@ RootIndexMap::RootIndexMap(Isolate* isolate) {
2324
// Since we map the raw address of an root item to its root list index, the
2425
// raw address must be constant, i.e. the object must be immovable.
2526
if (RootsTable::IsImmortalImmovable(root_index)) {
26-
HeapObject* heap_object = HeapObject::cast(root);
27+
HeapObject heap_object = HeapObject::cast(root);
2728
Maybe<uint32_t> maybe_index = map_->Get(heap_object);
2829
uint32_t index = static_cast<uint32_t>(root_index);
2930
if (maybe_index.IsJust()) {
@@ -37,5 +38,9 @@ RootIndexMap::RootIndexMap(Isolate* isolate) {
3738
isolate->set_root_index_map(map_);
3839
}
3940

41+
bool RootIndexMap::Lookup(Address obj, RootIndex* out_root_list) const {
42+
return Lookup(HeapObject::cast(ObjectPtr(obj)), out_root_list);
43+
}
44+
4045
} // namespace internal
4146
} // namespace v8

src/address-map.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "include/v8.h"
99
#include "src/assert-scope.h"
1010
#include "src/base/hashmap.h"
11-
#include "src/objects.h"
11+
#include "src/objects/heap-object.h"
1212

1313
namespace v8 {
1414
namespace internal {
@@ -44,30 +44,28 @@ inline uintptr_t PointerToIndexHashMap<Address>::Key(Address value) {
4444
return static_cast<uintptr_t>(value);
4545
}
4646

47-
template <typename Type>
48-
inline uintptr_t PointerToIndexHashMap<Type>::Key(Type value) {
49-
return reinterpret_cast<uintptr_t>(value);
47+
template <>
48+
inline uintptr_t PointerToIndexHashMap<HeapObject>::Key(HeapObject value) {
49+
return value.ptr();
5050
}
5151

5252
class AddressToIndexHashMap : public PointerToIndexHashMap<Address> {};
53-
class HeapObjectToIndexHashMap : public PointerToIndexHashMap<HeapObject*> {};
53+
class HeapObjectToIndexHashMap : public PointerToIndexHashMap<HeapObject> {};
5454

5555
class RootIndexMap {
5656
public:
5757
explicit RootIndexMap(Isolate* isolate);
5858

5959
// Returns true on successful lookup and sets *|out_root_list|.
60-
bool Lookup(HeapObject* obj, RootIndex* out_root_list) const {
60+
bool Lookup(HeapObject obj, RootIndex* out_root_list) const {
6161
Maybe<uint32_t> maybe_index = map_->Get(obj);
6262
if (maybe_index.IsJust()) {
6363
*out_root_list = static_cast<RootIndex>(maybe_index.FromJust());
6464
return true;
6565
}
6666
return false;
6767
}
68-
bool Lookup(Address obj, RootIndex* out_root_list) {
69-
return Lookup(reinterpret_cast<HeapObject*>(obj), out_root_list);
70-
}
68+
bool Lookup(Address obj, RootIndex* out_root_list) const;
7169

7270
private:
7371
HeapObjectToIndexHashMap* map_;

src/api-arguments.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PropertyCallbackArguments::PropertyCallbackArguments(Isolate* isolate,
2323

2424
// Here the hole is set as default value.
2525
// It cannot escape into js as it's removed in Call below.
26-
HeapObject* the_hole = ReadOnlyRoots(isolate).the_hole_value();
26+
HeapObject the_hole = ReadOnlyRoots(isolate).the_hole_value();
2727
slot_at(T::kReturnValueDefaultValueIndex).store(the_hole);
2828
slot_at(T::kReturnValueIndex).store(the_hole);
2929
DCHECK((*slot_at(T::kHolderIndex))->IsHeapObject());
@@ -32,16 +32,16 @@ PropertyCallbackArguments::PropertyCallbackArguments(Isolate* isolate,
3232

3333
FunctionCallbackArguments::FunctionCallbackArguments(
3434
internal::Isolate* isolate, internal::Object* data,
35-
internal::HeapObject* callee, internal::Object* holder,
36-
internal::HeapObject* new_target, internal::Address* argv, int argc)
35+
internal::HeapObject callee, internal::Object* holder,
36+
internal::HeapObject new_target, internal::Address* argv, int argc)
3737
: Super(isolate), argv_(argv), argc_(argc) {
3838
slot_at(T::kDataIndex).store(data);
3939
slot_at(T::kHolderIndex).store(holder);
4040
slot_at(T::kNewTargetIndex).store(new_target);
4141
slot_at(T::kIsolateIndex).store(reinterpret_cast<internal::Object*>(isolate));
4242
// Here the hole is set as default value.
4343
// It cannot escape into js as it's remove in Call below.
44-
HeapObject* the_hole = ReadOnlyRoots(isolate).the_hole_value();
44+
HeapObject the_hole = ReadOnlyRoots(isolate).the_hole_value();
4545
slot_at(T::kReturnValueDefaultValueIndex).store(the_hole);
4646
slot_at(T::kReturnValueIndex).store(the_hole);
4747
DCHECK((*slot_at(T::kHolderIndex))->IsHeapObject());

src/api-arguments.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ class FunctionCallbackArguments
161161
static const int kNewTargetIndex = T::kNewTargetIndex;
162162

163163
FunctionCallbackArguments(internal::Isolate* isolate, internal::Object* data,
164-
internal::HeapObject* callee,
164+
internal::HeapObject callee,
165165
internal::Object* holder,
166-
internal::HeapObject* new_target,
166+
internal::HeapObject new_target,
167167
internal::Address* argv, int argc);
168168

169169
/*

src/api.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ StartupData SnapshotCreator::CreateBlob(
762762

763763
{ // Heap allocation is disallowed within this scope.
764764
i::HeapIterator heap_iterator(isolate->heap());
765-
while (i::HeapObject* current_obj = heap_iterator.next()) {
765+
for (i::HeapObject current_obj = heap_iterator.next();
766+
!current_obj.is_null(); current_obj = heap_iterator.next()) {
766767
if (current_obj->IsSharedFunctionInfo()) {
767768
i::SharedFunctionInfo shared =
768769
i::SharedFunctionInfo::cast(current_obj);
@@ -807,7 +808,8 @@ StartupData SnapshotCreator::CreateBlob(
807808
CHECK(handle_checker.CheckGlobalAndEternalHandles());
808809

809810
i::HeapIterator heap_iterator(isolate->heap());
810-
while (i::HeapObject* current_obj = heap_iterator.next()) {
811+
for (i::HeapObject current_obj = heap_iterator.next(); !current_obj.is_null();
812+
current_obj = heap_iterator.next()) {
811813
if (current_obj->IsJSFunction()) {
812814
i::JSFunction fun = i::JSFunction::cast(current_obj);
813815

@@ -1108,7 +1110,8 @@ i::Address* HandleScope::CreateHandle(i::Isolate* isolate, i::Address value) {
11081110

11091111
i::Address* HandleScope::CreateHandle(
11101112
i::NeverReadOnlySpaceObject* writable_object, i::Address value) {
1111-
DCHECK(reinterpret_cast<i::HeapObject*>(writable_object)->IsHeapObject());
1113+
DCHECK(i::ObjectPtr(reinterpret_cast<i::Address>(writable_object))
1114+
.IsHeapObject());
11121115
return i::HandleScope::CreateHandle(writable_object->GetIsolate(), value);
11131116
}
11141117

@@ -8630,8 +8633,8 @@ void Isolate::LowMemoryNotification() {
86308633
}
86318634
{
86328635
i::HeapIterator iterator(isolate->heap());
8633-
i::HeapObject* obj;
8634-
while ((obj = iterator.next()) != nullptr) {
8636+
for (i::HeapObject obj = iterator.next(); !obj.is_null();
8637+
obj = iterator.next()) {
86358638
if (obj->IsAbstractCode()) {
86368639
i::AbstractCode::cast(obj)->DropStackFrameCache();
86378640
}

src/arm/assembler-arm-inl.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ int RelocInfo::target_address_size() {
9696
return kPointerSize;
9797
}
9898

99-
HeapObject* RelocInfo::target_object() {
99+
HeapObject RelocInfo::target_object() {
100100
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
101-
return HeapObject::cast(reinterpret_cast<Object*>(
102-
Assembler::target_address_at(pc_, constant_pool_)));
101+
return HeapObject::cast(
102+
ObjectPtr(Assembler::target_address_at(pc_, constant_pool_)));
103103
}
104104

105105
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
@@ -111,19 +111,17 @@ Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
111111
return origin->relative_code_target_object_handle_at(pc_);
112112
}
113113

114-
void RelocInfo::set_target_object(Heap* heap, HeapObject* target,
114+
void RelocInfo::set_target_object(Heap* heap, HeapObject target,
115115
WriteBarrierMode write_barrier_mode,
116116
ICacheFlushMode icache_flush_mode) {
117117
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
118-
Assembler::set_target_address_at(pc_, constant_pool_,
119-
reinterpret_cast<Address>(target),
118+
Assembler::set_target_address_at(pc_, constant_pool_, target->ptr(),
120119
icache_flush_mode);
121-
if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != nullptr) {
120+
if (write_barrier_mode == UPDATE_WRITE_BARRIER && !host().is_null()) {
122121
WriteBarrierForCode(host(), this, target);
123122
}
124123
}
125124

126-
127125
Address RelocInfo::target_external_reference() {
128126
DCHECK(rmode_ == EXTERNAL_REFERENCE);
129127
return Assembler::target_address_at(pc_, constant_pool_);

src/arm/simulator-arm.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,12 @@ void ArmDebugger::Debug() {
328328
while (cur < end) {
329329
PrintF(" 0x%08" V8PRIxPTR ": 0x%08x %10d",
330330
reinterpret_cast<intptr_t>(cur), *cur, *cur);
331-
HeapObject* obj = reinterpret_cast<HeapObject*>(*cur);
332-
int value = *cur;
331+
ObjectPtr obj(*cur);
333332
Heap* current_heap = sim_->isolate_->heap();
334-
if (((value & 1) == 0) || current_heap->Contains(obj)) {
333+
if (obj.IsSmi() || current_heap->Contains(HeapObject::cast(obj))) {
335334
PrintF(" (");
336-
if ((value & 1) == 0) {
337-
PrintF("smi %d", value / 2);
335+
if (obj.IsSmi()) {
336+
PrintF("smi %d", Smi::ToInt(obj));
338337
} else {
339338
obj->ShortPrint();
340339
}

src/arm64/assembler-arm64-inl.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,10 @@ Address RelocInfo::constant_pool_entry_address() {
685685
return Assembler::target_pointer_address_at(pc_);
686686
}
687687

688-
HeapObject* RelocInfo::target_object() {
688+
HeapObject RelocInfo::target_object() {
689689
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
690-
return HeapObject::cast(reinterpret_cast<Object*>(
691-
Assembler::target_address_at(pc_, constant_pool_)));
690+
return HeapObject::cast(
691+
ObjectPtr(Assembler::target_address_at(pc_, constant_pool_)));
692692
}
693693

694694
Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
@@ -701,19 +701,17 @@ Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
701701
}
702702
}
703703

704-
void RelocInfo::set_target_object(Heap* heap, HeapObject* target,
704+
void RelocInfo::set_target_object(Heap* heap, HeapObject target,
705705
WriteBarrierMode write_barrier_mode,
706706
ICacheFlushMode icache_flush_mode) {
707707
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
708-
Assembler::set_target_address_at(pc_, constant_pool_,
709-
reinterpret_cast<Address>(target),
708+
Assembler::set_target_address_at(pc_, constant_pool_, target->ptr(),
710709
icache_flush_mode);
711-
if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != nullptr) {
710+
if (write_barrier_mode == UPDATE_WRITE_BARRIER && !host().is_null()) {
712711
WriteBarrierForCode(host(), this, target);
713712
}
714713
}
715714

716-
717715
Address RelocInfo::target_external_reference() {
718716
DCHECK(rmode_ == EXTERNAL_REFERENCE);
719717
return Assembler::target_address_at(pc_, constant_pool_);

src/arm64/simulator-arm64.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,15 +3291,12 @@ void Simulator::Debug() {
32913291
while (cur < end) {
32923292
PrintF(" 0x%016" PRIx64 ": 0x%016" PRIx64 " %10" PRId64,
32933293
reinterpret_cast<uint64_t>(cur), *cur, *cur);
3294-
HeapObject* obj = reinterpret_cast<HeapObject*>(*cur);
3295-
int64_t value = *cur;
3294+
ObjectPtr obj(*cur);
32963295
Heap* current_heap = isolate_->heap();
3297-
if (((value & 1) == 0) || current_heap->Contains(obj)) {
3296+
if (obj.IsSmi() || current_heap->Contains(HeapObject::cast(obj))) {
32983297
PrintF(" (");
3299-
if ((value & kSmiTagMask) == 0) {
3300-
DCHECK(SmiValuesAre32Bits() || SmiValuesAre31Bits());
3301-
int32_t untagged = (value >> kSmiShift) & 0xFFFFFFFF;
3302-
PrintF("smi %" PRId32, untagged);
3298+
if (obj.IsSmi()) {
3299+
PrintF("smi %" PRId32, Smi::ToInt(obj));
33033300
} else {
33043301
obj->ShortPrint();
33053302
}

0 commit comments

Comments
 (0)