Commit a3de69da authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[ptr-compr] Get Isolate via object address

To get the Isolate from a HeapObject, rather than masking off the
MemoryChunk and then loading the heap from the MemoryChunk (which won't
work when RO_SPACE is shared between Isolates), get the Isolate by
masking off the bottom 32 bits and apply the Isolate bias.

Also fixes up a stale comment and makes several methods in RootsTable
and Isolate const to support this change.

Bug: v8:10454
Change-Id: I5f8eb873d8486b699460223dbe3454a5dcf1854f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2280088
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68671}
parent 268490c2
...@@ -950,6 +950,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { ...@@ -950,6 +950,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
} }
RootsTable& roots_table() { return isolate_data()->roots(); } RootsTable& roots_table() { return isolate_data()->roots(); }
const RootsTable& roots_table() const { return isolate_data()->roots(); }
// A sub-region of the Isolate object that has "predictable" layout which // A sub-region of the Isolate object that has "predictable" layout which
// depends only on the pointer size and therefore it's guaranteed that there // depends only on the pointer size and therefore it's guaranteed that there
......
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
#ifndef V8_HEAP_READ_ONLY_HEAP_INL_H_ #ifndef V8_HEAP_READ_ONLY_HEAP_INL_H_
#define V8_HEAP_READ_ONLY_HEAP_INL_H_ #define V8_HEAP_READ_ONLY_HEAP_INL_H_
#include "src/heap/read-only-heap.h"
#include "src/execution/isolate-utils-inl.h" #include "src/execution/isolate-utils-inl.h"
#include "src/heap/read-only-heap.h"
#include "src/roots/roots-inl.h" #include "src/roots/roots-inl.h"
namespace v8 { namespace v8 {
...@@ -15,14 +14,19 @@ namespace internal { ...@@ -15,14 +14,19 @@ namespace internal {
// static // static
ReadOnlyRoots ReadOnlyHeap::GetReadOnlyRoots(HeapObject object) { ReadOnlyRoots ReadOnlyHeap::GetReadOnlyRoots(HeapObject object) {
#ifdef V8_COMPRESS_POINTERS
const Isolate* isolate = GetIsolateForPtrCompr(object);
return ReadOnlyRoots(isolate);
#else
#ifdef V8_SHARED_RO_HEAP #ifdef V8_SHARED_RO_HEAP
// This fails if we are creating heap objects and the roots haven't yet been // This fails if we are creating heap objects and the roots haven't yet been
// copied into the read-only heap or it has been cleared for testing. // copied into the read-only heap.
if (shared_ro_heap_ != nullptr && shared_ro_heap_->init_complete_) { if (shared_ro_heap_ != nullptr && shared_ro_heap_->init_complete_) {
return ReadOnlyRoots(shared_ro_heap_->read_only_roots_); return ReadOnlyRoots(shared_ro_heap_->read_only_roots_);
} }
#endif #endif // V8_SHARED_RO_HEAP
return ReadOnlyRoots(GetHeapFromWritableObject(object)); return ReadOnlyRoots(GetHeapFromWritableObject(object));
#endif // V8_COMPRESS_POINTERS
} }
} // namespace internal } // namespace internal
......
...@@ -65,7 +65,7 @@ ReadOnlyRoots::ReadOnlyRoots(Heap* heap) ...@@ -65,7 +65,7 @@ ReadOnlyRoots::ReadOnlyRoots(Heap* heap)
ReadOnlyRoots::ReadOnlyRoots(OffThreadHeap* heap) ReadOnlyRoots::ReadOnlyRoots(OffThreadHeap* heap)
: ReadOnlyRoots(OffThreadIsolate::FromHeap(heap)) {} : ReadOnlyRoots(OffThreadIsolate::FromHeap(heap)) {}
ReadOnlyRoots::ReadOnlyRoots(Isolate* isolate) ReadOnlyRoots::ReadOnlyRoots(const Isolate* isolate)
: read_only_roots_(reinterpret_cast<Address*>( : read_only_roots_(reinterpret_cast<Address*>(
isolate->roots_table().read_only_roots_begin().address())) {} isolate->roots_table().read_only_roots_begin().address())) {}
......
...@@ -465,42 +465,42 @@ class RootsTable { ...@@ -465,42 +465,42 @@ class RootsTable {
} }
// Used for iterating over all of the read-only and mutable strong roots. // Used for iterating over all of the read-only and mutable strong roots.
FullObjectSlot strong_or_read_only_roots_begin() { FullObjectSlot strong_or_read_only_roots_begin() const {
STATIC_ASSERT(static_cast<size_t>(RootIndex::kLastReadOnlyRoot) == STATIC_ASSERT(static_cast<size_t>(RootIndex::kLastReadOnlyRoot) ==
static_cast<size_t>(RootIndex::kFirstStrongRoot) - 1); static_cast<size_t>(RootIndex::kFirstStrongRoot) - 1);
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kFirstStrongOrReadOnlyRoot)]); &roots_[static_cast<size_t>(RootIndex::kFirstStrongOrReadOnlyRoot)]);
} }
FullObjectSlot strong_or_read_only_roots_end() { FullObjectSlot strong_or_read_only_roots_end() const {
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kLastStrongOrReadOnlyRoot) + 1]); &roots_[static_cast<size_t>(RootIndex::kLastStrongOrReadOnlyRoot) + 1]);
} }
// The read-only, strong and Smi roots as defined by these accessors are all // The read-only, strong and Smi roots as defined by these accessors are all
// disjoint. // disjoint.
FullObjectSlot read_only_roots_begin() { FullObjectSlot read_only_roots_begin() const {
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kFirstReadOnlyRoot)]); &roots_[static_cast<size_t>(RootIndex::kFirstReadOnlyRoot)]);
} }
FullObjectSlot read_only_roots_end() { FullObjectSlot read_only_roots_end() const {
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kLastReadOnlyRoot) + 1]); &roots_[static_cast<size_t>(RootIndex::kLastReadOnlyRoot) + 1]);
} }
FullObjectSlot strong_roots_begin() { FullObjectSlot strong_roots_begin() const {
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kFirstStrongRoot)]); &roots_[static_cast<size_t>(RootIndex::kFirstStrongRoot)]);
} }
FullObjectSlot strong_roots_end() { FullObjectSlot strong_roots_end() const {
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kLastStrongRoot) + 1]); &roots_[static_cast<size_t>(RootIndex::kLastStrongRoot) + 1]);
} }
FullObjectSlot smi_roots_begin() { FullObjectSlot smi_roots_begin() const {
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kFirstSmiRoot)]); &roots_[static_cast<size_t>(RootIndex::kFirstSmiRoot)]);
} }
FullObjectSlot smi_roots_end() { FullObjectSlot smi_roots_end() const {
return FullObjectSlot( return FullObjectSlot(
&roots_[static_cast<size_t>(RootIndex::kLastSmiRoot) + 1]); &roots_[static_cast<size_t>(RootIndex::kLastSmiRoot) + 1]);
} }
...@@ -529,7 +529,7 @@ class ReadOnlyRoots { ...@@ -529,7 +529,7 @@ class ReadOnlyRoots {
V8_INLINE explicit ReadOnlyRoots(Heap* heap); V8_INLINE explicit ReadOnlyRoots(Heap* heap);
V8_INLINE explicit ReadOnlyRoots(OffThreadHeap* heap); V8_INLINE explicit ReadOnlyRoots(OffThreadHeap* heap);
V8_INLINE explicit ReadOnlyRoots(Isolate* isolate); V8_INLINE explicit ReadOnlyRoots(const Isolate* isolate);
V8_INLINE explicit ReadOnlyRoots(OffThreadIsolate* isolate); V8_INLINE explicit ReadOnlyRoots(OffThreadIsolate* isolate);
V8_INLINE explicit ReadOnlyRoots(LocalIsolateWrapper wrapper); V8_INLINE explicit ReadOnlyRoots(LocalIsolateWrapper wrapper);
V8_INLINE explicit ReadOnlyRoots(LocalHeapWrapper wrapper); V8_INLINE explicit ReadOnlyRoots(LocalHeapWrapper wrapper);
......
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