LCOV - code coverage report
Current view: top level - src/objects - descriptor-array-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 83 83 100.0 %
Date: 2019-01-20 Functions: 22 22 100.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_DESCRIPTOR_ARRAY_INL_H_
       6             : #define V8_OBJECTS_DESCRIPTOR_ARRAY_INL_H_
       7             : 
       8             : #include "src/objects/descriptor-array.h"
       9             : 
      10             : #include "src/field-type.h"
      11             : #include "src/heap/heap-write-barrier.h"
      12             : #include "src/heap/heap.h"
      13             : #include "src/isolate.h"
      14             : #include "src/lookup-cache.h"
      15             : #include "src/objects/heap-object-inl.h"
      16             : #include "src/objects/maybe-object.h"
      17             : #include "src/objects/struct-inl.h"
      18             : #include "src/property.h"
      19             : 
      20             : // Has to be the last include (doesn't have include guards):
      21             : #include "src/objects/object-macros.h"
      22             : 
      23             : namespace v8 {
      24             : namespace internal {
      25             : 
      26  1689915526 : OBJECT_CONSTRUCTORS_IMPL(DescriptorArray, HeapObject)
      27     5454370 : OBJECT_CONSTRUCTORS_IMPL(EnumCache, Tuple2)
      28             : 
      29   845022361 : CAST_ACCESSOR(DescriptorArray)
      30     2727184 : CAST_ACCESSOR(EnumCache)
      31             : 
      32   116976751 : ACCESSORS(DescriptorArray, enum_cache, EnumCache, kEnumCacheOffset)
      33   128983134 : RELAXED_INT16_ACCESSORS(DescriptorArray, number_of_all_descriptors,
      34             :                         kNumberOfAllDescriptorsOffset)
      35   196710279 : RELAXED_INT16_ACCESSORS(DescriptorArray, number_of_descriptors,
      36             :                         kNumberOfDescriptorsOffset)
      37    83267322 : RELAXED_INT16_ACCESSORS(DescriptorArray, raw_number_of_marked_descriptors,
      38             :                         kRawNumberOfMarkedDescriptorsOffset)
      39    19496111 : RELAXED_INT16_ACCESSORS(DescriptorArray, filler16bits, kFiller16BitsOffset)
      40             : 
      41     7569666 : inline int16_t DescriptorArray::number_of_slack_descriptors() const {
      42     7569666 :   return number_of_all_descriptors() - number_of_descriptors();
      43             : }
      44             : 
      45             : inline int DescriptorArray::number_of_entries() const {
      46    13344340 :   return number_of_descriptors();
      47             : }
      48             : 
      49    24697829 : inline int16_t DescriptorArray::CompareAndSwapRawNumberOfMarkedDescriptors(
      50             :     int16_t expected, int16_t value) {
      51             :   return base::Relaxed_CompareAndSwap(
      52             :       reinterpret_cast<base::Atomic16*>(
      53    24697829 :           FIELD_ADDR(this, kRawNumberOfMarkedDescriptorsOffset)),
      54    49395658 :       expected, value);
      55             : }
      56             : 
      57     2272950 : void DescriptorArray::CopyEnumCacheFrom(DescriptorArray array) {
      58     2272950 :   set_enum_cache(array->enum_cache());
      59     2272954 : }
      60             : 
      61             : int DescriptorArray::Search(Name name, int valid_descriptors) {
      62             :   DCHECK(name->IsUniqueName());
      63             :   return internal::Search<VALID_ENTRIES>(this, name, valid_descriptors,
      64    40877454 :                                          nullptr);
      65             : }
      66             : 
      67             : int DescriptorArray::Search(Name name, Map map) {
      68             :   DCHECK(name->IsUniqueName());
      69     2951400 :   int number_of_own_descriptors = map->NumberOfOwnDescriptors();
      70     2951400 :   if (number_of_own_descriptors == 0) return kNotFound;
      71             :   return Search(name, number_of_own_descriptors);
      72             : }
      73             : 
      74    92330016 : int DescriptorArray::SearchWithCache(Isolate* isolate, Name name, Map map) {
      75             :   DCHECK(name->IsUniqueName());
      76   111280231 :   int number_of_own_descriptors = map->NumberOfOwnDescriptors();
      77   111280264 :   if (number_of_own_descriptors == 0) return kNotFound;
      78             : 
      79    92330016 :   DescriptorLookupCache* cache = isolate->descriptor_lookup_cache();
      80    92330017 :   int number = cache->Lookup(map, name);
      81             : 
      82    92330025 :   if (number == DescriptorLookupCache::kAbsent) {
      83             :     number = Search(name, number_of_own_descriptors);
      84    37712403 :     cache->Update(map, name, number);
      85             :   }
      86             : 
      87             :   return number;
      88             : }
      89             : 
      90    11692120 : ObjectSlot DescriptorArray::GetFirstPointerSlot() {
      91    11692120 :   return RawField(DescriptorArray::kPointersStartOffset);
      92             : }
      93             : 
      94    32674379 : ObjectSlot DescriptorArray::GetDescriptorSlot(int descriptor) {
      95             :   // Allow descriptor == number_of_all_descriptors() for computing the slot
      96             :   // address that comes after the last descriptor (for iterating).
      97             :   DCHECK_LE(descriptor, number_of_all_descriptors());
      98    32674379 :   return RawField(OffsetOfDescriptorAt(descriptor));
      99             : }
     100             : 
     101             : ObjectSlot DescriptorArray::GetKeySlot(int descriptor) {
     102             :   DCHECK_LE(descriptor, number_of_all_descriptors());
     103             :   ObjectSlot slot = GetDescriptorSlot(descriptor) + kEntryKeyIndex;
     104             :   DCHECK((*slot)->IsObject());
     105             :   return slot;
     106             : }
     107             : 
     108   972188231 : Name DescriptorArray::GetKey(int descriptor_number) const {
     109             :   DCHECK(descriptor_number < number_of_descriptors());
     110             :   return Name::cast(
     111  1944376483 :       get(ToKeyIndex(descriptor_number))->GetHeapObjectAssumeStrong());
     112             : }
     113             : 
     114             : int DescriptorArray::GetSortedKeyIndex(int descriptor_number) {
     115  2510960383 :   return GetDetails(descriptor_number).pointer();
     116             : }
     117             : 
     118   719287246 : Name DescriptorArray::GetSortedKey(int descriptor_number) {
     119   719287638 :   return GetKey(GetSortedKeyIndex(descriptor_number));
     120             : }
     121             : 
     122   754828976 : void DescriptorArray::SetSortedKey(int descriptor_index, int pointer) {
     123   754828976 :   PropertyDetails details = GetDetails(descriptor_index);
     124             :   set(ToDetailsIndex(descriptor_index),
     125   754828891 :       MaybeObject::FromObject(details.set_pointer(pointer).AsSmi()));
     126   754829854 : }
     127             : 
     128             : MaybeObjectSlot DescriptorArray::GetValueSlot(int descriptor) {
     129             :   DCHECK_LT(descriptor, number_of_descriptors());
     130             :   return MaybeObjectSlot(GetDescriptorSlot(descriptor) + kEntryValueIndex);
     131             : }
     132             : 
     133    13194343 : Object DescriptorArray::GetStrongValue(int descriptor_number) {
     134             :   DCHECK(descriptor_number < number_of_descriptors());
     135    13194343 :   return get(ToValueIndex(descriptor_number))->cast<Object>();
     136             : }
     137             : 
     138             : void DescriptorArray::SetValue(int descriptor_index, Object value) {
     139      236230 :   set(ToValueIndex(descriptor_index), MaybeObject::FromObject(value));
     140             : }
     141             : 
     142             : MaybeObject DescriptorArray::GetValue(int descriptor_number) {
     143             :   DCHECK_LT(descriptor_number, number_of_descriptors());
     144   159048165 :   return get(ToValueIndex(descriptor_number));
     145             : }
     146             : 
     147  3696789608 : PropertyDetails DescriptorArray::GetDetails(int descriptor_number) {
     148             :   DCHECK(descriptor_number < number_of_descriptors());
     149  3696789608 :   MaybeObject details = get(ToDetailsIndex(descriptor_number));
     150  7393589247 :   return PropertyDetails(details->ToSmi());
     151             : }
     152             : 
     153             : int DescriptorArray::GetFieldIndex(int descriptor_number) {
     154             :   DCHECK_EQ(GetDetails(descriptor_number).location(), kField);
     155    91837756 :   return GetDetails(descriptor_number).field_index();
     156             : }
     157             : 
     158    39420538 : FieldType DescriptorArray::GetFieldType(int descriptor_number) {
     159             :   DCHECK_EQ(GetDetails(descriptor_number).location(), kField);
     160    39420541 :   MaybeObject wrapped_type = GetValue(descriptor_number);
     161    39420541 :   return Map::UnwrapFieldType(wrapped_type);
     162             : }
     163             : 
     164   140149569 : void DescriptorArray::Set(int descriptor_number, Name key, MaybeObject value,
     165             :                           PropertyDetails details) {
     166             :   // Range check.
     167             :   DCHECK(descriptor_number < number_of_descriptors());
     168   140149569 :   set(ToKeyIndex(descriptor_number), MaybeObject::FromObject(key));
     169   140149616 :   set(ToValueIndex(descriptor_number), value);
     170             :   set(ToDetailsIndex(descriptor_number),
     171   140149656 :       MaybeObject::FromObject(details.AsSmi()));
     172   140149651 : }
     173             : 
     174    20012370 : void DescriptorArray::Set(int descriptor_number, Descriptor* desc) {
     175    20012373 :   Name key = *desc->GetKey();
     176    20012373 :   MaybeObject value = *desc->GetValue();
     177    20012377 :   Set(descriptor_number, key, value, desc->GetDetails());
     178    20012407 : }
     179             : 
     180    18005131 : void DescriptorArray::Append(Descriptor* desc) {
     181             :   DisallowHeapAllocation no_gc;
     182    18005131 :   int descriptor_number = number_of_descriptors();
     183             :   DCHECK_LE(descriptor_number + 1, number_of_all_descriptors());
     184    18005131 :   set_number_of_descriptors(descriptor_number + 1);
     185    18005131 :   Set(descriptor_number, desc);
     186             : 
     187    18005173 :   uint32_t hash = desc->GetKey()->Hash();
     188             : 
     189             :   int insertion;
     190             : 
     191   192787475 :   for (insertion = descriptor_number; insertion > 0; --insertion) {
     192   167540153 :     Name key = GetSortedKey(insertion - 1);
     193   167540151 :     if (key->Hash() <= hash) break;
     194   156777164 :     SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1));
     195             :   }
     196             : 
     197    18005172 :   SetSortedKey(insertion, descriptor_number);
     198    18005174 : }
     199             : 
     200   243888608 : void DescriptorArray::SwapSortedKeys(int first, int second) {
     201             :   int first_key = GetSortedKeyIndex(first);
     202   243887272 :   SetSortedKey(first, GetSortedKeyIndex(second));
     203   243887344 :   SetSortedKey(second, first_key);
     204   243887040 : }
     205             : 
     206             : int DescriptorArray::length() const {
     207             :   return number_of_all_descriptors() * kEntrySize;
     208             : }
     209             : 
     210  4841243721 : MaybeObject DescriptorArray::get(int index) const {
     211             :   DCHECK(index >= 0 && index < this->length());
     212  9682487442 :   return RELAXED_READ_WEAK_FIELD(*this, offset(index));
     213             : }
     214             : 
     215  1180590375 : void DescriptorArray::set(int index, MaybeObject value) {
     216             :   DCHECK(index >= 0 && index < this->length());
     217  1180590375 :   RELAXED_WRITE_WEAK_FIELD(*this, offset(index), value);
     218  2361181896 :   WEAK_WRITE_BARRIER(*this, offset(index), value);
     219  1180591987 : }
     220             : 
     221             : }  // namespace internal
     222             : }  // namespace v8
     223             : 
     224             : #include "src/objects/object-macros-undef.h"
     225             : 
     226             : #endif  // V8_OBJECTS_DESCRIPTOR_ARRAY_INL_H_

Generated by: LCOV version 1.10