LCOV - code coverage report
Current view: top level - src/objects - dictionary-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 73 75 97.3 %
Date: 2019-02-19 Functions: 35 43 81.4 %

          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_DICTIONARY_INL_H_
       6             : #define V8_OBJECTS_DICTIONARY_INL_H_
       7             : 
       8             : #include "src/objects/dictionary.h"
       9             : 
      10             : #include "src/hash-seed-inl.h"
      11             : #include "src/objects/hash-table-inl.h"
      12             : #include "src/objects/oddball.h"
      13             : #include "src/objects/property-cell-inl.h"
      14             : 
      15             : // Has to be the last include (doesn't have include guards):
      16             : #include "src/objects/object-macros.h"
      17             : 
      18             : namespace v8 {
      19             : namespace internal {
      20             : 
      21   262320634 : CAST_ACCESSOR(GlobalDictionary)
      22   115797540 : CAST_ACCESSOR(NameDictionary)
      23    82243823 : CAST_ACCESSOR(NumberDictionary)
      24      348777 : CAST_ACCESSOR(SimpleNumberDictionary)
      25             : 
      26             : template <typename Derived, typename Shape>
      27           0 : Dictionary<Derived, Shape>::Dictionary(Address ptr)
      28           0 :     : HashTable<Derived, Shape>(ptr) {}
      29             : 
      30             : template <typename Derived, typename Shape>
      31             : BaseNameDictionary<Derived, Shape>::BaseNameDictionary(Address ptr)
      32             :     : Dictionary<Derived, Shape>(ptr) {}
      33             : 
      34   262320781 : GlobalDictionary::GlobalDictionary(Address ptr)
      35             :     : BaseNameDictionary<GlobalDictionary, GlobalDictionaryShape>(ptr) {
      36             :   SLOW_DCHECK(IsGlobalDictionary());
      37   262320781 : }
      38             : 
      39   115797579 : NameDictionary::NameDictionary(Address ptr)
      40             :     : BaseNameDictionary<NameDictionary, NameDictionaryShape>(ptr) {
      41             :   SLOW_DCHECK(IsNameDictionary());
      42   115797579 : }
      43             : 
      44    82484811 : NumberDictionary::NumberDictionary(Address ptr)
      45             :     : Dictionary<NumberDictionary, NumberDictionaryShape>(ptr) {
      46             :   SLOW_DCHECK(IsNumberDictionary());
      47    82484811 : }
      48             : 
      49      348777 : SimpleNumberDictionary::SimpleNumberDictionary(Address ptr)
      50             :     : Dictionary<SimpleNumberDictionary, SimpleNumberDictionaryShape>(ptr) {
      51             :   SLOW_DCHECK(IsSimpleNumberDictionary());
      52      348777 : }
      53             : 
      54     2444451 : bool NumberDictionary::requires_slow_elements() {
      55     2444451 :   Object max_index_object = get(kMaxNumberKeyIndex);
      56     2444451 :   if (!max_index_object->IsSmi()) return false;
      57     2056872 :   return 0 != (Smi::ToInt(max_index_object) & kRequiresSlowElementsMask);
      58             : }
      59             : 
      60     1327874 : uint32_t NumberDictionary::max_number_key() {
      61             :   DCHECK(!requires_slow_elements());
      62     1327874 :   Object max_index_object = get(kMaxNumberKeyIndex);
      63     1327874 :   if (!max_index_object->IsSmi()) return 0;
      64     1326730 :   uint32_t value = static_cast<uint32_t>(Smi::ToInt(max_index_object));
      65     1326730 :   return value >> kRequiresSlowElementsTagSize;
      66             : }
      67             : 
      68          56 : void NumberDictionary::set_requires_slow_elements() {
      69          56 :   set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask));
      70          56 : }
      71             : 
      72             : template <typename Derived, typename Shape>
      73       47376 : void Dictionary<Derived, Shape>::ClearEntry(Isolate* isolate, int entry) {
      74       94752 :   Object the_hole = this->GetReadOnlyRoots().the_hole_value();
      75       47376 :   PropertyDetails details = PropertyDetails::Empty();
      76       47376 :   Derived::cast(*this)->SetEntry(isolate, entry, the_hole, the_hole, details);
      77       47376 : }
      78             : 
      79             : template <typename Derived, typename Shape>
      80     8570463 : void Dictionary<Derived, Shape>::SetEntry(Isolate* isolate, int entry,
      81             :                                           Object key, Object value,
      82             :                                           PropertyDetails details) {
      83             :   DCHECK(Dictionary::kEntrySize == 2 || Dictionary::kEntrySize == 3);
      84             :   DCHECK(!key->IsName() || details.dictionary_index() > 0);
      85             :   int index = DerivedHashTable::EntryToIndex(entry);
      86             :   DisallowHeapAllocation no_gc;
      87     8570463 :   WriteBarrierMode mode = this->GetWriteBarrierMode(no_gc);
      88     8570463 :   this->set(index + Derived::kEntryKeyIndex, key, mode);
      89     8570462 :   this->set(index + Derived::kEntryValueIndex, value, mode);
      90     8496904 :   if (Shape::kHasDetails) DetailsAtPut(isolate, entry, details);
      91     8570464 : }
      92             : 
      93    17147383 : Object GlobalDictionaryShape::Unwrap(Object object) {
      94    17147383 :   return PropertyCell::cast(object)->name();
      95             : }
      96             : 
      97             : RootIndex GlobalDictionaryShape::GetMapRootIndex() {
      98             :   return RootIndex::kGlobalDictionaryMap;
      99             : }
     100             : 
     101     8149038 : Name NameDictionary::NameAt(int entry) { return Name::cast(KeyAt(entry)); }
     102             : 
     103             : RootIndex NameDictionaryShape::GetMapRootIndex() {
     104             :   return RootIndex::kNameDictionaryMap;
     105             : }
     106             : 
     107   237309222 : PropertyCell GlobalDictionary::CellAt(int entry) {
     108             :   DCHECK(KeyAt(entry)->IsPropertyCell());
     109   474618504 :   return PropertyCell::cast(KeyAt(entry));
     110             : }
     111             : 
     112   117746871 : bool GlobalDictionaryShape::IsLive(ReadOnlyRoots roots, Object k) {
     113             :   DCHECK_NE(roots.the_hole_value(), k);
     114   117746873 :   return k != roots.undefined_value();
     115             : }
     116             : 
     117    37559688 : bool GlobalDictionaryShape::IsKey(ReadOnlyRoots roots, Object k) {
     118    71901921 :   return IsLive(roots, k) && !PropertyCell::cast(k)->value()->IsTheHole(roots);
     119             : }
     120             : 
     121     7650251 : Name GlobalDictionary::NameAt(int entry) { return CellAt(entry)->name(); }
     122    14208549 : Object GlobalDictionary::ValueAt(int entry) { return CellAt(entry)->value(); }
     123             : 
     124     8147968 : void GlobalDictionary::SetEntry(Isolate* isolate, int entry, Object key,
     125             :                                 Object value, PropertyDetails details) {
     126             :   DCHECK_EQ(key, PropertyCell::cast(value)->name());
     127     8147968 :   set(EntryToIndex(entry) + kEntryKeyIndex, value);
     128     8147969 :   DetailsAtPut(isolate, entry, details);
     129     8147969 : }
     130             : 
     131             : void GlobalDictionary::ValueAtPut(int entry, Object value) {
     132       19994 :   set(EntryToIndex(entry), value);
     133             : }
     134             : 
     135             : bool NumberDictionaryBaseShape::IsMatch(uint32_t key, Object other) {
     136             :   DCHECK(other->IsNumber());
     137    55144929 :   return key == static_cast<uint32_t>(other->Number());
     138             : }
     139             : 
     140    99599290 : uint32_t NumberDictionaryBaseShape::Hash(Isolate* isolate, uint32_t key) {
     141   199198580 :   return ComputeSeededHash(key, HashSeed(isolate));
     142             : }
     143             : 
     144     1786117 : uint32_t NumberDictionaryBaseShape::HashForObject(Isolate* isolate,
     145             :                                                   Object other) {
     146             :   DCHECK(other->IsNumber());
     147     1786117 :   return ComputeSeededHash(static_cast<uint32_t>(other->Number()),
     148     5358351 :                            HashSeed(isolate));
     149             : }
     150             : 
     151             : Handle<Object> NumberDictionaryBaseShape::AsHandle(Isolate* isolate,
     152             :                                                    uint32_t key) {
     153     3840308 :   return isolate->factory()->NewNumberFromUint(key);
     154             : }
     155             : 
     156             : RootIndex NumberDictionaryShape::GetMapRootIndex() {
     157             :   return RootIndex::kNumberDictionaryMap;
     158             : }
     159             : 
     160             : RootIndex SimpleNumberDictionaryShape::GetMapRootIndex() {
     161             :   return RootIndex::kSimpleNumberDictionaryMap;
     162             : }
     163             : 
     164             : bool NameDictionaryShape::IsMatch(Handle<Name> key, Object other) {
     165             :   DCHECK(other->IsTheHole() || Name::cast(other)->IsUniqueName());
     166             :   DCHECK(key->IsUniqueName());
     167             :   return *key == other;
     168             : }
     169             : 
     170    58945255 : uint32_t NameDictionaryShape::Hash(Isolate* isolate, Handle<Name> key) {
     171    58945257 :   return key->Hash();
     172             : }
     173             : 
     174     4784348 : uint32_t NameDictionaryShape::HashForObject(Isolate* isolate, Object other) {
     175     4784348 :   return Name::cast(other)->Hash();
     176             : }
     177             : 
     178    40639463 : bool GlobalDictionaryShape::IsMatch(Handle<Name> key, Object other) {
     179             :   DCHECK(PropertyCell::cast(other)->name()->IsUniqueName());
     180    81278925 :   return *key == PropertyCell::cast(other)->name();
     181             : }
     182             : 
     183    29309316 : uint32_t GlobalDictionaryShape::HashForObject(Isolate* isolate, Object other) {
     184    29309316 :   return PropertyCell::cast(other)->name()->Hash();
     185             : }
     186             : 
     187             : Handle<Object> NameDictionaryShape::AsHandle(Isolate* isolate,
     188             :                                              Handle<Name> key) {
     189             :   DCHECK(key->IsUniqueName());
     190             :   return key;
     191             : }
     192             : 
     193             : template <typename Dictionary>
     194             : PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary dict, int entry) {
     195             :   DCHECK_LE(0, entry);  // Not found is -1, which is not caught by get().
     196   167750113 :   return dict->CellAt(entry)->property_details();
     197             : }
     198             : 
     199             : template <typename Dictionary>
     200     8157248 : void GlobalDictionaryShape::DetailsAtPut(Isolate* isolate, Dictionary dict,
     201             :                                          int entry, PropertyDetails value) {
     202             :   DCHECK_LE(0, entry);  // Not found is -1, which is not caught by get().
     203     8157248 :   PropertyCell cell = dict->CellAt(entry);
     204    16314496 :   if (cell->property_details().IsReadOnly() != value.IsReadOnly()) {
     205        8029 :     cell->dependent_code()->DeoptimizeDependentCodeGroup(
     206       16058 :         isolate, DependentCode::kPropertyCellChangedGroup);
     207             :   }
     208             :   cell->set_property_details(value);
     209     8157248 : }
     210             : 
     211             : }  // namespace internal
     212             : }  // namespace v8
     213             : 
     214             : #include "src/objects/object-macros-undef.h"
     215             : 
     216             : #endif  // V8_OBJECTS_DICTIONARY_INL_H_

Generated by: LCOV version 1.10