Commit 8377214a authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[objects] Pass isolate to HashTable accesses

Change-Id: I90612ae0e54b46e7147d9a3392783f56da598b2b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2287499
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68750}
parent a1b752a7
......@@ -428,10 +428,9 @@ PropertyAccessInfo AccessInfoFactory::ComputeAccessorDescriptorAccessInfo(
isolate());
Handle<JSModuleNamespace> module_namespace(
JSModuleNamespace::cast(proto_info->module_namespace()), isolate());
Handle<Cell> cell(
Cell::cast(module_namespace->module().exports().Lookup(
ReadOnlyRoots(isolate()), name, Smi::ToInt(name->GetHash()))),
isolate());
Handle<Cell> cell(Cell::cast(module_namespace->module().exports().Lookup(
isolate(), name, Smi::ToInt(name->GetHash()))),
isolate());
if (cell->value().IsTheHole(isolate())) {
// This module has not been fully initialized yet.
return PropertyAccessInfo::Invalid(zone());
......
......@@ -5,10 +5,10 @@
#ifndef V8_EXECUTION_ISOLATE_UTILS_INL_H_
#define V8_EXECUTION_ISOLATE_UTILS_INL_H_
#include "src/execution/isolate-utils.h"
#include "src/common/ptr-compr-inl.h"
#include "src/execution/isolate-utils.h"
#include "src/execution/isolate.h"
#include "src/execution/local-isolate-wrapper.h"
#include "src/heap/heap-write-barrier-inl.h"
namespace v8 {
......@@ -22,6 +22,31 @@ inline const Isolate* GetIsolateForPtrCompr(HeapObject object) {
#endif // V8_COMPRESS_POINTERS
}
inline const Isolate* GetIsolateForPtrCompr(const Isolate* isolate) {
#ifdef V8_COMPRESS_POINTERS
return isolate;
#else
return nullptr;
#endif // V8_COMPRESS_POINTERS
}
inline const Isolate* GetIsolateForPtrCompr(const OffThreadIsolate* isolate) {
#ifdef V8_COMPRESS_POINTERS
return isolate->GetIsolateForPtrCompr();
#else
return nullptr;
#endif // V8_COMPRESS_POINTERS
}
inline const Isolate* GetIsolateForPtrCompr(LocalIsolateWrapper isolate) {
#ifdef V8_COMPRESS_POINTERS
return isolate.is_main_thread() ? isolate.main_thread()
: GetIsolateForPtrCompr(isolate.off_thread());
#else
return nullptr;
#endif // V8_COMPRESS_POINTERS
}
V8_INLINE Heap* GetHeapFromWritableObject(HeapObject object) {
// Avoid using the below GetIsolateFromWritableObject because we want to be
// able to get the heap, but not the isolate, for off-thread objects.
......
......@@ -89,6 +89,8 @@ class V8_EXPORT_PRIVATE OffThreadIsolate final
inline ReadOnlyHeap* read_only_heap();
inline Object root(RootIndex index);
const Isolate* GetIsolateForPtrCompr() const { return isolate_; }
v8::internal::OffThreadFactory* factory() {
// Upcast to the privately inherited base-class using c-style casts to avoid
// undefined behavior (as static_cast cannot cast across private bases).
......
......@@ -16,7 +16,7 @@ namespace internal {
ReadOnlyRoots ReadOnlyHeap::GetReadOnlyRoots(HeapObject object) {
#ifdef V8_COMPRESS_POINTERS
const Isolate* isolate = GetIsolateForPtrCompr(object);
return ReadOnlyRoots(isolate);
return ReadOnlyRoots(const_cast<Isolate*>(isolate));
#else
#ifdef V8_SHARED_RO_HEAP
// This fails if we are creating heap objects and the roots haven't yet been
......
......@@ -828,8 +828,9 @@ Handle<Object> LoadIC::ComputeHandler(LookupIterator* lookup) {
Handle<ObjectHashTable> exports(
Handle<JSModuleNamespace>::cast(holder)->module().exports(),
isolate());
InternalIndex entry = exports->FindEntry(
roots, lookup->name(), Smi::ToInt(lookup->name()->GetHash()));
InternalIndex entry =
exports->FindEntry(isolate(), roots, lookup->name(),
Smi::ToInt(lookup->name()->GetHash()));
// We found the accessor, so the entry must exist.
DCHECK(entry.is_found());
int index = ObjectHashTable::EntryToValueIndex(entry);
......
......@@ -1365,7 +1365,7 @@ class DictionaryElementsAccessor
// Find last non-deletable element in range of elements to be
// deleted and adjust range accordingly.
for (InternalIndex entry : dict->IterateEntries()) {
Object index = dict->KeyAt(entry);
Object index = dict->KeyAt(isolate, entry);
if (dict->IsKey(roots, index)) {
uint32_t number = static_cast<uint32_t>(index.Number());
if (length <= number && number < old_length) {
......@@ -1383,7 +1383,7 @@ class DictionaryElementsAccessor
// Remove elements that should be deleted.
int removed_entries = 0;
for (InternalIndex entry : dict->IterateEntries()) {
Object index = dict->KeyAt(entry);
Object index = dict->KeyAt(isolate, entry);
if (dict->IsKey(roots, index)) {
uint32_t number = static_cast<uint32_t>(index.Number());
if (length <= number && number < old_length) {
......@@ -1423,9 +1423,10 @@ class DictionaryElementsAccessor
DisallowHeapAllocation no_gc;
NumberDictionary dict = NumberDictionary::cast(backing_store);
if (!dict.requires_slow_elements()) return false;
ReadOnlyRoots roots = holder.GetReadOnlyRoots();
const Isolate* isolate = GetIsolateForPtrCompr(holder);
ReadOnlyRoots roots = holder.GetReadOnlyRoots(isolate);
for (InternalIndex i : dict.IterateEntries()) {
Object key = dict.KeyAt(i);
Object key = dict.KeyAt(isolate, i);
if (!dict.IsKey(roots, key)) continue;
PropertyDetails details = dict.DetailsAt(i);
if (details.kind() == kAccessor) return true;
......@@ -1488,7 +1489,7 @@ class DictionaryElementsAccessor
InternalIndex entry) {
DisallowHeapAllocation no_gc;
NumberDictionary dict = NumberDictionary::cast(store);
Object index = dict.KeyAt(entry);
Object index = dict.KeyAt(isolate, entry);
return !index.IsTheHole(isolate);
}
......@@ -1535,7 +1536,7 @@ class DictionaryElementsAccessor
InternalIndex entry,
PropertyFilter filter) {
DisallowHeapAllocation no_gc;
Object raw_key = dictionary->KeyAt(entry);
Object raw_key = dictionary->KeyAt(isolate, entry);
if (!dictionary->IsKey(ReadOnlyRoots(isolate), raw_key)) return kMaxUInt32;
return FilterKey(dictionary, entry, raw_key, filter);
}
......@@ -1554,7 +1555,7 @@ class DictionaryElementsAccessor
ReadOnlyRoots roots(isolate);
for (InternalIndex i : dictionary->IterateEntries()) {
AllowHeapAllocation allow_gc;
Object raw_key = dictionary->KeyAt(i);
Object raw_key = dictionary->KeyAt(isolate, i);
if (!dictionary->IsKey(roots, raw_key)) continue;
uint32_t key = FilterKey(dictionary, i, raw_key, filter);
if (key == kMaxUInt32) {
......@@ -1601,9 +1602,9 @@ class DictionaryElementsAccessor
NumberDictionary::cast(receiver->elements()), isolate);
ReadOnlyRoots roots(isolate);
for (InternalIndex i : dictionary->IterateEntries()) {
Object k = dictionary->KeyAt(i);
Object k = dictionary->KeyAt(isolate, i);
if (!dictionary->IsKey(roots, k)) continue;
Object value = dictionary->ValueAt(i);
Object value = dictionary->ValueAt(isolate, i);
DCHECK(!value.IsTheHole(isolate));
DCHECK(!value.IsAccessorPair());
DCHECK(!value.IsAccessorInfo());
......@@ -1624,7 +1625,7 @@ class DictionaryElementsAccessor
// must be accessed in order via the slow path.
bool found = false;
for (InternalIndex i : dictionary.IterateEntries()) {
Object k = dictionary.KeyAt(i);
Object k = dictionary.KeyAt(isolate, i);
if (k == the_hole) continue;
if (k == undefined) continue;
......@@ -1638,7 +1639,7 @@ class DictionaryElementsAccessor
// access getters out of order
return false;
} else if (!found) {
Object element_k = dictionary.ValueAt(i);
Object element_k = dictionary.ValueAt(isolate, i);
if (value->SameValueZero(element_k)) found = true;
}
}
......
......@@ -5,11 +5,10 @@
#ifndef V8_OBJECTS_HASH_TABLE_INL_H_
#define V8_OBJECTS_HASH_TABLE_INL_H_
#include "src/objects/hash-table.h"
#include "src/execution/isolate-utils-inl.h"
#include "src/heap/heap.h"
#include "src/objects/fixed-array-inl.h"
#include "src/objects/hash-table.h"
#include "src/objects/heap-object-inl.h"
#include "src/objects/objects-inl.h"
#include "src/roots/roots-inl.h"
......@@ -132,19 +131,18 @@ Handle<Map> EphemeronHashTableShape::GetMap(ReadOnlyRoots roots) {
}
template <typename Derived, typename Shape>
InternalIndex HashTable<Derived, Shape>::FindEntry(Isolate* isolate, Key key) {
return FindEntry(ReadOnlyRoots(isolate), key);
}
template <typename Derived, typename Shape>
InternalIndex HashTable<Derived, Shape>::FindEntry(ReadOnlyRoots roots,
template <typename LocalIsolate>
InternalIndex HashTable<Derived, Shape>::FindEntry(LocalIsolate* isolate,
Key key) {
return FindEntry(roots, key, Shape::Hash(roots, key));
ReadOnlyRoots roots(isolate);
return FindEntry(isolate, roots, key, Shape::Hash(roots, key));
}
// Find entry for key otherwise return kNotFound.
template <typename Derived, typename Shape>
InternalIndex HashTable<Derived, Shape>::FindEntry(ReadOnlyRoots roots, Key key,
template <typename LocalIsolate>
InternalIndex HashTable<Derived, Shape>::FindEntry(const LocalIsolate* isolate,
ReadOnlyRoots roots, Key key,
int32_t hash) {
uint32_t capacity = Capacity();
InternalIndex entry = FirstProbe(hash, capacity);
......@@ -154,7 +152,7 @@ InternalIndex HashTable<Derived, Shape>::FindEntry(ReadOnlyRoots roots, Key key,
Object the_hole = roots.the_hole_value();
USE(the_hole);
while (true) {
Object element = KeyAt(entry);
Object element = KeyAt(isolate, entry);
// Empty entry. Uses raw unchecked accessors because it is called by the
// string table during bootstrapping.
if (element == undefined) break;
......@@ -176,8 +174,8 @@ bool HashTable<Derived, Shape>::ToKey(ReadOnlyRoots roots, InternalIndex entry,
}
template <typename Derived, typename Shape>
bool HashTable<Derived, Shape>::ToKey(Isolate* isolate, InternalIndex entry,
Object* out_k) {
bool HashTable<Derived, Shape>::ToKey(const Isolate* isolate,
InternalIndex entry, Object* out_k) {
Object k = KeyAt(isolate, entry);
if (!IsKey(GetReadOnlyRoots(isolate), k)) return false;
*out_k = Shape::Unwrap(k);
......@@ -191,9 +189,11 @@ Object HashTable<Derived, Shape>::KeyAt(InternalIndex entry) {
}
template <typename Derived, typename Shape>
Object HashTable<Derived, Shape>::KeyAt(const Isolate* isolate,
template <typename LocalIsolate>
Object HashTable<Derived, Shape>::KeyAt(const LocalIsolate* isolate,
InternalIndex entry) {
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
return get(GetIsolateForPtrCompr(isolate),
EntryToIndex(entry) + kEntryKeyIndex);
}
template <typename Derived, typename Shape>
......@@ -230,13 +230,14 @@ bool BaseShape<KeyT>::IsLive(ReadOnlyRoots roots, Object k) {
}
bool ObjectHashSet::Has(Isolate* isolate, Handle<Object> key, int32_t hash) {
return FindEntry(ReadOnlyRoots(isolate), key, hash).is_found();
return FindEntry(isolate, ReadOnlyRoots(isolate), key, hash).is_found();
}
bool ObjectHashSet::Has(Isolate* isolate, Handle<Object> key) {
Object hash = key->GetHash();
if (!hash.IsSmi()) return false;
return FindEntry(ReadOnlyRoots(isolate), key, Smi::ToInt(hash)).is_found();
return FindEntry(isolate, ReadOnlyRoots(isolate), key, Smi::ToInt(hash))
.is_found();
}
bool ObjectHashTableShape::IsMatch(Handle<Object> key, Object other) {
......
......@@ -140,12 +140,14 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
void IterateElements(ObjectVisitor* visitor);
// Find entry for key otherwise return kNotFound.
inline InternalIndex FindEntry(ReadOnlyRoots roots, Key key, int32_t hash);
inline InternalIndex FindEntry(ReadOnlyRoots roots, Key key);
inline InternalIndex FindEntry(Isolate* isolate, Key key);
template <typename LocalIsolate>
inline InternalIndex FindEntry(const LocalIsolate* isolate,
ReadOnlyRoots roots, Key key, int32_t hash);
template <typename LocalIsolate>
inline InternalIndex FindEntry(LocalIsolate* isolate, Key key);
// Rehashes the table in-place.
void Rehash(ReadOnlyRoots roots);
void Rehash(const Isolate* isolate);
// Returns whether k is a real key. The hole and undefined are not allowed as
// keys and can be used to indicate missing or deleted elements.
......@@ -154,11 +156,12 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
}
inline bool ToKey(ReadOnlyRoots roots, InternalIndex entry, Object* out_k);
inline bool ToKey(Isolate* isolate, InternalIndex entry, Object* out_k);
inline bool ToKey(const Isolate* isolate, InternalIndex entry, Object* out_k);
// Returns the key at entry.
inline Object KeyAt(InternalIndex entry);
inline Object KeyAt(const Isolate* isolate, InternalIndex entry);
template <typename LocalIsolate>
inline Object KeyAt(const LocalIsolate* isolate, InternalIndex entry);
static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
static const int kEntrySize = Shape::kEntrySize;
......@@ -210,7 +213,9 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
// Find the entry at which to insert element with the given key that
// has the given hash value.
InternalIndex FindInsertionEntry(uint32_t hash);
InternalIndex FindInsertionEntry(const Isolate* isolate, ReadOnlyRoots roots,
uint32_t hash);
InternalIndex FindInsertionEntry(Isolate* isolate, uint32_t hash);
// Attempt to shrink hash table after removal of key.
V8_WARN_UNUSED_RESULT static Handle<Derived> Shrink(
......@@ -242,7 +247,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
void Swap(InternalIndex entry1, InternalIndex entry2, WriteBarrierMode mode);
// Rehashes this hash-table into the new table.
void Rehash(ReadOnlyRoots roots, Derived new_table);
void Rehash(const Isolate* isolate, Derived new_table);
OBJECT_CONSTRUCTORS(HashTable, HashTableBase);
};
......@@ -308,7 +313,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) ObjectHashTableBase
// returned in case the key is not present.
Object Lookup(Handle<Object> key);
Object Lookup(Handle<Object> key, int32_t hash);
Object Lookup(ReadOnlyRoots roots, Handle<Object> key, int32_t hash);
Object Lookup(const Isolate* isolate, Handle<Object> key, int32_t hash);
// Returns the value at entry.
Object ValueAt(InternalIndex entry);
......
......@@ -2323,17 +2323,16 @@ void JSObject::SetNormalizedProperty(Handle<JSObject> object, Handle<Name> name,
Handle<JSGlobalObject> global_obj = Handle<JSGlobalObject>::cast(object);
Handle<GlobalDictionary> dictionary(global_obj->global_dictionary(),
isolate);
InternalIndex entry =
dictionary->FindEntry(ReadOnlyRoots(isolate), name, hash);
ReadOnlyRoots roots(isolate);
InternalIndex entry = dictionary->FindEntry(isolate, roots, name, hash);
if (entry.is_not_found()) {
DCHECK_IMPLIES(global_obj->map().is_prototype_map(),
Map::IsPrototypeChainInvalidated(global_obj->map()));
auto cell = isolate->factory()->NewPropertyCell(name);
cell->set_value(*value);
auto cell_type = value->IsUndefined(isolate)
? PropertyCellType::kUndefined
: PropertyCellType::kConstant;
auto cell_type = value->IsUndefined(roots) ? PropertyCellType::kUndefined
: PropertyCellType::kConstant;
details = details.set_cell_type(cell_type);
value = cell;
dictionary =
......@@ -3326,7 +3325,7 @@ void JSObject::MigrateSlowToFast(Handle<JSObject> object,
ReadOnlyRoots roots(isolate);
for (int i = 0; i < instance_descriptor_length; i++) {
InternalIndex index(Smi::ToInt(iteration_order->get(i)));
DCHECK(dictionary->IsKey(roots, dictionary->KeyAt(index)));
DCHECK(dictionary->IsKey(roots, dictionary->KeyAt(isolate, index)));
PropertyKind kind = dictionary->DetailsAt(index).kind();
if (kind == kData) {
......
......@@ -133,7 +133,7 @@ void AddToDictionaryTemplate(LocalIsolate* isolate,
int key_index,
ClassBoilerplate::ValueKind value_kind,
Smi value) {
InternalIndex entry = dictionary->FindEntry(ReadOnlyRoots(isolate), key);
InternalIndex entry = dictionary->FindEntry(isolate, key);
if (entry.is_not_found()) {
// Entry not found, add new one.
......
This diff is collapsed.
......@@ -96,7 +96,8 @@ T TaggedField<T, kFieldOffset>::Relaxed_Load(HeapObject host, int offset) {
// static
template <typename T, int kFieldOffset>
T TaggedField<T, kFieldOffset>::Relaxed_Load(const Isolate* isolate,
template <typename LocalIsolate>
T TaggedField<T, kFieldOffset>::Relaxed_Load(const LocalIsolate* isolate,
HeapObject host, int offset) {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location(host, offset));
return T(tagged_to_full(isolate, value));
......@@ -125,7 +126,8 @@ T TaggedField<T, kFieldOffset>::Acquire_Load(HeapObject host, int offset) {
// static
template <typename T, int kFieldOffset>
T TaggedField<T, kFieldOffset>::Acquire_Load(const Isolate* isolate,
template <typename LocalIsolate>
T TaggedField<T, kFieldOffset>::Acquire_Load(const LocalIsolate* isolate,
HeapObject host, int offset) {
AtomicTagged_t value = AsAtomicTagged::Acquire_Load(location(host, offset));
return T(tagged_to_full(isolate, value));
......
......@@ -44,14 +44,16 @@ class TaggedField : public AllStatic {
static inline void store(HeapObject host, int offset, T value);
static inline T Relaxed_Load(HeapObject host, int offset = 0);
static inline T Relaxed_Load(const Isolate* isolate, HeapObject host,
template <typename LocalIsolate>
static inline T Relaxed_Load(const LocalIsolate* isolate, HeapObject host,
int offset = 0);
static inline void Relaxed_Store(HeapObject host, T value);
static inline void Relaxed_Store(HeapObject host, int offset, T value);
static inline T Acquire_Load(HeapObject host, int offset = 0);
static inline T Acquire_Load(const Isolate* isolate, HeapObject host,
template <typename LocalIsolate>
static inline T Acquire_Load(const LocalIsolate* isolate, HeapObject host,
int offset = 0);
static inline void Release_Store(HeapObject host, T value);
......
......@@ -65,7 +65,7 @@ ReadOnlyRoots::ReadOnlyRoots(Heap* heap)
ReadOnlyRoots::ReadOnlyRoots(OffThreadHeap* heap)
: ReadOnlyRoots(OffThreadIsolate::FromHeap(heap)) {}
ReadOnlyRoots::ReadOnlyRoots(const Isolate* isolate)
ReadOnlyRoots::ReadOnlyRoots(Isolate* isolate)
: read_only_roots_(reinterpret_cast<Address*>(
isolate->roots_table().read_only_roots_begin().address())) {}
......
......@@ -529,7 +529,7 @@ class ReadOnlyRoots {
V8_INLINE explicit ReadOnlyRoots(Heap* heap);
V8_INLINE explicit ReadOnlyRoots(OffThreadHeap* heap);
V8_INLINE explicit ReadOnlyRoots(const Isolate* isolate);
V8_INLINE explicit ReadOnlyRoots(Isolate* isolate);
V8_INLINE explicit ReadOnlyRoots(OffThreadIsolate* isolate);
V8_INLINE explicit ReadOnlyRoots(LocalIsolateWrapper wrapper);
V8_INLINE explicit ReadOnlyRoots(LocalHeapWrapper wrapper);
......
......@@ -218,7 +218,7 @@ TEST(HashTableRehash) {
for (int i = 0; i < capacity - 1; i++) {
t.insert(InternalIndex(i), i * i, i);
}
t.Rehash(ReadOnlyRoots(isolate));
t.Rehash(isolate);
for (int i = 0; i < capacity - 1; i++) {
CHECK_EQ(i, t.lookup(i * i));
}
......@@ -231,7 +231,7 @@ TEST(HashTableRehash) {
for (int i = 0; i < capacity / 2; i++) {
t.insert(InternalIndex(i), i * i, i);
}
t.Rehash(ReadOnlyRoots(isolate));
t.Rehash(isolate);
for (int i = 0; i < capacity / 2; i++) {
CHECK_EQ(i, t.lookup(i * i));
}
......
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