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
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
#include "src/ic/handler-configuration-inl.h"
|
|
|
|
|
2017-11-07 06:50:22 +00:00
|
|
|
// Has to be the last include (doesn't have include guards):
|
|
|
|
#include "src/objects/object-macros.h"
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
template <TransitionsAccessor::Encoding enc>
|
|
|
|
WeakCell* TransitionsAccessor::GetTargetCell() {
|
|
|
|
DCHECK(!needs_reload_);
|
|
|
|
if (target_cell_ != nullptr) return target_cell_;
|
|
|
|
if (enc == kWeakCell) {
|
|
|
|
target_cell_ = WeakCell::cast(raw_transitions_);
|
2017-09-28 07:37:26 +00:00
|
|
|
} else if (enc == kHandler) {
|
|
|
|
target_cell_ = StoreHandler::GetTransitionCell(raw_transitions_);
|
2017-07-28 07:01:59 +00:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return target_cell_;
|
|
|
|
}
|
|
|
|
|
|
|
|
TransitionArray* TransitionsAccessor::transitions() {
|
|
|
|
DCHECK_EQ(kFullTransitionArray, encoding());
|
|
|
|
return TransitionArray::cast(raw_transitions_);
|
|
|
|
}
|
2012-07-05 13:54:20 +00:00
|
|
|
|
2017-11-07 06:50:22 +00:00
|
|
|
CAST_ACCESSOR(TransitionArray)
|
2012-07-05 13:54:20 +00:00
|
|
|
|
2012-07-10 07:53:00 +00:00
|
|
|
bool TransitionArray::HasPrototypeTransitions() {
|
2016-10-07 13:05:07 +00:00
|
|
|
return get(kPrototypeTransitionsIndex) != Smi::kZero;
|
2012-07-10 07:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FixedArray* TransitionArray::GetPrototypeTransitions() {
|
2015-03-06 14:08:33 +00:00
|
|
|
DCHECK(HasPrototypeTransitions()); // Callers must check first.
|
2012-07-10 07:53:00 +00:00
|
|
|
Object* prototype_transitions = get(kPrototypeTransitionsIndex);
|
|
|
|
return FixedArray::cast(prototype_transitions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-11 11:24:37 +00:00
|
|
|
void TransitionArray::SetPrototypeTransitions(FixedArray* transitions) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(transitions->IsFixedArray());
|
2015-12-11 11:24:37 +00:00
|
|
|
set(kPrototypeTransitionsIndex, transitions);
|
2012-07-10 07:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object** TransitionArray::GetPrototypeTransitionsSlot() {
|
2015-03-06 14:08:33 +00:00
|
|
|
return RawFieldOfElementAt(kPrototypeTransitionsIndex);
|
2012-07-10 07:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
Object** TransitionArray::GetKeySlot(int transition_number) {
|
2014-08-04 11:34:54 +00:00
|
|
|
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) {
|
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
|
|
|
}
|
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
Name* TransitionsAccessor::GetKey(int transition_number) {
|
|
|
|
WeakCell* cell = nullptr;
|
|
|
|
switch (encoding()) {
|
|
|
|
case kPrototypeInfo:
|
|
|
|
case kUninitialized:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
case kWeakCell:
|
|
|
|
cell = GetTargetCell<kWeakCell>();
|
|
|
|
break;
|
2017-09-28 07:37:26 +00:00
|
|
|
case kHandler:
|
|
|
|
cell = GetTargetCell<kHandler>();
|
2017-07-28 07:01:59 +00:00
|
|
|
break;
|
|
|
|
case kFullTransitionArray:
|
|
|
|
return transitions()->GetKey(transition_number);
|
2015-03-06 14:08:33 +00:00
|
|
|
}
|
2017-07-28 07:01:59 +00:00
|
|
|
DCHECK(!cell->cleared());
|
|
|
|
return GetSimpleTransitionKey(Map::cast(cell->value()));
|
2015-03-06 14:08:33 +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(transition_number < number_of_transitions());
|
2012-07-05 13:54:20 +00:00
|
|
|
set(ToKeyIndex(transition_number), key);
|
|
|
|
}
|
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
Object** TransitionArray::GetTargetSlot(int transition_number) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(transition_number < number_of_transitions());
|
2017-07-28 07:01:59 +00:00
|
|
|
return RawFieldOfElementAt(ToTargetIndex(transition_number));
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
// static
|
|
|
|
PropertyDetails TransitionsAccessor::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-07-05 13:54:20 +00:00
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
// static
|
|
|
|
Map* TransitionsAccessor::GetTargetFromRaw(Object* raw) {
|
2017-09-28 07:37:26 +00:00
|
|
|
if (raw->IsWeakCell()) return Map::cast(WeakCell::cast(raw)->value());
|
|
|
|
return Map::cast(StoreHandler::GetTransitionCell(raw)->value());
|
2015-03-05 20:41:47 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
Object* TransitionArray::GetRawTarget(int transition_number) {
|
|
|
|
DCHECK(transition_number < number_of_transitions());
|
|
|
|
return get(ToTargetIndex(transition_number));
|
|
|
|
}
|
2015-03-05 20:41:47 +00:00
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
Map* TransitionArray::GetTarget(int transition_number) {
|
|
|
|
Object* raw = GetRawTarget(transition_number);
|
|
|
|
return TransitionsAccessor::GetTargetFromRaw(raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map* TransitionsAccessor::GetTarget(int transition_number) {
|
|
|
|
WeakCell* cell = nullptr;
|
|
|
|
switch (encoding()) {
|
|
|
|
case kPrototypeInfo:
|
|
|
|
case kUninitialized:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
case kWeakCell:
|
|
|
|
cell = GetTargetCell<kWeakCell>();
|
|
|
|
break;
|
2017-09-28 07:37:26 +00:00
|
|
|
case kHandler:
|
|
|
|
cell = GetTargetCell<kHandler>();
|
2017-07-28 07:01:59 +00:00
|
|
|
break;
|
|
|
|
case kFullTransitionArray:
|
|
|
|
return transitions()->GetTarget(transition_number);
|
|
|
|
}
|
|
|
|
DCHECK(!cell->cleared());
|
|
|
|
return Map::cast(cell->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransitionArray::SetTarget(int transition_number, Object* value) {
|
2017-08-30 12:42:04 +00:00
|
|
|
DCHECK(!value->IsMap());
|
2015-03-06 14:08:33 +00:00
|
|
|
DCHECK(transition_number < number_of_transitions());
|
|
|
|
set(ToTargetIndex(transition_number), value);
|
2014-10-23 11:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-10 15:18:44 +00:00
|
|
|
int TransitionArray::SearchName(Name* name, int* out_insertion_index) {
|
2016-02-18 14:33:34 +00:00
|
|
|
DCHECK(name->IsUniqueName());
|
|
|
|
return internal::Search<ALL_ENTRIES>(this, name, number_of_entries(),
|
|
|
|
out_insertion_index);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
void TransitionArray::Set(int transition_number, Name* key, Object* target) {
|
2015-11-25 19:23:51 +00:00
|
|
|
set(ToKeyIndex(transition_number), key);
|
|
|
|
set(ToTargetIndex(transition_number), target);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 07:01:59 +00:00
|
|
|
int TransitionArray::Capacity() {
|
|
|
|
if (length() <= kFirstIndex) return 0;
|
|
|
|
return (length() - kFirstIndex) / kTransitionSize;
|
|
|
|
}
|
2012-07-05 13:54:20 +00:00
|
|
|
|
2014-11-03 16:44:58 +00:00
|
|
|
void TransitionArray::SetNumberOfTransitions(int number_of_transitions) {
|
2017-07-28 07:01:59 +00:00
|
|
|
DCHECK(number_of_transitions <= Capacity());
|
2015-03-06 14:08:33 +00:00
|
|
|
set(kTransitionLengthIndex, Smi::FromInt(number_of_transitions));
|
2014-11-03 16:44:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2012-07-05 13:54:20 +00:00
|
|
|
|
2017-11-07 06:50:22 +00:00
|
|
|
#include "src/objects/object-macros-undef.h"
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
#endif // V8_TRANSITIONS_INL_H_
|