2012-07-05 13:54:20 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2012-07-05 13:54:20 +00:00
|
|
|
|
|
|
|
#ifndef V8_TRANSITIONS_INL_H_
|
|
|
|
#define V8_TRANSITIONS_INL_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/transitions.h"
|
2012-07-05 13:54:20 +00:00
|
|
|
|
|
|
|
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) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(object->IsTransitionArray());
|
2012-07-05 13:54:20 +00:00
|
|
|
return reinterpret_cast<TransitionArray*>(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TransitionArray::HasElementsTransition() {
|
2014-12-10 15:18:44 +00:00
|
|
|
return SearchSpecial(GetHeap()->elements_transition_symbol()) != kNotFound;
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-13 08:43:16 +00:00
|
|
|
Object* TransitionArray::back_pointer_storage() {
|
|
|
|
return get(kBackPointerStorageIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TransitionArray::set_back_pointer_storage(Object* back_pointer,
|
|
|
|
WriteBarrierMode mode) {
|
|
|
|
Heap* heap = GetHeap();
|
|
|
|
WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer);
|
|
|
|
CONDITIONAL_WRITE_BARRIER(
|
|
|
|
heap, this, kBackPointerStorageOffset, back_pointer, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-10 07:53:00 +00:00
|
|
|
bool TransitionArray::HasPrototypeTransitions() {
|
2012-09-19 09:54:10 +00:00
|
|
|
return IsFullTransitionArray() &&
|
|
|
|
get(kPrototypeTransitionsIndex) != Smi::FromInt(0);
|
2012-07-10 07:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FixedArray* TransitionArray::GetPrototypeTransitions() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsFullTransitionArray());
|
2012-07-10 07:53:00 +00:00
|
|
|
Object* prototype_transitions = get(kPrototypeTransitionsIndex);
|
|
|
|
return FixedArray::cast(prototype_transitions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TransitionArray::SetPrototypeTransitions(FixedArray* transitions,
|
|
|
|
WriteBarrierMode mode) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsFullTransitionArray());
|
|
|
|
DCHECK(transitions->IsFixedArray());
|
2012-07-10 07:53:00 +00:00
|
|
|
Heap* heap = GetHeap();
|
|
|
|
WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
|
|
|
|
CONDITIONAL_WRITE_BARRIER(
|
|
|
|
heap, this, kPrototypeTransitionsOffset, transitions, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object** TransitionArray::GetPrototypeTransitionsSlot() {
|
|
|
|
return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
|
|
|
|
kPrototypeTransitionsOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
Object** TransitionArray::GetKeySlot(int transition_number) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!IsSimpleTransition());
|
|
|
|
DCHECK(transition_number < number_of_transitions());
|
2013-12-23 14:42:42 +00:00
|
|
|
return RawFieldOfElementAt(ToKeyIndex(transition_number));
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* TransitionArray::GetKey(int transition_number) {
|
2012-09-19 09:54:10 +00:00
|
|
|
if (IsSimpleTransition()) {
|
|
|
|
Map* target = GetTarget(kSimpleTransitionIndex);
|
|
|
|
int descriptor = target->LastAdded();
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* key = target->instance_descriptors()->GetKey(descriptor);
|
2012-09-19 09:54:10 +00:00
|
|
|
return key;
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(transition_number < number_of_transitions());
|
2013-03-04 15:00:57 +00:00
|
|
|
return Name::cast(get(ToKeyIndex(transition_number)));
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void TransitionArray::SetKey(int transition_number, Name* key) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!IsSimpleTransition());
|
|
|
|
DCHECK(transition_number < number_of_transitions());
|
2012-07-05 13:54:20 +00:00
|
|
|
set(ToKeyIndex(transition_number), key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-16 14:02:50 +00:00
|
|
|
Map* TransitionArray::GetTarget(int transition_number) {
|
2012-09-19 09:54:10 +00:00
|
|
|
if (IsSimpleTransition()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(transition_number == kSimpleTransitionIndex);
|
2012-09-19 09:54:10 +00:00
|
|
|
return Map::cast(get(kSimpleTransitionTarget));
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(transition_number < number_of_transitions());
|
2012-07-16 14:02:50 +00:00
|
|
|
return Map::cast(get(ToTargetIndex(transition_number)));
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-16 14:02:50 +00:00
|
|
|
void TransitionArray::SetTarget(int transition_number, Map* value) {
|
2012-09-19 09:54:10 +00:00
|
|
|
if (IsSimpleTransition()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(transition_number == kSimpleTransitionIndex);
|
2012-09-19 09:54:10 +00:00
|
|
|
return set(kSimpleTransitionTarget, value);
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(transition_number < number_of_transitions());
|
2012-07-16 14:02:50 +00:00
|
|
|
set(ToTargetIndex(transition_number), value);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
|
2012-07-16 14:02:50 +00:00
|
|
|
Map* map = GetTarget(transition_number);
|
2014-02-18 12:19:32 +00:00
|
|
|
return map->GetLastDescriptorDetails();
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-23 11:31:33 +00:00
|
|
|
Object* TransitionArray::GetTargetValue(int transition_number) {
|
|
|
|
Map* map = GetTarget(transition_number);
|
|
|
|
return map->instance_descriptors()->GetValue(map->LastAdded());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-10 15:18:44 +00:00
|
|
|
int TransitionArray::SearchName(Name* name, int* out_insertion_index) {
|
2012-10-19 15:03:27 +00:00
|
|
|
if (IsSimpleTransition()) {
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* key = GetKey(kSimpleTransitionIndex);
|
2012-10-19 15:03:27 +00:00
|
|
|
if (key->Equals(name)) return kSimpleTransitionIndex;
|
2014-11-24 14:31:31 +00:00
|
|
|
if (out_insertion_index != NULL) {
|
|
|
|
*out_insertion_index = key->Hash() > name->Hash() ? 0 : 1;
|
|
|
|
}
|
2012-10-19 15:03:27 +00:00
|
|
|
return kNotFound;
|
|
|
|
}
|
2014-11-24 14:31:31 +00:00
|
|
|
return internal::Search<ALL_ENTRIES>(this, name, 0, out_insertion_index);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-10 15:18:44 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool TransitionArray::IsSpecialTransition(Name* name) {
|
|
|
|
if (!name->IsSymbol()) return false;
|
|
|
|
Heap* heap = name->GetHeap();
|
2014-12-10 20:02:48 +00:00
|
|
|
return name == heap->nonextensible_symbol() ||
|
|
|
|
name == heap->sealed_symbol() || name == heap->frozen_symbol() ||
|
2014-12-10 15:18:44 +00:00
|
|
|
name == heap->elements_transition_symbol() ||
|
|
|
|
name == heap->observed_symbol();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-12-12 15:27:38 +00:00
|
|
|
int TransitionArray::CompareKeys(Name* key1, uint32_t hash1, PropertyKind kind1,
|
2014-12-10 15:18:44 +00:00
|
|
|
PropertyAttributes attributes1, Name* key2,
|
2014-12-12 15:27:38 +00:00
|
|
|
uint32_t hash2, PropertyKind kind2,
|
2014-12-10 15:18:44 +00:00
|
|
|
PropertyAttributes attributes2) {
|
|
|
|
int cmp = CompareNames(key1, hash1, key2, hash2);
|
|
|
|
if (cmp != 0) return cmp;
|
|
|
|
|
2014-12-12 15:27:38 +00:00
|
|
|
return CompareDetails(kind1, attributes1, kind2, attributes2);
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TransitionArray::CompareNames(Name* key1, uint32_t hash1, Name* key2,
|
|
|
|
uint32_t hash2) {
|
|
|
|
if (key1 != key2) {
|
|
|
|
// In case of hash collisions key1 is always "less" than key2.
|
|
|
|
return hash1 <= hash2 ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-12 15:27:38 +00:00
|
|
|
int TransitionArray::CompareDetails(PropertyKind kind1,
|
2014-12-10 15:18:44 +00:00
|
|
|
PropertyAttributes attributes1,
|
2014-12-12 15:27:38 +00:00
|
|
|
PropertyKind kind2,
|
2014-12-10 15:18:44 +00:00
|
|
|
PropertyAttributes attributes2) {
|
2014-12-12 15:27:38 +00:00
|
|
|
if (kind1 != kind2) {
|
|
|
|
return static_cast<int>(kind1) < static_cast<int>(kind2) ? -1 : 1;
|
2014-12-10 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attributes1 != attributes2) {
|
|
|
|
return static_cast<int>(attributes1) < static_cast<int>(attributes2) ? -1
|
|
|
|
: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PropertyDetails TransitionArray::GetTargetDetails(Name* name, Map* target) {
|
|
|
|
DCHECK(!IsSpecialTransition(name));
|
|
|
|
int descriptor = target->LastAdded();
|
|
|
|
DescriptorArray* descriptors = target->instance_descriptors();
|
|
|
|
// Transitions are allowed only for the last added property.
|
|
|
|
DCHECK(descriptors->GetKey(descriptor)->Equals(name));
|
|
|
|
return descriptors->GetDetails(descriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 15:10:31 +00:00
|
|
|
void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* key,
|
2012-09-14 15:10:31 +00:00
|
|
|
Map* target) {
|
|
|
|
FixedArray::NoIncrementalWriteBarrierSet(
|
|
|
|
this, ToKeyIndex(transition_number), key);
|
|
|
|
FixedArray::NoIncrementalWriteBarrierSet(
|
|
|
|
this, ToTargetIndex(transition_number), target);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-03 16:44:58 +00:00
|
|
|
void TransitionArray::SetNumberOfTransitions(int number_of_transitions) {
|
|
|
|
if (IsFullTransitionArray()) {
|
|
|
|
DCHECK(number_of_transitions <= number_of_transitions_storage());
|
|
|
|
WRITE_FIELD(this, kTransitionLengthOffset,
|
|
|
|
Smi::FromInt(number_of_transitions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
#undef FIELD_ADDR
|
|
|
|
#undef WRITE_FIELD
|
|
|
|
#undef CONDITIONAL_WRITE_BARRIER
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_TRANSITIONS_INL_H_
|