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/+/1517886
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Dan Elphick <delphick@chromium.org>
Commit-Queue: Maciej Goszczycki <goszczycki@google.com>
Cr-Commit-Position: refs/heads/master@{#60222}
This commit is contained in:
Maciej Goszczycki 2019-03-13 15:24:44 +00:00 committed by Commit Bot
parent e5f01ba13f
commit 1140f202e7
13 changed files with 30 additions and 23 deletions

View File

@ -18,6 +18,7 @@
#include "src/heap/heap-inl.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/mark-compact-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/ic/handler-configuration-inl.h"
#include "src/interpreter/interpreter.h"
#include "src/isolate-inl.h"
@ -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_instance_size(instance_size);
if (map->IsJSObjectMap()) {
DCHECK(!isolate()->heap()->InReadOnlySpace(map));
DCHECK(!ReadOnlyHeap::Contains(map));
map->SetInObjectPropertiesStartInWords(instance_size / kTaggedSize -
inobject_properties);
DCHECK_EQ(map->GetInObjectProperties(), inobject_properties);

View File

@ -376,10 +376,6 @@ bool Heap::InToPage(HeapObject heap_object) {
bool Heap::InOldSpace(Object object) { return old_space_->Contains(object); }
bool Heap::InReadOnlySpace(Object object) {
return read_only_space_->Contains(object);
}
// static
Heap* Heap::FromWritableHeapObject(const HeapObject obj) {
MemoryChunk* chunk = MemoryChunk::FromHeapObject(obj);

View File

@ -3640,14 +3640,14 @@ class VerifyReadOnlyPointersVisitor : public VerifyPointersVisitor {
void VerifyPointers(HeapObject host, MaybeObjectSlot start,
MaybeObjectSlot end) override {
if (!host.is_null()) {
CHECK(heap_->InReadOnlySpace(host->map()));
CHECK(ReadOnlyHeap::Contains(host->map()));
}
VerifyPointersVisitor::VerifyPointers(host, start, end);
for (MaybeObjectSlot current = start; current < end; ++current) {
HeapObject 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,
void Heap::VerifyRememberedSetFor(HeapObject 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.
base::LockGuard<base::Mutex, base::NullBehavior::kIgnoreIfNull> lock_guard(
chunk->mutex());

View File

@ -929,9 +929,6 @@ class Heap {
// Returns whether the object resides in old space.
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
// area and unused area).
bool Contains(HeapObject value);

View File

@ -26,5 +26,10 @@ void ReadOnlyHeap::OnHeapTearDown() {
delete this;
}
// static
bool ReadOnlyHeap::Contains(Object object) {
return Page::FromAddress(object.ptr())->owner()->identity() == RO_SPACE;
}
} // namespace internal
} // namespace v8

View File

@ -7,6 +7,7 @@
#include "src/base/macros.h"
#include "src/heap/heap.h"
#include "src/objects.h"
#include "src/roots.h"
#include "src/snapshot/read-only-deserializer.h"
@ -32,6 +33,9 @@ class ReadOnlyHeap {
// called.
void OnHeapTearDown();
// Returns whether the object resides in the read-only space.
static bool Contains(Object object);
std::vector<Object>* read_only_object_cache() {
return &read_only_object_cache_;
}

View File

@ -39,6 +39,7 @@
#include "src/function-kind.h"
#include "src/globals.h"
#include "src/heap/heap-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/ic/ic.h"
#include "src/identity-map.h"
#include "src/isolate-inl.h"
@ -2360,8 +2361,7 @@ bool HeapObject::CanBeRehashed() const {
return false;
}
void HeapObject::RehashBasedOnMap(Heap* heap) {
ReadOnlyRoots roots(heap);
void HeapObject::RehashBasedOnMap(ReadOnlyRoots roots) {
switch (map()->instance_type()) {
case HASH_TABLE_TYPE:
UNREACHABLE();
@ -2400,7 +2400,7 @@ void HeapObject::RehashBasedOnMap(Heap* heap) {
case ONE_BYTE_INTERNALIZED_STRING_TYPE:
case INTERNALIZED_STRING_TYPE:
// Rare case, rehash read-only space strings before they are sealed.
DCHECK(heap->InReadOnlySpace(*this));
DCHECK(ReadOnlyHeap::Contains(*this));
String::cast(*this)->Hash();
break;
default:

View File

@ -175,7 +175,7 @@ class HeapObject : public Object {
bool CanBeRehashed() const;
// Rehash the object based on the layout inferred from its map.
void RehashBasedOnMap(Heap* heap);
void RehashBasedOnMap(ReadOnlyRoots root);
// Layout description.
#define HEAP_OBJECT_FIELDS(V) \

View File

@ -64,7 +64,9 @@ void Deserializer::Initialize(Isolate* isolate) {
void Deserializer::Rehash() {
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() {

View File

@ -7,7 +7,7 @@
#include "src/api.h"
#include "src/code-tracer.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/slots.h"
#include "src/snapshot/startup-serializer.h"
@ -26,7 +26,7 @@ ReadOnlySerializer::~ReadOnlySerializer() {
}
void ReadOnlySerializer::SerializeObject(HeapObject obj) {
CHECK(isolate()->heap()->InReadOnlySpace(obj));
CHECK(ReadOnlyHeap::Contains(obj));
CHECK_IMPLIES(obj->IsString(), obj->IsInternalizedString());
if (SerializeHotObject(obj)) return;
@ -80,7 +80,7 @@ bool ReadOnlySerializer::MustBeDeferred(HeapObject object) {
bool ReadOnlySerializer::SerializeUsingReadOnlyObjectCache(
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
// necessary.

View File

@ -6,6 +6,7 @@
#include "src/assembler-inl.h"
#include "src/heap/heap-inl.h" // For Space::identity().
#include "src/heap/read-only-heap.h"
#include "src/interpreter/interpreter.h"
#include "src/objects/code.h"
#include "src/objects/js-array-buffer-inl.h"
@ -540,7 +541,7 @@ void Serializer::ObjectSerializer::Serialize() {
if (object_->IsExternalString()) {
SerializeExternalString();
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
// been cleared elsewhere.
if (object_->IsSeqOneByteString()) {

View File

@ -10,6 +10,7 @@
#include "src/deoptimizer.h"
#include "src/global-handles.h"
#include "src/heap/heap-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/objects-inl.h"
#include "src/objects/foreign-inl.h"
#include "src/objects/slots.h"
@ -111,7 +112,7 @@ void StartupSerializer::SerializeObject(HeapObject obj) {
CheckRehashability(obj);
// Object has not yet been serialized. Serialize it here.
DCHECK(!isolate()->heap()->InReadOnlySpace(obj));
DCHECK(!ReadOnlyHeap::Contains(obj));
ObjectSerializer object_serializer(this, obj, &sink_);
object_serializer.Serialize();
}

View File

@ -39,6 +39,7 @@
#include "src/debug/debug.h"
#include "src/hash-seed-inl.h"
#include "src/heap/heap-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/heap/spaces.h"
#include "src/interpreter/interpreter.h"
#include "src/macro-assembler-inl.h"
@ -856,8 +857,7 @@ UNINITIALIZED_TEST(CustomSnapshotDataBlobStringNotInternalized) {
i::String str = *v8::Utils::OpenHandle(*result.As<v8::String>());
CHECK_EQ(std::string(str->ToCString().get()), "A");
CHECK(!str.IsInternalizedString());
CHECK(
!reinterpret_cast<i::Isolate*>(isolate1)->heap()->InReadOnlySpace(str));
CHECK(!i::ReadOnlyHeap::Contains(str));
}
isolate1->Dispose();
delete[] data1.data; // We can dispose of the snapshot blob now.