Commit 58339dfe authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[GetIsolate] Add a mixin for safe GetIsolate types

To avoid repeating code for the few places where we can call GetIsolate
and GetHeap safely.

Bug: v8:7786
Change-Id: I6c6de81488bfa79dca50cfd2b6356f432401b68e
Reviewed-on: https://chromium-review.googlesource.com/1104684
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53828}
parent 97f0ddfa
......@@ -45,8 +45,6 @@ Context* Context::cast(Object* context) {
return reinterpret_cast<Context*>(context);
}
Isolate* Context::GetIsolate() const { return GetHeap()->isolate(); }
void Context::set_scope_info(ScopeInfo* scope_info) {
set(SCOPE_INFO_INDEX, scope_info);
}
......
......@@ -434,13 +434,16 @@ class ScriptContextTable : public FixedArray {
// Script contexts from all top-level scripts are gathered in
// ScriptContextTable.
class Context : public FixedArray {
class Context : public FixedArray, public NeverReadOnlySpaceObject {
public:
// Use the mixin methods over the HeapObject methods.
// TODO(v8:7786) Remove once the HeapObject methods are gone.
using NeverReadOnlySpaceObject::GetHeap;
using NeverReadOnlySpaceObject::GetIsolate;
// Conversions.
static inline Context* cast(Object* context);
inline Isolate* GetIsolate() const;
// The default context slot layout; indices are FixedArray slot indices.
enum Field {
// These slots are in all contexts.
......
......@@ -1016,7 +1016,19 @@ Isolate* HeapObject::GetIsolate() const {
return GetHeap()->isolate();
}
Isolate* JSReceiver::GetIsolate() const { return GetHeap()->isolate(); }
Heap* NeverReadOnlySpaceObject::GetHeap() const {
MemoryChunk* chunk =
MemoryChunk::FromAddress(reinterpret_cast<Address>(this));
// Make sure we are not accessing an object in RO space.
SLOW_DCHECK(chunk->owner()->identity() != RO_SPACE);
Heap* heap = chunk->heap();
SLOW_DCHECK(heap != nullptr);
return heap;
}
Isolate* NeverReadOnlySpaceObject::GetIsolate() const {
return GetHeap()->isolate();
}
Map* HeapObject::map() const {
return map_word().ToMap();
......
......@@ -1809,14 +1809,14 @@ class HeapObject: public Object {
// The Heap the object was allocated in. Used also to access Isolate.
#ifdef DEPRECATE_GET_ISOLATE
[[deprecated("Pass Heap explicitly")]]
[[deprecated("Pass Heap explicitly or use a NeverReadOnlyHeapObject")]]
#endif
inline Heap*
GetHeap() const;
// Convenience method to get current isolate.
#ifdef DEPRECATE_GET_ISOLATE
[[deprecated("Pass Isolate explicitly")]]
[[deprecated("Pass Isolate explicitly or use a NeverReadOnlyHeapObject")]]
#endif
inline Isolate*
GetIsolate() const;
......@@ -1953,6 +1953,17 @@ class HeapObject: public Object {
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
};
// Mixin class for objects that can never be in RO space.
// TODO(leszeks): Add checks in the factory that we never allocate these objects
// in RO space.
class NeverReadOnlySpaceObject {
public:
// The Heap the object was allocated in. Used also to access Isolate.
inline Heap* GetHeap() const;
// Convenience method to get current isolate.
inline Isolate* GetIsolate() const;
};
template <int start_offset, int end_offset, int size>
class FixedBodyDescriptor;
......@@ -2096,13 +2107,16 @@ class PropertyArray : public HeapObject {
// JSReceiver includes types on which properties can be defined, i.e.,
// JSObject and JSProxy.
class JSReceiver: public HeapObject {
class JSReceiver : public HeapObject, public NeverReadOnlySpaceObject {
public:
// Use the mixin methods over the HeapObject methods.
// TODO(v8:7786) Remove once the HeapObject methods are gone.
using NeverReadOnlySpaceObject::GetHeap;
using NeverReadOnlySpaceObject::GetIsolate;
// Returns true if there is no slow (ie, dictionary) backing store.
inline bool HasFastProperties() const;
inline Isolate* GetIsolate() const;
// Returns the properties array backing store if it
// exists. Otherwise, returns an empty_property_array when there's a
// Smi (hash code) or an empty_fixed_array for a fast properties
......
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