Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / v8 / 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 "objects-inl.h"
32 #include "transitions.h"
33
34 namespace v8 {
35 namespace internal {
36
37
38 #define FIELD_ADDR(p, offset) \
39   (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
40
41 #define WRITE_FIELD(p, offset, value) \
42   (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value)
43
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);                     \
50     }                                                                   \
51   }
52
53
54 TransitionArray* TransitionArray::cast(Object* object) {
55   ASSERT(object->IsTransitionArray());
56   return reinterpret_cast<TransitionArray*>(object);
57 }
58
59
60 bool TransitionArray::HasElementsTransition() {
61   return Search(GetHeap()->elements_transition_symbol()) != kNotFound;
62 }
63
64
65 Object* TransitionArray::back_pointer_storage() {
66   return get(kBackPointerStorageIndex);
67 }
68
69
70 void TransitionArray::set_back_pointer_storage(Object* back_pointer,
71                                                WriteBarrierMode mode) {
72   Heap* heap = GetHeap();
73   WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer);
74   CONDITIONAL_WRITE_BARRIER(
75       heap, this, kBackPointerStorageOffset, back_pointer, mode);
76 }
77
78
79 bool TransitionArray::HasPrototypeTransitions() {
80   return IsFullTransitionArray() &&
81       get(kPrototypeTransitionsIndex) != Smi::FromInt(0);
82 }
83
84
85 FixedArray* TransitionArray::GetPrototypeTransitions() {
86   ASSERT(IsFullTransitionArray());
87   Object* prototype_transitions = get(kPrototypeTransitionsIndex);
88   return FixedArray::cast(prototype_transitions);
89 }
90
91
92 HeapObject* TransitionArray::UncheckedPrototypeTransitions() {
93   ASSERT(HasPrototypeTransitions());
94   return reinterpret_cast<HeapObject*>(get(kPrototypeTransitionsIndex));
95 }
96
97
98 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions,
99                                               WriteBarrierMode mode) {
100   ASSERT(IsFullTransitionArray());
101   ASSERT(transitions->IsFixedArray());
102   Heap* heap = GetHeap();
103   WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
104   CONDITIONAL_WRITE_BARRIER(
105       heap, this, kPrototypeTransitionsOffset, transitions, mode);
106 }
107
108
109 Object** TransitionArray::GetPrototypeTransitionsSlot() {
110   return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
111                               kPrototypeTransitionsOffset);
112 }
113
114
115 Object** TransitionArray::GetKeySlot(int transition_number) {
116   ASSERT(!IsSimpleTransition());
117   ASSERT(transition_number < number_of_transitions());
118   return RawFieldOfElementAt(ToKeyIndex(transition_number));
119 }
120
121
122 Name* TransitionArray::GetKey(int transition_number) {
123   if (IsSimpleTransition()) {
124     Map* target = GetTarget(kSimpleTransitionIndex);
125     int descriptor = target->LastAdded();
126     Name* key = target->instance_descriptors()->GetKey(descriptor);
127     return key;
128   }
129   ASSERT(transition_number < number_of_transitions());
130   return Name::cast(get(ToKeyIndex(transition_number)));
131 }
132
133
134 void TransitionArray::SetKey(int transition_number, Name* key) {
135   ASSERT(!IsSimpleTransition());
136   ASSERT(transition_number < number_of_transitions());
137   set(ToKeyIndex(transition_number), key);
138 }
139
140
141 Map* TransitionArray::GetTarget(int transition_number) {
142   if (IsSimpleTransition()) {
143     ASSERT(transition_number == kSimpleTransitionIndex);
144     return Map::cast(get(kSimpleTransitionTarget));
145   }
146   ASSERT(transition_number < number_of_transitions());
147   return Map::cast(get(ToTargetIndex(transition_number)));
148 }
149
150
151 void TransitionArray::SetTarget(int transition_number, Map* value) {
152   if (IsSimpleTransition()) {
153     ASSERT(transition_number == kSimpleTransitionIndex);
154     return set(kSimpleTransitionTarget, value);
155   }
156   ASSERT(transition_number < number_of_transitions());
157   set(ToTargetIndex(transition_number), value);
158 }
159
160
161 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
162   Map* map = GetTarget(transition_number);
163   return map->GetLastDescriptorDetails();
164 }
165
166
167 int TransitionArray::Search(Name* name) {
168   if (IsSimpleTransition()) {
169     Name* key = GetKey(kSimpleTransitionIndex);
170     if (key->Equals(name)) return kSimpleTransitionIndex;
171     return kNotFound;
172   }
173   return internal::Search<ALL_ENTRIES>(this, name);
174 }
175
176
177 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
178                                                    Name* key,
179                                                    Map* target) {
180   FixedArray::NoIncrementalWriteBarrierSet(
181       this, ToKeyIndex(transition_number), key);
182   FixedArray::NoIncrementalWriteBarrierSet(
183       this, ToTargetIndex(transition_number), target);
184 }
185
186
187 #undef FIELD_ADDR
188 #undef WRITE_FIELD
189 #undef CONDITIONAL_WRITE_BARRIER
190
191
192 } }  // namespace v8::internal
193
194 #endif  // V8_TRANSITIONS_INL_H_