v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
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_OBJECTS_FIELD_INDEX_H_
6#define V8_OBJECTS_FIELD_INDEX_H_
7
8// TODO(jkummerow): Consider forward-declaring instead.
11#include "src/utils/utils.h"
12
13namespace v8 {
14namespace internal {
15
16class Map;
17
18// Wrapper class to hold a field index, usually but not necessarily generated
19// from a property index. When available, the wrapper class captures additional
20// information to allow the field index to be translated back into the property
21// index it was originally generated from.
22class FieldIndex final {
23 public:
25
27
28 static inline FieldIndex ForPropertyIndex(
29 Tagged<Map> map, int index,
30 Representation representation = Representation::Tagged());
31 static inline FieldIndex ForInObjectOffset(int offset, Encoding encoding);
32 static inline FieldIndex ForSmiLoadHandler(Tagged<Map> map, int32_t handler);
33 static inline FieldIndex ForDescriptor(Tagged<Map> map,
34 InternalIndex descriptor_index);
35 static inline FieldIndex ForDescriptor(PtrComprCageBase cage_base,
36 Tagged<Map> map,
37 InternalIndex descriptor_index);
38 static inline FieldIndex ForDetails(Tagged<Map> map, PropertyDetails details);
39
40 inline int GetLoadByFieldIndex() const;
41
43
44 bool is_double() const { return EncodingBits::decode(bit_field_) == kDouble; }
45
46 int offset() const { return OffsetBits::decode(bit_field_); }
47
48 uint64_t bit_field() const { return bit_field_; }
49
50 // Zero-indexed from beginning of the object.
51 int index() const {
53 return offset() / kTaggedSize;
54 }
55
60
61 // Zero-based from the first inobject property. Overflows to out-of-object
62 // properties.
70
75
76 bool operator==(FieldIndex const& other) const {
77 return bit_field_ == other.bit_field_;
78 }
79 bool operator!=(FieldIndex const& other) const { return !(*this == other); }
80
81 private:
92
93 static Encoding FieldEncoding(Representation representation) {
94 switch (representation.kind()) {
99 return kTagged;
101 return kDouble;
102 default:
103 break;
104 }
105 PrintF("%s\n", representation.Mnemonic());
106 UNREACHABLE();
107 return kTagged;
108 }
109
113
114 static const int kOffsetBitsSize =
116
117 // Index from beginning of object.
121 // Number of inobject properties.
124 // Offset of first inobject property from beginning of object.
128
129 uint64_t bit_field_;
130};
131
132} // namespace internal
133} // namespace v8
134
135#endif // V8_OBJECTS_FIELD_INDEX_H_
static constexpr int kLastUsedBit
Definition bit-field.h:42
static constexpr T decode(U value)
Definition bit-field.h:66
static constexpr U encode(T value)
Definition bit-field.h:55
static constexpr U kMask
Definition bit-field.h:41
bool operator!=(FieldIndex const &other) const
Definition field-index.h:79
uint64_t bit_field() const
Definition field-index.h:48
static FieldIndex ForSmiLoadHandler(Tagged< Map > map, int32_t handler)
static FieldIndex ForPropertyIndex(Tagged< Map > map, int index, Representation representation=Representation::Tagged())
int first_inobject_property_offset() const
static const int kOffsetBitsSize
static Encoding FieldEncoding(Representation representation)
Definition field-index.h:93
int outobject_array_index() const
Definition field-index.h:56
static FieldIndex ForDetails(Tagged< Map > map, PropertyDetails details)
bool operator==(FieldIndex const &other) const
Definition field-index.h:76
FieldIndex(bool is_inobject, int offset, Encoding encoding, int inobject_properties, int first_inobject_property_offset)
Definition field-index.h:82
static FieldIndex ForDescriptor(Tagged< Map > map, InternalIndex descriptor_index)
static FieldIndex ForInObjectOffset(int offset, Encoding encoding)
int GetFieldAccessStubKey() const
Definition field-index.h:71
const char * Mnemonic() const
constexpr Kind kind() const
static constexpr Representation Tagged()
ZoneVector< RpoNumber > & result
constexpr int kTaggedSize
Definition globals.h:542
void PrintF(const char *format,...)
Definition utils.cc:39
constexpr int kTaggedSizeLog2
Definition globals.h:543
static const int kDescriptorIndexBitCount
#define DCHECK(condition)
Definition logging.h:482
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403