Commit cfc79faa authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[hashtable] Move data table to the beginning

TBR: hpayer@chromium.org
Bug: v8:6443, v8:7569
Change-Id: Idd952ed0a832c469b76f1cbc919f700e09dc975d
Reviewed-on: https://chromium-review.googlesource.com/1031559
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52930}
parent a9e2b2ce
......@@ -441,7 +441,7 @@ Handle<SmallOrderedHashSet> Factory::NewSmallOrderedHashSet(
CHECK_LE(capacity, SmallOrderedHashSet::kMaxCapacity);
DCHECK_EQ(0, capacity % SmallOrderedHashSet::kLoadFactor);
int size = SmallOrderedHashSet::Size(capacity);
int size = SmallOrderedHashSet::SizeFor(capacity);
Map* map = *small_ordered_hash_set_map();
HeapObject* result = AllocateRawWithImmortalMap(size, pretenure, map);
Handle<SmallOrderedHashSet> table(SmallOrderedHashSet::cast(result),
......@@ -456,7 +456,7 @@ Handle<SmallOrderedHashMap> Factory::NewSmallOrderedHashMap(
CHECK_LE(capacity, SmallOrderedHashMap::kMaxCapacity);
DCHECK_EQ(0, capacity % SmallOrderedHashMap::kLoadFactor);
int size = SmallOrderedHashMap::Size(capacity);
int size = SmallOrderedHashMap::SizeFor(capacity);
Map* map = *small_ordered_hash_map_map();
HeapObject* result = AllocateRawWithImmortalMap(size, pretenure, map);
Handle<SmallOrderedHashMap> table(SmallOrderedHashMap::cast(result),
......
......@@ -181,7 +181,8 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final
public:
static bool IsValidSlot(Map* map, HeapObject* obj, int offset) {
Derived* table = reinterpret_cast<Derived*>(obj);
if (offset < table->GetDataTableStartOffset()) return false;
if (offset < kDataTableStartOffset) return false;
if (offset >= table->GetBucketsStartOffset()) return false;
return IsValidSlotImpl(map, obj, offset);
}
......@@ -189,7 +190,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final
static inline void IterateBody(Map* map, HeapObject* obj, int object_size,
ObjectVisitor* v) {
Derived* table = reinterpret_cast<Derived*>(obj);
int start = table->GetDataTableStartOffset();
int start = kDataTableStartOffset;
for (int i = 0; i < table->Capacity(); i++) {
IteratePointer(obj, start + (i * kPointerSize), v);
}
......@@ -197,7 +198,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final
static inline int SizeOf(Map* map, HeapObject* obj) {
Derived* table = reinterpret_cast<Derived*>(obj);
return table->Size();
return table->SizeFor(table->Capacity());
}
};
......
......@@ -2252,14 +2252,16 @@ int HeapObject::SizeFromMap(Map* map) const {
instance_type);
}
if (instance_type == SMALL_ORDERED_HASH_SET_TYPE) {
return reinterpret_cast<const SmallOrderedHashSet*>(this)->Size();
return SmallOrderedHashSet::SizeFor(
reinterpret_cast<const SmallOrderedHashSet*>(this)->Capacity());
}
if (instance_type == PROPERTY_ARRAY_TYPE) {
return PropertyArray::SizeFor(
reinterpret_cast<const PropertyArray*>(this)->synchronized_length());
}
if (instance_type == SMALL_ORDERED_HASH_MAP_TYPE) {
return reinterpret_cast<const SmallOrderedHashMap*>(this)->Size();
return SmallOrderedHashMap::SizeFor(
reinterpret_cast<const SmallOrderedHashMap*>(this)->Capacity());
}
if (instance_type == FEEDBACK_VECTOR_TYPE) {
return FeedbackVector::SizeFor(
......@@ -2609,9 +2611,10 @@ void Foreign::set_foreign_address(Address value) {
template <class Derived>
void SmallOrderedHashTable<Derived>::SetDataEntry(int entry, int relative_index,
Object* value) {
int entry_offset = GetDataEntryOffset(entry, relative_index);
Address entry_offset =
kHeaderSize + GetDataEntryOffset(entry, relative_index);
RELAXED_WRITE_FIELD(this, entry_offset, value);
WRITE_BARRIER(GetHeap(), this, entry_offset, value);
WRITE_BARRIER(GetHeap(), this, static_cast<int>(entry_offset), value);
}
ACCESSORS(JSGeneratorObject, function, JSFunction, kFunctionOffset)
......
......@@ -3573,18 +3573,6 @@ void HeapNumber::HeapNumberPrint(std::ostream& os) { // NOLINT
os << value();
}
#define FIELD_ADDR(p, offset) \
(reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
#define READ_INT32_FIELD(p, offset) \
(*reinterpret_cast<const int32_t*>(FIELD_ADDR(p, offset)))
#define READ_INT64_FIELD(p, offset) \
(*reinterpret_cast<const int64_t*>(FIELD_ADDR(p, offset)))
#define READ_BYTE_FIELD(p, offset) \
(*reinterpret_cast<const byte*>(FIELD_ADDR(p, offset)))
String* JSReceiver::class_name() {
if (IsFunction()) return GetHeap()->Function_string();
if (IsJSArgumentsObject()) return GetHeap()->Arguments_string();
......@@ -18570,6 +18558,7 @@ SmallOrderedHashTable<SmallOrderedHashMap>::Allocate(Isolate* isolate,
template <class Derived>
void SmallOrderedHashTable<Derived>::Initialize(Isolate* isolate,
int capacity) {
DisallowHeapAllocation no_gc;
int num_buckets = capacity / kLoadFactor;
int num_chains = capacity;
......@@ -18577,12 +18566,12 @@ void SmallOrderedHashTable<Derived>::Initialize(Isolate* isolate,
SetNumberOfElements(0);
SetNumberOfDeletedElements(0);
byte* hashtable_start =
FIELD_ADDR(this, kHeaderSize + (kBucketsStartOffset * kOneByteSize));
memset(hashtable_start, kNotFound, num_buckets + num_chains);
Address hashtable_start = GetHashTableStartAddress(capacity);
memset(reinterpret_cast<byte*>(hashtable_start), kNotFound,
num_buckets + num_chains);
if (isolate->heap()->InNewSpace(this)) {
MemsetPointer(RawField(this, GetDataTableStartOffset()),
MemsetPointer(RawField(this, kHeaderSize + kDataTableStartOffset),
isolate->heap()->the_hole_value(),
capacity * Derived::kEntrySize);
} else {
......@@ -18601,6 +18590,12 @@ void SmallOrderedHashTable<Derived>::Initialize(Isolate* isolate,
for (int i = 0; i < num_chains; ++i) {
DCHECK_EQ(kNotFound, GetNextEntry(i));
}
for (int i = 0; i < capacity; ++i) {
for (int j = 0; j < Derived::kEntrySize; j++) {
DCHECK_EQ(isolate->heap()->the_hole_value(), GetDataEntry(i, j));
}
}
#endif // DEBUG
}
......@@ -19567,10 +19562,5 @@ MaybeHandle<Name> FunctionTemplateInfo::TryGetCachedPropertyName(
return MaybeHandle<Name>();
}
#undef FIELD_ADDR
#undef READ_INT32_FIELD
#undef READ_INT64_FIELD
#undef READ_BYTE_FIELD
} // namespace internal
} // namespace v8
This diff is collapsed.
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