Commit 1140f202 authored by Maciej Goszczycki's avatar Maciej Goszczycki Committed by Commit Bot

Make Heap::InReadOnlySpace static

This enables things like simple DCHECKs in functions that do not have
access to isolate or heap.

Change-Id: I7962c28f0c6a4928ee880f1373501f29e45ae1f8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1517886Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Commit-Queue: Maciej Goszczycki <goszczycki@google.com>
Cr-Commit-Position: refs/heads/master@{#60222}
parent e5f01ba1
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "src/heap/heap-inl.h" #include "src/heap/heap-inl.h"
#include "src/heap/incremental-marking.h" #include "src/heap/incremental-marking.h"
#include "src/heap/mark-compact-inl.h" #include "src/heap/mark-compact-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/ic/handler-configuration-inl.h" #include "src/ic/handler-configuration-inl.h"
#include "src/interpreter/interpreter.h" #include "src/interpreter/interpreter.h"
#include "src/isolate-inl.h" #include "src/isolate-inl.h"
...@@ -1980,7 +1981,7 @@ Map Factory::InitializeMap(Map map, InstanceType type, int instance_size, ...@@ -1980,7 +1981,7 @@ Map Factory::InitializeMap(Map map, InstanceType type, int instance_size,
map->set_constructor_or_backpointer(*null_value(), SKIP_WRITE_BARRIER); map->set_constructor_or_backpointer(*null_value(), SKIP_WRITE_BARRIER);
map->set_instance_size(instance_size); map->set_instance_size(instance_size);
if (map->IsJSObjectMap()) { if (map->IsJSObjectMap()) {
DCHECK(!isolate()->heap()->InReadOnlySpace(map)); DCHECK(!ReadOnlyHeap::Contains(map));
map->SetInObjectPropertiesStartInWords(instance_size / kTaggedSize - map->SetInObjectPropertiesStartInWords(instance_size / kTaggedSize -
inobject_properties); inobject_properties);
DCHECK_EQ(map->GetInObjectProperties(), inobject_properties); DCHECK_EQ(map->GetInObjectProperties(), inobject_properties);
......
...@@ -376,10 +376,6 @@ bool Heap::InToPage(HeapObject heap_object) { ...@@ -376,10 +376,6 @@ bool Heap::InToPage(HeapObject heap_object) {
bool Heap::InOldSpace(Object object) { return old_space_->Contains(object); } bool Heap::InOldSpace(Object object) { return old_space_->Contains(object); }
bool Heap::InReadOnlySpace(Object object) {
return read_only_space_->Contains(object);
}
// static // static
Heap* Heap::FromWritableHeapObject(const HeapObject obj) { Heap* Heap::FromWritableHeapObject(const HeapObject obj) {
MemoryChunk* chunk = MemoryChunk::FromHeapObject(obj); MemoryChunk* chunk = MemoryChunk::FromHeapObject(obj);
......
...@@ -3640,14 +3640,14 @@ class VerifyReadOnlyPointersVisitor : public VerifyPointersVisitor { ...@@ -3640,14 +3640,14 @@ class VerifyReadOnlyPointersVisitor : public VerifyPointersVisitor {
void VerifyPointers(HeapObject host, MaybeObjectSlot start, void VerifyPointers(HeapObject host, MaybeObjectSlot start,
MaybeObjectSlot end) override { MaybeObjectSlot end) override {
if (!host.is_null()) { if (!host.is_null()) {
CHECK(heap_->InReadOnlySpace(host->map())); CHECK(ReadOnlyHeap::Contains(host->map()));
} }
VerifyPointersVisitor::VerifyPointers(host, start, end); VerifyPointersVisitor::VerifyPointers(host, start, end);
for (MaybeObjectSlot current = start; current < end; ++current) { for (MaybeObjectSlot current = start; current < end; ++current) {
HeapObject heap_object; HeapObject heap_object;
if ((*current)->GetHeapObject(&heap_object)) { if ((*current)->GetHeapObject(&heap_object)) {
CHECK(heap_->InReadOnlySpace(heap_object)); CHECK(ReadOnlyHeap::Contains(heap_object));
} }
} }
} }
...@@ -3780,7 +3780,7 @@ void CollectSlots(MemoryChunk* chunk, Address start, Address end, ...@@ -3780,7 +3780,7 @@ void CollectSlots(MemoryChunk* chunk, Address start, Address end,
void Heap::VerifyRememberedSetFor(HeapObject object) { void Heap::VerifyRememberedSetFor(HeapObject object) {
MemoryChunk* chunk = MemoryChunk::FromHeapObject(object); MemoryChunk* chunk = MemoryChunk::FromHeapObject(object);
DCHECK_IMPLIES(chunk->mutex() == nullptr, InReadOnlySpace(object)); DCHECK_IMPLIES(chunk->mutex() == nullptr, ReadOnlyHeap::Contains(object));
// In RO_SPACE chunk->mutex() may be nullptr, so just ignore it. // In RO_SPACE chunk->mutex() may be nullptr, so just ignore it.
base::LockGuard<base::Mutex, base::NullBehavior::kIgnoreIfNull> lock_guard( base::LockGuard<base::Mutex, base::NullBehavior::kIgnoreIfNull> lock_guard(
chunk->mutex()); chunk->mutex());
......
...@@ -929,9 +929,6 @@ class Heap { ...@@ -929,9 +929,6 @@ class Heap {
// Returns whether the object resides in old space. // Returns whether the object resides in old space.
inline bool InOldSpace(Object object); inline bool InOldSpace(Object object);
// Returns whether the object resides in read-only space.
inline bool InReadOnlySpace(Object object);
// Checks whether an address/object in the heap (including auxiliary // Checks whether an address/object in the heap (including auxiliary
// area and unused area). // area and unused area).
bool Contains(HeapObject value); bool Contains(HeapObject value);
......
...@@ -26,5 +26,10 @@ void ReadOnlyHeap::OnHeapTearDown() { ...@@ -26,5 +26,10 @@ void ReadOnlyHeap::OnHeapTearDown() {
delete this; delete this;
} }
// static
bool ReadOnlyHeap::Contains(Object object) {
return Page::FromAddress(object.ptr())->owner()->identity() == RO_SPACE;
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/objects.h"
#include "src/roots.h" #include "src/roots.h"
#include "src/snapshot/read-only-deserializer.h" #include "src/snapshot/read-only-deserializer.h"
...@@ -32,6 +33,9 @@ class ReadOnlyHeap { ...@@ -32,6 +33,9 @@ class ReadOnlyHeap {
// called. // called.
void OnHeapTearDown(); void OnHeapTearDown();
// Returns whether the object resides in the read-only space.
static bool Contains(Object object);
std::vector<Object>* read_only_object_cache() { std::vector<Object>* read_only_object_cache() {
return &read_only_object_cache_; return &read_only_object_cache_;
} }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "src/function-kind.h" #include "src/function-kind.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/heap/heap-inl.h" #include "src/heap/heap-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/ic/ic.h" #include "src/ic/ic.h"
#include "src/identity-map.h" #include "src/identity-map.h"
#include "src/isolate-inl.h" #include "src/isolate-inl.h"
...@@ -2360,8 +2361,7 @@ bool HeapObject::CanBeRehashed() const { ...@@ -2360,8 +2361,7 @@ bool HeapObject::CanBeRehashed() const {
return false; return false;
} }
void HeapObject::RehashBasedOnMap(Heap* heap) { void HeapObject::RehashBasedOnMap(ReadOnlyRoots roots) {
ReadOnlyRoots roots(heap);
switch (map()->instance_type()) { switch (map()->instance_type()) {
case HASH_TABLE_TYPE: case HASH_TABLE_TYPE:
UNREACHABLE(); UNREACHABLE();
...@@ -2400,7 +2400,7 @@ void HeapObject::RehashBasedOnMap(Heap* heap) { ...@@ -2400,7 +2400,7 @@ void HeapObject::RehashBasedOnMap(Heap* heap) {
case ONE_BYTE_INTERNALIZED_STRING_TYPE: case ONE_BYTE_INTERNALIZED_STRING_TYPE:
case INTERNALIZED_STRING_TYPE: case INTERNALIZED_STRING_TYPE:
// Rare case, rehash read-only space strings before they are sealed. // Rare case, rehash read-only space strings before they are sealed.
DCHECK(heap->InReadOnlySpace(*this)); DCHECK(ReadOnlyHeap::Contains(*this));
String::cast(*this)->Hash(); String::cast(*this)->Hash();
break; break;
default: default:
......
...@@ -175,7 +175,7 @@ class HeapObject : public Object { ...@@ -175,7 +175,7 @@ class HeapObject : public Object {
bool CanBeRehashed() const; bool CanBeRehashed() const;
// Rehash the object based on the layout inferred from its map. // Rehash the object based on the layout inferred from its map.
void RehashBasedOnMap(Heap* heap); void RehashBasedOnMap(ReadOnlyRoots root);
// Layout description. // Layout description.
#define HEAP_OBJECT_FIELDS(V) \ #define HEAP_OBJECT_FIELDS(V) \
......
...@@ -64,7 +64,9 @@ void Deserializer::Initialize(Isolate* isolate) { ...@@ -64,7 +64,9 @@ void Deserializer::Initialize(Isolate* isolate) {
void Deserializer::Rehash() { void Deserializer::Rehash() {
DCHECK(can_rehash() || deserializing_user_code()); DCHECK(can_rehash() || deserializing_user_code());
for (HeapObject item : to_rehash_) item->RehashBasedOnMap(isolate_->heap()); for (HeapObject item : to_rehash_) {
item->RehashBasedOnMap(ReadOnlyRoots(isolate_));
}
} }
Deserializer::~Deserializer() { Deserializer::~Deserializer() {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "src/api.h" #include "src/api.h"
#include "src/code-tracer.h" #include "src/code-tracer.h"
#include "src/global-handles.h" #include "src/global-handles.h"
#include "src/heap/heap-inl.h" // For InReadOnlySpace. #include "src/heap/read-only-heap.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/objects/slots.h" #include "src/objects/slots.h"
#include "src/snapshot/startup-serializer.h" #include "src/snapshot/startup-serializer.h"
...@@ -26,7 +26,7 @@ ReadOnlySerializer::~ReadOnlySerializer() { ...@@ -26,7 +26,7 @@ ReadOnlySerializer::~ReadOnlySerializer() {
} }
void ReadOnlySerializer::SerializeObject(HeapObject obj) { void ReadOnlySerializer::SerializeObject(HeapObject obj) {
CHECK(isolate()->heap()->InReadOnlySpace(obj)); CHECK(ReadOnlyHeap::Contains(obj));
CHECK_IMPLIES(obj->IsString(), obj->IsInternalizedString()); CHECK_IMPLIES(obj->IsString(), obj->IsInternalizedString());
if (SerializeHotObject(obj)) return; if (SerializeHotObject(obj)) return;
...@@ -80,7 +80,7 @@ bool ReadOnlySerializer::MustBeDeferred(HeapObject object) { ...@@ -80,7 +80,7 @@ bool ReadOnlySerializer::MustBeDeferred(HeapObject object) {
bool ReadOnlySerializer::SerializeUsingReadOnlyObjectCache( bool ReadOnlySerializer::SerializeUsingReadOnlyObjectCache(
SnapshotByteSink* sink, HeapObject obj) { SnapshotByteSink* sink, HeapObject obj) {
if (!isolate()->heap()->InReadOnlySpace(obj)) return false; if (!ReadOnlyHeap::Contains(obj)) return false;
// Get the cache index and serialize it into the read-only snapshot if // Get the cache index and serialize it into the read-only snapshot if
// necessary. // necessary.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/assembler-inl.h" #include "src/assembler-inl.h"
#include "src/heap/heap-inl.h" // For Space::identity(). #include "src/heap/heap-inl.h" // For Space::identity().
#include "src/heap/read-only-heap.h"
#include "src/interpreter/interpreter.h" #include "src/interpreter/interpreter.h"
#include "src/objects/code.h" #include "src/objects/code.h"
#include "src/objects/js-array-buffer-inl.h" #include "src/objects/js-array-buffer-inl.h"
...@@ -540,7 +541,7 @@ void Serializer::ObjectSerializer::Serialize() { ...@@ -540,7 +541,7 @@ void Serializer::ObjectSerializer::Serialize() {
if (object_->IsExternalString()) { if (object_->IsExternalString()) {
SerializeExternalString(); SerializeExternalString();
return; return;
} else if (!serializer_->isolate()->heap()->InReadOnlySpace(object_)) { } else if (!ReadOnlyHeap::Contains(object_)) {
// Only clear padding for strings outside RO_SPACE. RO_SPACE should have // Only clear padding for strings outside RO_SPACE. RO_SPACE should have
// been cleared elsewhere. // been cleared elsewhere.
if (object_->IsSeqOneByteString()) { if (object_->IsSeqOneByteString()) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/deoptimizer.h" #include "src/deoptimizer.h"
#include "src/global-handles.h" #include "src/global-handles.h"
#include "src/heap/heap-inl.h" #include "src/heap/heap-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/objects/foreign-inl.h" #include "src/objects/foreign-inl.h"
#include "src/objects/slots.h" #include "src/objects/slots.h"
...@@ -111,7 +112,7 @@ void StartupSerializer::SerializeObject(HeapObject obj) { ...@@ -111,7 +112,7 @@ void StartupSerializer::SerializeObject(HeapObject obj) {
CheckRehashability(obj); CheckRehashability(obj);
// Object has not yet been serialized. Serialize it here. // Object has not yet been serialized. Serialize it here.
DCHECK(!isolate()->heap()->InReadOnlySpace(obj)); DCHECK(!ReadOnlyHeap::Contains(obj));
ObjectSerializer object_serializer(this, obj, &sink_); ObjectSerializer object_serializer(this, obj, &sink_);
object_serializer.Serialize(); object_serializer.Serialize();
} }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/hash-seed-inl.h" #include "src/hash-seed-inl.h"
#include "src/heap/heap-inl.h" #include "src/heap/heap-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/heap/spaces.h" #include "src/heap/spaces.h"
#include "src/interpreter/interpreter.h" #include "src/interpreter/interpreter.h"
#include "src/macro-assembler-inl.h" #include "src/macro-assembler-inl.h"
...@@ -856,8 +857,7 @@ UNINITIALIZED_TEST(CustomSnapshotDataBlobStringNotInternalized) { ...@@ -856,8 +857,7 @@ UNINITIALIZED_TEST(CustomSnapshotDataBlobStringNotInternalized) {
i::String str = *v8::Utils::OpenHandle(*result.As<v8::String>()); i::String str = *v8::Utils::OpenHandle(*result.As<v8::String>());
CHECK_EQ(std::string(str->ToCString().get()), "A"); CHECK_EQ(std::string(str->ToCString().get()), "A");
CHECK(!str.IsInternalizedString()); CHECK(!str.IsInternalizedString());
CHECK( CHECK(!i::ReadOnlyHeap::Contains(str));
!reinterpret_cast<i::Isolate*>(isolate1)->heap()->InReadOnlySpace(str));
} }
isolate1->Dispose(); isolate1->Dispose();
delete[] data1.data; // We can dispose of the snapshot blob now. delete[] data1.data; // We can dispose of the snapshot blob now.
......
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