diff options
author | Michaël Zasso <targos@protonmail.com> | 2017-02-14 11:27:26 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2017-02-22 15:55:42 +0100 |
commit | 7a77daf24344db7942e34c962b0f1ee729ab7af5 (patch) | |
tree | e7cbe7bf4e2f4b802a8f5bc18336c546cd6a0d7f /deps/v8/src/address-map.h | |
parent | 5f08871ee93ea739148cc49e0f7679e33c70295a (diff) | |
download | android-node-v8-7a77daf24344db7942e34c962b0f1ee729ab7af5.tar.gz android-node-v8-7a77daf24344db7942e34c962b0f1ee729ab7af5.tar.bz2 android-node-v8-7a77daf24344db7942e34c962b0f1ee729ab7af5.zip |
deps: update V8 to 5.6.326.55
PR-URL: https://github.com/nodejs/node/pull/10992
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/src/address-map.h')
-rw-r--r-- | deps/v8/src/address-map.h | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/deps/v8/src/address-map.h b/deps/v8/src/address-map.h index 95e9cb064b..d50847fcd4 100644 --- a/deps/v8/src/address-map.h +++ b/deps/v8/src/address-map.h @@ -5,6 +5,7 @@ #ifndef V8_ADDRESS_MAP_H_ #define V8_ADDRESS_MAP_H_ +#include "include/v8.h" #include "src/assert-scope.h" #include "src/base/hashmap.h" #include "src/objects.h" @@ -12,49 +13,50 @@ namespace v8 { namespace internal { -class AddressMapBase { - protected: - static void SetValue(base::HashMap::Entry* entry, uint32_t v) { - entry->value = reinterpret_cast<void*>(v); - } +template <typename Type> +class PointerToIndexHashMap + : public base::TemplateHashMapImpl<uintptr_t, uint32_t, + base::KeyEqualityMatcher<intptr_t>, + base::DefaultAllocationPolicy> { + public: + typedef base::TemplateHashMapEntry<uintptr_t, uint32_t> Entry; - static uint32_t GetValue(base::HashMap::Entry* entry) { - return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value)); + inline void Set(Type value, uint32_t index) { + uintptr_t key = Key(value); + LookupOrInsert(key, Hash(key))->value = index; } - inline static base::HashMap::Entry* LookupEntry(base::HashMap* map, - HeapObject* obj, - bool insert) { - if (insert) { - map->LookupOrInsert(Key(obj), Hash(obj)); - } - return map->Lookup(Key(obj), Hash(obj)); + inline Maybe<uint32_t> Get(Type value) const { + uintptr_t key = Key(value); + Entry* entry = Lookup(key, Hash(key)); + if (entry == nullptr) return Nothing<uint32_t>(); + return Just(entry->value); } private: - static uint32_t Hash(HeapObject* obj) { - return static_cast<int32_t>(reinterpret_cast<intptr_t>(obj->address())); + static uintptr_t Key(Type value) { + return reinterpret_cast<uintptr_t>(value); } - static void* Key(HeapObject* obj) { - return reinterpret_cast<void*>(obj->address()); - } + static uint32_t Hash(uintptr_t key) { return static_cast<uint32_t>(key); } }; -class RootIndexMap : public AddressMapBase { +class AddressToIndexHashMap : public PointerToIndexHashMap<Address> {}; +class HeapObjectToIndexHashMap : public PointerToIndexHashMap<HeapObject*> {}; + +class RootIndexMap { public: explicit RootIndexMap(Isolate* isolate); static const int kInvalidRootIndex = -1; int Lookup(HeapObject* obj) { - base::HashMap::Entry* entry = LookupEntry(map_, obj, false); - if (entry) return GetValue(entry); - return kInvalidRootIndex; + Maybe<uint32_t> maybe_index = map_->Get(obj); + return maybe_index.IsJust() ? maybe_index.FromJust() : kInvalidRootIndex; } private: - base::HashMap* map_; + HeapObjectToIndexHashMap* map_; DISALLOW_COPY_AND_ASSIGN(RootIndexMap); }; @@ -186,21 +188,21 @@ class SerializerReference { // Mapping objects to their location after deserialization. // This is used during building, but not at runtime by V8. -class SerializerReferenceMap : public AddressMapBase { +class SerializerReferenceMap { public: SerializerReferenceMap() : no_allocation_(), map_(), attached_reference_index_(0) {} SerializerReference Lookup(HeapObject* obj) { - base::HashMap::Entry* entry = LookupEntry(&map_, obj, false); - return entry ? SerializerReference(GetValue(entry)) : SerializerReference(); + Maybe<uint32_t> maybe_index = map_.Get(obj); + return maybe_index.IsJust() ? SerializerReference(maybe_index.FromJust()) + : SerializerReference(); } void Add(HeapObject* obj, SerializerReference b) { DCHECK(b.is_valid()); - DCHECK_NULL(LookupEntry(&map_, obj, false)); - base::HashMap::Entry* entry = LookupEntry(&map_, obj, true); - SetValue(entry, b.bitfield_); + DCHECK(map_.Get(obj).IsNothing()); + map_.Set(obj, b.bitfield_); } SerializerReference AddAttachedReference(HeapObject* attached_reference) { @@ -212,7 +214,7 @@ class SerializerReferenceMap : public AddressMapBase { private: DisallowHeapAllocation no_allocation_; - base::HashMap map_; + HeapObjectToIndexHashMap map_; int attached_reference_index_; DISALLOW_COPY_AND_ASSIGN(SerializerReferenceMap); }; |