OLD | NEW |
---|---|
(Empty) | |
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.h" | |
32 #include "objects-inl.h" | |
33 #include "transitions.h" | |
34 | |
35 namespace v8 { | |
36 namespace internal { | |
37 | |
38 | |
39 #define FIELD_ADDR(p, offset) \ | |
40 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) | |
41 | |
42 #define WRITE_FIELD(p, offset, value) \ | |
43 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) | |
44 | |
45 #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ | |
46 if (mode == UPDATE_WRITE_BARRIER) { \ | |
47 heap->incremental_marking()->RecordWrite( \ | |
48 object, HeapObject::RawField(object, offset), value); \ | |
49 if (heap->InNewSpace(value)) { \ | |
50 heap->RecordWrite(object->address(), offset); \ | |
51 } \ | |
52 } | |
53 | |
54 | |
55 TransitionArray* TransitionArray::cast(Object* object) { | |
56 ASSERT(object->IsTransitionArray()); | |
57 return reinterpret_cast<TransitionArray*>(object); | |
58 } | |
59 | |
60 | |
61 Map* TransitionArray::elements_transition() { | |
62 Object* transition_map = get(kElementsTransitionIndex); | |
63 return Map::cast(transition_map); | |
64 } | |
65 | |
66 | |
67 void TransitionArray::ClearElementsTransition() { | |
68 WRITE_FIELD(this, kElementsTransitionOffset, Smi::FromInt(0)); | |
69 } | |
70 | |
71 | |
72 bool TransitionArray::HasElementsTransition() { | |
73 return get(kElementsTransitionIndex) != Smi::FromInt(0); | |
74 } | |
75 | |
76 | |
77 void TransitionArray::set_elements_transition( | |
78 Map* transition_map, WriteBarrierMode mode) { | |
79 ASSERT(this != NULL); | |
80 Heap* heap = GetHeap(); | |
81 WRITE_FIELD(this, kElementsTransitionOffset, transition_map); | |
82 CONDITIONAL_WRITE_BARRIER( | |
83 heap, this, kElementsTransitionOffset, transition_map, mode); | |
84 } | |
85 | |
86 | |
87 Object** TransitionArray::GetKeySlot(int transition_number) { | |
88 ASSERT(transition_number < number_of_transitions()); | |
89 return HeapObject::RawField( | |
90 reinterpret_cast<HeapObject*>(this), | |
91 OffsetOfElementAt(ToKeyIndex(transition_number))); | |
92 } | |
93 | |
94 | |
95 String* TransitionArray::GetKey(int transition_number) { | |
96 ASSERT(transition_number < number_of_transitions()); | |
97 return String::cast(get(ToKeyIndex(transition_number))); | |
98 } | |
99 | |
100 | |
101 void TransitionArray::SetKeyUnchecked(Heap* heap, | |
102 int transition_number, | |
103 String* key) { | |
104 ASSERT(transition_number < number_of_transitions()); | |
105 set_unchecked(heap, | |
106 ToKeyIndex(transition_number), | |
107 key, | |
108 UPDATE_WRITE_BARRIER); | |
109 } | |
110 | |
111 | |
112 Object* TransitionArray::GetValue(int transition_number) { | |
113 ASSERT(transition_number < number_of_transitions()); | |
114 return get(ToValueIndex(transition_number)); | |
115 } | |
116 | |
117 | |
118 Object** TransitionArray::GetValueSlot(int transition_number) { | |
119 ASSERT(transition_number < number_of_transitions()); | |
120 return HeapObject::RawField( | |
121 reinterpret_cast<HeapObject*>(this), | |
122 OffsetOfElementAt(ToValueIndex(transition_number))); | |
123 } | |
124 | |
125 | |
126 void TransitionArray::SetValueUnchecked(Heap* heap, | |
127 int transition_number, | |
128 Object* value) { | |
129 ASSERT(transition_number < number_of_transitions()); | |
130 set_unchecked(heap, | |
131 ToValueIndex(transition_number), | |
132 value, | |
133 UPDATE_WRITE_BARRIER); | |
134 } | |
135 | |
136 | |
137 Map* TransitionArray::GetTargetMap(int transition_number) { | |
138 Object* value = GetValue(transition_number); | |
139 if (value->IsAccessorPair()) { | |
140 // TODO(verwaest) Currently details are always taken from the getter if it | |
141 // is a transition, otherwise from the setter which in that case has to be | |
142 // a transition. Details should be dependent on which component is | |
143 // requested. | |
144 AccessorPair* accessors = AccessorPair::cast(value); | |
145 if (accessors->getter()->IsMap()) { | |
146 return Map::cast(accessors->getter()); | |
147 } | |
148 return Map::cast(accessors->setter()); | |
149 } | |
150 return Map::cast(value); | |
151 } | |
152 | |
153 | |
154 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) { | |
155 Map* map = GetTargetMap(transition_number); | |
156 DescriptorArray* descriptors = map->instance_descriptors(); | |
157 String* key = GetKey(transition_number); | |
158 int descriptor = descriptors->SearchWithCache(key); | |
159 ASSERT(descriptor != DescriptorArray::kNotFound); | |
160 return descriptors->GetDetails(descriptor); | |
161 } | |
162 | |
163 | |
164 Object** TransitionArray::GetElementsSlot() { | |
165 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), | |
166 kElementsTransitionOffset); | |
167 } | |
168 | |
169 | |
170 int TransitionArray::Search(String* name) { | |
171 return internal::Search(this, name); | |
172 } | |
173 | |
174 | |
175 void TransitionArray::Set(int transition_number, String* key, Object* value) { | |
Michael Starzinger
2012/07/05 12:55:51
This setter should take a WhitenessWitness as the
| |
176 NoIncrementalWriteBarrierSet(this, | |
177 ToKeyIndex(transition_number), | |
178 key); | |
Michael Starzinger
2012/07/05 12:55:51
Actually I think it might be a good idea to pass t
| |
179 NoIncrementalWriteBarrierSet(this, | |
180 ToValueIndex(transition_number), | |
181 value); | |
182 } | |
183 | |
184 | |
185 #undef FIELD_ADDR | |
186 #undef WRITE_FIELD | |
187 #undef CONDITIONAL_WRITE_BARRIER | |
188 | |
189 | |
190 } } // namespace v8::internal | |
191 | |
192 #endif // V8_TRANSITIONS_INL_H_ | |
OLD | NEW |