1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef V8_TRANSITIONS_INL_H_
29 #define V8_TRANSITIONS_INL_H_
31 #include "objects-inl.h"
32 #include "transitions.h"
38 #define FIELD_ADDR(p, offset) \
39 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
41 #define WRITE_FIELD(p, offset, value) \
42 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value)
44 #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \
45 if (mode == UPDATE_WRITE_BARRIER) { \
46 heap->incremental_marking()->RecordWrite( \
47 object, HeapObject::RawField(object, offset), value); \
48 if (heap->InNewSpace(value)) { \
49 heap->RecordWrite(object->address(), offset); \
54 TransitionArray* TransitionArray::cast(Object* object) {
55 ASSERT(object->IsTransitionArray());
56 return reinterpret_cast<TransitionArray*>(object);
60 Map* TransitionArray::elements_transition() {
61 Object* transition_map = get(kElementsTransitionIndex);
62 return Map::cast(transition_map);
66 void TransitionArray::ClearElementsTransition() {
67 WRITE_FIELD(this, kElementsTransitionOffset, Smi::FromInt(0));
71 bool TransitionArray::HasElementsTransition() {
72 return get(kElementsTransitionIndex) != Smi::FromInt(0);
76 void TransitionArray::set_elements_transition(Map* transition_map,
77 WriteBarrierMode mode) {
78 Heap* heap = GetHeap();
79 WRITE_FIELD(this, kElementsTransitionOffset, transition_map);
80 CONDITIONAL_WRITE_BARRIER(
81 heap, this, kElementsTransitionOffset, transition_map, mode);
85 DescriptorArray* TransitionArray::descriptors() {
86 return DescriptorArray::cast(get(kDescriptorsIndex));
90 void TransitionArray::set_descriptors(DescriptorArray* descriptors,
91 WriteBarrierMode mode) {
92 Heap* heap = GetHeap();
93 WRITE_FIELD(this, kDescriptorsOffset, descriptors);
94 CONDITIONAL_WRITE_BARRIER(
95 heap, this, kDescriptorsOffset, descriptors, mode);
99 Object** TransitionArray::GetDescriptorsSlot() {
100 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
105 Object* TransitionArray::back_pointer_storage() {
106 return get(kBackPointerStorageIndex);
110 void TransitionArray::set_back_pointer_storage(Object* back_pointer,
111 WriteBarrierMode mode) {
112 Heap* heap = GetHeap();
113 WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer);
114 CONDITIONAL_WRITE_BARRIER(
115 heap, this, kBackPointerStorageOffset, back_pointer, mode);
119 bool TransitionArray::HasPrototypeTransitions() {
120 Object* prototype_transitions = get(kPrototypeTransitionsIndex);
121 return prototype_transitions != Smi::FromInt(0);
125 FixedArray* TransitionArray::GetPrototypeTransitions() {
126 Object* prototype_transitions = get(kPrototypeTransitionsIndex);
127 return FixedArray::cast(prototype_transitions);
131 HeapObject* TransitionArray::UncheckedPrototypeTransitions() {
132 ASSERT(HasPrototypeTransitions());
133 return reinterpret_cast<HeapObject*>(get(kPrototypeTransitionsIndex));
137 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions,
138 WriteBarrierMode mode) {
139 ASSERT(this != NULL);
140 ASSERT(transitions->IsFixedArray());
141 Heap* heap = GetHeap();
142 WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
143 CONDITIONAL_WRITE_BARRIER(
144 heap, this, kPrototypeTransitionsOffset, transitions, mode);
148 Object** TransitionArray::GetPrototypeTransitionsSlot() {
149 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
150 kPrototypeTransitionsOffset);
154 Object** TransitionArray::GetKeySlot(int transition_number) {
155 ASSERT(transition_number < number_of_transitions());
156 return HeapObject::RawField(
157 reinterpret_cast<HeapObject*>(this),
158 OffsetOfElementAt(ToKeyIndex(transition_number)));
162 String* TransitionArray::GetKey(int transition_number) {
163 ASSERT(transition_number < number_of_transitions());
164 return String::cast(get(ToKeyIndex(transition_number)));
168 void TransitionArray::SetKey(int transition_number, String* key) {
169 ASSERT(transition_number < number_of_transitions());
170 set(ToKeyIndex(transition_number), key);
174 Map* TransitionArray::GetTarget(int transition_number) {
175 ASSERT(transition_number < number_of_transitions());
176 return Map::cast(get(ToTargetIndex(transition_number)));
180 void TransitionArray::SetTarget(int transition_number, Map* value) {
181 ASSERT(transition_number < number_of_transitions());
182 set(ToTargetIndex(transition_number), value);
186 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
187 Map* map = GetTarget(transition_number);
188 DescriptorArray* descriptors = map->instance_descriptors();
189 int descriptor = map->LastAdded();
190 ASSERT(descriptor != Map::kNoneAdded);
191 return descriptors->GetDetails(descriptor);
195 int TransitionArray::Search(String* name) {
196 return internal::Search(this, name);
200 void TransitionArray::Set(int transition_number,
203 const WhitenessWitness&) {
204 NoIncrementalWriteBarrierSet(this,
205 ToKeyIndex(transition_number),
207 NoIncrementalWriteBarrierSet(this,
208 ToTargetIndex(transition_number),
215 #undef CONDITIONAL_WRITE_BARRIER
218 } } // namespace v8::internal
220 #endif // V8_TRANSITIONS_INL_H_