Commit de50f63f authored by verwaest@chromium.org's avatar verwaest@chromium.org

Clean up the public interface of Map.

BUG=
R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/234573005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20716 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 97585ab8
......@@ -5026,19 +5026,6 @@ uint32_t Map::bit_field3() {
}
void Map::ClearTransitions(Heap* heap, WriteBarrierMode mode) {
Object* back_pointer = GetBackPointer();
if (Heap::ShouldZapGarbage() && HasTransitionArray()) {
ZapTransitions();
}
WRITE_FIELD(this, kTransitionsOrBackPointerOffset, back_pointer);
CONDITIONAL_WRITE_BARRIER(
heap, this, kTransitionsOrBackPointerOffset, back_pointer, mode);
}
void Map::AppendDescriptor(Descriptor* desc) {
DescriptorArray* descriptors = instance_descriptors();
int number_of_own_descriptors = NumberOfOwnDescriptors();
......@@ -5084,11 +5071,6 @@ bool Map::CanHaveMoreTransitions() {
}
void Map::SetTransition(int transition_index, Map* target) {
transitions()->SetTarget(transition_index, target);
}
Map* Map::GetTransition(int transition_index) {
return transitions()->GetTarget(transition_index);
}
......
......@@ -2607,7 +2607,7 @@ Handle<Map> Map::GeneralizeRepresentation(Handle<Map> old_map,
// Add missing transitions.
Handle<Map> new_map = split_map;
for (; descriptor < descriptors; descriptor++) {
new_map = Map::CopyInstallDescriptors(new_map, descriptor, new_descriptors);
new_map = CopyInstallDescriptors(new_map, descriptor, new_descriptors);
}
new_map->set_owns_descriptors(true);
......@@ -6766,7 +6766,7 @@ Handle<Map> Map::CopyNormalized(Handle<Map> map,
new_instance_size -= map->inobject_properties() * kPointerSize;
}
Handle<Map> result = Map::RawCopy(map, new_instance_size);
Handle<Map> result = RawCopy(map, new_instance_size);
if (mode != CLEAR_INOBJECT_PROPERTIES) {
result->set_inobject_properties(map->inobject_properties());
......@@ -6811,7 +6811,7 @@ Handle<Map> Map::ShareDescriptor(Handle<Map> map,
ASSERT(map->NumberOfOwnDescriptors() ==
map->instance_descriptors()->number_of_descriptors());
Handle<Map> result = Map::CopyDropDescriptors(map);
Handle<Map> result = CopyDropDescriptors(map);
Handle<Name> name = descriptor->GetKey();
Handle<TransitionArray> transitions =
TransitionArray::CopyInsert(map, name, result, SIMPLE_TRANSITION);
......@@ -6822,7 +6822,7 @@ Handle<Map> Map::ShareDescriptor(Handle<Map> map,
if (old_size == 0) {
descriptors = DescriptorArray::Allocate(map->GetIsolate(), 0, 1);
} else {
Map::EnsureDescriptorSlack(map, old_size < 4 ? 1 : old_size / 2);
EnsureDescriptorSlack(map, old_size < 4 ? 1 : old_size / 2);
descriptors = handle(map->instance_descriptors());
}
}
......@@ -6847,7 +6847,7 @@ Handle<Map> Map::CopyReplaceDescriptors(Handle<Map> map,
Handle<DescriptorArray> descriptors,
TransitionFlag flag,
SimpleTransitionFlag simple_flag) {
return Map::CopyReplaceDescriptors(
return CopyReplaceDescriptors(
map, descriptors, flag, Handle<Name>::null(), simple_flag);
}
......@@ -6882,7 +6882,7 @@ Handle<Map> Map::CopyInstallDescriptors(Handle<Map> map,
Handle<DescriptorArray> descriptors) {
ASSERT(descriptors->IsSortedNoDuplicates());
Handle<Map> result = Map::CopyDropDescriptors(map);
Handle<Map> result = CopyDropDescriptors(map);
result->InitializeDescriptors(*descriptors);
result->SetNumberOfOwnDescriptors(new_descriptor + 1);
......@@ -6930,7 +6930,7 @@ Handle<Map> Map::CopyAsElementsKind(Handle<Map> map, ElementsKind kind,
if (insert_transition && map->owns_descriptors()) {
// In case the map owned its own descriptors, share the descriptors and
// transfer ownership to the new map.
Handle<Map> new_map = Map::CopyDropDescriptors(map);
Handle<Map> new_map = CopyDropDescriptors(map);
SetElementsTransitionMap(map, new_map);
......@@ -6944,7 +6944,7 @@ Handle<Map> Map::CopyAsElementsKind(Handle<Map> map, ElementsKind kind,
// In case the map did not own its own descriptors, a split is forced by
// copying the map; creating a new descriptor array cell.
// Create a new free-floating map only if we are not allowed to store it.
Handle<Map> new_map = Map::Copy(map);
Handle<Map> new_map = Copy(map);
new_map->set_elements_kind(kind);
......@@ -6966,9 +6966,9 @@ Handle<Map> Map::CopyForObserved(Handle<Map> map) {
// transfer ownership to the new map.
Handle<Map> new_map;
if (map->owns_descriptors()) {
new_map = Map::CopyDropDescriptors(map);
new_map = CopyDropDescriptors(map);
} else {
new_map = Map::Copy(map);
new_map = Copy(map);
}
Handle<TransitionArray> transitions = TransitionArray::CopyInsert(
......@@ -6993,7 +6993,7 @@ Handle<Map> Map::Copy(Handle<Map> map) {
int number_of_own_descriptors = map->NumberOfOwnDescriptors();
Handle<DescriptorArray> new_descriptors =
DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors);
return Map::CopyReplaceDescriptors(map, new_descriptors, OMIT_TRANSITION);
return CopyReplaceDescriptors(map, new_descriptors, OMIT_TRANSITION);
}
......@@ -7037,14 +7037,14 @@ Handle<Map> Map::CopyAddDescriptor(Handle<Map> map,
if (flag == INSERT_TRANSITION &&
map->owns_descriptors() &&
map->CanHaveMoreTransitions()) {
return Map::ShareDescriptor(map, descriptors, descriptor);
return ShareDescriptor(map, descriptors, descriptor);
}
Handle<DescriptorArray> new_descriptors = DescriptorArray::CopyUpTo(
descriptors, map->NumberOfOwnDescriptors(), 1);
new_descriptors->Append(descriptor);
return Map::CopyReplaceDescriptors(
return CopyReplaceDescriptors(
map, new_descriptors, flag, descriptor->GetKey(), SIMPLE_TRANSITION);
}
......@@ -7060,10 +7060,9 @@ Handle<Map> Map::CopyInsertDescriptor(Handle<Map> map,
// We replace the key if it is already present.
int index = old_descriptors->SearchWithCache(*descriptor->GetKey(), *map);
if (index != DescriptorArray::kNotFound) {
return Map::CopyReplaceDescriptor(
map, old_descriptors, descriptor, index, flag);
return CopyReplaceDescriptor(map, old_descriptors, descriptor, index, flag);
}
return Map::CopyAddDescriptor(map, descriptor, flag);
return CopyAddDescriptor(map, descriptor, flag);
}
......@@ -7139,8 +7138,7 @@ Handle<Map> Map::CopyReplaceDescriptor(Handle<Map> map,
(insertion_index == descriptors->number_of_descriptors() - 1)
? SIMPLE_TRANSITION
: FULL_TRANSITION;
return Map::CopyReplaceDescriptors(
map, new_descriptors, flag, key, simple_flag);
return CopyReplaceDescriptors(map, new_descriptors, flag, key, simple_flag);
}
......@@ -11510,7 +11508,7 @@ Handle<Map> Map::PutPrototypeTransition(Handle<Map> map,
Factory* factory = map->GetIsolate()->factory();
cache = factory->CopySizeFixedArray(cache, transitions * 2 * step + header);
Map::SetPrototypeTransitions(map, cache);
SetPrototypeTransitions(map, cache);
}
// Reload number of transitions as GC might shrink them.
......@@ -11790,6 +11788,18 @@ void DependentCode::AddToDependentICList(Handle<Code> stub) {
}
Handle<Map> Map::TransitionToPrototype(Handle<Map> map,
Handle<Object> prototype) {
Handle<Map> new_map = GetPrototypeTransition(map, prototype);
if (new_map.is_null()) {
new_map = Copy(map);
PutPrototypeTransition(map, prototype, new_map);
new_map->set_prototype(*prototype);
}
return new_map;
}
Handle<Object> JSObject::SetPrototype(Handle<JSObject> object,
Handle<Object> value,
bool skip_hidden_prototypes) {
......@@ -11860,12 +11870,7 @@ Handle<Object> JSObject::SetPrototype(Handle<JSObject> object,
JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(value));
}
Handle<Map> new_map = Map::GetPrototypeTransition(map, value);
if (new_map.is_null()) {
new_map = Map::Copy(map);
Map::PutPrototypeTransition(map, value, new_map);
new_map->set_prototype(*value);
}
Handle<Map> new_map = Map::TransitionToPrototype(map, value);
ASSERT(new_map->prototype() == *value);
JSObject::MigrateToMap(real_receiver, new_map);
......
......@@ -6209,21 +6209,13 @@ class Map: public HeapObject {
inline Map* elements_transition_map();
static Handle<TransitionArray> SetElementsTransitionMap(
Handle<Map> map, Handle<Map> transitioned_map);
inline void SetTransition(int transition_index, Map* target);
inline Map* GetTransition(int transition_index);
inline int SearchTransition(Name* name);
inline FixedArrayBase* GetInitialElements();
DECL_ACCESSORS(transitions, TransitionArray)
inline void ClearTransitions(Heap* heap,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
void DeprecateTransitionTree();
void DeprecateTarget(Name* key, DescriptorArray* new_descriptors);
Map* FindRootMap();
Map* FindUpdatedMap(int verbatim, int length, DescriptorArray* descriptors);
Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
inline int GetInObjectPropertyOffset(int index);
......@@ -6248,15 +6240,6 @@ class Map: public HeapObject {
PropertyAttributes attributes,
const char* reason);
void PrintGeneralization(FILE* file,
const char* reason,
int modify_index,
int split,
int descriptors,
bool constant_to_field,
Representation old_representation,
Representation new_representation);
// Returns the constructor name (the name (possibly, inferred name) of the
// function that was used to instantiate the object).
String* constructor_name();
......@@ -6322,8 +6305,6 @@ class Map: public HeapObject {
// 2 + 2 * i: prototype
// 3 + 2 * i: target map
inline FixedArray* GetPrototypeTransitions();
static inline void SetPrototypeTransitions(
Handle<Map> map, Handle<FixedArray> prototype_transitions);
inline bool HasPrototypeTransitions();
static const int kProtoTransitionHeaderSize = 1;
......@@ -6415,7 +6396,6 @@ class Map: public HeapObject {
// Same as above, but does not touch the prototype chain.
static Handle<Map> CurrentMapForDeprecatedInternal(Handle<Map> map);
static Handle<Map> RawCopy(Handle<Map> map, int instance_size);
static Handle<Map> CopyDropDescriptors(Handle<Map> map);
static Handle<Map> CopyReplaceDescriptors(
Handle<Map> map,
......@@ -6428,25 +6408,17 @@ class Map: public HeapObject {
Handle<DescriptorArray> descriptors,
TransitionFlag flag,
SimpleTransitionFlag simple_flag = FULL_TRANSITION);
static Handle<Map> CopyInstallDescriptors(
Handle<Map> map,
int new_descriptor,
Handle<DescriptorArray> descriptors);
static Handle<Map> ShareDescriptor(Handle<Map> map,
Handle<DescriptorArray> descriptors,
Descriptor* descriptor);
static Handle<Map> CopyAddDescriptor(Handle<Map> map,
Descriptor* descriptor,
TransitionFlag flag);
static Handle<Map> CopyInsertDescriptor(Handle<Map> map,
Descriptor* descriptor,
TransitionFlag flag);
static Handle<Map> CopyReplaceDescriptor(
Handle<Map> map,
Handle<DescriptorArray> descriptors,
Descriptor* descriptor,
int index,
TransitionFlag flag);
static Handle<Map> CopyReplaceDescriptor(Handle<Map> map,
Handle<DescriptorArray> descriptors,
Descriptor* descriptor,
int index,
TransitionFlag flag);
static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind);
......@@ -6522,14 +6494,6 @@ class Map: public HeapObject {
// Computes a hash value for this map, to be used in HashTables and such.
int Hash();
bool EquivalentToForTransition(Map* other);
// Compares this map to another to see if they describe equivalent objects.
// If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
// it had exactly zero inobject properties.
// The "shared" flags of both this map and |other| are ignored.
bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
// Returns the map that this map transitions to if its elements_kind
// is changed to |elements_kind|, or NULL if no such map is cached yet.
// |safe_to_add_transitions| is set to false if adding transitions is not
......@@ -6542,15 +6506,6 @@ class Map: public HeapObject {
Handle<Map> FindTransitionedMap(MapHandleList* candidates);
Map* FindTransitionedMap(MapList* candidates);
// Zaps the contents of backing data structures. Note that the
// heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
// holding weak references when incremental marking is used, because it also
// iterates over objects that are otherwise unreachable.
// In general we only want to call these functions in release mode when
// heap verification is turned on.
void ZapPrototypeTransitions();
void ZapTransitions();
bool CanTransition() {
// Only JSObject and subtypes have map transitions and back pointers.
STATIC_ASSERT(LAST_TYPE == LAST_JS_OBJECT_TYPE);
......@@ -6611,11 +6566,8 @@ class Map: public HeapObject {
// transitions are in the form of a map where the keys are prototype objects
// and the values are the maps the are transitioned to.
static const int kMaxCachedPrototypeTransitions = 256;
static Handle<Map> GetPrototypeTransition(Handle<Map> map,
Handle<Object> prototype);
static Handle<Map> PutPrototypeTransition(Handle<Map> map,
Handle<Object> prototype,
Handle<Map> target_map);
static Handle<Map> TransitionToPrototype(Handle<Map> map,
Handle<Object> prototype);
static const int kMaxPreAllocatedPropertyFields = 255;
......@@ -6699,7 +6651,57 @@ class Map: public HeapObject {
kPointerFieldsEndOffset,
kSize> BodyDescriptor;
// Compares this map to another to see if they describe equivalent objects.
// If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
// it had exactly zero inobject properties.
// The "shared" flags of both this map and |other| are ignored.
bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
private:
bool EquivalentToForTransition(Map* other);
static Handle<Map> RawCopy(Handle<Map> map, int instance_size);
static Handle<Map> ShareDescriptor(Handle<Map> map,
Handle<DescriptorArray> descriptors,
Descriptor* descriptor);
static Handle<Map> CopyInstallDescriptors(
Handle<Map> map,
int new_descriptor,
Handle<DescriptorArray> descriptors);
// Zaps the contents of backing data structures. Note that the
// heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
// holding weak references when incremental marking is used, because it also
// iterates over objects that are otherwise unreachable.
// In general we only want to call these functions in release mode when
// heap verification is turned on.
void ZapPrototypeTransitions();
void ZapTransitions();
void DeprecateTransitionTree();
void DeprecateTarget(Name* key, DescriptorArray* new_descriptors);
Map* FindUpdatedMap(int verbatim, int length, DescriptorArray* descriptors);
Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
void PrintGeneralization(FILE* file,
const char* reason,
int modify_index,
int split,
int descriptors,
bool constant_to_field,
Representation old_representation,
Representation new_representation);
static inline void SetPrototypeTransitions(
Handle<Map> map,
Handle<FixedArray> prototype_transitions);
static Handle<Map> GetPrototypeTransition(Handle<Map> map,
Handle<Object> prototype);
static Handle<Map> PutPrototypeTransition(Handle<Map> map,
Handle<Object> prototype,
Handle<Map> target_map);
DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
};
......
......@@ -2072,10 +2072,6 @@ TEST(PrototypeTransitionClearing) {
CHECK(!space->LastPage()->Contains(
map->GetPrototypeTransitions()->address()));
CHECK(space->LastPage()->Contains(prototype->address()));
JSObject::SetPrototype(baseObject, prototype, false);
CHECK(Map::GetPrototypeTransition(map, prototype)->IsMap());
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK(Map::GetPrototypeTransition(map, prototype)->IsMap());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment