OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 | 51 |
52 namespace v8 { | 52 namespace v8 { |
53 namespace internal { | 53 namespace internal { |
54 | 54 |
55 PropertyDetails::PropertyDetails(Smi* smi) { | 55 PropertyDetails::PropertyDetails(Smi* smi) { |
56 value_ = smi->value(); | 56 value_ = smi->value(); |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 Smi* PropertyDetails::AsSmi() { | 60 Smi* PropertyDetails::AsSmi() { |
61 return Smi::FromInt(value_); | 61 int value = value_ << 1; |
danno
2013/04/24 15:23:00
Comment why this is needed?
Toon Verwaest
2013/04/25 10:59:38
Done.
| |
62 return Smi::FromInt(value >> 1); | |
62 } | 63 } |
63 | 64 |
64 | 65 |
65 PropertyDetails PropertyDetails::AsDeleted() { | 66 PropertyDetails PropertyDetails::AsDeleted() { |
66 Smi* smi = Smi::FromInt(value_ | DeletedField::encode(1)); | 67 Smi* smi = Smi::FromInt(value_ | DeletedField::encode(1)); |
67 return PropertyDetails(smi); | 68 return PropertyDetails(smi); |
68 } | 69 } |
69 | 70 |
70 | 71 |
71 #define TYPE_CHECKER(type, instancetype) \ | 72 #define TYPE_CHECKER(type, instancetype) \ |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1468 MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(), elements_kind); | 1469 MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(), elements_kind); |
1469 Map* map; | 1470 Map* map; |
1470 if (!maybe->To(&map)) return maybe; | 1471 if (!maybe->To(&map)) return maybe; |
1471 set_map(map); | 1472 set_map(map); |
1472 initialize_elements(); | 1473 initialize_elements(); |
1473 | 1474 |
1474 return this; | 1475 return this; |
1475 } | 1476 } |
1476 | 1477 |
1477 | 1478 |
1478 MaybeObject* JSObject::AddFastPropertyUsingMap(Map* map) { | |
1479 ASSERT(this->map()->NumberOfOwnDescriptors() + 1 == | |
1480 map->NumberOfOwnDescriptors()); | |
1481 if (this->map()->unused_property_fields() == 0) { | |
1482 int new_size = properties()->length() + map->unused_property_fields() + 1; | |
1483 FixedArray* new_properties; | |
1484 MaybeObject* maybe_properties = properties()->CopySize(new_size); | |
1485 if (!maybe_properties->To(&new_properties)) return maybe_properties; | |
1486 set_properties(new_properties); | |
1487 } | |
1488 set_map(map); | |
1489 return this; | |
1490 } | |
1491 | |
1492 | |
1493 MaybeObject* JSObject::TransitionToMap(Map* map) { | 1479 MaybeObject* JSObject::TransitionToMap(Map* map) { |
1494 ASSERT(this->map()->inobject_properties() == map->inobject_properties()); | 1480 ASSERT(this->map()->inobject_properties() == map->inobject_properties()); |
1495 ElementsKind expected_kind = this->map()->elements_kind(); | 1481 ElementsKind expected_kind = this->map()->elements_kind(); |
1496 if (map->elements_kind() != expected_kind) { | 1482 if (map->elements_kind() != expected_kind) { |
1497 MaybeObject* maybe_map = map->AsElementsKind(expected_kind); | 1483 MaybeObject* maybe_map = map->AsElementsKind(expected_kind); |
1498 if (!maybe_map->To(&map)) return maybe_map; | 1484 if (!maybe_map->To(&map)) return maybe_map; |
1499 } | 1485 } |
1500 int total_size = | 1486 int total_size = |
1501 map->NumberOfOwnDescriptors() + map->unused_property_fields(); | 1487 map->NumberOfOwnDescriptors() + map->unused_property_fields(); |
1502 int out_of_object = total_size - map->inobject_properties(); | 1488 int out_of_object = total_size - map->inobject_properties(); |
1503 if (out_of_object != properties()->length()) { | 1489 if (out_of_object != properties()->length()) { |
1504 FixedArray* new_properties; | 1490 FixedArray* new_properties; |
1505 MaybeObject* maybe_properties = properties()->CopySize(out_of_object); | 1491 MaybeObject* maybe_properties = properties()->CopySize(out_of_object); |
1506 if (!maybe_properties->To(&new_properties)) return maybe_properties; | 1492 if (!maybe_properties->To(&new_properties)) return maybe_properties; |
1507 set_properties(new_properties); | 1493 set_properties(new_properties); |
1508 } | 1494 } |
1509 set_map(map); | 1495 set_map(map); |
1510 return this; | 1496 return this; |
1511 } | 1497 } |
1512 | 1498 |
1513 | 1499 |
1500 MaybeObject* JSObject::MigrateInstance() { | |
1501 // Converting any field to the most specific type will cause the | |
1502 // GeneralizeFieldRepresentation algorithm to create the most general existing | |
1503 // transition that matches the object. This achieves what is needed. | |
1504 return GeneralizeFieldRepresentation(0, Representation::Smi()); | |
1505 } | |
1506 | |
1507 | |
1514 Handle<String> JSObject::ExpectedTransitionKey(Handle<Map> map) { | 1508 Handle<String> JSObject::ExpectedTransitionKey(Handle<Map> map) { |
1515 AssertNoAllocation no_gc; | 1509 AssertNoAllocation no_gc; |
1516 if (!map->HasTransitionArray()) return Handle<String>::null(); | 1510 if (!map->HasTransitionArray()) return Handle<String>::null(); |
1517 TransitionArray* transitions = map->transitions(); | 1511 TransitionArray* transitions = map->transitions(); |
1518 if (!transitions->IsSimpleTransition()) return Handle<String>::null(); | 1512 if (!transitions->IsSimpleTransition()) return Handle<String>::null(); |
1519 int transition = TransitionArray::kSimpleTransitionIndex; | 1513 int transition = TransitionArray::kSimpleTransitionIndex; |
1520 PropertyDetails details = transitions->GetTargetDetails(transition); | 1514 PropertyDetails details = transitions->GetTargetDetails(transition); |
1521 Name* name = transitions->GetKey(transition); | 1515 Name* name = transitions->GetKey(transition); |
1522 if (details.type() != FIELD) return Handle<String>::null(); | 1516 if (details.type() != FIELD) return Handle<String>::null(); |
1523 if (details.attributes() != NONE) return Handle<String>::null(); | 1517 if (details.attributes() != NONE) return Handle<String>::null(); |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2232 return GetKey(GetSortedKeyIndex(descriptor_number)); | 2226 return GetKey(GetSortedKeyIndex(descriptor_number)); |
2233 } | 2227 } |
2234 | 2228 |
2235 | 2229 |
2236 void DescriptorArray::SetSortedKey(int descriptor_index, int pointer) { | 2230 void DescriptorArray::SetSortedKey(int descriptor_index, int pointer) { |
2237 PropertyDetails details = GetDetails(descriptor_index); | 2231 PropertyDetails details = GetDetails(descriptor_index); |
2238 set(ToDetailsIndex(descriptor_index), details.set_pointer(pointer).AsSmi()); | 2232 set(ToDetailsIndex(descriptor_index), details.set_pointer(pointer).AsSmi()); |
2239 } | 2233 } |
2240 | 2234 |
2241 | 2235 |
2236 void DescriptorArray::SetRepresentation(int descriptor_index, | |
2237 Representation representation) { | |
2238 ASSERT(!representation.IsNone()); | |
2239 PropertyDetails details = GetDetails(descriptor_index); | |
2240 set(ToDetailsIndex(descriptor_index), | |
2241 details.set_representation(representation).AsSmi()); | |
2242 } | |
2243 | |
2244 | |
2245 void DescriptorArray::InitializeRepresentations(Representation representation) { | |
2246 int length = number_of_descriptors(); | |
2247 for (int i = 0; i < length; i++) { | |
2248 PropertyDetails details = GetDetails(i); | |
2249 set(ToDetailsIndex(i), details.set_representation(representation).AsSmi()); | |
2250 } | |
2251 } | |
2252 | |
2253 | |
2242 Object** DescriptorArray::GetValueSlot(int descriptor_number) { | 2254 Object** DescriptorArray::GetValueSlot(int descriptor_number) { |
2243 ASSERT(descriptor_number < number_of_descriptors()); | 2255 ASSERT(descriptor_number < number_of_descriptors()); |
2244 return HeapObject::RawField( | 2256 return HeapObject::RawField( |
2245 reinterpret_cast<HeapObject*>(this), | 2257 reinterpret_cast<HeapObject*>(this), |
2246 OffsetOfElementAt(ToValueIndex(descriptor_number))); | 2258 OffsetOfElementAt(ToValueIndex(descriptor_number))); |
2247 } | 2259 } |
2248 | 2260 |
2249 | 2261 |
2250 Object* DescriptorArray::GetValue(int descriptor_number) { | 2262 Object* DescriptorArray::GetValue(int descriptor_number) { |
2251 ASSERT(descriptor_number < number_of_descriptors()); | 2263 ASSERT(descriptor_number < number_of_descriptors()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2297 | 2309 |
2298 void DescriptorArray::Set(int descriptor_number, | 2310 void DescriptorArray::Set(int descriptor_number, |
2299 Descriptor* desc, | 2311 Descriptor* desc, |
2300 const WhitenessWitness&) { | 2312 const WhitenessWitness&) { |
2301 // Range check. | 2313 // Range check. |
2302 ASSERT(descriptor_number < number_of_descriptors()); | 2314 ASSERT(descriptor_number < number_of_descriptors()); |
2303 ASSERT(desc->GetDetails().descriptor_index() <= | 2315 ASSERT(desc->GetDetails().descriptor_index() <= |
2304 number_of_descriptors()); | 2316 number_of_descriptors()); |
2305 ASSERT(desc->GetDetails().descriptor_index() > 0); | 2317 ASSERT(desc->GetDetails().descriptor_index() > 0); |
2306 | 2318 |
2319 ASSERT(!desc->GetDetails().representation().IsNone()); | |
2307 NoIncrementalWriteBarrierSet(this, | 2320 NoIncrementalWriteBarrierSet(this, |
2308 ToKeyIndex(descriptor_number), | 2321 ToKeyIndex(descriptor_number), |
2309 desc->GetKey()); | 2322 desc->GetKey()); |
2310 NoIncrementalWriteBarrierSet(this, | 2323 NoIncrementalWriteBarrierSet(this, |
2311 ToValueIndex(descriptor_number), | 2324 ToValueIndex(descriptor_number), |
2312 desc->GetValue()); | 2325 desc->GetValue()); |
2313 NoIncrementalWriteBarrierSet(this, | 2326 NoIncrementalWriteBarrierSet(this, |
2314 ToDetailsIndex(descriptor_number), | 2327 ToDetailsIndex(descriptor_number), |
2315 desc->GetDetails().AsSmi()); | 2328 desc->GetDetails().AsSmi()); |
2316 } | 2329 } |
2317 | 2330 |
2318 | 2331 |
2319 void DescriptorArray::Set(int descriptor_number, Descriptor* desc) { | 2332 void DescriptorArray::Set(int descriptor_number, Descriptor* desc) { |
2320 // Range check. | 2333 // Range check. |
2321 ASSERT(descriptor_number < number_of_descriptors()); | 2334 ASSERT(descriptor_number < number_of_descriptors()); |
2322 ASSERT(desc->GetDetails().descriptor_index() <= | 2335 ASSERT(desc->GetDetails().descriptor_index() <= |
2323 number_of_descriptors()); | 2336 number_of_descriptors()); |
2324 ASSERT(desc->GetDetails().descriptor_index() > 0); | 2337 ASSERT(desc->GetDetails().descriptor_index() > 0); |
2338 ASSERT(!desc->GetDetails().representation().IsNone()); | |
2325 | 2339 |
2326 set(ToKeyIndex(descriptor_number), desc->GetKey()); | 2340 set(ToKeyIndex(descriptor_number), desc->GetKey()); |
2327 set(ToValueIndex(descriptor_number), desc->GetValue()); | 2341 set(ToValueIndex(descriptor_number), desc->GetValue()); |
2328 set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi()); | 2342 set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi()); |
2329 } | 2343 } |
2330 | 2344 |
2331 | 2345 |
2332 void DescriptorArray::Append(Descriptor* desc, | 2346 void DescriptorArray::Append(Descriptor* desc, |
2333 const WhitenessWitness& witness) { | 2347 const WhitenessWitness& witness) { |
2334 int descriptor_number = number_of_descriptors(); | 2348 int descriptor_number = number_of_descriptors(); |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3528 has_slow_elements_kind() || has_external_array_elements()); | 3542 has_slow_elements_kind() || has_external_array_elements()); |
3529 set_bit_field3(IsObserved::update(bit_field3(), is_observed)); | 3543 set_bit_field3(IsObserved::update(bit_field3(), is_observed)); |
3530 } | 3544 } |
3531 | 3545 |
3532 | 3546 |
3533 bool Map::is_observed() { | 3547 bool Map::is_observed() { |
3534 return IsObserved::decode(bit_field3()); | 3548 return IsObserved::decode(bit_field3()); |
3535 } | 3549 } |
3536 | 3550 |
3537 | 3551 |
3552 void Map::invalidate_transition() { | |
3553 set_bit_field3(InvalidTransition::update(bit_field3(), true)); | |
3554 } | |
3555 | |
3556 | |
3557 bool Map::is_invalid_transition() { | |
3558 if (!FLAG_track_fields) return false; | |
3559 return InvalidTransition::decode(bit_field3()); | |
3560 } | |
3561 | |
3562 | |
3563 bool Map::CanTransitionBeInvalidated() { | |
danno
2013/04/24 15:23:00
CanBeDeprecated
Toon Verwaest
2013/04/25 10:59:38
Done.
| |
3564 if (!FLAG_track_fields) return false; | |
3565 int descriptor = LastAdded(); | |
3566 for (int i = 0; i <= descriptor; i++) { | |
3567 PropertyDetails details = instance_descriptors()->GetDetails(i); | |
3568 if (!details.representation().IsTagged()) return true; | |
3569 } | |
3570 return false; | |
3571 } | |
3572 | |
3573 | |
3538 void Map::NotifyLeafMapLayoutChange() { | 3574 void Map::NotifyLeafMapLayoutChange() { |
3539 dependent_code()->DeoptimizeDependentCodeGroup( | 3575 dependent_code()->DeoptimizeDependentCodeGroup( |
3540 GetIsolate(), | 3576 GetIsolate(), |
3541 DependentCode::kPrototypeCheckGroup); | 3577 DependentCode::kPrototypeCheckGroup); |
3542 } | 3578 } |
3543 | 3579 |
3544 | 3580 |
3545 bool Map::CanOmitPrototypeChecks() { | 3581 bool Map::CanOmitPrototypeChecks() { |
3546 return !HasTransitionArray() && !is_dictionary_map() && | 3582 return !HasTransitionArray() && !is_dictionary_map() && |
3547 FLAG_omit_prototype_checks_for_leaf_maps; | 3583 FLAG_omit_prototype_checks_for_leaf_maps; |
(...skipping 2571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6119 #undef WRITE_UINT32_FIELD | 6155 #undef WRITE_UINT32_FIELD |
6120 #undef READ_SHORT_FIELD | 6156 #undef READ_SHORT_FIELD |
6121 #undef WRITE_SHORT_FIELD | 6157 #undef WRITE_SHORT_FIELD |
6122 #undef READ_BYTE_FIELD | 6158 #undef READ_BYTE_FIELD |
6123 #undef WRITE_BYTE_FIELD | 6159 #undef WRITE_BYTE_FIELD |
6124 | 6160 |
6125 | 6161 |
6126 } } // namespace v8::internal | 6162 } } // namespace v8::internal |
6127 | 6163 |
6128 #endif // V8_OBJECTS_INL_H_ | 6164 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |