v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
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_OBJECTS_FIELD_INDEX_INL_H_
6#define V8_OBJECTS_FIELD_INDEX_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
13#include "src/objects/map-inl.h"
16
17namespace v8 {
18namespace internal {
19
26
29
31 int inobject_properties = map->GetInObjectProperties();
32 int first_inobject_offset;
33 if (is_inobject) {
34 first_inobject_offset = map->GetInObjectPropertyOffset(0);
35 } else {
36 first_inobject_offset = OFFSET_OF_DATA_START(FixedArray);
37 }
38 return FieldIndex(
41 inobject_properties, first_inobject_offset);
42}
43
45 Representation representation) {
46 DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE);
47 int inobject_properties = map->GetInObjectProperties();
48 bool is_inobject = property_index < inobject_properties;
49 int first_inobject_offset;
50 int offset;
51 if (is_inobject) {
52 first_inobject_offset = map->GetInObjectPropertyOffset(0);
53 offset = map->GetInObjectPropertyOffset(property_index);
54 } else {
55 first_inobject_offset = OFFSET_OF_DATA_START(FixedArray);
56 property_index -= inobject_properties;
58 }
59 Encoding encoding = FieldEncoding(representation);
60 return FieldIndex(is_inobject, offset, encoding, inobject_properties,
61 first_inobject_offset);
62}
63
64// Returns the index format accepted by the LoadFieldByIndex instruction.
65// (In-object: zero-based from (object start + JSObject::kHeaderSize),
66// out-of-object: zero-based from OFFSET_OF_DATA_START(FixedArray).)
68 // For efficiency, the LoadByFieldIndex instruction takes an index that is
69 // optimized for quick access. If the property is inline, the index is
70 // positive. If it's out-of-line, the encoded index is -raw_index - 1 to
71 // disambiguate the zero out-of-line index from the zero inobject case.
72 // The index itself is shifted up by one bit, the lower-most bit
73 // signifying if the field is a mutable double box (1) or not (0).
74 int result = index();
75 if (is_inobject()) {
76 result -= JSObject::kHeaderSize / kTaggedSize;
77 } else {
79 result = -result - 1;
80 }
81 result = static_cast<uint32_t>(result) << 1;
82 return is_double() ? (result | 1) : result;
83}
84
86 InternalIndex descriptor_index) {
88 return ForDescriptor(cage_base, map, descriptor_index);
89}
90
92 Tagged<Map> map,
93 InternalIndex descriptor_index) {
94 PropertyDetails details = map->instance_descriptors(cage_base, kRelaxedLoad)
95 ->GetDetails(descriptor_index);
96 return ForDetails(map, details);
97}
98
100 int field_index = details.field_index();
101 return ForPropertyIndex(map, field_index, details.representation());
102}
103
104} // namespace internal
105} // namespace v8
106
107#endif // V8_OBJECTS_FIELD_INDEX_INL_H_
static constexpr T decode(U value)
Definition bit-field.h:66
static FieldIndex ForSmiLoadHandler(Tagged< Map > map, int32_t handler)
static FieldIndex ForPropertyIndex(Tagged< Map > map, int index, Representation representation=Representation::Tagged())
static Encoding FieldEncoding(Representation representation)
Definition field-index.h:93
static FieldIndex ForDetails(Tagged< Map > map, PropertyDetails details)
static FieldIndex ForDescriptor(Tagged< Map > map, InternalIndex descriptor_index)
static FieldIndex ForInObjectOffset(int offset, Encoding encoding)
static constexpr int OffsetOfElementAt(int index)
Representation representation() const
int32_t offset
ZoneVector< RpoNumber > & result
constexpr int kTaggedSize
Definition globals.h:542
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
constexpr int kInt32Size
Definition globals.h:401
constexpr int kDoubleSize
Definition globals.h:407
static constexpr RelaxedLoadTag kRelaxedLoad
Definition globals.h:2909
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403
#define OFFSET_OF_DATA_START(Type)