@@ -2726,10 +2726,23 @@ void Map::UpdateFieldType(int descriptor, Handle<Name> name,
27262726}
27272727
27282728
2729+ bool FieldTypeIsCleared(Representation rep, Handle<HeapType> type) {
2730+ return type->Is(HeapType::None()) && rep.IsHeapObject();
2731+ }
2732+
2733+
27292734// static
2730- Handle<HeapType> Map::GeneralizeFieldType(Handle<HeapType> type1,
2735+ Handle<HeapType> Map::GeneralizeFieldType(Representation rep1,
2736+ Handle<HeapType> type1,
2737+ Representation rep2,
27312738 Handle<HeapType> type2,
27322739 Isolate* isolate) {
2740+ // Cleared field types need special treatment. They represent lost knowledge,
2741+ // so we must be conservative, so their generalization with any other type
2742+ // is "Any".
2743+ if (FieldTypeIsCleared(rep1, type1) || FieldTypeIsCleared(rep2, type2)) {
2744+ return HeapType::Any(isolate);
2745+ }
27332746 if (type1->NowIs(type2)) return type2;
27342747 if (type2->NowIs(type1)) return type1;
27352748 return HeapType::Any(isolate);
@@ -2750,10 +2763,13 @@ void Map::GeneralizeFieldType(Handle<Map> map, int modify_index,
27502763 isolate);
27512764
27522765 if (old_representation.Equals(new_representation) &&
2766+ !FieldTypeIsCleared(new_representation, new_field_type) &&
2767+ // Checking old_field_type for being cleared is not necessary because
2768+ // the NowIs check below would fail anyway in that case.
27532769 new_field_type->NowIs(old_field_type)) {
2754- DCHECK(Map::GeneralizeFieldType(old_field_type,
2755- new_field_type,
2756- isolate) ->NowIs(old_field_type));
2770+ DCHECK(Map::GeneralizeFieldType(old_representation, old_field_type,
2771+ new_representation, new_field_type, isolate)
2772+ ->NowIs(old_field_type));
27572773 return;
27582774 }
27592775
@@ -2762,17 +2778,10 @@ void Map::GeneralizeFieldType(Handle<Map> map, int modify_index,
27622778 Handle<DescriptorArray> descriptors(
27632779 field_owner->instance_descriptors(), isolate);
27642780 DCHECK_EQ(*old_field_type, descriptors->GetFieldType(modify_index));
2765- bool old_field_type_was_cleared =
2766- old_field_type->Is(HeapType::None()) && old_representation.IsHeapObject();
27672781
2768- // Determine the generalized new field type. Conservatively assume type Any
2769- // for cleared field types because the cleared type could have been a
2770- // deprecated map and there still could be live instances with a non-
2771- // deprecated version of the map.
27722782 new_field_type =
2773- old_field_type_was_cleared
2774- ? HeapType::Any(isolate)
2775- : Map::GeneralizeFieldType(old_field_type, new_field_type, isolate);
2783+ Map::GeneralizeFieldType(old_representation, old_field_type,
2784+ new_representation, new_field_type, isolate);
27762785
27772786 PropertyDetails details = descriptors->GetDetails(modify_index);
27782787 Handle<Name> name(descriptors->GetKey(modify_index));
@@ -2996,8 +3005,10 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
29963005 Handle<HeapType> old_field_type =
29973006 GetFieldType(isolate, old_descriptors, i,
29983007 old_details.location(), tmp_representation);
2999- next_field_type =
3000- GeneralizeFieldType(next_field_type, old_field_type, isolate);
3008+ Representation old_representation = old_details.representation();
3009+ next_field_type = GeneralizeFieldType(
3010+ old_representation, old_field_type, new_representation,
3011+ next_field_type, isolate);
30013012 }
30023013 } else {
30033014 Handle<HeapType> old_field_type =
@@ -3161,21 +3172,24 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
31613172
31623173 Handle<HeapType> next_field_type;
31633174 if (modify_index == i) {
3164- next_field_type =
3165- GeneralizeFieldType(target_field_type, new_field_type, isolate);
3175+ next_field_type = GeneralizeFieldType(
3176+ target_details.representation(), target_field_type,
3177+ new_representation, new_field_type, isolate);
31663178 if (!property_kind_reconfiguration) {
31673179 Handle<HeapType> old_field_type =
31683180 GetFieldType(isolate, old_descriptors, i,
31693181 old_details.location(), next_representation);
3170- next_field_type =
3171- GeneralizeFieldType(next_field_type, old_field_type, isolate);
3182+ next_field_type = GeneralizeFieldType(
3183+ old_details.representation(), old_field_type,
3184+ next_representation, next_field_type, isolate);
31723185 }
31733186 } else {
31743187 Handle<HeapType> old_field_type =
31753188 GetFieldType(isolate, old_descriptors, i, old_details.location(),
31763189 next_representation);
3177- next_field_type =
3178- GeneralizeFieldType(target_field_type, old_field_type, isolate);
3190+ next_field_type = GeneralizeFieldType(
3191+ old_details.representation(), old_field_type, next_representation,
3192+ target_field_type, isolate);
31793193 }
31803194 Handle<Object> wrapped_type(WrapType(next_field_type));
31813195 DataDescriptor d(target_key, current_offset, wrapped_type,
@@ -3236,8 +3250,9 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
32363250 Handle<HeapType> old_field_type =
32373251 GetFieldType(isolate, old_descriptors, i,
32383252 old_details.location(), next_representation);
3239- next_field_type =
3240- GeneralizeFieldType(next_field_type, old_field_type, isolate);
3253+ next_field_type = GeneralizeFieldType(
3254+ old_details.representation(), old_field_type,
3255+ next_representation, next_field_type, isolate);
32413256 }
32423257 } else {
32433258 Handle<HeapType> old_field_type =
@@ -3798,6 +3813,11 @@ MaybeHandle<Object> Object::SetDataProperty(LookupIterator* it,
37983813 Object);
37993814 }
38003815
3816+ #if VERIFY_HEAP
3817+ if (FLAG_verify_heap) {
3818+ receiver->JSObjectVerify();
3819+ }
3820+ #endif
38013821 return value;
38023822}
38033823
@@ -3920,6 +3940,11 @@ MaybeHandle<Object> Object::AddDataProperty(LookupIterator* it,
39203940 it->factory()->the_hole_value()),
39213941 Object);
39223942 }
3943+ #if VERIFY_HEAP
3944+ if (FLAG_verify_heap) {
3945+ receiver->JSObjectVerify();
3946+ }
3947+ #endif
39233948 }
39243949
39253950 return value;
@@ -4572,6 +4597,11 @@ void JSObject::MigrateInstance(Handle<JSObject> object) {
45724597 if (FLAG_trace_migration) {
45734598 object->PrintInstanceMigration(stdout, *original_map, *map);
45744599 }
4600+ #if VERIFY_HEAP
4601+ if (FLAG_verify_heap) {
4602+ object->JSObjectVerify();
4603+ }
4604+ #endif
45754605}
45764606
45774607
@@ -4588,6 +4618,11 @@ bool JSObject::TryMigrateInstance(Handle<JSObject> object) {
45884618 if (FLAG_trace_migration) {
45894619 object->PrintInstanceMigration(stdout, *original_map, object->map());
45904620 }
4621+ #if VERIFY_HEAP
4622+ if (FLAG_verify_heap) {
4623+ object->JSObjectVerify();
4624+ }
4625+ #endif
45914626 return true;
45924627}
45934628
@@ -4696,7 +4731,6 @@ MaybeHandle<Object> JSObject::DefineOwnPropertyIgnoreAttributes(
46964731 it->TransitionToAccessorPair(new_data, attributes);
46974732 } else {
46984733 it->ReconfigureDataProperty(value, attributes);
4699- it->WriteDataValue(value);
47004734 }
47014735
47024736 if (is_observed) {
@@ -4732,7 +4766,6 @@ MaybeHandle<Object> JSObject::DefineOwnPropertyIgnoreAttributes(
47324766 if (is_observed) old_value = it->GetDataValue();
47334767
47344768 it->ReconfigureDataProperty(value, attributes);
4735- it->WriteDataValue(value);
47364769
47374770 if (is_observed) {
47384771 if (old_value->SameValue(*value)) {
0 commit comments