v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
prototype-info-inl.h
Go to the documentation of this file.
1// Copyright 2018 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_PROTOTYPE_INFO_INL_H_
6#define V8_OBJECTS_PROTOTYPE_INFO_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
13#include "src/objects/map-inl.h"
17
18// Has to be the last include (doesn't have include guards):
20
21namespace v8 {
22namespace internal {
23
24#include "torque-generated/src/objects/prototype-info-tq-inl.inc"
25
26TQ_OBJECT_CONSTRUCTORS_IMPL(PrototypeInfo)
27
32 kDerivedMapsOffset)
33
35 auto derived = derived_maps();
36 if (IsUndefined(derived)) {
37 return Tagged<MaybeObject>();
38 }
39 // Index 0 is the map for object create
40 Tagged<WeakArrayList> derived_list = Cast<WeakArrayList>(derived);
41 DCHECK_GT(derived_list->length(), 0);
42 Tagged<MaybeObject> el = derived_list->Get(0);
44 return el;
45}
46
48 auto derived = derived_maps(tag);
49 if (IsUndefined(derived)) {
50 return Tagged<MaybeObject>();
51 }
52 // Index 0 is the map for object create
53 Tagged<WeakArrayList> derived_list = Cast<WeakArrayList>(derived);
54 DCHECK_GT(derived_list->length(), 0);
55 Tagged<MaybeObject> el = derived_list->Get(0);
57 return el;
58}
59
60// static
63 Isolate* isolate) {
64 if (IsUndefined(info->derived_maps())) {
65 Tagged<WeakArrayList> derived = *isolate->factory()->NewWeakArrayList(1);
66 derived->Set(0, MakeWeak(*map));
67 derived->set_length(1);
68 info->set_derived_maps(derived, kReleaseStore);
69 } else {
70 Tagged<WeakArrayList> derived = Cast<WeakArrayList>(info->derived_maps());
71 DCHECK(derived->Get(0).IsCleared());
72 DCHECK_GT(derived->length(), 0);
73 derived->Set(0, MakeWeak(*map));
74 }
75}
76
78 if (IsUndefined(derived_maps())) {
79 return Tagged<MaybeObject>();
80 }
81 auto derived = Cast<WeakArrayList>(derived_maps());
82 // Index 0 is the map for object create
83 for (int i = 1; i < derived->length(); ++i) {
84 Tagged<MaybeObject> el = derived->Get(i);
85 Tagged<Map> map_obj;
86 if (el.GetHeapObjectIfWeak(&map_obj)) {
87 Tagged<Map> to = Cast<Map>(map_obj);
88 if (to->GetConstructor() == from->GetConstructor() &&
89 to->instance_type() == from->instance_type()) {
90 return el;
91 }
92 }
93 }
94 return Tagged<MaybeObject>();
95}
96
97// static
99 DirectHandle<Map> to, Isolate* isolate) {
100 if (IsUndefined(info->derived_maps())) {
101 // Index 0 is the map for object create
102 Tagged<WeakArrayList> derived = *isolate->factory()->NewWeakArrayList(2);
103 // GetConstructMap assumes a weak pointer.
104 derived->Set(0, ClearedValue(isolate));
105 derived->Set(1, MakeWeak(*to));
106 derived->set_length(2);
107 info->set_derived_maps(derived, kReleaseStore);
108 return;
109 }
110 auto derived = handle(Cast<WeakArrayList>(info->derived_maps()), isolate);
111 // Index 0 is the map for object create
112 int i = 1;
113 for (; i < derived->length(); ++i) {
114 Tagged<MaybeObject> el = derived->Get(i);
115 if (el.IsCleared()) {
116 derived->Set(i, MakeWeak(*to));
117 return;
118 }
119 }
120
121 auto bigger = WeakArrayList::EnsureSpace(isolate, derived, i + 1);
122 bigger->Set(i, MakeWeak(*to));
123 bigger->set_length(i + 1);
124 if (*bigger != *derived) {
125 info->set_derived_maps(*bigger, kReleaseStore);
126 }
127}
128
130 bool is_proto_info = object != Smi::zero();
131 DCHECK_EQ(is_proto_info, IsPrototypeInfo(object));
132 return is_proto_info;
133}
134
136 ShouldBeFastBit::kShift)
137
139 DCHECK_GT(index, 0);
140 DCHECK_LT(index, array->length());
141 // Chain the empty slots into a linked list (each empty slot contains the
142 // index of the next empty slot).
143 array->Set(index, empty_slot_index(array));
144 set_empty_slot_index(array, index);
145}
146
150
152 int index) {
153 array->Set(kEmptySlotIndex, Smi::FromInt(index));
154}
155
156} // namespace internal
157} // namespace v8
158
160
161#endif // V8_OBJECTS_PROTOTYPE_INFO_INL_H_
static void AddDerivedMap(DirectHandle< PrototypeInfo > info, DirectHandle< Map > to, Isolate *isolate)
Tagged< MaybeObject > GetDerivedMap(DirectHandle< Map > from)
static void SetObjectCreateMap(DirectHandle< PrototypeInfo > info, DirectHandle< Map > map, Isolate *isolate)
Tagged< MaybeObject > ObjectCreateMap()
static bool IsPrototypeInfoFast(Tagged< Object > object)
static void set_empty_slot_index(Tagged< WeakArrayList > array, int index)
static const int kEmptySlotIndex
static void MarkSlotEmpty(Tagged< WeakArrayList > array, int index)
static Tagged< Smi > empty_slot_index(Tagged< WeakArrayList > array)
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
static constexpr Tagged< Smi > zero()
Definition smi.h:99
static PtrType load(Tagged< HeapObject > host, int offset=0)
constexpr bool IsCleared() const
bool GetHeapObjectIfWeak(Tagged< HeapObject > *result) const
bool ToSmi(Tagged< Smi > *value) const
constexpr bool IsWeakOrCleared() const
static Handle< WeakArrayList > EnsureSpace(Isolate *isolate, Handle< WeakArrayList > array, int length, AllocationType allocation=AllocationType::kYoung)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
Tagged(T object) -> Tagged< T >
Tagged< MaybeWeak< T > > MakeWeak(Tagged< T > value)
Definition tagged.h:893
Tagged< ClearedWeakValue > ClearedValue(PtrComprCageBase cage_base)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
static constexpr ReleaseStoreTag kReleaseStore
Definition globals.h:2910
#define BOOL_ACCESSORS(holder, field, name, offset)
#define TQ_OBJECT_CONSTRUCTORS_IMPL(Type)
#define RELEASE_ACQUIRE_ACCESSORS(holder, name, type, offset)
#define DEF_GETTER(Camel, Lower, Bit)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define DCHECK_GT(v1, v2)
Definition logging.h:487