V8 Project
field-index-inl.h
Go to the documentation of this file.
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 
10 namespace v8 {
11 namespace internal {
12 
13 
14 inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) {
15  DCHECK((offset % kPointerSize) == 0);
16  int index = offset / kPointerSize;
17  if (map == NULL) {
18  return FieldIndex(true, index, false, index + 1, 0, true);
19  }
20  int first_inobject_offset = map->GetInObjectPropertyOffset(0);
21  if (offset < first_inobject_offset) {
22  return FieldIndex(true, index, false, 0, 0, true);
23  } else {
24  return FieldIndex::ForPropertyIndex(map, offset / kPointerSize);
25  }
26 }
27 
28 
29 inline FieldIndex FieldIndex::ForPropertyIndex(Map* map,
30  int property_index,
31  bool is_double) {
32  DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE);
33  int inobject_properties = map->inobject_properties();
34  bool is_inobject = property_index < inobject_properties;
35  int first_inobject_offset;
36  if (is_inobject) {
37  first_inobject_offset = map->GetInObjectPropertyOffset(0);
38  } else {
39  first_inobject_offset = FixedArray::kHeaderSize;
40  property_index -= inobject_properties;
41  }
42  return FieldIndex(is_inobject,
43  property_index + first_inobject_offset / kPointerSize,
44  is_double, inobject_properties, first_inobject_offset);
45 }
46 
47 
48 // Takes an index as computed by GetLoadFieldByIndex and reconstructs a
49 // FieldIndex object from it.
50 inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) {
51  int field_index = orig_index;
52  int is_inobject = true;
53  bool is_double = field_index & 1;
54  int first_inobject_offset = 0;
55  field_index >>= 1;
56  if (field_index < 0) {
57  field_index = -(field_index + 1);
58  is_inobject = false;
59  first_inobject_offset = FixedArray::kHeaderSize;
60  field_index += FixedArray::kHeaderSize / kPointerSize;
61  } else {
62  first_inobject_offset = map->GetInObjectPropertyOffset(0);
63  field_index += JSObject::kHeaderSize / kPointerSize;
64  }
65  FieldIndex result(is_inobject, field_index, is_double,
66  map->inobject_properties(), first_inobject_offset);
67  DCHECK(result.GetLoadByFieldIndex() == orig_index);
68  return result;
69 }
70 
71 
72 // Returns the index format accepted by the HLoadFieldByIndex instruction.
73 // (In-object: zero-based from (object start + JSObject::kHeaderSize),
74 // out-of-object: zero-based from FixedArray::kHeaderSize.)
75 inline int FieldIndex::GetLoadByFieldIndex() const {
76  // For efficiency, the LoadByFieldIndex instruction takes an index that is
77  // optimized for quick access. If the property is inline, the index is
78  // positive. If it's out-of-line, the encoded index is -raw_index - 1 to
79  // disambiguate the zero out-of-line index from the zero inobject case.
80  // The index itself is shifted up by one bit, the lower-most bit
81  // signifying if the field is a mutable double box (1) or not (0).
82  int result = index();
83  if (is_inobject()) {
85  } else {
87  result = -result - 1;
88  }
89  result <<= 1;
90  return is_double() ? (result | 1) : result;
91 }
92 
93 
94 inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) {
95  PropertyDetails details =
96  map->instance_descriptors()->GetDetails(descriptor_index);
97  int field_index =
98  map->instance_descriptors()->GetFieldIndex(descriptor_index);
99  return ForPropertyIndex(map, field_index,
100  details.representation().IsDouble());
101 }
102 
103 
104 inline FieldIndex FieldIndex::ForKeyedLookupCacheIndex(Map* map, int index) {
105  if (FLAG_compiled_keyed_generic_loads) {
106  return ForLoadByFieldIndex(map, index);
107  } else {
108  return ForPropertyIndex(map, index);
109  }
110 }
111 
112 
113 inline FieldIndex FieldIndex::FromFieldAccessStubKey(int key) {
114  return FieldIndex(key);
115 }
116 
117 
118 inline int FieldIndex::GetKeyedLookupCacheIndex() const {
119  if (FLAG_compiled_keyed_generic_loads) {
120  return GetLoadByFieldIndex();
121  } else {
122  return property_index();
123  }
124 }
125 
126 
127 } } // namespace v8::internal
128 
129 #endif
static const int kHeaderSize
Definition: objects.h:2393
static const int kHeaderSize
Definition: objects.h:2195
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
const int kPointerSize
Definition: globals.h:129
@ FIRST_NONSTRING_TYPE
Definition: objects.h:758
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20