Commit 4b71ac6b authored by Frank Emrich's avatar Frank Emrich Committed by Commit Bot

[dict-proto] Printing of orderded hash tables

This adds support for OrderedHashSet, OrderedHashMap, and
OrderedNameDictionary to Object::Print.
It also refactors the existing printing of (unordered) hash sets, maps,
and dictionaries to increase code reuse.

Bug: v8:7569
Change-Id: I598f6a025f4170e440d3840ce18234772068a7ca
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2523320
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@{#71122}
parent 0d827da3
This diff is collapsed.
......@@ -43,6 +43,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
// Set the details for entry.
inline void DetailsAtPut(InternalIndex entry, PropertyDetails value);
static const bool kIsOrderedDictionaryType = false;
// Delete a property from the dictionary.
V8_WARN_UNUSED_RESULT static Handle<Derived> DeleteEntry(
Isolate* isolate, Handle<Derived> dictionary, InternalIndex entry);
......@@ -55,12 +57,6 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
int NumberOfEnumerableProperties();
#ifdef OBJECT_PRINT
// For our gdb macros, we should perhaps change these in the future.
void Print();
void Print(std::ostream& os); // NOLINT
#endif
// Returns the key (slow).
Object SlowReverseLookup(Object value);
......@@ -131,8 +127,6 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) BaseNameDictionary
static const int kObjectHashIndex = kNextEnumerationIndexIndex + 1;
static const int kEntryValueIndex = 1;
static const bool kIsOrderedDictionaryType = false;
inline void SetHash(int hash);
inline int Hash() const;
......@@ -181,6 +175,7 @@ class V8_EXPORT_PRIVATE NameDictionary
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
DECL_CAST(NameDictionary)
DECL_PRINTER(NameDictionary)
static const int kEntryValueIndex = 1;
static const int kEntryDetailsIndex = 2;
......@@ -222,6 +217,7 @@ class V8_EXPORT_PRIVATE GlobalDictionary
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
DECL_CAST(GlobalDictionary)
DECL_PRINTER(GlobalDictionary)
inline Object ValueAt(InternalIndex entry);
inline Object ValueAt(IsolateRoot isolate, InternalIndex entry);
......
......@@ -5172,39 +5172,6 @@ bool JSArray::WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index) {
return false;
}
// Certain compilers request function template instantiation when they
// see the definition of the other template functions in the
// class. This requires us to have the template functions put
// together, so even though this function belongs in objects-debug.cc,
// we keep it here instead to satisfy certain compilers.
#ifdef OBJECT_PRINT
template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::Print(std::ostream& os) {
DisallowHeapAllocation no_gc;
IsolateRoot isolate = GetIsolateForPtrCompr(*this);
ReadOnlyRoots roots = this->GetReadOnlyRoots(isolate);
Derived dictionary = Derived::cast(*this);
for (InternalIndex i : dictionary.IterateEntries()) {
Object k = dictionary.KeyAt(isolate, i);
if (!dictionary.ToKey(roots, i, &k)) continue;
os << "\n ";
if (k.IsString()) {
String::cast(k).PrintUC16(os);
} else {
os << Brief(k);
}
os << ": " << Brief(dictionary.ValueAt(i)) << " ";
dictionary.DetailsAt(i).PrintAsSlowTo(os);
}
}
template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::Print() {
StdoutStream os;
Print(os);
os << std::endl;
}
#endif
int FixedArrayBase::GetMaxLengthForNewSpaceAllocation(ElementsKind kind) {
return ((kMaxRegularHeapObjectSize - FixedArrayBase::kHeaderSize) >>
ElementsKindToShiftSize(kind));
......
......@@ -108,6 +108,8 @@ class OrderedHashTable : public FixedArray {
return NumberOfElements() + NumberOfDeletedElements();
}
int Capacity() { return NumberOfBuckets() * kLoadFactor; }
int NumberOfBuckets() const {
return Smi::ToInt(get(NumberOfBucketsIndex()));
}
......@@ -255,8 +257,6 @@ class OrderedHashTable : public FixedArray {
set(NumberOfDeletedElementsIndex(), Smi::FromInt(num));
}
// Returns the number elements that can fit into the allocated buffer.
int Capacity() { return NumberOfBuckets() * kLoadFactor; }
void SetNextTable(Derived next_table) { set(NextTableIndex(), next_table); }
......@@ -276,6 +276,7 @@ class V8_EXPORT_PRIVATE OrderedHashSet
public:
DECL_CAST(OrderedHashSet)
DECL_PRINTER(OrderedHashSet)
static MaybeHandle<OrderedHashSet> Add(Isolate* isolate,
Handle<OrderedHashSet> table,
......@@ -310,6 +311,7 @@ class V8_EXPORT_PRIVATE OrderedHashMap
public:
DECL_CAST(OrderedHashMap)
DECL_PRINTER(OrderedHashMap)
// Returns a value if the OrderedHashMap contains the key, otherwise
// returns undefined.
......@@ -759,6 +761,7 @@ class V8_EXPORT_PRIVATE OrderedNameDictionary
public:
DECL_CAST(OrderedNameDictionary)
DECL_PRINTER(OrderedNameDictionary)
template <typename LocalIsolate>
static MaybeHandle<OrderedNameDictionary> Add(
......
......@@ -365,7 +365,7 @@ class PropertyDetails {
kForTransitions = kPrintAttributes,
kPrintFull = -1,
};
void PrintAsSlowTo(std::ostream& out);
void PrintAsSlowTo(std::ostream& out, bool print_dict_index);
void PrintAsFastTo(std::ostream& out, PrintMode mode = kPrintFull);
private:
......
......@@ -98,11 +98,13 @@ Descriptor Descriptor::AccessorConstant(Handle<Name> key,
}
// Outputs PropertyDetails as a dictionary details.
void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
void PropertyDetails::PrintAsSlowTo(std::ostream& os, bool print_dict_index) {
os << "(";
if (constness() == PropertyConstness::kConst) os << "const ";
os << (kind() == kData ? "data" : "accessor");
os << ", dict_index: " << dictionary_index();
if (print_dict_index) {
os << ", dict_index: " << dictionary_index();
}
os << ", attrs: " << attributes() << ")";
}
......@@ -135,7 +137,7 @@ void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
void PropertyDetails::Print(bool dictionary_mode) {
StdoutStream os;
if (dictionary_mode) {
PrintAsSlowTo(os);
PrintAsSlowTo(os, true);
} else {
PrintAsFastTo(os, PrintMode::kPrintFull);
}
......
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