Chromium Code Reviews| 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" | |
|
Jakob Kummerow
2012/06/29 16:31:36
Again, #including objects.h is unnecessary if you
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 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() { | |
| 62 Object* transition_map = get(kElementsTransitionIndex); | |
| 63 if (transition_map == Smi::FromInt(0)) { | |
| 64 return NULL; | |
| 65 } else { | |
| 66 return Map::cast(transition_map); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 | |
| 71 void TransitionArray::ClearElements() { | |
| 72 WRITE_FIELD(this, kElementsTransitionOffset, Smi::FromInt(0)); | |
| 73 } | |
| 74 | |
| 75 | |
| 76 bool TransitionArray::HasElementsTransition() { | |
| 77 return elements() != NULL; | |
| 78 } | |
| 79 | |
| 80 | |
| 81 void TransitionArray::set_elements( | |
| 82 Map* transition_map, WriteBarrierMode mode) { | |
|
Jakob Kummerow
2012/06/29 16:31:36
one line per argument, please.
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 83 ASSERT(this != NULL); | |
|
Jakob Kummerow
2012/06/29 16:31:36
can this happen?
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 84 Heap* heap = GetHeap(); | |
| 85 WRITE_FIELD(this, kElementsTransitionOffset, transition_map); | |
| 86 CONDITIONAL_WRITE_BARRIER( | |
| 87 heap, this, kElementsTransitionOffset, transition_map, mode); | |
| 88 } | |
| 89 | |
| 90 | |
| 91 Object** TransitionArray::GetKeySlot(int transition_number) { | |
| 92 ASSERT(transition_number < number_of_transitions()); | |
| 93 return HeapObject::RawField( | |
| 94 reinterpret_cast<HeapObject*>(this), | |
| 95 OffsetOfElementAt(ToKeyIndex(transition_number))); | |
| 96 } | |
| 97 | |
| 98 | |
| 99 String* TransitionArray::GetKey(int transition_number) { | |
| 100 ASSERT(transition_number < number_of_transitions()); | |
| 101 return String::cast(get(ToKeyIndex(transition_number))); | |
| 102 } | |
| 103 | |
| 104 | |
| 105 void TransitionArray::SetKeyUnchecked(Heap* heap, | |
| 106 int transition_number, | |
| 107 String* key) { | |
| 108 ASSERT(transition_number < number_of_transitions()); | |
| 109 set_unchecked(heap, | |
| 110 ToKeyIndex(transition_number), | |
| 111 key, | |
| 112 UPDATE_WRITE_BARRIER); | |
| 113 } | |
| 114 | |
| 115 | |
| 116 Object* TransitionArray::GetValue(int transition_number) { | |
| 117 ASSERT(transition_number < number_of_transitions()); | |
| 118 return get(ToValueIndex(transition_number)); | |
| 119 } | |
| 120 | |
| 121 | |
| 122 Object** TransitionArray::GetValueSlot(int transition_number) { | |
| 123 ASSERT(transition_number < number_of_transitions()); | |
| 124 return HeapObject::RawField( | |
| 125 reinterpret_cast<HeapObject*>(this), | |
| 126 OffsetOfElementAt(ToValueIndex(transition_number))); | |
| 127 } | |
| 128 | |
| 129 | |
| 130 void TransitionArray::SetValueUnchecked(Heap* heap, | |
| 131 int transition_number, | |
| 132 Object* value) { | |
| 133 ASSERT(transition_number < number_of_transitions()); | |
| 134 set_unchecked(heap, | |
| 135 ToValueIndex(transition_number), | |
| 136 value, | |
| 137 UPDATE_WRITE_BARRIER); | |
| 138 } | |
| 139 | |
| 140 | |
| 141 Map* TransitionArray::GetTargetMap(int transition_number) { | |
| 142 Object* value = GetValue(transition_number); | |
| 143 if (value->IsAccessorPair()) { | |
| 144 // TODO(verwaest) Currently details are always taken from the getter if it | |
|
Jakob Kummerow
2012/06/29 16:31:36
nit: missing colon ("// TODO(verwaest): ...")
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 145 // is a transition, otherwise from the setter which in that case has to be | |
| 146 // a transition. Details should be dependent on which component is | |
| 147 // requested. | |
| 148 AccessorPair* accessors = AccessorPair::cast(value); | |
| 149 if (accessors->getter()->IsMap()) { | |
| 150 return Map::cast(accessors->getter()); | |
| 151 } | |
| 152 return Map::cast(accessors->setter()); | |
| 153 } | |
| 154 return Map::cast(value); | |
| 155 } | |
| 156 | |
| 157 | |
| 158 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) { | |
| 159 Map* map = GetTargetMap(transition_number); | |
| 160 DescriptorArray* descriptors = map->instance_descriptors(); | |
| 161 String* key = GetKey(transition_number); | |
| 162 int descriptor = descriptors->SearchWithCache(key); | |
| 163 ASSERT(descriptor != DescriptorArray::kNotFound); | |
| 164 return descriptors->GetDetails(descriptor); | |
| 165 } | |
| 166 | |
| 167 | |
| 168 Object** TransitionArray::GetElementsSlot() { | |
| 169 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), | |
| 170 kElementsTransitionOffset); | |
| 171 } | |
| 172 | |
| 173 | |
| 174 int TransitionArray::Search(String* name) { | |
| 175 if (this == NULL) return kNotFound; | |
|
Jakob Kummerow
2012/06/29 16:31:36
can this happen?
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 176 return internal::Search(this, name); | |
| 177 } | |
| 178 | |
| 179 | |
| 180 void TransitionArray::Set(int transition_number, String* key, Object* value) { | |
| 181 NoIncrementalWriteBarrierSet(this, | |
| 182 ToKeyIndex(transition_number), | |
| 183 key); | |
| 184 NoIncrementalWriteBarrierSet(this, | |
| 185 ToValueIndex(transition_number), | |
| 186 value); | |
| 187 } | |
| 188 | |
| 189 | |
| 190 #undef FIELD_ADDR | |
| 191 #undef WRITE_FIELD | |
| 192 #undef CONDITIONAL_WRITE_BARRIER | |
| 193 | |
| 194 | |
| 195 } } // namespace v8::internal | |
| 196 | |
| 197 #endif // V8_TRANSITIONS_INL_H_ | |
| OLD | NEW |