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
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2012-07-05 13:54:20 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/objects.h"
|
|
|
|
#include "src/transitions-inl.h"
|
|
|
|
#include "src/utils.h"
|
2012-07-05 13:54:20 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2014-04-11 12:13:53 +00:00
|
|
|
Handle<TransitionArray> TransitionArray::Allocate(Isolate* isolate,
|
|
|
|
int number_of_transitions) {
|
|
|
|
Handle<FixedArray> array =
|
|
|
|
isolate->factory()->NewFixedArray(ToKeyIndex(number_of_transitions));
|
2012-07-10 07:53:00 +00:00
|
|
|
array->set(kPrototypeTransitionsIndex, Smi::FromInt(0));
|
2014-04-11 12:13:53 +00:00
|
|
|
return Handle<TransitionArray>::cast(array);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 12:13:53 +00:00
|
|
|
Handle<TransitionArray> TransitionArray::AllocateSimple(Isolate* isolate,
|
|
|
|
Handle<Map> target) {
|
|
|
|
Handle<FixedArray> array =
|
|
|
|
isolate->factory()->NewFixedArray(kSimpleTransitionSize);
|
|
|
|
array->set(kSimpleTransitionTarget, *target);
|
|
|
|
return Handle<TransitionArray>::cast(array);
|
2014-04-09 14:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 15:10:31 +00:00
|
|
|
void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin,
|
|
|
|
int origin_transition,
|
|
|
|
int target_transition) {
|
|
|
|
NoIncrementalWriteBarrierSet(target_transition,
|
|
|
|
origin->GetKey(origin_transition),
|
|
|
|
origin->GetTarget(origin_transition));
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
static bool InsertionPointFound(Name* key1, Name* key2) {
|
2012-07-05 13:54:20 +00:00
|
|
|
return key1->Hash() > key2->Hash();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-10 13:06:52 +00:00
|
|
|
Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map,
|
|
|
|
Handle<Name> name,
|
2014-04-09 14:26:32 +00:00
|
|
|
Handle<Map> target,
|
2014-04-10 13:06:52 +00:00
|
|
|
SimpleTransitionFlag flag) {
|
2014-04-09 14:26:32 +00:00
|
|
|
Handle<TransitionArray> result;
|
2014-04-11 12:13:53 +00:00
|
|
|
Isolate* isolate = name->GetIsolate();
|
2012-09-19 09:54:10 +00:00
|
|
|
|
|
|
|
if (flag == SIMPLE_TRANSITION) {
|
2014-04-11 12:13:53 +00:00
|
|
|
result = AllocateSimple(isolate, target);
|
2012-09-19 09:54:10 +00:00
|
|
|
} else {
|
2014-04-11 12:13:53 +00:00
|
|
|
result = Allocate(isolate, 1);
|
2014-04-10 13:06:52 +00:00
|
|
|
result->NoIncrementalWriteBarrierSet(0, *name, *target);
|
2012-09-19 09:54:10 +00:00
|
|
|
}
|
2014-04-10 13:06:52 +00:00
|
|
|
result->set_back_pointer_storage(map->GetBackPointer());
|
2012-09-19 09:54:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
2012-07-05 13:54:20 +00:00
|
|
|
|
|
|
|
|
2014-04-11 12:13:53 +00:00
|
|
|
Handle<TransitionArray> TransitionArray::ExtendToFullTransitionArray(
|
2014-04-11 14:25:00 +00:00
|
|
|
Handle<Map> containing_map) {
|
|
|
|
ASSERT(!containing_map->transitions()->IsFullTransitionArray());
|
|
|
|
int nof = containing_map->transitions()->number_of_transitions();
|
2012-09-19 09:54:10 +00:00
|
|
|
|
2014-04-11 14:25:00 +00:00
|
|
|
// A transition array may shrink during GC.
|
|
|
|
Handle<TransitionArray> result = Allocate(containing_map->GetIsolate(), nof);
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
int new_nof = containing_map->transitions()->number_of_transitions();
|
|
|
|
if (new_nof != nof) {
|
|
|
|
ASSERT(new_nof == 0);
|
|
|
|
result->Shrink(ToKeyIndex(0));
|
|
|
|
} else if (nof == 1) {
|
2014-04-11 12:13:53 +00:00
|
|
|
result->NoIncrementalWriteBarrierCopyFrom(
|
2014-04-11 14:25:00 +00:00
|
|
|
containing_map->transitions(), kSimpleTransitionIndex, 0);
|
2012-09-19 09:54:10 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 14:25:00 +00:00
|
|
|
result->set_back_pointer_storage(
|
|
|
|
containing_map->transitions()->back_pointer_storage());
|
2012-07-05 13:54:20 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map,
|
|
|
|
Handle<Name> name,
|
2014-04-10 13:06:52 +00:00
|
|
|
Handle<Map> target,
|
|
|
|
SimpleTransitionFlag flag) {
|
|
|
|
if (!map->HasTransitionArray()) {
|
|
|
|
return TransitionArray::NewWith(map, name, target, flag);
|
|
|
|
}
|
2012-07-05 13:54:20 +00:00
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
int number_of_transitions = map->transitions()->number_of_transitions();
|
2012-07-05 13:54:20 +00:00
|
|
|
int new_size = number_of_transitions;
|
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
int insertion_index = map->transitions()->Search(*name);
|
2012-07-05 13:54:20 +00:00
|
|
|
if (insertion_index == kNotFound) ++new_size;
|
|
|
|
|
2014-04-11 12:13:53 +00:00
|
|
|
Handle<TransitionArray> result = Allocate(map->GetIsolate(), new_size);
|
2014-04-09 14:26:32 +00:00
|
|
|
|
2014-04-14 08:58:00 +00:00
|
|
|
// The map's transition array may grown smaller during the allocation above as
|
|
|
|
// it was weakly traversed, though it is guaranteed not to disappear. Trim the
|
|
|
|
// result copy if needed, and recompute variables.
|
|
|
|
ASSERT(map->HasTransitionArray());
|
2014-04-09 14:26:32 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
TransitionArray* array = map->transitions();
|
|
|
|
if (array->number_of_transitions() != number_of_transitions) {
|
|
|
|
ASSERT(array->number_of_transitions() < number_of_transitions);
|
|
|
|
|
|
|
|
number_of_transitions = array->number_of_transitions();
|
|
|
|
new_size = number_of_transitions;
|
|
|
|
|
|
|
|
insertion_index = array->Search(*name);
|
|
|
|
if (insertion_index == kNotFound) ++new_size;
|
2012-07-05 13:54:20 +00:00
|
|
|
|
2014-04-10 13:06:52 +00:00
|
|
|
result->Shrink(ToKeyIndex(new_size));
|
2014-04-09 14:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (array->HasPrototypeTransitions()) {
|
|
|
|
result->SetPrototypeTransitions(array->GetPrototypeTransitions());
|
2012-07-10 07:53:00 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
if (insertion_index != kNotFound) {
|
|
|
|
for (int i = 0; i < number_of_transitions; ++i) {
|
2012-09-14 15:10:31 +00:00
|
|
|
if (i != insertion_index) {
|
2014-04-09 14:26:32 +00:00
|
|
|
result->NoIncrementalWriteBarrierCopyFrom(array, i, i);
|
2012-09-14 15:10:31 +00:00
|
|
|
}
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
2014-04-09 14:26:32 +00:00
|
|
|
result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target);
|
|
|
|
result->set_back_pointer_storage(array->back_pointer_storage());
|
2012-07-05 13:54:20 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
insertion_index = 0;
|
|
|
|
for (; insertion_index < number_of_transitions; ++insertion_index) {
|
2014-04-09 14:26:32 +00:00
|
|
|
if (InsertionPointFound(array->GetKey(insertion_index), *name)) break;
|
2012-09-14 15:10:31 +00:00
|
|
|
result->NoIncrementalWriteBarrierCopyFrom(
|
2014-04-09 14:26:32 +00:00
|
|
|
array, insertion_index, insertion_index);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target);
|
2012-07-05 13:54:20 +00:00
|
|
|
|
|
|
|
for (; insertion_index < number_of_transitions; ++insertion_index) {
|
2012-09-14 15:10:31 +00:00
|
|
|
result->NoIncrementalWriteBarrierCopyFrom(
|
2014-04-09 14:26:32 +00:00
|
|
|
array, insertion_index, insertion_index + 1);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
result->set_back_pointer_storage(array->back_pointer_storage());
|
2012-07-05 13:54:20 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|