v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transitions-inl.h
Go to the documentation of this file.
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 
55  ASSERT(object->IsTransitionArray());
56  return reinterpret_cast<TransitionArray*>(object);
57 }
58 
59 
61  Object* transition_map = get(kElementsTransitionIndex);
62  return Map::cast(transition_map);
63 }
64 
65 
68 }
69 
70 
72  return IsFullTransitionArray() &&
74 }
75 
76 
78  WriteBarrierMode mode) {
80  Heap* heap = GetHeap();
81  WRITE_FIELD(this, kElementsTransitionOffset, transition_map);
83  heap, this, kElementsTransitionOffset, transition_map, mode);
84 }
85 
86 
88  return get(kBackPointerStorageIndex);
89 }
90 
91 
93  WriteBarrierMode mode) {
94  Heap* heap = GetHeap();
95  WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer);
97  heap, this, kBackPointerStorageOffset, back_pointer, mode);
98 }
99 
100 
102  return IsFullTransitionArray() &&
104 }
105 
106 
109  Object* prototype_transitions = get(kPrototypeTransitionsIndex);
110  return FixedArray::cast(prototype_transitions);
111 }
112 
113 
116  return reinterpret_cast<HeapObject*>(get(kPrototypeTransitionsIndex));
117 }
118 
119 
121  WriteBarrierMode mode) {
123  ASSERT(transitions->IsFixedArray());
124  Heap* heap = GetHeap();
125  WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
127  heap, this, kPrototypeTransitionsOffset, transitions, mode);
128 }
129 
130 
132  return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
134 }
135 
136 
137 Object** TransitionArray::GetKeySlot(int transition_number) {
139  ASSERT(transition_number < number_of_transitions());
140  return HeapObject::RawField(
141  reinterpret_cast<HeapObject*>(this),
142  OffsetOfElementAt(ToKeyIndex(transition_number)));
143 }
144 
145 
146 String* TransitionArray::GetKey(int transition_number) {
147  if (IsSimpleTransition()) {
149  int descriptor = target->LastAdded();
150  String* key = target->instance_descriptors()->GetKey(descriptor);
151  return key;
152  }
153  ASSERT(transition_number < number_of_transitions());
154  return String::cast(get(ToKeyIndex(transition_number)));
155 }
156 
157 
158 void TransitionArray::SetKey(int transition_number, String* key) {
160  ASSERT(transition_number < number_of_transitions());
161  set(ToKeyIndex(transition_number), key);
162 }
163 
164 
165 Map* TransitionArray::GetTarget(int transition_number) {
166  if (IsSimpleTransition()) {
167  ASSERT(transition_number == kSimpleTransitionIndex);
168  return Map::cast(get(kSimpleTransitionTarget));
169  }
170  ASSERT(transition_number < number_of_transitions());
171  return Map::cast(get(ToTargetIndex(transition_number)));
172 }
173 
174 
175 void TransitionArray::SetTarget(int transition_number, Map* value) {
176  if (IsSimpleTransition()) {
177  ASSERT(transition_number == kSimpleTransitionIndex);
178  return set(kSimpleTransitionTarget, value);
179  }
180  ASSERT(transition_number < number_of_transitions());
181  set(ToTargetIndex(transition_number), value);
182 }
183 
184 
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);
190 }
191 
192 
194  if (IsSimpleTransition()) {
196  if (key->Equals(name)) return kSimpleTransitionIndex;
197  return kNotFound;
198  }
199  return internal::Search<ALL_ENTRIES>(this, name);
200 }
201 
202 
203 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
204  String* key,
205  Map* target) {
207  this, ToKeyIndex(transition_number), key);
209  this, ToTargetIndex(transition_number), target);
210 }
211 
212 
213 #undef FIELD_ADDR
214 #undef WRITE_FIELD
215 #undef CONDITIONAL_WRITE_BARRIER
216 
217 
218 } } // namespace v8::internal
219 
220 #endif // V8_TRANSITIONS_INL_H_
void set(int index, Object *value)
Definition: objects-inl.h:1757
static String * cast(Object *obj)
static Smi * FromInt(int value)
Definition: objects-inl.h:981
#define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode)
HeapObject * UncheckedPrototypeTransitions()
static const int kElementsTransitionOffset
Definition: transitions.h:155
static Map * cast(Object *obj)
static const int kPrototypeTransitionsIndex
Definition: transitions.h:143
void SetKey(int transition_number, String *value)
#define ASSERT(condition)
Definition: checks.h:270
static const int kElementsTransitionIndex
Definition: transitions.h:142
static const int kSimpleTransitionTarget
Definition: transitions.h:147
static Object ** RawField(HeapObject *obj, int offset)
Definition: objects-inl.h:971
bool Equals(String *other)
Definition: objects-inl.h:2419
static const int kNotFound
Definition: transitions.h:137
void SetPrototypeTransitions(FixedArray *prototype_transitions, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
PropertyDetails GetDetails(int descriptor_number)
Definition: objects-inl.h:2129
static const int kSimpleTransitionIndex
Definition: transitions.h:149
static int OffsetOfElementAt(int index)
Definition: objects.h:2356
String * GetKey(int transition_number)
static TransitionArray * cast(Object *obj)
static const int kBackPointerStorageOffset
Definition: transitions.h:152
Map * GetTarget(int transition_number)
static const int kBackPointerStorageIndex
Definition: transitions.h:139
void set_back_pointer_storage(Object *back_pointer, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
static void NoIncrementalWriteBarrierSet(FixedArray *array, int index, Object *value)
Definition: objects-inl.h:1850
#define WRITE_FIELD(p, offset, value)
static FixedArray * cast(Object *obj)
FixedArray * GetPrototypeTransitions()
static const int kPrototypeTransitionsOffset
Definition: transitions.h:157
void set_elements_transition(Map *target, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
Object ** GetKeySlot(int transition_number)
void SetTarget(int transition_number, Map *target)
PropertyDetails GetTargetDetails(int transition_number)