LCOV - code coverage report
Current view: top level - src - field-index-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 19 19 100.0 %
Date: 2019-01-20 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright 2014 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_FIELD_INDEX_INL_H_
       6             : #define V8_FIELD_INDEX_INL_H_
       7             : 
       8             : #include "src/field-index.h"
       9             : #include "src/objects-inl.h"
      10             : #include "src/objects/descriptor-array.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15       68490 : inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Encoding encoding) {
      16             :   DCHECK_IMPLIES(encoding == kWord32, IsAligned(offset, kInt32Size));
      17             :   DCHECK_IMPLIES(encoding == kTagged, IsAligned(offset, kTaggedSize));
      18             :   DCHECK_IMPLIES(encoding == kDouble, IsAligned(offset, kDoubleSize));
      19       68490 :   return FieldIndex(true, offset, encoding, 0, 0);
      20             : }
      21             : 
      22   113412985 : inline FieldIndex FieldIndex::ForPropertyIndex(const Map map,
      23             :                                                int property_index,
      24             :                                                Representation representation) {
      25             :   DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE);
      26   113412985 :   int inobject_properties = map->GetInObjectProperties();
      27   113413018 :   bool is_inobject = property_index < inobject_properties;
      28             :   int first_inobject_offset;
      29             :   int offset;
      30   113413018 :   if (is_inobject) {
      31             :     first_inobject_offset = map->GetInObjectPropertyOffset(0);
      32             :     offset = map->GetInObjectPropertyOffset(property_index);
      33             :   } else {
      34             :     first_inobject_offset = FixedArray::kHeaderSize;
      35    72434634 :     property_index -= inobject_properties;
      36             :     offset = PropertyArray::OffsetOfElementAt(property_index);
      37             :   }
      38   113413018 :   Encoding encoding = FieldEncoding(representation);
      39             :   return FieldIndex(is_inobject, offset, encoding, inobject_properties,
      40   113412988 :                     first_inobject_offset);
      41             : }
      42             : 
      43             : // Returns the index format accepted by the HLoadFieldByIndex instruction.
      44             : // (In-object: zero-based from (object start + JSObject::kHeaderSize),
      45             : // out-of-object: zero-based from FixedArray::kHeaderSize.)
      46      231478 : inline int FieldIndex::GetLoadByFieldIndex() const {
      47             :   // For efficiency, the LoadByFieldIndex instruction takes an index that is
      48             :   // optimized for quick access. If the property is inline, the index is
      49             :   // positive. If it's out-of-line, the encoded index is -raw_index - 1 to
      50             :   // disambiguate the zero out-of-line index from the zero inobject case.
      51             :   // The index itself is shifted up by one bit, the lower-most bit
      52             :   // signifying if the field is a mutable double box (1) or not (0).
      53             :   int result = index();
      54      231478 :   if (is_inobject()) {
      55      138636 :     result -= JSObject::kHeaderSize / kTaggedSize;
      56             :   } else {
      57       92842 :     result -= FixedArray::kHeaderSize / kTaggedSize;
      58       92842 :     result = -result - 1;
      59             :   }
      60      231478 :   result <<= 1;
      61      231478 :   return is_double() ? (result | 1) : result;
      62             : }
      63             : 
      64   101523846 : inline FieldIndex FieldIndex::ForDescriptor(const Map map,
      65             :                                             int descriptor_index) {
      66             :   PropertyDetails details =
      67   101523846 :       map->instance_descriptors()->GetDetails(descriptor_index);
      68             :   int field_index = details.field_index();
      69   101523891 :   return ForPropertyIndex(map, field_index, details.representation());
      70             : }
      71             : 
      72             : }  // namespace internal
      73             : }  // namespace v8
      74             : 
      75             : #endif  // V8_FIELD_INDEX_INL_H_

Generated by: LCOV version 1.10