Removed obsolete and dead includes.
[platform/upstream/v8.git] / src / transitions-inl.h
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
4 // met:
5 //
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.
15 //
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.
27
28 #ifndef V8_TRANSITIONS_INL_H_
29 #define V8_TRANSITIONS_INL_H_
30
31 #include "transitions.h"
32
33 namespace v8 {
34 namespace internal {
35
36
37 #define FIELD_ADDR(p, offset) \
38   (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
39
40 #define WRITE_FIELD(p, offset, value) \
41   (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value)
42
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);                     \
49     }                                                                   \
50   }
51
52
53 TransitionArray* TransitionArray::cast(Object* object) {
54   ASSERT(object->IsTransitionArray());
55   return reinterpret_cast<TransitionArray*>(object);
56 }
57
58
59 bool TransitionArray::HasElementsTransition() {
60   return Search(GetHeap()->elements_transition_symbol()) != kNotFound;
61 }
62
63
64 Object* TransitionArray::back_pointer_storage() {
65   return get(kBackPointerStorageIndex);
66 }
67
68
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);
75 }
76
77
78 bool TransitionArray::HasPrototypeTransitions() {
79   return IsFullTransitionArray() &&
80       get(kPrototypeTransitionsIndex) != Smi::FromInt(0);
81 }
82
83
84 FixedArray* TransitionArray::GetPrototypeTransitions() {
85   ASSERT(IsFullTransitionArray());
86   Object* prototype_transitions = get(kPrototypeTransitionsIndex);
87   return FixedArray::cast(prototype_transitions);
88 }
89
90
91 HeapObject* TransitionArray::UncheckedPrototypeTransitions() {
92   ASSERT(HasPrototypeTransitions());
93   return reinterpret_cast<HeapObject*>(get(kPrototypeTransitionsIndex));
94 }
95
96
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);
105 }
106
107
108 Object** TransitionArray::GetPrototypeTransitionsSlot() {
109   return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
110                               kPrototypeTransitionsOffset);
111 }
112
113
114 Object** TransitionArray::GetKeySlot(int transition_number) {
115   ASSERT(!IsSimpleTransition());
116   ASSERT(transition_number < number_of_transitions());
117   return RawFieldOfElementAt(ToKeyIndex(transition_number));
118 }
119
120
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);
126     return key;
127   }
128   ASSERT(transition_number < number_of_transitions());
129   return Name::cast(get(ToKeyIndex(transition_number)));
130 }
131
132
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);
137 }
138
139
140 Map* TransitionArray::GetTarget(int transition_number) {
141   if (IsSimpleTransition()) {
142     ASSERT(transition_number == kSimpleTransitionIndex);
143     return Map::cast(get(kSimpleTransitionTarget));
144   }
145   ASSERT(transition_number < number_of_transitions());
146   return Map::cast(get(ToTargetIndex(transition_number)));
147 }
148
149
150 void TransitionArray::SetTarget(int transition_number, Map* value) {
151   if (IsSimpleTransition()) {
152     ASSERT(transition_number == kSimpleTransitionIndex);
153     return set(kSimpleTransitionTarget, value);
154   }
155   ASSERT(transition_number < number_of_transitions());
156   set(ToTargetIndex(transition_number), value);
157 }
158
159
160 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
161   Map* map = GetTarget(transition_number);
162   return map->GetLastDescriptorDetails();
163 }
164
165
166 int TransitionArray::Search(Name* name) {
167   if (IsSimpleTransition()) {
168     Name* key = GetKey(kSimpleTransitionIndex);
169     if (key->Equals(name)) return kSimpleTransitionIndex;
170     return kNotFound;
171   }
172   return internal::Search<ALL_ENTRIES>(this, name);
173 }
174
175
176 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
177                                                    Name* key,
178                                                    Map* target) {
179   FixedArray::NoIncrementalWriteBarrierSet(
180       this, ToKeyIndex(transition_number), key);
181   FixedArray::NoIncrementalWriteBarrierSet(
182       this, ToTargetIndex(transition_number), target);
183 }
184
185
186 #undef FIELD_ADDR
187 #undef WRITE_FIELD
188 #undef CONDITIONAL_WRITE_BARRIER
189
190
191 } }  // namespace v8::internal
192
193 #endif  // V8_TRANSITIONS_INL_H_