Commit 44d5a2a3 authored by Frank Emrich's avatar Frank Emrich Committed by Commit Bot

[dict-proto] Preparing ordered hash tables for usage as property dicts

This contains more changes to ordered hash tables towards using them as
property dictionaries.
Most notably, this CL makes the type of the used isolates a template
parameter for certain operations. This is already the case for
unordered hash tables, and necessary in follow-up CLs where ordered
name dictionaries are used with LocalIsolate as the isolate type.

Bug: v8:7569
Change-Id: I5c938425a2c196ccd0866b66318a350ebeac8be2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2523319
Commit-Queue: Frank Emrich <emrich@google.com>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71112}
parent e02cfac6
......@@ -117,6 +117,17 @@ Name OrderedNameDictionary::NameAt(InternalIndex entry) {
return Name::cast(KeyAt(entry));
}
// Parameter |roots| only here for compatibility with HashTable<...>::ToKey.
template <class Derived, int entrysize>
bool OrderedHashTable<Derived, entrysize>::ToKey(ReadOnlyRoots roots,
InternalIndex entry,
Object* out_key) {
Object k = KeyAt(entry);
if (!IsKey(roots, k)) return false;
*out_key = k;
return true;
}
// Set the value for entry.
inline void OrderedNameDictionary::ValueAtPut(InternalIndex entry,
Object value) {
......
......@@ -16,8 +16,9 @@ namespace v8 {
namespace internal {
template <class Derived, int entrysize>
template <typename LocalIsolate>
MaybeHandle<Derived> OrderedHashTable<Derived, entrysize>::Allocate(
Isolate* isolate, int capacity, AllocationType allocation) {
LocalIsolate* isolate, int capacity, AllocationType allocation) {
// Capacity must be a power of two, since we depend on being able
// to divide and multiple by 2 (kLoadFactor) to derive capacity
// from number of buckets. If we decide to change kLoadFactor
......@@ -62,8 +63,9 @@ MaybeHandle<Derived> OrderedHashTable<Derived, entrysize>::AllocateEmpty(
}
template <class Derived, int entrysize>
template <typename LocalIsolate>
MaybeHandle<Derived> OrderedHashTable<Derived, entrysize>::EnsureGrowable(
Isolate* isolate, Handle<Derived> table) {
LocalIsolate* isolate, Handle<Derived> table) {
DCHECK(!table->IsObsolete());
int nof = table->NumberOfElements();
......@@ -236,15 +238,17 @@ HeapObject OrderedHashMap::GetEmpty(ReadOnlyRoots ro_roots) {
}
template <class Derived, int entrysize>
template <typename LocalIsolate>
MaybeHandle<Derived> OrderedHashTable<Derived, entrysize>::Rehash(
Isolate* isolate, Handle<Derived> table) {
LocalIsolate* isolate, Handle<Derived> table) {
return OrderedHashTable<Derived, entrysize>::Rehash(isolate, table,
table->Capacity());
}
template <class Derived, int entrysize>
template <typename LocalIsolate>
MaybeHandle<Derived> OrderedHashTable<Derived, entrysize>::Rehash(
Isolate* isolate, Handle<Derived> table, int new_capacity) {
LocalIsolate* isolate, Handle<Derived> table, int new_capacity) {
DCHECK(!table->IsObsolete());
MaybeHandle<Derived> new_table_candidate =
......@@ -316,8 +320,10 @@ MaybeHandle<OrderedHashMap> OrderedHashMap::Rehash(Isolate* isolate,
return Base::Rehash(isolate, table, new_capacity);
}
template <typename LocalIsolate>
MaybeHandle<OrderedNameDictionary> OrderedNameDictionary::Rehash(
Isolate* isolate, Handle<OrderedNameDictionary> table, int new_capacity) {
LocalIsolate* isolate, Handle<OrderedNameDictionary> table,
int new_capacity) {
MaybeHandle<OrderedNameDictionary> new_table_candidate =
Base::Rehash(isolate, table, new_capacity);
Handle<OrderedNameDictionary> new_table;
......@@ -349,17 +355,6 @@ bool OrderedHashTable<Derived, entrysize>::Delete(Isolate* isolate,
return true;
}
// Parameter |roots| only here for compatibility with HashTable<...>::ToKey.
template <class Derived, int entrysize>
bool OrderedHashTable<Derived, entrysize>::ToKey(ReadOnlyRoots roots,
InternalIndex entry,
Object* out_key) {
Object k = KeyAt(entry);
if (!IsKey(roots, k)) return false;
*out_key = k;
return true;
}
Address OrderedHashMap::GetHash(Isolate* isolate, Address raw_key) {
DisallowHeapAllocation no_gc;
Object key(raw_key);
......@@ -412,7 +407,9 @@ MaybeHandle<OrderedHashMap> OrderedHashMap::Add(Isolate* isolate,
return table;
}
InternalIndex OrderedNameDictionary::FindEntry(Isolate* isolate, Object key) {
template <typename LocalIsolate>
InternalIndex OrderedNameDictionary::FindEntry(LocalIsolate* isolate,
Object key) {
DisallowHeapAllocation no_gc;
DCHECK(key.IsUniqueName());
......@@ -473,9 +470,10 @@ int OrderedNameDictionary::NumberOfEnumerableProperties() {
return result;
}
template <typename LocalIsolate>
MaybeHandle<OrderedNameDictionary> OrderedNameDictionary::Add(
Isolate* isolate, Handle<OrderedNameDictionary> table, Handle<Name> key,
Handle<Object> value, PropertyDetails details) {
LocalIsolate* isolate, Handle<OrderedNameDictionary> table,
Handle<Name> key, Handle<Object> value, PropertyDetails details) {
DCHECK(table->FindEntry(isolate, *key).is_not_found());
MaybeHandle<OrderedNameDictionary> table_candidate =
......@@ -538,18 +536,21 @@ Handle<OrderedNameDictionary> OrderedNameDictionary::DeleteEntry(
return Shrink(isolate, table);
}
template <typename LocalIsolate>
MaybeHandle<OrderedHashSet> OrderedHashSet::Allocate(
Isolate* isolate, int capacity, AllocationType allocation) {
LocalIsolate* isolate, int capacity, AllocationType allocation) {
return Base::Allocate(isolate, capacity, allocation);
}
template <typename LocalIsolate>
MaybeHandle<OrderedHashMap> OrderedHashMap::Allocate(
Isolate* isolate, int capacity, AllocationType allocation) {
LocalIsolate* isolate, int capacity, AllocationType allocation) {
return Base::Allocate(isolate, capacity, allocation);
}
template <typename LocalIsolate>
MaybeHandle<OrderedNameDictionary> OrderedNameDictionary::Allocate(
Isolate* isolate, int capacity, AllocationType allocation) {
LocalIsolate* isolate, int capacity, AllocationType allocation) {
MaybeHandle<OrderedNameDictionary> table_candidate =
Base::Allocate(isolate, capacity, allocation);
Handle<OrderedNameDictionary> table;
......@@ -596,6 +597,9 @@ template V8_EXPORT_PRIVATE Handle<OrderedHashSet>
OrderedHashTable<OrderedHashSet, 1>::Clear(Isolate* isolate,
Handle<OrderedHashSet> table);
template V8_EXPORT_PRIVATE MaybeHandle<OrderedHashSet> OrderedHashSet::Allocate(
Isolate* isolate, int capacity, AllocationType allocation);
template V8_EXPORT_PRIVATE bool OrderedHashTable<OrderedHashSet, 1>::HasKey(
Isolate* isolate, OrderedHashSet table, Object key);
......@@ -617,6 +621,9 @@ template V8_EXPORT_PRIVATE Handle<OrderedHashMap>
OrderedHashTable<OrderedHashMap, 2>::Clear(Isolate* isolate,
Handle<OrderedHashMap> table);
template V8_EXPORT_PRIVATE MaybeHandle<OrderedHashMap> OrderedHashMap::Allocate(
Isolate* isolate, int capacity, AllocationType allocation);
template V8_EXPORT_PRIVATE bool OrderedHashTable<OrderedHashMap, 2>::HasKey(
Isolate* isolate, OrderedHashMap table, Object key);
......@@ -634,6 +641,37 @@ template MaybeHandle<OrderedNameDictionary>
OrderedHashTable<OrderedNameDictionary, 3>::EnsureGrowable(
Isolate* isolate, Handle<OrderedNameDictionary> table);
template V8_EXPORT_PRIVATE MaybeHandle<OrderedNameDictionary>
OrderedNameDictionary::Allocate(Isolate* isolate, int capacity,
AllocationType allocation);
template V8_EXPORT_PRIVATE MaybeHandle<OrderedNameDictionary>
OrderedNameDictionary::Allocate(LocalIsolate* isolate, int capacity,
AllocationType allocation);
template V8_EXPORT_PRIVATE MaybeHandle<OrderedNameDictionary>
OrderedNameDictionary::Rehash(Isolate* isolate,
Handle<OrderedNameDictionary> table,
int new_capacity);
template V8_EXPORT_PRIVATE InternalIndex
OrderedNameDictionary::FindEntry(Isolate* isolate, Object key);
template V8_EXPORT_PRIVATE InternalIndex
OrderedNameDictionary::FindEntry(LocalIsolate* isolate, Object key);
template V8_EXPORT_PRIVATE MaybeHandle<OrderedNameDictionary>
OrderedNameDictionary::Add(Isolate* isolate,
Handle<OrderedNameDictionary> table,
Handle<Name> key, Handle<Object> value,
PropertyDetails details);
template V8_EXPORT_PRIVATE MaybeHandle<OrderedNameDictionary>
OrderedNameDictionary::Add(LocalIsolate* isolate,
Handle<OrderedNameDictionary> table,
Handle<Name> key, Handle<Object> value,
PropertyDetails details);
template <>
Handle<SmallOrderedHashSet>
SmallOrderedHashTable<SmallOrderedHashSet>::Allocate(
......
......@@ -67,7 +67,8 @@ class OrderedHashTable : public FixedArray {
public:
// Returns an OrderedHashTable (possibly |table|) with enough space
// to add at least one new element.
static MaybeHandle<Derived> EnsureGrowable(Isolate* isolate,
template <typename LocalIsolate>
static MaybeHandle<Derived> EnsureGrowable(LocalIsolate* isolate,
Handle<Derived> table);
// Returns an OrderedHashTable (possibly |table|) that's shrunken
......@@ -123,7 +124,7 @@ class OrderedHashTable : public FixedArray {
// Similar to KeyAt, but indicates whether the given entry is valid
// (not deleted one)
bool ToKey(ReadOnlyRoots roots, InternalIndex entry, Object* out_key);
inline bool ToKey(ReadOnlyRoots roots, InternalIndex entry, Object* out_key);
bool IsObsolete() { return !get(NextTableIndex()).IsSmi(); }
......@@ -199,17 +200,21 @@ class OrderedHashTable : public FixedArray {
protected:
// Returns an OrderedHashTable with a capacity of at least |capacity|.
template <typename LocalIsolate>
static MaybeHandle<Derived> Allocate(
Isolate* isolate, int capacity,
LocalIsolate* isolate, int capacity,
AllocationType allocation = AllocationType::kYoung);
static MaybeHandle<Derived> AllocateEmpty(Isolate* isolate,
AllocationType allocation,
RootIndex root_ndex);
static MaybeHandle<Derived> Rehash(Isolate* isolate, Handle<Derived> table);
static MaybeHandle<Derived> Rehash(Isolate* isolate, Handle<Derived> table,
int new_capacity);
template <typename LocalIsolate>
static MaybeHandle<Derived> Rehash(LocalIsolate* isolate,
Handle<Derived> table);
template <typename LocalIsolate>
static MaybeHandle<Derived> Rehash(LocalIsolate* isolate,
Handle<Derived> table, int new_capacity);
int HashToEntryRaw(int hash) {
int bucket = HashToBucket(hash);
......@@ -283,8 +288,9 @@ class V8_EXPORT_PRIVATE OrderedHashSet
int new_capacity);
static MaybeHandle<OrderedHashSet> Rehash(Isolate* isolate,
Handle<OrderedHashSet> table);
template <typename LocalIsolate>
static MaybeHandle<OrderedHashSet> Allocate(
Isolate* isolate, int capacity,
LocalIsolate* isolate, int capacity,
AllocationType allocation = AllocationType::kYoung);
static MaybeHandle<OrderedHashSet> AllocateEmpty(
......@@ -312,8 +318,9 @@ class V8_EXPORT_PRIVATE OrderedHashMap
Handle<Object> key,
Handle<Object> value);
template <typename LocalIsolate>
static MaybeHandle<OrderedHashMap> Allocate(
Isolate* isolate, int capacity,
LocalIsolate* isolate, int capacity,
AllocationType allocation = AllocationType::kYoung);
static MaybeHandle<OrderedHashMap> AllocateEmpty(
......@@ -753,14 +760,26 @@ class V8_EXPORT_PRIVATE OrderedNameDictionary
public:
DECL_CAST(OrderedNameDictionary)
template <typename LocalIsolate>
static MaybeHandle<OrderedNameDictionary> Add(
Isolate* isolate, Handle<OrderedNameDictionary> table, Handle<Name> key,
Handle<Object> value, PropertyDetails details);
LocalIsolate* isolate, Handle<OrderedNameDictionary> table,
Handle<Name> key, Handle<Object> value, PropertyDetails details);
void SetEntry(InternalIndex entry, Object key, Object value,
PropertyDetails details);
InternalIndex FindEntry(Isolate* isolate, Object key);
template <typename LocalIsolate>
InternalIndex FindEntry(LocalIsolate* isolate, Object key);
// This is to make the interfaces of NameDictionary::FindEntry and
// OrderedNameDictionary::FindEntry compatible.
// TODO(emrich) clean this up: NameDictionary uses Handle<Object>
// for FindEntry keys due to its Key typedef, but that's also used
// for adding, where we do need handles.
template <typename LocalIsolate>
InternalIndex FindEntry(LocalIsolate* isolate, Handle<Object> key) {
return FindEntry(isolate, *key);
}
int NumberOfEnumerableProperties();
......@@ -770,15 +789,18 @@ class V8_EXPORT_PRIVATE OrderedNameDictionary
Isolate* isolate, Handle<OrderedNameDictionary> table,
InternalIndex entry);
template <typename LocalIsolate>
static MaybeHandle<OrderedNameDictionary> Allocate(
Isolate* isolate, int capacity,
LocalIsolate* isolate, int capacity,
AllocationType allocation = AllocationType::kYoung);
static MaybeHandle<OrderedNameDictionary> AllocateEmpty(
Isolate* isolate, AllocationType allocation = AllocationType::kReadOnly);
template <typename LocalIsolate>
static MaybeHandle<OrderedNameDictionary> Rehash(
Isolate* isolate, Handle<OrderedNameDictionary> table, int new_capacity);
LocalIsolate* isolate, Handle<OrderedNameDictionary> table,
int new_capacity);
// Returns the value for entry.
inline Object ValueAt(InternalIndex entry);
......
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