Commit 449fe719 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[ubsan] Port SmallOrderedHashTable and subclasses

to the new design.

Bug: v8:3770
Change-Id: Ic77a4f645a1ca3ed9be87690155e988723132471
Reviewed-on: https://chromium-review.googlesource.com/c/1350285Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57884}
parent 74f363a8
...@@ -33,6 +33,9 @@ class ObjectPtr; ...@@ -33,6 +33,9 @@ class ObjectPtr;
class OrderedHashMap; class OrderedHashMap;
class OrderedHashSet; class OrderedHashSet;
class OrderedNameDictionary; class OrderedNameDictionary;
class SmallOrderedHashMap;
class SmallOrderedHashSet;
class SmallOrderedNameDictionary;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Base class for Handle instantiations. Don't use directly. // Base class for Handle instantiations. Don't use directly.
...@@ -160,6 +163,9 @@ class Handle final : public HandleBase { ...@@ -160,6 +163,9 @@ class Handle final : public HandleBase {
std::is_same<S, OrderedNameDictionary>::value || std::is_same<S, OrderedNameDictionary>::value ||
std::is_same<S, ScriptContextTable>::value || std::is_same<S, ScriptContextTable>::value ||
std::is_same<S, ScopeInfo>::value || std::is_same<S, ScopeInfo>::value ||
std::is_same<S, SmallOrderedHashMap>::value ||
std::is_same<S, SmallOrderedHashSet>::value ||
std::is_same<S, SmallOrderedNameDictionary>::value ||
std::is_same<S, String>::value || std::is_same<S, String>::value ||
std::is_same<S, Symbol>::value))>::type> std::is_same<S, Symbol>::value))>::type>
V8_INLINE Handle(Handle<S> handle) : HandleBase(handle) {} V8_INLINE Handle(Handle<S> handle) : HandleBase(handle) {}
......
...@@ -68,9 +68,9 @@ class WasmInstanceObject; ...@@ -68,9 +68,9 @@ class WasmInstanceObject;
V(SeqTwoByteString, SeqTwoByteString) \ V(SeqTwoByteString, SeqTwoByteString) \
V(SharedFunctionInfo, SharedFunctionInfo*) \ V(SharedFunctionInfo, SharedFunctionInfo*) \
V(SlicedString, SlicedString) \ V(SlicedString, SlicedString) \
V(SmallOrderedHashMap, SmallOrderedHashMap*) \ V(SmallOrderedHashMap, SmallOrderedHashMap) \
V(SmallOrderedHashSet, SmallOrderedHashSet*) \ V(SmallOrderedHashSet, SmallOrderedHashSet) \
V(SmallOrderedNameDictionary, SmallOrderedNameDictionary*) \ V(SmallOrderedNameDictionary, SmallOrderedNameDictionary) \
V(Symbol, Symbol) \ V(Symbol, Symbol) \
V(ThinString, ThinString) \ V(ThinString, ThinString) \
V(TransitionArray, TransitionArray*) \ V(TransitionArray, TransitionArray*) \
......
...@@ -276,7 +276,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final ...@@ -276,7 +276,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final
: public BodyDescriptorBase { : public BodyDescriptorBase {
public: public:
static bool IsValidSlot(Map map, HeapObject* obj, int offset) { static bool IsValidSlot(Map map, HeapObject* obj, int offset) {
Derived* table = reinterpret_cast<Derived*>(obj); Derived table = Derived::cast(obj);
if (offset < kDataTableStartOffset) return false; if (offset < kDataTableStartOffset) return false;
if (offset >= table->GetBucketsStartOffset()) return false; if (offset >= table->GetBucketsStartOffset()) return false;
return IsValidSlotImpl(map, obj, offset); return IsValidSlotImpl(map, obj, offset);
...@@ -285,7 +285,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final ...@@ -285,7 +285,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final
template <typename ObjectVisitor> template <typename ObjectVisitor>
static inline void IterateBody(Map map, HeapObject* obj, int object_size, static inline void IterateBody(Map map, HeapObject* obj, int object_size,
ObjectVisitor* v) { ObjectVisitor* v) {
Derived* table = reinterpret_cast<Derived*>(obj); Derived table = Derived::cast(obj);
int offset = kDataTableStartOffset; int offset = kDataTableStartOffset;
int entry = 0; int entry = 0;
...@@ -298,7 +298,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final ...@@ -298,7 +298,7 @@ class SmallOrderedHashTable<Derived>::BodyDescriptor final
} }
static inline int SizeOf(Map map, HeapObject* obj) { static inline int SizeOf(Map map, HeapObject* obj) {
Derived* table = reinterpret_cast<Derived*>(obj); Derived table = Derived::cast(obj);
return table->SizeFor(table->Capacity()); return table->SizeFor(table->Capacity());
} }
}; };
......
...@@ -487,6 +487,17 @@ OrderedNameDictionary::OrderedNameDictionary(Address ptr) ...@@ -487,6 +487,17 @@ OrderedNameDictionary::OrderedNameDictionary(Address ptr)
SLOW_DCHECK(IsOrderedNameDictionary()); SLOW_DCHECK(IsOrderedNameDictionary());
} }
template <class Derived>
SmallOrderedHashTable<Derived>::SmallOrderedHashTable(Address ptr)
: HeapObjectPtr(ptr) {}
OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashSet,
SmallOrderedHashTable<SmallOrderedHashSet>)
OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashMap,
SmallOrderedHashTable<SmallOrderedHashMap>)
OBJECT_CONSTRUCTORS_IMPL(SmallOrderedNameDictionary,
SmallOrderedHashTable<SmallOrderedNameDictionary>)
OBJECT_CONSTRUCTORS_IMPL(RegExpMatchInfo, FixedArray) OBJECT_CONSTRUCTORS_IMPL(RegExpMatchInfo, FixedArray)
OBJECT_CONSTRUCTORS_IMPL(ScopeInfo, FixedArray) OBJECT_CONSTRUCTORS_IMPL(ScopeInfo, FixedArray)
...@@ -522,9 +533,9 @@ CAST_ACCESSOR(PropertyCell) ...@@ -522,9 +533,9 @@ CAST_ACCESSOR(PropertyCell)
CAST_ACCESSOR2(RegExpMatchInfo) CAST_ACCESSOR2(RegExpMatchInfo)
CAST_ACCESSOR2(ScopeInfo) CAST_ACCESSOR2(ScopeInfo)
CAST_ACCESSOR2(SimpleNumberDictionary) CAST_ACCESSOR2(SimpleNumberDictionary)
CAST_ACCESSOR(SmallOrderedHashMap) CAST_ACCESSOR2(SmallOrderedHashMap)
CAST_ACCESSOR(SmallOrderedHashSet) CAST_ACCESSOR2(SmallOrderedHashSet)
CAST_ACCESSOR(SmallOrderedNameDictionary) CAST_ACCESSOR2(SmallOrderedNameDictionary)
CAST_ACCESSOR2(StringSet) CAST_ACCESSOR2(StringSet)
CAST_ACCESSOR2(StringTable) CAST_ACCESSOR2(StringTable)
CAST_ACCESSOR(Struct) CAST_ACCESSOR(Struct)
...@@ -1579,15 +1590,15 @@ int HeapObject::SizeFromMap(Map map) const { ...@@ -1579,15 +1590,15 @@ int HeapObject::SizeFromMap(Map map) const {
} }
if (instance_type == SMALL_ORDERED_HASH_SET_TYPE) { if (instance_type == SMALL_ORDERED_HASH_SET_TYPE) {
return SmallOrderedHashSet::SizeFor( return SmallOrderedHashSet::SizeFor(
reinterpret_cast<const SmallOrderedHashSet*>(this)->Capacity()); SmallOrderedHashSet::unchecked_cast(this)->Capacity());
} }
if (instance_type == SMALL_ORDERED_HASH_MAP_TYPE) { if (instance_type == SMALL_ORDERED_HASH_MAP_TYPE) {
return SmallOrderedHashMap::SizeFor( return SmallOrderedHashMap::SizeFor(
reinterpret_cast<const SmallOrderedHashMap*>(this)->Capacity()); SmallOrderedHashMap::unchecked_cast(this)->Capacity());
} }
if (instance_type == SMALL_ORDERED_NAME_DICTIONARY_TYPE) { if (instance_type == SMALL_ORDERED_NAME_DICTIONARY_TYPE) {
return SmallOrderedNameDictionary::SizeFor( return SmallOrderedNameDictionary::SizeFor(
reinterpret_cast<const SmallOrderedNameDictionary*>(this)->Capacity()); SmallOrderedNameDictionary::unchecked_cast(this)->Capacity());
} }
if (instance_type == PROPERTY_ARRAY_TYPE) { if (instance_type == PROPERTY_ARRAY_TYPE) {
return PropertyArray::SizeFor( return PropertyArray::SizeFor(
......
...@@ -48,6 +48,11 @@ ODDBALL_LIST(TYPE_CHECK_FORWARDER) ...@@ -48,6 +48,11 @@ ODDBALL_LIST(TYPE_CHECK_FORWARDER)
bool ObjectPtr::IsHashTableBase() const { return IsHashTable(); } bool ObjectPtr::IsHashTableBase() const { return IsHashTable(); }
bool ObjectPtr::IsSmallOrderedHashTable() const {
return IsSmallOrderedHashSet() || IsSmallOrderedHashMap() ||
IsSmallOrderedNameDictionary();
}
double ObjectPtr::Number() const { double ObjectPtr::Number() const {
return reinterpret_cast<Object*>(ptr())->Number(); return reinterpret_cast<Object*>(ptr())->Number();
} }
......
...@@ -57,6 +57,7 @@ class ObjectPtr { ...@@ -57,6 +57,7 @@ class ObjectPtr {
ODDBALL_LIST(IS_TYPE_FUNCTION_DECL) ODDBALL_LIST(IS_TYPE_FUNCTION_DECL)
#undef IS_TYPE_FUNCTION_DECL #undef IS_TYPE_FUNCTION_DECL
inline bool IsHashTableBase() const; inline bool IsHashTableBase() const;
V8_INLINE bool IsSmallOrderedHashTable() const;
inline bool IsObject() const { return true; } inline bool IsObject() const { return true; }
inline double Number() const; inline double Number() const;
...@@ -182,6 +183,7 @@ class HeapObjectPtr : public ObjectPtr { ...@@ -182,6 +183,7 @@ class HeapObjectPtr : public ObjectPtr {
#endif #endif
static const int kMapOffset = HeapObject::kMapOffset; static const int kMapOffset = HeapObject::kMapOffset;
static const int kHeaderSize = HeapObject::kHeaderSize;
inline Address GetFieldAddress(int field_offset) const; inline Address GetFieldAddress(int field_offset) const;
......
...@@ -460,8 +460,8 @@ void SmallOrderedHashTable<Derived>::Initialize(Isolate* isolate, ...@@ -460,8 +460,8 @@ void SmallOrderedHashTable<Derived>::Initialize(Isolate* isolate,
memset(reinterpret_cast<byte*>(hashtable_start), kNotFound, memset(reinterpret_cast<byte*>(hashtable_start), kNotFound,
num_buckets + num_chains); num_buckets + num_chains);
if (Heap::InNewSpace(this)) { if (Heap::InNewSpace(*this)) {
MemsetPointer(RawField(this, kDataTableStartOffset), MemsetPointer(RawField(kDataTableStartOffset),
ReadOnlyRoots(isolate).the_hole_value(), ReadOnlyRoots(isolate).the_hole_value(),
capacity * Derived::kEntrySize); capacity * Derived::kEntrySize);
} else { } else {
...@@ -604,7 +604,7 @@ bool SmallOrderedHashTable<Derived>::HasKey(Isolate* isolate, ...@@ -604,7 +604,7 @@ bool SmallOrderedHashTable<Derived>::HasKey(Isolate* isolate,
} }
template <class Derived> template <class Derived>
bool SmallOrderedHashTable<Derived>::Delete(Isolate* isolate, Derived* table, bool SmallOrderedHashTable<Derived>::Delete(Isolate* isolate, Derived table,
Object* key) { Object* key) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
int entry = table->FindEntry(isolate, key); int entry = table->FindEntry(isolate, key);
...@@ -748,9 +748,9 @@ template void SmallOrderedHashTable<SmallOrderedHashMap>::Initialize( ...@@ -748,9 +748,9 @@ template void SmallOrderedHashTable<SmallOrderedHashMap>::Initialize(
Isolate* isolate, int capacity); Isolate* isolate, int capacity);
template bool SmallOrderedHashTable<SmallOrderedHashMap>::Delete( template bool SmallOrderedHashTable<SmallOrderedHashMap>::Delete(
Isolate* isolate, SmallOrderedHashMap* table, Object* key); Isolate* isolate, SmallOrderedHashMap table, Object* key);
template bool SmallOrderedHashTable<SmallOrderedHashSet>::Delete( template bool SmallOrderedHashTable<SmallOrderedHashSet>::Delete(
Isolate* isolate, SmallOrderedHashSet* table, Object* key); Isolate* isolate, SmallOrderedHashSet table, Object* key);
template void SmallOrderedHashTable<SmallOrderedNameDictionary>::Initialize( template void SmallOrderedHashTable<SmallOrderedNameDictionary>::Initialize(
Isolate* isolate, int capacity); Isolate* isolate, int capacity);
......
...@@ -272,7 +272,7 @@ class OrderedHashMap : public OrderedHashTable<OrderedHashMap, 2> { ...@@ -272,7 +272,7 @@ class OrderedHashMap : public OrderedHashTable<OrderedHashMap, 2> {
// [45] : empty // [45] : empty
// //
template <class Derived> template <class Derived>
class SmallOrderedHashTable : public HeapObject { class SmallOrderedHashTable : public HeapObjectPtr {
public: public:
// Offset points to a relative location in the table // Offset points to a relative location in the table
typedef int Offset; typedef int Offset;
...@@ -291,7 +291,7 @@ class SmallOrderedHashTable : public HeapObject { ...@@ -291,7 +291,7 @@ class SmallOrderedHashTable : public HeapObject {
// Returns a true value if the table contains the key and // Returns a true value if the table contains the key and
// the key has been deleted. This does not shrink the table. // the key has been deleted. This does not shrink the table.
static bool Delete(Isolate* isolate, Derived* table, Object* key); static bool Delete(Isolate* isolate, Derived table, Object* key);
// Returns an SmallOrderedHashTable (possibly |table|) with enough // Returns an SmallOrderedHashTable (possibly |table|) with enough
// space to add at least one new element. Returns empty handle if // space to add at least one new element. Returns empty handle if
...@@ -497,11 +497,13 @@ class SmallOrderedHashTable : public HeapObject { ...@@ -497,11 +497,13 @@ class SmallOrderedHashTable : public HeapObject {
friend class OrderedHashMapHandler; friend class OrderedHashMapHandler;
friend class OrderedHashSetHandler; friend class OrderedHashSetHandler;
friend class CodeStubAssembler; friend class CodeStubAssembler;
OBJECT_CONSTRUCTORS(SmallOrderedHashTable, HeapObjectPtr)
}; };
class SmallOrderedHashSet : public SmallOrderedHashTable<SmallOrderedHashSet> { class SmallOrderedHashSet : public SmallOrderedHashTable<SmallOrderedHashSet> {
public: public:
DECL_CAST(SmallOrderedHashSet) DECL_CAST2(SmallOrderedHashSet)
DECL_PRINTER(SmallOrderedHashSet) DECL_PRINTER(SmallOrderedHashSet)
...@@ -516,11 +518,14 @@ class SmallOrderedHashSet : public SmallOrderedHashTable<SmallOrderedHashSet> { ...@@ -516,11 +518,14 @@ class SmallOrderedHashSet : public SmallOrderedHashTable<SmallOrderedHashSet> {
Handle<Object> key); Handle<Object> key);
static inline bool Is(Handle<HeapObject> table); static inline bool Is(Handle<HeapObject> table);
static inline RootIndex GetMapRootIndex(); static inline RootIndex GetMapRootIndex();
OBJECT_CONSTRUCTORS(SmallOrderedHashSet,
SmallOrderedHashTable<SmallOrderedHashSet>)
}; };
class SmallOrderedHashMap : public SmallOrderedHashTable<SmallOrderedHashMap> { class SmallOrderedHashMap : public SmallOrderedHashTable<SmallOrderedHashMap> {
public: public:
DECL_CAST(SmallOrderedHashMap) DECL_CAST2(SmallOrderedHashMap)
DECL_PRINTER(SmallOrderedHashMap) DECL_PRINTER(SmallOrderedHashMap)
...@@ -537,6 +542,9 @@ class SmallOrderedHashMap : public SmallOrderedHashTable<SmallOrderedHashMap> { ...@@ -537,6 +542,9 @@ class SmallOrderedHashMap : public SmallOrderedHashTable<SmallOrderedHashMap> {
Handle<Object> value); Handle<Object> value);
static inline bool Is(Handle<HeapObject> table); static inline bool Is(Handle<HeapObject> table);
static inline RootIndex GetMapRootIndex(); static inline RootIndex GetMapRootIndex();
OBJECT_CONSTRUCTORS(SmallOrderedHashMap,
SmallOrderedHashTable<SmallOrderedHashMap>)
}; };
// TODO(gsathya): Rename this to OrderedHashTable, after we rename // TODO(gsathya): Rename this to OrderedHashTable, after we rename
...@@ -612,7 +620,7 @@ class OrderedNameDictionary ...@@ -612,7 +620,7 @@ class OrderedNameDictionary
class SmallOrderedNameDictionary class SmallOrderedNameDictionary
: public SmallOrderedHashTable<SmallOrderedNameDictionary> { : public SmallOrderedHashTable<SmallOrderedNameDictionary> {
public: public:
DECL_CAST(SmallOrderedNameDictionary) DECL_CAST2(SmallOrderedNameDictionary)
DECL_PRINTER(SmallOrderedNameDictionary) DECL_PRINTER(SmallOrderedNameDictionary)
...@@ -640,6 +648,9 @@ class SmallOrderedNameDictionary ...@@ -640,6 +648,9 @@ class SmallOrderedNameDictionary
Isolate* isolate, Handle<SmallOrderedNameDictionary> table, Isolate* isolate, Handle<SmallOrderedNameDictionary> table,
Handle<Name> key, Handle<Object> value, PropertyDetails details); Handle<Name> key, Handle<Object> value, PropertyDetails details);
static inline RootIndex GetMapRootIndex(); static inline RootIndex GetMapRootIndex();
OBJECT_CONSTRUCTORS(SmallOrderedNameDictionary,
SmallOrderedHashTable<SmallOrderedNameDictionary>)
}; };
class JSCollectionIterator : public JSObject { class JSCollectionIterator : public JSObject {
......
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