Set LastAdded to kNoneAdded in RawCopy.

This ensures it is properly initialized if no descriptors are later set.

Review URL: https://chromiumcodereview.appspot.com/10833033

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12202 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
verwaest@chromium.org 2012-07-26 13:48:34 +00:00
parent 80c35c6522
commit 1c7aa4d172
3 changed files with 25 additions and 33 deletions

View File

@ -4125,13 +4125,11 @@ MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) {
int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512; int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512;
// Allocate a dictionary object for backing storage. // Allocate a dictionary object for backing storage.
Object* obj; StringDictionary* dictionary;
{ MaybeObject* maybe_obj = MaybeObject* maybe_dictionary =
StringDictionary::Allocate( StringDictionary::Allocate(
map->NumberOfDescribedProperties() * 2 + initial_size); map->NumberOfDescribedProperties() * 2 + initial_size);
if (!maybe_obj->ToObject(&obj)) return maybe_obj; if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
}
StringDictionary* dictionary = StringDictionary::cast(obj);
// The global object might be created from an object template with accessors. // The global object might be created from an object template with accessors.
// Fill these accessors into the dictionary. // Fill these accessors into the dictionary.
@ -4142,29 +4140,26 @@ MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) {
PropertyDetails d = PropertyDetails d =
PropertyDetails(details.attributes(), CALLBACKS, details.index()); PropertyDetails(details.attributes(), CALLBACKS, details.index());
Object* value = descs->GetCallbacksObject(i); Object* value = descs->GetCallbacksObject(i);
{ MaybeObject* maybe_value = AllocateJSGlobalPropertyCell(value); MaybeObject* maybe_value = AllocateJSGlobalPropertyCell(value);
if (!maybe_value->ToObject(&value)) return maybe_value; if (!maybe_value->ToObject(&value)) return maybe_value;
}
Object* result; MaybeObject* maybe_added = dictionary->Add(descs->GetKey(i), value, d);
{ MaybeObject* maybe_result = dictionary->Add(descs->GetKey(i), value, d); if (!maybe_added->To(&dictionary)) return maybe_added;
if (!maybe_result->ToObject(&result)) return maybe_result;
}
dictionary = StringDictionary::cast(result);
} }
// Allocate the global object and initialize it with the backing store. // Allocate the global object and initialize it with the backing store.
{ MaybeObject* maybe_obj = Allocate(map, OLD_POINTER_SPACE); JSObject* global;
if (!maybe_obj->ToObject(&obj)) return maybe_obj; MaybeObject* maybe_global = Allocate(map, OLD_POINTER_SPACE);
} if (!maybe_global->To(&global)) return maybe_global;
JSObject* global = JSObject::cast(obj);
InitializeJSObjectFromMap(global, dictionary, map); InitializeJSObjectFromMap(global, dictionary, map);
// Create a new map for the global object. // Create a new map for the global object.
Map* new_map; Map* new_map;
{ MaybeObject* maybe_map = map->CopyDropDescriptors(); MaybeObject* maybe_map = map->CopyDropDescriptors();
if (!maybe_map->To(&new_map)) return maybe_map; if (!maybe_map->To(&new_map)) return maybe_map;
}
ASSERT(new_map->LastAdded() == Map::kNoneAdded);
// Set up the global object as a normalized object. // Set up the global object as a normalized object.
global->set_map(new_map); global->set_map(new_map);

View File

@ -3523,7 +3523,7 @@ void Map::InitializeDescriptors(DescriptorArray* descriptors) {
} }
} }
ASSERT(len == 0 || ASSERT((len == 0 && LastAdded() == kNoneAdded) ||
len == descriptors->GetDetails(LastAdded()).index()); len == descriptors->GetDetails(LastAdded()).index());
} }

View File

@ -4805,16 +4805,16 @@ Object* JSObject::SlowReverseLookup(Object* value) {
MaybeObject* Map::RawCopy(int instance_size) { MaybeObject* Map::RawCopy(int instance_size) {
Map* result; Map* result;
{ MaybeObject* maybe_result = MaybeObject* maybe_result =
GetHeap()->AllocateMap(instance_type(), instance_size); GetHeap()->AllocateMap(instance_type(), instance_size);
if (!maybe_result->To(&result)) return maybe_result; if (!maybe_result->To(&result)) return maybe_result;
}
result->set_prototype(prototype()); result->set_prototype(prototype());
result->set_constructor(constructor()); result->set_constructor(constructor());
result->set_bit_field(bit_field()); result->set_bit_field(bit_field());
result->set_bit_field2(bit_field2()); result->set_bit_field2(bit_field2());
result->set_bit_field3(bit_field3()); result->set_bit_field3(bit_field3());
result->SetLastAdded(kNoneAdded);
return result; return result;
} }
@ -4834,12 +4834,11 @@ MaybeObject* Map::CopyNormalized(PropertyNormalizationMode mode,
result->set_inobject_properties(inobject_properties()); result->set_inobject_properties(inobject_properties());
} }
result->SetLastAdded(kNoneAdded);
result->set_code_cache(code_cache()); result->set_code_cache(code_cache());
result->set_is_shared(sharing == SHARED_NORMALIZED_MAP); result->set_is_shared(sharing == SHARED_NORMALIZED_MAP);
#ifdef DEBUG #ifdef DEBUG
if (FLAG_verify_heap && Map::cast(result)->is_shared()) { if (FLAG_verify_heap && result->is_shared()) {
result->SharedMapVerify(); result->SharedMapVerify();
} }
#endif #endif
@ -4938,9 +4937,7 @@ MaybeObject* Map::CopyWithPreallocatedFieldDescriptors() {
initial_descriptors->Copy(DescriptorArray::MAY_BE_SHARED); initial_descriptors->Copy(DescriptorArray::MAY_BE_SHARED);
if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors; if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors;
int last_added = initial_descriptors->IsEmpty() int last_added = initial_map->LastAdded();
? kNoneAdded
: initial_map->LastAdded();
return CopyReplaceDescriptors(descriptors, NULL, last_added, OMIT_TRANSITION); return CopyReplaceDescriptors(descriptors, NULL, last_added, OMIT_TRANSITION);
} }
@ -4952,7 +4949,7 @@ MaybeObject* Map::Copy(DescriptorArray::SharedMode shared_mode) {
MaybeObject* maybe_descriptors = source_descriptors->Copy(shared_mode); MaybeObject* maybe_descriptors = source_descriptors->Copy(shared_mode);
if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors; if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors;
int last_added = source_descriptors->IsEmpty() ? kNoneAdded : LastAdded(); int last_added = LastAdded();
return CopyReplaceDescriptors(descriptors, NULL, last_added, OMIT_TRANSITION); return CopyReplaceDescriptors(descriptors, NULL, last_added, OMIT_TRANSITION);
} }