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 IsFullTransitionArray() &&
73 get(kElementsTransitionIndex) != Smi::FromInt(0);
77 void TransitionArray::set_elements_transition(Map* transition_map,
78 WriteBarrierMode mode) {
79 ASSERT(IsFullTransitionArray());
80 Heap* heap = GetHeap();
81 WRITE_FIELD(this, kElementsTransitionOffset, transition_map);
82 CONDITIONAL_WRITE_BARRIER(
83 heap, this, kElementsTransitionOffset, transition_map, mode);
87 Object* TransitionArray::back_pointer_storage() {
88 return get(kBackPointerStorageIndex);
92 void TransitionArray::set_back_pointer_storage(Object* back_pointer,
93 WriteBarrierMode mode) {
94 Heap* heap = GetHeap();
95 WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer);
96 CONDITIONAL_WRITE_BARRIER(
97 heap, this, kBackPointerStorageOffset, back_pointer, mode);
101 bool TransitionArray::HasPrototypeTransitions() {
102 return IsFullTransitionArray() &&
103 get(kPrototypeTransitionsIndex) != Smi::FromInt(0);
107 FixedArray* TransitionArray::GetPrototypeTransitions() {
108 ASSERT(IsFullTransitionArray());
109 Object* prototype_transitions = get(kPrototypeTransitionsIndex);
110 return FixedArray::cast(prototype_transitions);
114 HeapObject* TransitionArray::UncheckedPrototypeTransitions() {
115 ASSERT(HasPrototypeTransitions());
116 return reinterpret_cast<HeapObject*>(get(kPrototypeTransitionsIndex));
120 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions,
121 WriteBarrierMode mode) {
122 ASSERT(IsFullTransitionArray());
123 ASSERT(transitions->IsFixedArray());
124 Heap* heap = GetHeap();
125 WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
126 CONDITIONAL_WRITE_BARRIER(
127 heap, this, kPrototypeTransitionsOffset, transitions, mode);
131 Object** TransitionArray::GetPrototypeTransitionsSlot() {
132 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
133 kPrototypeTransitionsOffset);
137 Object** TransitionArray::GetKeySlot(int transition_number) {
138 ASSERT(!IsSimpleTransition());
139 ASSERT(transition_number < number_of_transitions());
140 return HeapObject::RawField(
141 reinterpret_cast<HeapObject*>(this),
142 OffsetOfElementAt(ToKeyIndex(transition_number)));
146 String* TransitionArray::GetKey(int transition_number) {
147 if (IsSimpleTransition()) {
148 Map* target = GetTarget(kSimpleTransitionIndex);
149 int descriptor = target->LastAdded();
150 String* key = target->instance_descriptors()->GetKey(descriptor);
153 ASSERT(transition_number < number_of_transitions());
154 return String::cast(get(ToKeyIndex(transition_number)));
158 void TransitionArray::SetKey(int transition_number, String* key) {
159 ASSERT(!IsSimpleTransition());
160 ASSERT(transition_number < number_of_transitions());
161 set(ToKeyIndex(transition_number), key);
165 Map* TransitionArray::GetTarget(int transition_number) {
166 if (IsSimpleTransition()) {
167 ASSERT(transition_number == kSimpleTransitionIndex);
168 return Map::cast(get(kSimpleTransitionTarget));
170 ASSERT(transition_number < number_of_transitions());
171 return Map::cast(get(ToTargetIndex(transition_number)));
175 void TransitionArray::SetTarget(int transition_number, Map* value) {
176 if (IsSimpleTransition()) {
177 ASSERT(transition_number == kSimpleTransitionIndex);
178 return set(kSimpleTransitionTarget, value);
180 ASSERT(transition_number < number_of_transitions());
181 set(ToTargetIndex(transition_number), value);
185 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
186 Map* map = GetTarget(transition_number);
187 DescriptorArray* descriptors = map->instance_descriptors();
188 int descriptor = map->LastAdded();
189 return descriptors->GetDetails(descriptor);
193 int TransitionArray::Search(String* name) {
194 return internal::Search<ALL_ENTRIES>(this, name);
198 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
201 FixedArray::NoIncrementalWriteBarrierSet(
202 this, ToKeyIndex(transition_number), key);
203 FixedArray::NoIncrementalWriteBarrierSet(
204 this, ToTargetIndex(transition_number), target);
210 #undef CONDITIONAL_WRITE_BARRIER
213 } } // namespace v8::internal
215 #endif // V8_TRANSITIONS_INL_H_