LCOV - code coverage report
Current view: top level - src/objects - ordered-hash-table-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 26 31 83.9 %
Date: 2019-04-17 Functions: 8 10 80.0 %

          Line data    Source code
       1             : // Copyright 2018 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_OBJECTS_ORDERED_HASH_TABLE_INL_H_
       6             : #define V8_OBJECTS_ORDERED_HASH_TABLE_INL_H_
       7             : 
       8             : #include "src/objects/ordered-hash-table.h"
       9             : 
      10             : #include "src/heap/heap.h"
      11             : #include "src/objects-inl.h"
      12             : #include "src/objects/compressed-slots.h"
      13             : #include "src/objects/fixed-array-inl.h"
      14             : #include "src/objects/js-collection-iterator.h"
      15             : #include "src/objects/slots.h"
      16             : 
      17             : // Has to be the last include (doesn't have include guards):
      18             : #include "src/objects/object-macros.h"
      19             : 
      20             : namespace v8 {
      21             : namespace internal {
      22             : 
      23             : CAST_ACCESSOR(OrderedNameDictionary)
      24             : CAST_ACCESSOR(SmallOrderedNameDictionary)
      25             : CAST_ACCESSOR(OrderedHashMap)
      26             : CAST_ACCESSOR(OrderedHashSet)
      27             : CAST_ACCESSOR(SmallOrderedHashMap)
      28             : CAST_ACCESSOR(SmallOrderedHashSet)
      29             : 
      30             : template <class Derived, int entrysize>
      31             : OrderedHashTable<Derived, entrysize>::OrderedHashTable(Address ptr)
      32             :     : FixedArray(ptr) {}
      33             : 
      34             : OrderedHashSet::OrderedHashSet(Address ptr)
      35             :     : OrderedHashTable<OrderedHashSet, 1>(ptr) {
      36             :   SLOW_DCHECK(IsOrderedHashSet());
      37             : }
      38             : 
      39             : OrderedHashMap::OrderedHashMap(Address ptr)
      40             :     : OrderedHashTable<OrderedHashMap, 2>(ptr) {
      41             :   SLOW_DCHECK(IsOrderedHashMap());
      42             : }
      43             : 
      44             : OrderedNameDictionary::OrderedNameDictionary(Address ptr)
      45             :     : OrderedHashTable<OrderedNameDictionary, 3>(ptr) {
      46             :   SLOW_DCHECK(IsOrderedNameDictionary());
      47             : }
      48             : 
      49             : template <class Derived>
      50             : SmallOrderedHashTable<Derived>::SmallOrderedHashTable(Address ptr)
      51             :     : HeapObject(ptr) {}
      52             : 
      53             : template <class Derived>
      54             : Object SmallOrderedHashTable<Derived>::KeyAt(int entry) const {
      55             :   DCHECK_LT(entry, Capacity());
      56           0 :   Offset entry_offset = GetDataEntryOffset(entry, Derived::kKeyIndex);
      57     3639025 :   return READ_FIELD(*this, entry_offset);
      58             : }
      59             : 
      60             : template <class Derived>
      61             : Object SmallOrderedHashTable<Derived>::GetDataEntry(int entry,
      62             :                                                     int relative_index) {
      63             :   DCHECK_LT(entry, Capacity());
      64             :   DCHECK_LE(static_cast<unsigned>(relative_index), Derived::kEntrySize);
      65        2600 :   Offset entry_offset = GetDataEntryOffset(entry, relative_index);
      66       28335 :   return READ_FIELD(*this, entry_offset);
      67             : }
      68             : 
      69             : OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashSet,
      70             :                          SmallOrderedHashTable<SmallOrderedHashSet>)
      71             : OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashMap,
      72             :                          SmallOrderedHashTable<SmallOrderedHashMap>)
      73             : OBJECT_CONSTRUCTORS_IMPL(SmallOrderedNameDictionary,
      74             :                          SmallOrderedHashTable<SmallOrderedNameDictionary>)
      75             : 
      76             : RootIndex OrderedHashSet::GetMapRootIndex() {
      77             :   return RootIndex::kOrderedHashSetMap;
      78             : }
      79             : 
      80             : RootIndex OrderedHashMap::GetMapRootIndex() {
      81             :   return RootIndex::kOrderedHashMapMap;
      82             : }
      83             : 
      84             : RootIndex OrderedNameDictionary::GetMapRootIndex() {
      85             :   return RootIndex::kOrderedNameDictionaryMap;
      86             : }
      87             : 
      88             : RootIndex SmallOrderedNameDictionary::GetMapRootIndex() {
      89             :   return RootIndex::kSmallOrderedNameDictionaryMap;
      90             : }
      91             : 
      92             : RootIndex SmallOrderedHashMap::GetMapRootIndex() {
      93             :   return RootIndex::kSmallOrderedHashMapMap;
      94             : }
      95             : 
      96             : RootIndex SmallOrderedHashSet::GetMapRootIndex() {
      97             :   return RootIndex::kSmallOrderedHashSetMap;
      98             : }
      99             : 
     100        5395 : inline Object OrderedHashMap::ValueAt(int entry) {
     101             :   DCHECK_NE(entry, kNotFound);
     102             :   DCHECK_LT(entry, UsedCapacity());
     103       10790 :   return get(EntryToIndex(entry) + kValueOffset);
     104             : }
     105             : 
     106          35 : inline Object OrderedNameDictionary::ValueAt(int entry) {
     107             :   DCHECK_NE(entry, kNotFound);
     108             :   DCHECK_LT(entry, UsedCapacity());
     109          70 :   return get(EntryToIndex(entry) + kValueOffset);
     110             : }
     111             : 
     112             : // Set the value for entry.
     113          10 : inline void OrderedNameDictionary::ValueAtPut(int entry, Object value) {
     114             :   DCHECK_NE(entry, kNotFound);
     115             :   DCHECK_LT(entry, UsedCapacity());
     116          10 :   this->set(EntryToIndex(entry) + kValueOffset, value);
     117          10 : }
     118             : 
     119             : // Returns the property details for the property at entry.
     120          25 : inline PropertyDetails OrderedNameDictionary::DetailsAt(int entry) {
     121             :   DCHECK_NE(entry, kNotFound);
     122             :   DCHECK_LT(entry, this->UsedCapacity());
     123             :   // TODO(gsathya): Optimize the cast away.
     124             :   return PropertyDetails(
     125          50 :       Smi::cast(get(EntryToIndex(entry) + kPropertyDetailsOffset)));
     126             : }
     127             : 
     128          10 : inline void OrderedNameDictionary::DetailsAtPut(int entry,
     129             :                                                 PropertyDetails value) {
     130             :   DCHECK_NE(entry, kNotFound);
     131             :   DCHECK_LT(entry, this->UsedCapacity());
     132             :   // TODO(gsathya): Optimize the cast away.
     133             :   this->set(EntryToIndex(entry) + kPropertyDetailsOffset, value.AsSmi());
     134          10 : }
     135             : 
     136             : inline Object SmallOrderedNameDictionary::ValueAt(int entry) {
     137             :   return this->GetDataEntry(entry, kValueIndex);
     138             : }
     139             : 
     140             : // Set the value for entry.
     141             : inline void SmallOrderedNameDictionary::ValueAtPut(int entry, Object value) {
     142          10 :   this->SetDataEntry(entry, kValueIndex, value);
     143             : }
     144             : 
     145             : // Returns the property details for the property at entry.
     146             : inline PropertyDetails SmallOrderedNameDictionary::DetailsAt(int entry) {
     147             :   // TODO(gsathya): Optimize the cast away. And store this in the data table.
     148             :   return PropertyDetails(
     149             :       Smi::cast(this->GetDataEntry(entry, kPropertyDetailsIndex)));
     150             : }
     151             : 
     152             : // Set the details for entry.
     153             : inline void SmallOrderedNameDictionary::DetailsAtPut(int entry,
     154             :                                                      PropertyDetails value) {
     155             :   // TODO(gsathya): Optimize the cast away. And store this in the data table.
     156          10 :   this->SetDataEntry(entry, kPropertyDetailsIndex, value.AsSmi());
     157             : }
     158             : 
     159             : inline bool OrderedHashSet::Is(Handle<HeapObject> table) {
     160          10 :   return table->IsOrderedHashSet();
     161             : }
     162             : 
     163             : inline bool OrderedHashMap::Is(Handle<HeapObject> table) {
     164          10 :   return table->IsOrderedHashMap();
     165             : }
     166             : 
     167             : inline bool SmallOrderedHashSet::Is(Handle<HeapObject> table) {
     168     5248040 :   return table->IsSmallOrderedHashSet();
     169             : }
     170             : 
     171             : inline bool SmallOrderedHashMap::Is(Handle<HeapObject> table) {
     172     5248040 :   return table->IsSmallOrderedHashMap();
     173             : }
     174             : 
     175             : template <class Derived>
     176       51575 : void SmallOrderedHashTable<Derived>::SetDataEntry(int entry, int relative_index,
     177             :                                                   Object value) {
     178             :   DCHECK_NE(kNotFound, entry);
     179             :   int entry_offset = GetDataEntryOffset(entry, relative_index);
     180       51575 :   RELAXED_WRITE_FIELD(*this, entry_offset, value);
     181       51575 :   WRITE_BARRIER(*this, entry_offset, value);
     182       51575 : }
     183             : 
     184             : template <class Derived, class TableType>
     185           0 : Object OrderedHashTableIterator<Derived, TableType>::CurrentKey() {
     186           0 :   TableType table = TableType::cast(this->table());
     187             :   int index = Smi::ToInt(this->index());
     188           0 :   Object key = table->KeyAt(index);
     189             :   DCHECK(!key->IsTheHole());
     190           0 :   return key;
     191             : }
     192             : 
     193             : inline void SmallOrderedNameDictionary::SetHash(int hash) {
     194             :   DCHECK(PropertyArray::HashField::is_valid(hash));
     195         370 :   WRITE_INT_FIELD(*this, PrefixOffset(), hash);
     196             : }
     197             : 
     198             : inline int SmallOrderedNameDictionary::Hash() {
     199        1440 :   int hash = READ_INT_FIELD(*this, PrefixOffset());
     200             :   DCHECK(PropertyArray::HashField::is_valid(hash));
     201             :   return hash;
     202             : }
     203             : 
     204             : inline void OrderedNameDictionary::SetHash(int hash) {
     205             :   DCHECK(PropertyArray::HashField::is_valid(hash));
     206             :   this->set(PrefixIndex(), Smi::FromInt(hash));
     207             : }
     208             : 
     209             : inline int OrderedNameDictionary::Hash() {
     210             :   Object hash_obj = this->get(PrefixIndex());
     211             :   int hash = Smi::ToInt(hash_obj);
     212             :   DCHECK(PropertyArray::HashField::is_valid(hash));
     213             :   return hash;
     214             : }
     215             : 
     216             : }  // namespace internal
     217             : }  // namespace v8
     218             : 
     219             : #include "src/objects/object-macros-undef.h"
     220             : 
     221             : #endif  // V8_OBJECTS_ORDERED_HASH_TABLE_INL_H_

Generated by: LCOV version 1.10