V8 Project
field-index.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_H_
6 #define V8_FIELD_INDEX_H_
7 
8 #include "src/property-details.h"
9 #include "src/utils.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 class Map;
15 
16 // Wrapper class to hold a field index, usually but not necessarily generated
17 // from a property index. When available, the wrapper class captures additional
18 // information to allow the field index to be translated back into the property
19 // index it was originally generated from.
20 class FieldIndex FINAL {
21  public:
22  static FieldIndex ForPropertyIndex(Map* map,
23  int index,
24  bool is_double = false);
25  static FieldIndex ForInObjectOffset(int offset, Map* map = NULL);
26  static FieldIndex ForDescriptor(Map* map, int descriptor_index);
27  static FieldIndex ForLoadByFieldIndex(Map* map, int index);
28  static FieldIndex ForKeyedLookupCacheIndex(Map* map, int index);
29  static FieldIndex FromFieldAccessStubKey(int key);
30 
31  int GetLoadByFieldIndex() const;
32 
33  bool is_inobject() const {
34  return IsInObjectBits::decode(bit_field_);
35  }
36 
37  bool is_double() const {
38  return IsDoubleBits::decode(bit_field_);
39  }
40 
41  int offset() const {
42  return index() * kPointerSize;
43  }
44 
45  // Zero-indexed from beginning of the object.
46  int index() const {
47  return IndexBits::decode(bit_field_);
48  }
49 
50  int outobject_array_index() const {
51  DCHECK(!is_inobject());
52  return index() - first_inobject_property_offset() / kPointerSize;
53  }
54 
55  // Zero-based from the first inobject property. Overflows to out-of-object
56  // properties.
57  int property_index() const {
58  DCHECK(!IsHiddenField::decode(bit_field_));
59  int result = index() - first_inobject_property_offset() / kPointerSize;
60  if (!is_inobject()) {
61  result += InObjectPropertyBits::decode(bit_field_);
62  }
63  return result;
64  }
65 
67 
68  int GetFieldAccessStubKey() const {
69  return bit_field_ &
70  (IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask);
71  }
72 
73  private:
74  FieldIndex(bool is_inobject, int local_index, bool is_double,
75  int inobject_properties, int first_inobject_property_offset,
76  bool is_hidden = false) {
77  DCHECK((first_inobject_property_offset & (kPointerSize - 1)) == 0);
78  bit_field_ = IsInObjectBits::encode(is_inobject) |
79  IsDoubleBits::encode(is_double) |
80  FirstInobjectPropertyOffsetBits::encode(first_inobject_property_offset) |
81  IsHiddenField::encode(is_hidden) |
82  IndexBits::encode(local_index) |
83  InObjectPropertyBits::encode(inobject_properties);
84  }
85 
86  explicit FieldIndex(int bit_field) : bit_field_(bit_field) {}
87 
89  DCHECK(!IsHiddenField::decode(bit_field_));
90  return FirstInobjectPropertyOffsetBits::decode(bit_field_);
91  }
92 
93  static const int kIndexBitsSize = kDescriptorIndexBitCount + 1;
94 
95  // Index from beginning of object.
96  class IndexBits: public BitField<int, 0, kIndexBitsSize> {};
97  class IsInObjectBits: public BitField<bool, IndexBits::kNext, 1> {};
98  class IsDoubleBits: public BitField<bool, IsInObjectBits::kNext, 1> {};
99  // Number of inobject properties.
101  : public BitField<int, IsDoubleBits::kNext, kDescriptorIndexBitCount> {};
102  // Offset of first inobject property from beginning of object.
104  : public BitField<int, InObjectPropertyBits::kNext, 7> {};
106  : public BitField<bool, FirstInobjectPropertyOffsetBits::kNext, 1> {};
107  STATIC_ASSERT(IsHiddenField::kNext <= 32);
108 
110 };
111 
112 } } // namespace v8::internal
113 
114 #endif
bool is_double() const
Definition: field-index.h:37
STATIC_ASSERT(IsHiddenField::kNext<=32)
static FieldIndex ForPropertyIndex(Map *map, int index, bool is_double=false)
int GetFieldAccessStubKey() const
Definition: field-index.h:68
static FieldIndex FromFieldAccessStubKey(int key)
int property_index() const
Definition: field-index.h:57
int outobject_array_index() const
Definition: field-index.h:50
bool is_inobject() const
Definition: field-index.h:33
int GetKeyedLookupCacheIndex() const
int first_inobject_property_offset() const
Definition: field-index.h:88
int GetLoadByFieldIndex() const
static FieldIndex ForKeyedLookupCacheIndex(Map *map, int index)
static FieldIndex ForLoadByFieldIndex(Map *map, int index)
static FieldIndex ForDescriptor(Map *map, int descriptor_index)
int offset() const
Definition: field-index.h:41
FieldIndex(bool is_inobject, int local_index, bool is_double, int inobject_properties, int first_inobject_property_offset, bool is_hidden=false)
Definition: field-index.h:74
static FieldIndex ForInObjectOffset(int offset, Map *map=NULL)
FieldIndex(int bit_field)
Definition: field-index.h:86
int index() const
Definition: field-index.h:46
#define FINAL
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
static const int kDescriptorIndexBitCount
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20