Chromium Code Reviews

Side by Side Diff: src/objects-inl.h

Issue 14146005: Track representations of fields (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make double support consistent. Now DOUBLE always contains smi or heapnumber Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
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...)
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;
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...)
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 // GeneralizeFieldStorage algorithm to create the most general existing
1503 // transition that matches the object. This achieves what is needed.
1504 return GeneralizeFieldStorage(0, 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...)
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::SetStorageType(int descriptor_index, StorageType type) {
2237 PropertyDetails details = GetDetails(descriptor_index);
2238 set(ToDetailsIndex(descriptor_index), details.set_storage_type(type).AsSmi());
2239 }
2240
2241
2242 void DescriptorArray::InitializeStorageTypes(StorageType storage_type) {
2243 int length = number_of_descriptors();
2244 for (int i = 0; i < length; i++) {
2245 PropertyDetails details = GetDetails(i);
2246 set(ToDetailsIndex(i), details.set_storage_type(storage_type).AsSmi());
2247 }
2248 }
2249
2250
2242 Object** DescriptorArray::GetValueSlot(int descriptor_number) { 2251 Object** DescriptorArray::GetValueSlot(int descriptor_number) {
2243 ASSERT(descriptor_number < number_of_descriptors()); 2252 ASSERT(descriptor_number < number_of_descriptors());
2244 return HeapObject::RawField( 2253 return HeapObject::RawField(
2245 reinterpret_cast<HeapObject*>(this), 2254 reinterpret_cast<HeapObject*>(this),
2246 OffsetOfElementAt(ToValueIndex(descriptor_number))); 2255 OffsetOfElementAt(ToValueIndex(descriptor_number)));
2247 } 2256 }
2248 2257
2249 2258
2250 Object* DescriptorArray::GetValue(int descriptor_number) { 2259 Object* DescriptorArray::GetValue(int descriptor_number) {
2251 ASSERT(descriptor_number < number_of_descriptors()); 2260 ASSERT(descriptor_number < number_of_descriptors());
(...skipping 1276 matching lines...)
3528 has_slow_elements_kind() || has_external_array_elements()); 3537 has_slow_elements_kind() || has_external_array_elements());
3529 set_bit_field3(IsObserved::update(bit_field3(), is_observed)); 3538 set_bit_field3(IsObserved::update(bit_field3(), is_observed));
3530 } 3539 }
3531 3540
3532 3541
3533 bool Map::is_observed() { 3542 bool Map::is_observed() {
3534 return IsObserved::decode(bit_field3()); 3543 return IsObserved::decode(bit_field3());
3535 } 3544 }
3536 3545
3537 3546
3547 void Map::invalidate_transition() {
3548 set_bit_field3(InvalidTransition::update(bit_field3(), true));
3549 }
3550
3551
3552 bool Map::is_invalid_transition() {
3553 if (!FLAG_track_fields) return false;
3554 return InvalidTransition::decode(bit_field3());
3555 }
3556
3557
3558 bool Map::CanTransitionBeInvalidated() {
3559 if (!FLAG_track_fields) return false;
3560 int descriptor = LastAdded();
3561 for (int i = 0; i <= descriptor; i++) {
3562 PropertyDetails details = instance_descriptors()->GetDetails(i);
3563 if (details.storage_type() != TAGGED) return true;
3564 }
3565 return false;
3566 }
3567
3568
3538 void Map::NotifyLeafMapLayoutChange() { 3569 void Map::NotifyLeafMapLayoutChange() {
3539 dependent_code()->DeoptimizeDependentCodeGroup( 3570 dependent_code()->DeoptimizeDependentCodeGroup(
3540 GetIsolate(), 3571 GetIsolate(),
3541 DependentCode::kPrototypeCheckGroup); 3572 DependentCode::kPrototypeCheckGroup);
3542 } 3573 }
3543 3574
3544 3575
3545 bool Map::CanOmitPrototypeChecks() { 3576 bool Map::CanOmitPrototypeChecks() {
3546 return !HasTransitionArray() && !is_dictionary_map() && 3577 return !HasTransitionArray() && !is_dictionary_map() &&
3547 FLAG_omit_prototype_checks_for_leaf_maps; 3578 FLAG_omit_prototype_checks_for_leaf_maps;
(...skipping 2571 matching lines...)
6119 #undef WRITE_UINT32_FIELD 6150 #undef WRITE_UINT32_FIELD
6120 #undef READ_SHORT_FIELD 6151 #undef READ_SHORT_FIELD
6121 #undef WRITE_SHORT_FIELD 6152 #undef WRITE_SHORT_FIELD
6122 #undef READ_BYTE_FIELD 6153 #undef READ_BYTE_FIELD
6123 #undef WRITE_BYTE_FIELD 6154 #undef WRITE_BYTE_FIELD
6124 6155
6125 6156
6126 } } // namespace v8::internal 6157 } } // namespace v8::internal
6127 6158
6128 #endif // V8_OBJECTS_INL_H_ 6159 #endif // V8_OBJECTS_INL_H_
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | src/property.h » ('j') | no next file with comments »

Powered by Google App Engine