Chromium Code Reviews| Index: src/transitions-inl.h |
| diff --git a/src/transitions-inl.h b/src/transitions-inl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e369900c1e42307ac531af3ad3ba81e8ea659919 |
| --- /dev/null |
| +++ b/src/transitions-inl.h |
| @@ -0,0 +1,197 @@ |
| +// Copyright 2012 the V8 project authors. All rights reserved. |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following |
| +// disclaimer in the documentation and/or other materials provided |
| +// with the distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived |
| +// from this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +#ifndef V8_TRANSITIONS_INL_H_ |
| +#define V8_TRANSITIONS_INL_H_ |
| + |
| +#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.
|
| +#include "objects-inl.h" |
| +#include "transitions.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| + |
| +#define FIELD_ADDR(p, offset) \ |
| + (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) |
| + |
| +#define WRITE_FIELD(p, offset, value) \ |
| + (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) |
| + |
| +#define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ |
| + if (mode == UPDATE_WRITE_BARRIER) { \ |
| + heap->incremental_marking()->RecordWrite( \ |
| + object, HeapObject::RawField(object, offset), value); \ |
| + if (heap->InNewSpace(value)) { \ |
| + heap->RecordWrite(object->address(), offset); \ |
| + } \ |
| + } |
| + |
| + |
| +TransitionArray* TransitionArray::cast(Object* object) { |
| + ASSERT(object->IsTransitionArray()); |
| + return reinterpret_cast<TransitionArray*>(object); |
| +} |
| + |
| + |
| +Map* TransitionArray::elements() { |
| + Object* transition_map = get(kElementsTransitionIndex); |
| + if (transition_map == Smi::FromInt(0)) { |
| + return NULL; |
| + } else { |
| + return Map::cast(transition_map); |
| + } |
| +} |
| + |
| + |
| +void TransitionArray::ClearElements() { |
| + WRITE_FIELD(this, kElementsTransitionOffset, Smi::FromInt(0)); |
| +} |
| + |
| + |
| +bool TransitionArray::HasElementsTransition() { |
| + return elements() != NULL; |
| +} |
| + |
| + |
| +void TransitionArray::set_elements( |
| + 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.
|
| + ASSERT(this != NULL); |
|
Jakob Kummerow
2012/06/29 16:31:36
can this happen?
Toon Verwaest
2012/07/05 12:56:11
Done.
|
| + Heap* heap = GetHeap(); |
| + WRITE_FIELD(this, kElementsTransitionOffset, transition_map); |
| + CONDITIONAL_WRITE_BARRIER( |
| + heap, this, kElementsTransitionOffset, transition_map, mode); |
| +} |
| + |
| + |
| +Object** TransitionArray::GetKeySlot(int transition_number) { |
| + ASSERT(transition_number < number_of_transitions()); |
| + return HeapObject::RawField( |
| + reinterpret_cast<HeapObject*>(this), |
| + OffsetOfElementAt(ToKeyIndex(transition_number))); |
| +} |
| + |
| + |
| +String* TransitionArray::GetKey(int transition_number) { |
| + ASSERT(transition_number < number_of_transitions()); |
| + return String::cast(get(ToKeyIndex(transition_number))); |
| +} |
| + |
| + |
| +void TransitionArray::SetKeyUnchecked(Heap* heap, |
| + int transition_number, |
| + String* key) { |
| + ASSERT(transition_number < number_of_transitions()); |
| + set_unchecked(heap, |
| + ToKeyIndex(transition_number), |
| + key, |
| + UPDATE_WRITE_BARRIER); |
| +} |
| + |
| + |
| +Object* TransitionArray::GetValue(int transition_number) { |
| + ASSERT(transition_number < number_of_transitions()); |
| + return get(ToValueIndex(transition_number)); |
| +} |
| + |
| + |
| +Object** TransitionArray::GetValueSlot(int transition_number) { |
| + ASSERT(transition_number < number_of_transitions()); |
| + return HeapObject::RawField( |
| + reinterpret_cast<HeapObject*>(this), |
| + OffsetOfElementAt(ToValueIndex(transition_number))); |
| +} |
| + |
| + |
| +void TransitionArray::SetValueUnchecked(Heap* heap, |
| + int transition_number, |
| + Object* value) { |
| + ASSERT(transition_number < number_of_transitions()); |
| + set_unchecked(heap, |
| + ToValueIndex(transition_number), |
| + value, |
| + UPDATE_WRITE_BARRIER); |
| +} |
| + |
| + |
| +Map* TransitionArray::GetTargetMap(int transition_number) { |
| + Object* value = GetValue(transition_number); |
| + if (value->IsAccessorPair()) { |
| + // 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.
|
| + // is a transition, otherwise from the setter which in that case has to be |
| + // a transition. Details should be dependent on which component is |
| + // requested. |
| + AccessorPair* accessors = AccessorPair::cast(value); |
| + if (accessors->getter()->IsMap()) { |
| + return Map::cast(accessors->getter()); |
| + } |
| + return Map::cast(accessors->setter()); |
| + } |
| + return Map::cast(value); |
| +} |
| + |
| + |
| +PropertyDetails TransitionArray::GetTargetDetails(int transition_number) { |
| + Map* map = GetTargetMap(transition_number); |
| + DescriptorArray* descriptors = map->instance_descriptors(); |
| + String* key = GetKey(transition_number); |
| + int descriptor = descriptors->SearchWithCache(key); |
| + ASSERT(descriptor != DescriptorArray::kNotFound); |
| + return descriptors->GetDetails(descriptor); |
| +} |
| + |
| + |
| +Object** TransitionArray::GetElementsSlot() { |
| + return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
| + kElementsTransitionOffset); |
| +} |
| + |
| + |
| +int TransitionArray::Search(String* name) { |
| + 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.
|
| + return internal::Search(this, name); |
| +} |
| + |
| + |
| +void TransitionArray::Set(int transition_number, String* key, Object* value) { |
| + NoIncrementalWriteBarrierSet(this, |
| + ToKeyIndex(transition_number), |
| + key); |
| + NoIncrementalWriteBarrierSet(this, |
| + ToValueIndex(transition_number), |
| + value); |
| +} |
| + |
| + |
| +#undef FIELD_ADDR |
| +#undef WRITE_FIELD |
| +#undef CONDITIONAL_WRITE_BARRIER |
| + |
| + |
| +} } // namespace v8::internal |
| + |
| +#endif // V8_TRANSITIONS_INL_H_ |