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 "transitions.h"
37 #define FIELD_ADDR(p, offset) \
38 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
40 #define WRITE_FIELD(p, offset, value) \
41 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value)
43 #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \
44 if (mode == UPDATE_WRITE_BARRIER) { \
45 heap->incremental_marking()->RecordWrite( \
46 object, HeapObject::RawField(object, offset), value); \
47 if (heap->InNewSpace(value)) { \
48 heap->RecordWrite(object->address(), offset); \
53 TransitionArray* TransitionArray::cast(Object* object) {
54 ASSERT(object->IsTransitionArray());
55 return reinterpret_cast<TransitionArray*>(object);
59 bool TransitionArray::HasElementsTransition() {
60 return Search(GetHeap()->elements_transition_symbol()) != kNotFound;
64 Object* TransitionArray::back_pointer_storage() {
65 return get(kBackPointerStorageIndex);
69 void TransitionArray::set_back_pointer_storage(Object* back_pointer,
70 WriteBarrierMode mode) {
71 Heap* heap = GetHeap();
72 WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer);
73 CONDITIONAL_WRITE_BARRIER(
74 heap, this, kBackPointerStorageOffset, back_pointer, mode);
78 bool TransitionArray::HasPrototypeTransitions() {
79 return IsFullTransitionArray() &&
80 get(kPrototypeTransitionsIndex) != Smi::FromInt(0);
84 FixedArray* TransitionArray::GetPrototypeTransitions() {
85 ASSERT(IsFullTransitionArray());
86 Object* prototype_transitions = get(kPrototypeTransitionsIndex);
87 return FixedArray::cast(prototype_transitions);
91 HeapObject* TransitionArray::UncheckedPrototypeTransitions() {
92 ASSERT(HasPrototypeTransitions());
93 return reinterpret_cast<HeapObject*>(get(kPrototypeTransitionsIndex));
97 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions,
98 WriteBarrierMode mode) {
99 ASSERT(IsFullTransitionArray());
100 ASSERT(transitions->IsFixedArray());
101 Heap* heap = GetHeap();
102 WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
103 CONDITIONAL_WRITE_BARRIER(
104 heap, this, kPrototypeTransitionsOffset, transitions, mode);
108 Object** TransitionArray::GetPrototypeTransitionsSlot() {
109 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
110 kPrototypeTransitionsOffset);
114 Object** TransitionArray::GetKeySlot(int transition_number) {
115 ASSERT(!IsSimpleTransition());
116 ASSERT(transition_number < number_of_transitions());
117 return RawFieldOfElementAt(ToKeyIndex(transition_number));
121 Name* TransitionArray::GetKey(int transition_number) {
122 if (IsSimpleTransition()) {
123 Map* target = GetTarget(kSimpleTransitionIndex);
124 int descriptor = target->LastAdded();
125 Name* key = target->instance_descriptors()->GetKey(descriptor);
128 ASSERT(transition_number < number_of_transitions());
129 return Name::cast(get(ToKeyIndex(transition_number)));
133 void TransitionArray::SetKey(int transition_number, Name* key) {
134 ASSERT(!IsSimpleTransition());
135 ASSERT(transition_number < number_of_transitions());
136 set(ToKeyIndex(transition_number), key);
140 Map* TransitionArray::GetTarget(int transition_number) {
141 if (IsSimpleTransition()) {
142 ASSERT(transition_number == kSimpleTransitionIndex);
143 return Map::cast(get(kSimpleTransitionTarget));
145 ASSERT(transition_number < number_of_transitions());
146 return Map::cast(get(ToTargetIndex(transition_number)));
150 void TransitionArray::SetTarget(int transition_number, Map* value) {
151 if (IsSimpleTransition()) {
152 ASSERT(transition_number == kSimpleTransitionIndex);
153 return set(kSimpleTransitionTarget, value);
155 ASSERT(transition_number < number_of_transitions());
156 set(ToTargetIndex(transition_number), value);
160 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
161 Map* map = GetTarget(transition_number);
162 return map->GetLastDescriptorDetails();
166 int TransitionArray::Search(Name* name) {
167 if (IsSimpleTransition()) {
168 Name* key = GetKey(kSimpleTransitionIndex);
169 if (key->Equals(name)) return kSimpleTransitionIndex;
172 return internal::Search<ALL_ENTRIES>(this, name);
176 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
179 FixedArray::NoIncrementalWriteBarrierSet(
180 this, ToKeyIndex(transition_number), key);
181 FixedArray::NoIncrementalWriteBarrierSet(
182 this, ToTargetIndex(transition_number), target);
188 #undef CONDITIONAL_WRITE_BARRIER
191 } } // namespace v8::internal
193 #endif // V8_TRANSITIONS_INL_H_