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 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions,
92 WriteBarrierMode mode) {
93 ASSERT(IsFullTransitionArray());
94 ASSERT(transitions->IsFixedArray());
95 Heap* heap = GetHeap();
96 WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
97 CONDITIONAL_WRITE_BARRIER(
98 heap, this, kPrototypeTransitionsOffset, transitions, mode);
102 Object** TransitionArray::GetPrototypeTransitionsSlot() {
103 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
104 kPrototypeTransitionsOffset);
108 Object** TransitionArray::GetKeySlot(int transition_number) {
109 ASSERT(!IsSimpleTransition());
110 ASSERT(transition_number < number_of_transitions());
111 return RawFieldOfElementAt(ToKeyIndex(transition_number));
115 Name* TransitionArray::GetKey(int transition_number) {
116 if (IsSimpleTransition()) {
117 Map* target = GetTarget(kSimpleTransitionIndex);
118 int descriptor = target->LastAdded();
119 Name* key = target->instance_descriptors()->GetKey(descriptor);
122 ASSERT(transition_number < number_of_transitions());
123 return Name::cast(get(ToKeyIndex(transition_number)));
127 void TransitionArray::SetKey(int transition_number, Name* key) {
128 ASSERT(!IsSimpleTransition());
129 ASSERT(transition_number < number_of_transitions());
130 set(ToKeyIndex(transition_number), key);
134 Map* TransitionArray::GetTarget(int transition_number) {
135 if (IsSimpleTransition()) {
136 ASSERT(transition_number == kSimpleTransitionIndex);
137 return Map::cast(get(kSimpleTransitionTarget));
139 ASSERT(transition_number < number_of_transitions());
140 return Map::cast(get(ToTargetIndex(transition_number)));
144 void TransitionArray::SetTarget(int transition_number, Map* value) {
145 if (IsSimpleTransition()) {
146 ASSERT(transition_number == kSimpleTransitionIndex);
147 return set(kSimpleTransitionTarget, value);
149 ASSERT(transition_number < number_of_transitions());
150 set(ToTargetIndex(transition_number), value);
154 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
155 Map* map = GetTarget(transition_number);
156 return map->GetLastDescriptorDetails();
160 int TransitionArray::Search(Name* name) {
161 if (IsSimpleTransition()) {
162 Name* key = GetKey(kSimpleTransitionIndex);
163 if (key->Equals(name)) return kSimpleTransitionIndex;
166 return internal::Search<ALL_ENTRIES>(this, name);
170 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
173 FixedArray::NoIncrementalWriteBarrierSet(
174 this, ToKeyIndex(transition_number), key);
175 FixedArray::NoIncrementalWriteBarrierSet(
176 this, ToTargetIndex(transition_number), target);
182 #undef CONDITIONAL_WRITE_BARRIER
185 } } // namespace v8::internal
187 #endif // V8_TRANSITIONS_INL_H_