Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1507)

Side by Side Diff: src/objects.cc

Issue 10697015: Separating transitions from descriptors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing Michaels comments. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 if (r.IsProperty()) { 409 if (r.IsProperty()) {
410 return GetPropertyAttributeWithFailedAccessCheck(receiver, 410 return GetPropertyAttributeWithFailedAccessCheck(receiver,
411 &r, 411 &r,
412 name, 412 name,
413 continue_search); 413 continue_search);
414 } 414 }
415 break; 415 break;
416 } 416 }
417 417
418 case HANDLER: 418 case HANDLER:
419 case MAP_TRANSITION: 419 case TRANSITION:
420 case CONSTANT_TRANSITION:
421 case NONEXISTENT: 420 case NONEXISTENT:
422 UNREACHABLE(); 421 UNREACHABLE();
423 } 422 }
424 } 423 }
425 424
426 GetIsolate()->ReportFailedAccessCheck(this, v8::ACCESS_HAS); 425 GetIsolate()->ReportFailedAccessCheck(this, v8::ACCESS_HAS);
427 return ABSENT; 426 return ABSENT;
428 } 427 }
429 428
430 429
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 case CALLBACKS: 633 case CALLBACKS:
635 return result->holder()->GetPropertyWithCallback( 634 return result->holder()->GetPropertyWithCallback(
636 receiver, result->GetCallbackObject(), name); 635 receiver, result->GetCallbackObject(), name);
637 case HANDLER: 636 case HANDLER:
638 return result->proxy()->GetPropertyWithHandler(receiver, name); 637 return result->proxy()->GetPropertyWithHandler(receiver, name);
639 case INTERCEPTOR: { 638 case INTERCEPTOR: {
640 JSObject* recvr = JSObject::cast(receiver); 639 JSObject* recvr = JSObject::cast(receiver);
641 return result->holder()->GetPropertyWithInterceptor( 640 return result->holder()->GetPropertyWithInterceptor(
642 recvr, name, attributes); 641 recvr, name, attributes);
643 } 642 }
644 case MAP_TRANSITION: 643 case TRANSITION:
645 case CONSTANT_TRANSITION:
646 break;
647 case NONEXISTENT: 644 case NONEXISTENT:
648 UNREACHABLE(); 645 UNREACHABLE();
649 break; 646 break;
650 } 647 }
651 UNREACHABLE(); 648 UNREACHABLE();
652 return NULL; 649 return NULL;
653 } 650 }
654 651
655 652
656 MaybeObject* Object::GetElementWithReceiver(Object* receiver, uint32_t index) { 653 MaybeObject* Object::GetElementWithReceiver(Object* receiver, uint32_t index) {
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 if (proto->IsJSObject()) return JSObject::cast(proto)->constructor_name(); 1482 if (proto->IsJSObject()) return JSObject::cast(proto)->constructor_name();
1486 } 1483 }
1487 // TODO(rossberg): what about proxies? 1484 // TODO(rossberg): what about proxies?
1488 // If the constructor is not present, return "Object". 1485 // If the constructor is not present, return "Object".
1489 return GetHeap()->Object_symbol(); 1486 return GetHeap()->Object_symbol();
1490 } 1487 }
1491 1488
1492 1489
1493 MaybeObject* JSObject::AddFastPropertyUsingMap(Map* new_map, 1490 MaybeObject* JSObject::AddFastPropertyUsingMap(Map* new_map,
1494 String* name, 1491 String* name,
1495 Object* value) { 1492 Object* value,
1496 int index = new_map->PropertyIndexFor(name); 1493 int field_index) {
1497 if (map()->unused_property_fields() == 0) { 1494 if (map()->unused_property_fields() == 0) {
1498 ASSERT(map()->unused_property_fields() == 0);
1499 int new_unused = new_map->unused_property_fields(); 1495 int new_unused = new_map->unused_property_fields();
1500 Object* values; 1496 Object* values;
1501 { MaybeObject* maybe_values = 1497 { MaybeObject* maybe_values =
1502 properties()->CopySize(properties()->length() + new_unused + 1); 1498 properties()->CopySize(properties()->length() + new_unused + 1);
1503 if (!maybe_values->ToObject(&values)) return maybe_values; 1499 if (!maybe_values->To(&values)) return maybe_values;
1504 } 1500 }
1505 set_properties(FixedArray::cast(values)); 1501 set_properties(FixedArray::cast(values));
1506 } 1502 }
1507 set_map(new_map); 1503 set_map(new_map);
1508 return FastPropertyAtPut(index, value); 1504 return FastPropertyAtPut(field_index, value);
1509 } 1505 }
1510 1506
1511 1507
1512 static bool IsIdentifier(UnicodeCache* cache, 1508 static bool IsIdentifier(UnicodeCache* cache,
1513 unibrow::CharacterStream* buffer) { 1509 unibrow::CharacterStream* buffer) {
1514 // Checks whether the buffer contains an identifier (no escape). 1510 // Checks whether the buffer contains an identifier (no escape).
1515 if (!buffer->has_more()) return false; 1511 if (!buffer->has_more()) return false;
1516 if (!cache->IsIdentifierStart(buffer->GetNext())) { 1512 if (!cache->IsIdentifierStart(buffer->GetNext())) {
1517 return false; 1513 return false;
1518 } 1514 }
(...skipping 25 matching lines...) Expand all
1544 } 1540 }
1545 return AddSlowProperty(name, value, attributes); 1541 return AddSlowProperty(name, value, attributes);
1546 } 1542 }
1547 1543
1548 DescriptorArray* old_descriptors = map()->instance_descriptors(); 1544 DescriptorArray* old_descriptors = map()->instance_descriptors();
1549 // Compute the new index for new field. 1545 // Compute the new index for new field.
1550 int index = map()->NextFreePropertyIndex(); 1546 int index = map()->NextFreePropertyIndex();
1551 1547
1552 // Allocate new instance descriptors with (name, index) added 1548 // Allocate new instance descriptors with (name, index) added
1553 FieldDescriptor new_field(name, index, attributes); 1549 FieldDescriptor new_field(name, index, attributes);
1554 Object* new_descriptors; 1550 DescriptorArray* new_descriptors;
1555 { MaybeObject* maybe_new_descriptors = 1551 { MaybeObject* maybe_new_descriptors =
1556 old_descriptors->CopyInsert(&new_field, REMOVE_TRANSITIONS); 1552 old_descriptors->CopyInsert(&new_field);
1557 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { 1553 if (!maybe_new_descriptors->To(&new_descriptors)) {
1558 return maybe_new_descriptors; 1554 return maybe_new_descriptors;
1559 } 1555 }
1560 } 1556 }
1561 1557
1562 // Only allow map transition if the object isn't the global object and there 1558 // Only allow map transition if the object isn't the global object and there
1563 // is not a transition for the name, or there's a transition for the name but 1559 // is not a transition for the name, or there's a transition for the name but
1564 // it's unrelated to properties. 1560 // it's unrelated to properties.
1565 int descriptor_index = old_descriptors->Search(name); 1561 int descriptor_index = old_descriptors->SearchWithCache(name);
1566 1562
1567 // Element transitions are stored in the descriptor for property "", which is 1563 // Element transitions are stored in the descriptor for property "", which is
1568 // not a identifier and should have forced a switch to slow properties above. 1564 // not a identifier and should have forced a switch to slow properties above.
1569 bool can_insert_transition = descriptor_index == DescriptorArray::kNotFound; 1565 bool can_insert_transition = descriptor_index == DescriptorArray::kNotFound;
1570 bool allow_map_transition = 1566 bool allow_map_transition =
1571 can_insert_transition && 1567 can_insert_transition &&
1572 (isolate->context()->global_context()->object_function()->map() != map()); 1568 (isolate->context()->global_context()->object_function()->map() != map());
1573 1569
1574 ASSERT(index < map()->inobject_properties() || 1570 ASSERT(index < map()->inobject_properties() ||
1575 (index - map()->inobject_properties()) < properties()->length() || 1571 (index - map()->inobject_properties()) < properties()->length() ||
1576 map()->unused_property_fields() == 0); 1572 map()->unused_property_fields() == 0);
1577 // Allocate a new map for the object. 1573 // Allocate a new map for the object.
1578 Object* r; 1574 Object* r;
1579 { MaybeObject* maybe_r = map()->CopyDropDescriptors(); 1575 { MaybeObject* maybe_r = map()->CopyDropDescriptors();
1580 if (!maybe_r->ToObject(&r)) return maybe_r; 1576 if (!maybe_r->ToObject(&r)) return maybe_r;
1581 } 1577 }
1582 Map* new_map = Map::cast(r); 1578 Map* new_map = Map::cast(r);
1579
1580 TransitionArray* new_transitions = NULL;
1583 if (allow_map_transition) { 1581 if (allow_map_transition) {
1584 // Allocate new instance descriptors for the old map with map transition. 1582 MaybeObject* maybe_new_transitions = map()->AddTransition(name, new_map);
1585 MapTransitionDescriptor d(name, Map::cast(new_map), attributes); 1583 if (!maybe_new_transitions->To(&new_transitions)) {
1586 Object* r; 1584 // We have accomplished the main goal, so return success.
1587 { MaybeObject* maybe_r = old_descriptors->CopyInsert(&d, KEEP_TRANSITIONS); 1585 return maybe_new_transitions;
1588 if (!maybe_r->ToObject(&r)) return maybe_r;
1589 } 1586 }
1590 old_descriptors = DescriptorArray::cast(r);
1591 } 1587 }
1592 1588
1593 if (map()->unused_property_fields() == 0) { 1589 if (map()->unused_property_fields() == 0) {
1594 if (TooManyFastProperties(properties()->length(), store_mode)) { 1590 if (TooManyFastProperties(properties()->length(), store_mode)) {
1595 Object* obj; 1591 Object* obj;
1596 { MaybeObject* maybe_obj = 1592 { MaybeObject* maybe_obj =
1597 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); 1593 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
1598 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 1594 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
1599 } 1595 }
1600 return AddSlowProperty(name, value, attributes); 1596 return AddSlowProperty(name, value, attributes);
1601 } 1597 }
1602 // Make room for the new value 1598 // Make room for the new value
1603 Object* values; 1599 Object* values;
1604 { MaybeObject* maybe_values = 1600 { MaybeObject* maybe_values =
1605 properties()->CopySize(properties()->length() + kFieldsAdded); 1601 properties()->CopySize(properties()->length() + kFieldsAdded);
1606 if (!maybe_values->ToObject(&values)) return maybe_values; 1602 if (!maybe_values->ToObject(&values)) return maybe_values;
1607 } 1603 }
1608 set_properties(FixedArray::cast(values)); 1604 set_properties(FixedArray::cast(values));
1609 new_map->set_unused_property_fields(kFieldsAdded - 1); 1605 new_map->set_unused_property_fields(kFieldsAdded - 1);
1610 } else { 1606 } else {
1611 new_map->set_unused_property_fields(map()->unused_property_fields() - 1); 1607 new_map->set_unused_property_fields(map()->unused_property_fields() - 1);
1612 } 1608 }
1613 // We have now allocated all the necessary objects. 1609 // Apply all changes at once, so they are atomic.
1614 // All the changes can be applied at once, so they are atomic.
1615 if (allow_map_transition) { 1610 if (allow_map_transition) {
1616 map()->set_instance_descriptors(old_descriptors); 1611 MaybeObject* transition_added = map()->set_transitions(new_transitions);
1612 if (transition_added->IsFailure()) return transition_added;
1617 } 1613 }
1614 new_map->set_instance_descriptors(new_descriptors);
1618 new_map->SetBackPointer(map()); 1615 new_map->SetBackPointer(map());
1619 new_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors));
1620 set_map(new_map); 1616 set_map(new_map);
1621 return FastPropertyAtPut(index, value); 1617 return FastPropertyAtPut(index, value);
1622 } 1618 }
1623 1619
1624 1620
1625 MaybeObject* JSObject::AddConstantFunctionProperty( 1621 MaybeObject* JSObject::AddConstantFunctionProperty(
1626 String* name, 1622 String* name,
1627 JSFunction* function, 1623 JSFunction* function,
1628 PropertyAttributes attributes) { 1624 PropertyAttributes attributes) {
1629 // Allocate new instance descriptors with (name, function) added 1625 // Allocate new instance descriptors with (name, function) added
1630 ConstantFunctionDescriptor d(name, function, attributes); 1626 ConstantFunctionDescriptor d(name, function, attributes);
1631 Object* new_descriptors; 1627 DescriptorArray* new_descriptors;
1632 { MaybeObject* maybe_new_descriptors = 1628 { MaybeObject* maybe_new_descriptors =
1633 map()->instance_descriptors()->CopyInsert(&d, REMOVE_TRANSITIONS); 1629 map()->instance_descriptors()->CopyInsert(&d);
1634 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { 1630 if (!maybe_new_descriptors->To(&new_descriptors)) {
1635 return maybe_new_descriptors; 1631 return maybe_new_descriptors;
1636 } 1632 }
1637 } 1633 }
1638 1634
1639 // Allocate a new map for the object. 1635 // Allocate a new map for the object.
1640 Object* new_map; 1636 Object* new_map;
1641 { MaybeObject* maybe_new_map = map()->CopyDropDescriptors(); 1637 { MaybeObject* maybe_new_map = map()->CopyDropDescriptors();
1642 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; 1638 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map;
1643 } 1639 }
1644 1640
1645 DescriptorArray* descriptors = DescriptorArray::cast(new_descriptors); 1641 Map::cast(new_map)->set_instance_descriptors(new_descriptors);
1646 Map::cast(new_map)->set_instance_descriptors(descriptors);
1647 Map* old_map = map(); 1642 Map* old_map = map();
1648 set_map(Map::cast(new_map)); 1643 set_map(Map::cast(new_map));
1649 1644
1650 // If the old map is the global object map (from new Object()), 1645 // If the old map is the global object map (from new Object()),
1651 // then transitions are not added to it, so we are done. 1646 // then transitions are not added to it, so we are done.
1652 Heap* heap = GetHeap(); 1647 Heap* heap = GetHeap();
1653 if (old_map == heap->isolate()->context()->global_context()-> 1648 if (old_map == heap->isolate()->context()->global_context()->
1654 object_function()->map()) { 1649 object_function()->map()) {
1655 return function; 1650 return function;
1656 } 1651 }
1657 1652
1658 // Do not add CONSTANT_TRANSITIONS to global objects 1653 // Do not add CONSTANT_TRANSITIONS to global objects
1659 if (IsGlobalObject()) { 1654 if (IsGlobalObject()) {
1660 return function; 1655 return function;
1661 } 1656 }
1662 1657
1663 // Add a CONSTANT_TRANSITION descriptor to the old map, 1658 // Add a CONSTANT_TRANSITION descriptor to the old map,
1664 // so future assignments to this property on other objects 1659 // so future assignments to this property on other objects
1665 // of the same type will create a normal field, not a constant function. 1660 // of the same type will create a normal field, not a constant function.
1666 // Don't do this for special properties, with non-trival attributes. 1661 // Don't do this for special properties, with non-trival attributes.
1667 if (attributes != NONE) { 1662 if (attributes != NONE) {
1668 return function; 1663 return function;
1669 } 1664 }
1670 ConstTransitionDescriptor mark(name, Map::cast(new_map)); 1665
1671 { MaybeObject* maybe_new_descriptors = 1666 TransitionArray* new_transitions;
1672 old_map->instance_descriptors()->CopyInsert(&mark, KEEP_TRANSITIONS); 1667 MaybeObject* maybe_new_transitions =
1673 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { 1668 old_map->AddTransition(name, Map::cast(new_map));
1674 // We have accomplished the main goal, so return success. 1669 if (!maybe_new_transitions->To(&new_transitions)) {
1675 return function; 1670 // We have accomplished the main goal, so return success.
1676 } 1671 return function;
1677 } 1672 }
1678 old_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); 1673
1674 MaybeObject* transition_added = old_map->set_transitions(new_transitions);
1675 // We have accomplished the main goal, so return success.
1676 if (transition_added->IsFailure()) {
1677 return function;
1678 }
1679
1679 Map::cast(new_map)->SetBackPointer(old_map); 1680 Map::cast(new_map)->SetBackPointer(old_map);
1680
1681 return function; 1681 return function;
1682 } 1682 }
1683 1683
1684 1684
1685 // Add property in slow mode 1685 // Add property in slow mode
1686 MaybeObject* JSObject::AddSlowProperty(String* name, 1686 MaybeObject* JSObject::AddSlowProperty(String* name,
1687 Object* value, 1687 Object* value,
1688 PropertyAttributes attributes) { 1688 PropertyAttributes attributes) {
1689 ASSERT(!HasFastProperties()); 1689 ASSERT(!HasFastProperties());
1690 StringDictionary* dict = property_dictionary(); 1690 StringDictionary* dict = property_dictionary();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 1791
1792 1792
1793 MaybeObject* JSObject::ReplaceSlowProperty(String* name, 1793 MaybeObject* JSObject::ReplaceSlowProperty(String* name,
1794 Object* value, 1794 Object* value,
1795 PropertyAttributes attributes) { 1795 PropertyAttributes attributes) {
1796 StringDictionary* dictionary = property_dictionary(); 1796 StringDictionary* dictionary = property_dictionary();
1797 int old_index = dictionary->FindEntry(name); 1797 int old_index = dictionary->FindEntry(name);
1798 int new_enumeration_index = 0; // 0 means "Use the next available index." 1798 int new_enumeration_index = 0; // 0 means "Use the next available index."
1799 if (old_index != -1) { 1799 if (old_index != -1) {
1800 // All calls to ReplaceSlowProperty have had all transitions removed. 1800 // All calls to ReplaceSlowProperty have had all transitions removed.
1801 ASSERT(!dictionary->ContainsTransition(old_index));
1802 new_enumeration_index = dictionary->DetailsAt(old_index).index(); 1801 new_enumeration_index = dictionary->DetailsAt(old_index).index();
1803 } 1802 }
1804 1803
1805 PropertyDetails new_details(attributes, NORMAL, new_enumeration_index); 1804 PropertyDetails new_details(attributes, NORMAL, new_enumeration_index);
1806 return SetNormalizedProperty(name, value, new_details); 1805 return SetNormalizedProperty(name, value, new_details);
1807 } 1806 }
1808 1807
1809 1808
1810 MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition( 1809 MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition(
1811 String* name, 1810 String* name,
1812 Object* new_value, 1811 Object* new_value,
1813 PropertyAttributes attributes) { 1812 PropertyAttributes attributes) {
1814 Map* old_map = map(); 1813 Map* old_map = map();
1815 Object* result; 1814 Object* result;
1816 { MaybeObject* maybe_result = 1815 { MaybeObject* maybe_result =
1817 ConvertDescriptorToField(name, new_value, attributes); 1816 ConvertDescriptorToField(name, new_value, attributes);
1818 if (!maybe_result->ToObject(&result)) return maybe_result; 1817 if (!maybe_result->To(&result)) return maybe_result;
1819 } 1818 }
1820 // If we get to this point we have succeeded - do not return failure 1819 // If we get to this point we have succeeded - do not return failure
1821 // after this point. Later stuff is optional. 1820 // after this point. Later stuff is optional.
1822 if (!HasFastProperties()) { 1821 if (!HasFastProperties()) {
1823 return result; 1822 return result;
1824 } 1823 }
1825 // Do not add transitions to the map of "new Object()". 1824 // Do not add transitions to the map of "new Object()".
1826 if (map() == GetIsolate()->context()->global_context()-> 1825 if (map() == GetIsolate()->context()->global_context()->
1827 object_function()->map()) { 1826 object_function()->map()) {
1828 return result; 1827 return result;
1829 } 1828 }
1830 1829
1831 MapTransitionDescriptor transition(name, 1830 TransitionArray* new_transitions;
1832 map(), 1831 MaybeObject* maybe_new_transitions = old_map->AddTransition(name, map());
1833 attributes); 1832 if (!maybe_new_transitions->To(&new_transitions)) {
1834 Object* new_descriptors; 1833 // We have accomplished the main goal, so return success.
1835 { MaybeObject* maybe_new_descriptors = old_map->instance_descriptors()-> 1834 return result;
1836 CopyInsert(&transition, KEEP_TRANSITIONS);
1837 if (!maybe_new_descriptors->ToObject(&new_descriptors)) {
1838 return result; // Yes, return _result_.
1839 }
1840 } 1835 }
1841 old_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); 1836
1842 map()->SetBackPointer(old_map); 1837 MaybeObject* transition_added = old_map->set_transitions(new_transitions);
1838 // Return success if failure since we accomplished the main goal. Otherwise
1839 // also set backpointer.
1840 if (!transition_added->IsFailure()) {
1841 map()->SetBackPointer(old_map);
1842 }
1843 return result; 1843 return result;
1844 } 1844 }
1845 1845
1846 1846
1847 MaybeObject* JSObject::ConvertDescriptorToField(String* name, 1847 MaybeObject* JSObject::ConvertDescriptorToField(String* name,
1848 Object* new_value, 1848 Object* new_value,
1849 PropertyAttributes attributes) { 1849 PropertyAttributes attributes) {
1850 if (map()->unused_property_fields() == 0 && 1850 if (map()->unused_property_fields() == 0 &&
1851 TooManyFastProperties(properties()->length(), MAY_BE_STORE_FROM_KEYED)) { 1851 TooManyFastProperties(properties()->length(), MAY_BE_STORE_FROM_KEYED)) {
1852 Object* obj; 1852 Object* obj;
1853 { MaybeObject* maybe_obj = 1853 { MaybeObject* maybe_obj =
1854 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); 1854 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
1855 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 1855 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
1856 } 1856 }
1857 return ReplaceSlowProperty(name, new_value, attributes); 1857 return ReplaceSlowProperty(name, new_value, attributes);
1858 } 1858 }
1859 1859
1860 int index = map()->NextFreePropertyIndex(); 1860 int index = map()->NextFreePropertyIndex();
1861 FieldDescriptor new_field(name, index, attributes); 1861 FieldDescriptor new_field(name, index, attributes);
1862 // Make a new DescriptorArray replacing an entry with FieldDescriptor. 1862 // Make a new DescriptorArray replacing an entry with FieldDescriptor.
1863 Object* descriptors_unchecked; 1863 Object* descriptors_unchecked;
1864 { MaybeObject* maybe_descriptors_unchecked = map()->instance_descriptors()-> 1864 { MaybeObject* maybe_descriptors_unchecked =
1865 CopyInsert(&new_field, REMOVE_TRANSITIONS); 1865 map()->instance_descriptors()->CopyInsert(&new_field);
1866 if (!maybe_descriptors_unchecked->ToObject(&descriptors_unchecked)) { 1866 if (!maybe_descriptors_unchecked->ToObject(&descriptors_unchecked)) {
1867 return maybe_descriptors_unchecked; 1867 return maybe_descriptors_unchecked;
1868 } 1868 }
1869 } 1869 }
1870 DescriptorArray* new_descriptors = 1870 DescriptorArray* new_descriptors =
1871 DescriptorArray::cast(descriptors_unchecked); 1871 DescriptorArray::cast(descriptors_unchecked);
1872 1872
1873 // Make a new map for the object. 1873 // Make a new map for the object.
1874 Object* new_map_unchecked; 1874 Object* new_map_unchecked;
1875 { MaybeObject* maybe_new_map_unchecked = map()->CopyDropDescriptors(); 1875 { MaybeObject* maybe_new_map_unchecked = map()->CopyDropDescriptors();
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 case CALLBACKS: { 2149 case CALLBACKS: {
2150 if (!FLAG_es5_readonly && result.IsReadOnly()) break; 2150 if (!FLAG_es5_readonly && result.IsReadOnly()) break;
2151 *done = true; 2151 *done = true;
2152 return SetPropertyWithCallback(result.GetCallbackObject(), 2152 return SetPropertyWithCallback(result.GetCallbackObject(),
2153 name, value, result.holder(), strict_mode); 2153 name, value, result.holder(), strict_mode);
2154 } 2154 }
2155 case HANDLER: { 2155 case HANDLER: {
2156 return result.proxy()->SetPropertyViaPrototypesWithHandler( 2156 return result.proxy()->SetPropertyViaPrototypesWithHandler(
2157 this, name, value, attributes, strict_mode, done); 2157 this, name, value, attributes, strict_mode, done);
2158 } 2158 }
2159 case MAP_TRANSITION: 2159 case TRANSITION:
2160 case CONSTANT_TRANSITION:
2161 break;
2162 case NONEXISTENT: 2160 case NONEXISTENT:
2163 UNREACHABLE(); 2161 UNREACHABLE();
2164 break; 2162 break;
2165 } 2163 }
2166 } 2164 }
2167 2165
2168 // If we get here with *done true, we have encountered a read-only property. 2166 // If we get here with *done true, we have encountered a read-only property.
2169 if (!FLAG_es5_readonly) *done = false; 2167 if (!FLAG_es5_readonly) *done = false;
2170 if (*done) { 2168 if (*done) {
2171 if (strict_mode == kNonStrictMode) return value; 2169 if (strict_mode == kNonStrictMode) return value;
2172 Handle<Object> args[] = { Handle<Object>(name), Handle<Object>(this)}; 2170 Handle<Object> args[] = { Handle<Object>(name), Handle<Object>(this)};
2173 return isolate->Throw(*isolate->factory()->NewTypeError( 2171 return isolate->Throw(*isolate->factory()->NewTypeError(
2174 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)))); 2172 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args))));
2175 } 2173 }
2176 return heap->the_hole_value(); 2174 return heap->the_hole_value();
2177 } 2175 }
2178 2176
2179 2177
2180 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { 2178 void Map::LookupDescriptor(JSObject* holder,
2181 DescriptorArray* descriptors = map()->instance_descriptors(); 2179 String* name,
2180 LookupResult* result) {
2181 DescriptorArray* descriptors = this->instance_descriptors();
2182 int number = descriptors->SearchWithCache(name); 2182 int number = descriptors->SearchWithCache(name);
2183 if (number != DescriptorArray::kNotFound) { 2183 if (number != DescriptorArray::kNotFound) {
2184 result->DescriptorResult(this, descriptors->GetDetails(number), number);
2185 } else {
2186 result->NotFound();
2187 }
2188 }
2189
2190
2191 void Map::LookupInDescriptors(JSObject* holder,
2192 String* name,
2193 LookupResult* result) {
2194 DescriptorArray* descriptors = instance_descriptors();
2195 DescriptorLookupCache* cache =
2196 GetHeap()->isolate()->descriptor_lookup_cache();
2197 int number = cache->Lookup(descriptors, name);
2198 if (number == DescriptorLookupCache::kAbsent) {
2199 number = descriptors->Search(name);
2200 cache->Update(descriptors, name, number);
2201 }
2202 if (number != DescriptorArray::kNotFound) {
2203 result->DescriptorResult(holder, descriptors->GetDetails(number), number); 2184 result->DescriptorResult(holder, descriptors->GetDetails(number), number);
2204 } else { 2185 } else {
2205 result->NotFound(); 2186 result->NotFound();
2206 } 2187 }
2207 } 2188 }
2208 2189
2209 2190
2191 static void LookupTransition(Map* map,
2192 JSObject* holder,
2193 String* name,
2194 LookupResult* result) {
2195 if (map->HasTransitionArray()) {
2196 TransitionArray* transition_array = map->transitions();
2197 int number = transition_array->Search(name);
2198 if (number != TransitionArray::kNotFound) {
2199 return result->TransitionResult(holder, number);
2200 }
2201 }
2202 result->NotFound();
2203 }
2204
2205
2206 void Map::LookupTransitionOrDescriptor(JSObject* holder,
2207 String* name,
2208 LookupResult* result) {
2209 // AccessorPairs containing both a Descriptor and a Transition are shared
2210 // between the DescriptorArray and the Transition array. This is why looking
2211 // up the AccessorPair solely in the DescriptorArray works.
2212 // TODO(verwaest) This should be implemented differently so the
2213 // DescriptorArray is free of transitions; and so we can freely share it.
2214 this->LookupDescriptor(holder, name, result);
2215 if (result->IsFound()) return;
2216 LookupTransition(this, holder, name, result);
2217 }
2218
2219
2210 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { 2220 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) {
2211 ASSERT(!map.is_null()); 2221 ASSERT(!map.is_null());
2212 for (int i = 0; i < maps->length(); ++i) { 2222 for (int i = 0; i < maps->length(); ++i) {
2213 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; 2223 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true;
2214 } 2224 }
2215 return false; 2225 return false;
2216 } 2226 }
2217 2227
2218 2228
2219 template <class T> 2229 template <class T>
(...skipping 29 matching lines...) Expand all
2249 static Map* FindClosestElementsTransition(Map* map, ElementsKind to_kind) { 2259 static Map* FindClosestElementsTransition(Map* map, ElementsKind to_kind) {
2250 Map* current_map = map; 2260 Map* current_map = map;
2251 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind()); 2261 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind());
2252 int to_index = IsFastElementsKind(to_kind) 2262 int to_index = IsFastElementsKind(to_kind)
2253 ? GetSequenceIndexFromFastElementsKind(to_kind) 2263 ? GetSequenceIndexFromFastElementsKind(to_kind)
2254 : GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND); 2264 : GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
2255 2265
2256 ASSERT(index <= to_index); 2266 ASSERT(index <= to_index);
2257 2267
2258 for (; index < to_index; ++index) { 2268 for (; index < to_index; ++index) {
2269 if (!current_map->HasElementsTransition()) return current_map;
2270 current_map = current_map->elements_transition_map();
2271 }
2272 if (!IsFastElementsKind(to_kind) && current_map->HasElementsTransition()) {
2259 Map* next_map = current_map->elements_transition_map(); 2273 Map* next_map = current_map->elements_transition_map();
2260 if (next_map == NULL) { 2274 if (next_map->elements_kind() == to_kind) return next_map;
2261 return current_map;
2262 }
2263 current_map = next_map;
2264 } 2275 }
2265 if (!IsFastElementsKind(to_kind)) { 2276 ASSERT(IsFastElementsKind(to_kind)
2266 Map* next_map = current_map->elements_transition_map(); 2277 ? current_map->elements_kind() == to_kind
2267 if (next_map != NULL && next_map->elements_kind() == to_kind) { 2278 : current_map->elements_kind() == TERMINAL_FAST_ELEMENTS_KIND);
2268 return next_map;
2269 }
2270 ASSERT(current_map->elements_kind() == TERMINAL_FAST_ELEMENTS_KIND);
2271 } else {
2272 ASSERT(current_map->elements_kind() == to_kind);
2273 }
2274 return current_map; 2279 return current_map;
2275 } 2280 }
2276 2281
2277 2282
2278 Map* Map::LookupElementsTransitionMap(ElementsKind to_kind) { 2283 Map* Map::LookupElementsTransitionMap(ElementsKind to_kind) {
2279 Map* to_map = FindClosestElementsTransition(this, to_kind); 2284 Map* to_map = FindClosestElementsTransition(this, to_kind);
2280 if (to_map->elements_kind() == to_kind) return to_map; 2285 if (to_map->elements_kind() == to_kind) return to_map;
2281 return NULL; 2286 return NULL;
2282 } 2287 }
2283 2288
2284 2289
2285 MaybeObject* Map::CreateNextElementsTransition(ElementsKind next_kind) { 2290 MaybeObject* Map::CreateNextElementsTransition(ElementsKind next_kind) {
2286 ASSERT(elements_transition_map() == NULL || 2291 ASSERT(!HasElementsTransition() ||
2287 ((elements_transition_map()->elements_kind() == DICTIONARY_ELEMENTS || 2292 ((elements_transition_map()->elements_kind() == DICTIONARY_ELEMENTS ||
2288 IsExternalArrayElementsKind( 2293 IsExternalArrayElementsKind(
2289 elements_transition_map()->elements_kind())) && 2294 elements_transition_map()->elements_kind())) &&
2290 (next_kind == DICTIONARY_ELEMENTS || 2295 (next_kind == DICTIONARY_ELEMENTS ||
2291 IsExternalArrayElementsKind(next_kind)))); 2296 IsExternalArrayElementsKind(next_kind))));
2292 ASSERT(!IsFastElementsKind(next_kind) || 2297 ASSERT(!IsFastElementsKind(next_kind) ||
2293 IsMoreGeneralElementsKindTransition(elements_kind(), next_kind)); 2298 IsMoreGeneralElementsKindTransition(elements_kind(), next_kind));
2294 ASSERT(next_kind != elements_kind()); 2299 ASSERT(next_kind != elements_kind());
2295 2300
2296 Map* next_map; 2301 Map* next_map;
2297 MaybeObject* maybe_next_map = 2302 MaybeObject* maybe_next_map =
2298 this->CopyDropTransitions(DescriptorArray::CANNOT_BE_SHARED); 2303 this->CopyDropTransitions(DescriptorArray::CANNOT_BE_SHARED);
2299 if (!maybe_next_map->To(&next_map)) return maybe_next_map; 2304 if (!maybe_next_map->To(&next_map)) return maybe_next_map;
2300 2305
2306 MaybeObject* added_elements = this->set_elements_transition_map(next_map);
2307 if (added_elements->IsFailure()) return added_elements;
2308
2301 next_map->set_elements_kind(next_kind); 2309 next_map->set_elements_kind(next_kind);
2302 next_map->SetBackPointer(this); 2310 next_map->SetBackPointer(this);
2303 this->set_elements_transition_map(next_map);
2304 return next_map; 2311 return next_map;
2305 } 2312 }
2306 2313
2307 2314
2308 static MaybeObject* AddMissingElementsTransitions(Map* map, 2315 static MaybeObject* AddMissingElementsTransitions(Map* map,
2309 ElementsKind to_kind) { 2316 ElementsKind to_kind) {
2310 ASSERT(IsFastElementsKind(map->elements_kind())); 2317 ASSERT(IsFastElementsKind(map->elements_kind()));
2311 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind()); 2318 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind());
2312 int to_index = IsFastElementsKind(to_kind) 2319 int to_index = IsFastElementsKind(to_kind)
2313 ? GetSequenceIndexFromFastElementsKind(to_kind) 2320 ? GetSequenceIndexFromFastElementsKind(to_kind)
(...skipping 25 matching lines...) Expand all
2339 2346
2340 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, 2347 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object,
2341 ElementsKind to_kind) { 2348 ElementsKind to_kind) {
2342 Isolate* isolate = object->GetIsolate(); 2349 Isolate* isolate = object->GetIsolate();
2343 CALL_HEAP_FUNCTION(isolate, 2350 CALL_HEAP_FUNCTION(isolate,
2344 object->GetElementsTransitionMap(isolate, to_kind), 2351 object->GetElementsTransitionMap(isolate, to_kind),
2345 Map); 2352 Map);
2346 } 2353 }
2347 2354
2348 2355
2349 // If the map is using the empty descriptor array, install a new empty
2350 // descriptor array that will contain an element transition.
2351 // TODO(verwaest) Goes away once the descriptor array is immutable.
2352 static MaybeObject* EnsureMayContainTransitions(Map* map) {
2353 if (map->instance_descriptors()->MayContainTransitions()) return map;
2354 DescriptorArray* descriptor_array;
2355 MaybeObject* maybe_descriptor_array =
2356 DescriptorArray::Allocate(0, DescriptorArray::CANNOT_BE_SHARED);
2357 if (!maybe_descriptor_array->To(&descriptor_array)) {
2358 return maybe_descriptor_array;
2359 }
2360 map->set_instance_descriptors(descriptor_array);
2361 return map;
2362 }
2363
2364
2365 MaybeObject* JSObject::GetElementsTransitionMapSlow(ElementsKind to_kind) { 2356 MaybeObject* JSObject::GetElementsTransitionMapSlow(ElementsKind to_kind) {
2366 Map* start_map = map(); 2357 Map* start_map = map();
2367 ElementsKind from_kind = start_map->elements_kind(); 2358 ElementsKind from_kind = start_map->elements_kind();
2368 2359
2369 if (from_kind == to_kind) { 2360 if (from_kind == to_kind) {
2370 return start_map; 2361 return start_map;
2371 } 2362 }
2372 2363
2373 Context* global_context = GetIsolate()->context()->global_context(); 2364 Context* global_context = GetIsolate()->context()->global_context();
2374 bool allow_store_transition = 2365 bool allow_store_transition =
(...skipping 14 matching lines...) Expand all
2389 if (!allow_store_transition) { 2380 if (!allow_store_transition) {
2390 // Create a new free-floating map only if we are not allowed to store it. 2381 // Create a new free-floating map only if we are not allowed to store it.
2391 Map* new_map = NULL; 2382 Map* new_map = NULL;
2392 MaybeObject* maybe_new_map = 2383 MaybeObject* maybe_new_map =
2393 start_map->CopyDropTransitions(DescriptorArray::MAY_BE_SHARED); 2384 start_map->CopyDropTransitions(DescriptorArray::MAY_BE_SHARED);
2394 if (!maybe_new_map->To(&new_map)) return maybe_new_map; 2385 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
2395 new_map->set_elements_kind(to_kind); 2386 new_map->set_elements_kind(to_kind);
2396 return new_map; 2387 return new_map;
2397 } 2388 }
2398 2389
2399 EnsureMayContainTransitions(start_map);
2400 Map* closest_map = FindClosestElementsTransition(start_map, to_kind); 2390 Map* closest_map = FindClosestElementsTransition(start_map, to_kind);
2401 2391
2402 if (closest_map->elements_kind() == to_kind) { 2392 if (closest_map->elements_kind() == to_kind) {
2403 return closest_map; 2393 return closest_map;
2404 } 2394 }
2405 2395
2406 return AddMissingElementsTransitions(closest_map, to_kind); 2396 return AddMissingElementsTransitions(closest_map, to_kind);
2407 } 2397 }
2408 2398
2409 2399
2410 void JSObject::LocalLookupRealNamedProperty(String* name, 2400 void JSObject::LocalLookupRealNamedProperty(String* name,
2411 LookupResult* result) { 2401 LookupResult* result) {
2412 if (IsJSGlobalProxy()) { 2402 if (IsJSGlobalProxy()) {
2413 Object* proto = GetPrototype(); 2403 Object* proto = GetPrototype();
2414 if (proto->IsNull()) return result->NotFound(); 2404 if (proto->IsNull()) return result->NotFound();
2415 ASSERT(proto->IsJSGlobalObject()); 2405 ASSERT(proto->IsJSGlobalObject());
2416 // A GlobalProxy's prototype should always be a proper JSObject. 2406 // A GlobalProxy's prototype should always be a proper JSObject.
2417 return JSObject::cast(proto)->LocalLookupRealNamedProperty(name, result); 2407 return JSObject::cast(proto)->LocalLookupRealNamedProperty(name, result);
2418 } 2408 }
2419 2409
2420 if (HasFastProperties()) { 2410 if (HasFastProperties()) {
2421 LookupInDescriptor(name, result); 2411 map()->LookupTransitionOrDescriptor(this, name, result);
2422 if (result->IsFound()) { 2412 // A property or a map transition was found. We return all of these result
2423 // A property, a map transition or a null descriptor was found. 2413 // types because LocalLookupRealNamedProperty is used when setting
2424 // We return all of these result types because 2414 // properties where map transitions are handled.
2425 // LocalLookupRealNamedProperty is used when setting properties 2415 ASSERT(!result->IsFound() ||
2426 // where map transitions and null descriptors are handled. 2416 (result->holder() == this && result->IsFastPropertyType()));
2427 ASSERT(result->holder() == this && result->IsFastPropertyType()); 2417 // Disallow caching for uninitialized constants. These can only
2428 // Disallow caching for uninitialized constants. These can only 2418 // occur as fields.
2429 // occur as fields. 2419 if (result->IsField() &&
2430 if (result->IsField() && 2420 result->IsReadOnly() &&
2431 result->IsReadOnly() && 2421 FastPropertyAt(result->GetFieldIndex())->IsTheHole()) {
2432 FastPropertyAt(result->GetFieldIndex())->IsTheHole()) { 2422 result->DisallowCaching();
2433 result->DisallowCaching(); 2423 }
2424 return;
2425 }
2426
2427 int entry = property_dictionary()->FindEntry(name);
2428 if (entry != StringDictionary::kNotFound) {
2429 Object* value = property_dictionary()->ValueAt(entry);
2430 if (IsGlobalObject()) {
2431 PropertyDetails d = property_dictionary()->DetailsAt(entry);
2432 if (d.IsDeleted()) {
2433 result->NotFound();
2434 return;
2434 } 2435 }
2435 return; 2436 value = JSGlobalPropertyCell::cast(value)->value();
2436 } 2437 }
2437 } else { 2438 // Make sure to disallow caching for uninitialized constants
2438 int entry = property_dictionary()->FindEntry(name); 2439 // found in the dictionary-mode objects.
2439 if (entry != StringDictionary::kNotFound) { 2440 if (value->IsTheHole()) result->DisallowCaching();
2440 Object* value = property_dictionary()->ValueAt(entry); 2441 result->DictionaryResult(this, entry);
2441 if (IsGlobalObject()) { 2442 return;
2442 PropertyDetails d = property_dictionary()->DetailsAt(entry);
2443 if (d.IsDeleted()) {
2444 result->NotFound();
2445 return;
2446 }
2447 value = JSGlobalPropertyCell::cast(value)->value();
2448 }
2449 // Make sure to disallow caching for uninitialized constants
2450 // found in the dictionary-mode objects.
2451 if (value->IsTheHole()) result->DisallowCaching();
2452 result->DictionaryResult(this, entry);
2453 return;
2454 }
2455 } 2443 }
2444
2456 result->NotFound(); 2445 result->NotFound();
2457 } 2446 }
2458 2447
2459 2448
2460 void JSObject::LookupRealNamedProperty(String* name, LookupResult* result) { 2449 void JSObject::LookupRealNamedProperty(String* name, LookupResult* result) {
2461 LocalLookupRealNamedProperty(name, result); 2450 LocalLookupRealNamedProperty(name, result);
2462 if (result->IsProperty()) return; 2451 if (result->IsProperty()) return;
2463 2452
2464 LookupRealNamedPropertyInPrototypes(name, result); 2453 LookupRealNamedPropertyInPrototypes(name, result);
2465 } 2454 }
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 bool done = false; 2861 bool done = false;
2873 MaybeObject* result_object = 2862 MaybeObject* result_object =
2874 SetPropertyViaPrototypes(name, value, attributes, strict_mode, &done); 2863 SetPropertyViaPrototypes(name, value, attributes, strict_mode, &done);
2875 if (done) return result_object; 2864 if (done) return result_object;
2876 } 2865 }
2877 2866
2878 if (!result->IsFound()) { 2867 if (!result->IsFound()) {
2879 // Neither properties nor transitions found. 2868 // Neither properties nor transitions found.
2880 return AddProperty(name, value, attributes, strict_mode, store_mode); 2869 return AddProperty(name, value, attributes, strict_mode, store_mode);
2881 } 2870 }
2882 if (result->IsReadOnly() && result->IsProperty()) { 2871 if (result->IsProperty() && result->IsReadOnly()) {
2883 if (strict_mode == kStrictMode) { 2872 if (strict_mode == kStrictMode) {
2884 Handle<JSObject> self(this); 2873 Handle<JSObject> self(this);
2885 Handle<String> hname(name); 2874 Handle<String> hname(name);
2886 Handle<Object> args[] = { hname, self }; 2875 Handle<Object> args[] = { hname, self };
2887 return heap->isolate()->Throw(*heap->isolate()->factory()->NewTypeError( 2876 return heap->isolate()->Throw(*heap->isolate()->factory()->NewTypeError(
2888 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)))); 2877 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args))));
2889 } else { 2878 } else {
2890 return value; 2879 return value;
2891 } 2880 }
2892 } 2881 }
2882
2893 // This is a real property that is not read-only, or it is a 2883 // This is a real property that is not read-only, or it is a
2894 // transition or null descriptor and there are no setters in the prototypes. 2884 // transition or null descriptor and there are no setters in the prototypes.
2895 switch (result->type()) { 2885 switch (result->type()) {
2896 case NORMAL: 2886 case NORMAL:
2897 return SetNormalizedProperty(result, value); 2887 return SetNormalizedProperty(result, value);
2898 case FIELD: 2888 case FIELD:
2899 return FastPropertyAtPut(result->GetFieldIndex(), value); 2889 return FastPropertyAtPut(result->GetFieldIndex(), value);
2900 case MAP_TRANSITION:
2901 if (attributes == result->GetAttributes()) {
2902 // Only use map transition if the attributes match.
2903 return AddFastPropertyUsingMap(result->GetTransitionMap(),
2904 name,
2905 value);
2906 }
2907 return ConvertDescriptorToField(name, value, attributes);
2908 case CONSTANT_FUNCTION: 2890 case CONSTANT_FUNCTION:
2909 // Only replace the function if necessary. 2891 // Only replace the function if necessary.
2910 if (value == result->GetConstantFunction()) return value; 2892 if (value == result->GetConstantFunction()) return value;
2911 // Preserve the attributes of this existing property. 2893 // Preserve the attributes of this existing property.
2912 attributes = result->GetAttributes(); 2894 attributes = result->GetAttributes();
2913 return ConvertDescriptorToField(name, value, attributes); 2895 return ConvertDescriptorToField(name, value, attributes);
2914 case CALLBACKS: { 2896 case CALLBACKS: {
2915 Object* callback_object = result->GetCallbackObject(); 2897 Object* callback_object = result->GetCallbackObject();
2916 if (callback_object->IsAccessorPair() &&
2917 !AccessorPair::cast(callback_object)->ContainsAccessor()) {
2918 return ConvertDescriptorToField(name, value, attributes);
2919 }
2920 return SetPropertyWithCallback(callback_object, 2898 return SetPropertyWithCallback(callback_object,
2921 name, 2899 name,
2922 value, 2900 value,
2923 result->holder(), 2901 result->holder(),
2924 strict_mode); 2902 strict_mode);
2925 } 2903 }
2926 case INTERCEPTOR: 2904 case INTERCEPTOR:
2927 return SetPropertyWithInterceptor(name, value, attributes, strict_mode); 2905 return SetPropertyWithInterceptor(name, value, attributes, strict_mode);
2928 case CONSTANT_TRANSITION: { 2906 case TRANSITION: {
2907 Object* transition = result->GetTransitionValue();
2908
2909 if (transition->IsAccessorPair()) {
2910 if (!AccessorPair::cast(transition)->ContainsAccessor()) {
2911 return ConvertDescriptorToField(name, value, attributes);
2912 }
2913 return SetPropertyWithCallback(transition,
2914 name,
2915 value,
2916 result->holder(),
2917 strict_mode);
2918 }
2919
2920 Map* transition_map = Map::cast(transition);
2921 DescriptorArray* descriptors = transition_map->instance_descriptors();
2922 int descriptor = descriptors->SearchWithCache(name);
2923 PropertyDetails details = descriptors->GetDetails(descriptor);
2924 ASSERT(details.type() == FIELD || details.type() == CONSTANT_FUNCTION);
2925
2926 if (details.type() == FIELD) {
2927 if (attributes == details.attributes()) {
2928 int field_index = descriptors->GetFieldIndex(descriptor);
2929 return AddFastPropertyUsingMap(transition_map,
2930 name,
2931 value,
2932 field_index);
2933 }
2934 return ConvertDescriptorToField(name, value, attributes);
2935 }
2936
2937 // Is transition to CONSTANT_FUNCTION
2938 Object* constant_function = descriptors->GetValue(descriptor);
2929 // If the same constant function is being added we can simply 2939 // If the same constant function is being added we can simply
2930 // transition to the target map. 2940 // transition to the target map.
2931 Map* target_map = result->GetTransitionMap(); 2941 if (constant_function == value) {
2932 DescriptorArray* target_descriptors = target_map->instance_descriptors(); 2942 set_map(transition_map);
2933 int number = target_descriptors->SearchWithCache(name); 2943 return this;
2934 ASSERT(number != DescriptorArray::kNotFound);
2935 ASSERT(target_descriptors->GetType(number) == CONSTANT_FUNCTION);
2936 JSFunction* function =
2937 JSFunction::cast(target_descriptors->GetValue(number));
2938 if (value == function) {
2939 set_map(target_map);
2940 return value;
2941 } 2944 }
2942 // Otherwise, replace with a MAP_TRANSITION to a new map with a 2945 // Otherwise, replace with a map transition to a new map with a FIELD,
2943 // FIELD, even if the value is a constant function. 2946 // even if the value is a constant function.
2944 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); 2947 return ConvertDescriptorToFieldAndMapTransition(
2948 name, value, attributes);
2945 } 2949 }
2946 case HANDLER: 2950 case HANDLER:
2947 case NONEXISTENT: 2951 case NONEXISTENT:
2948 UNREACHABLE(); 2952 UNREACHABLE();
2949 return value; 2953 return value;
2950 } 2954 }
2951 UNREACHABLE(); // keep the compiler happy 2955 UNREACHABLE(); // keep the compiler happy
2952 return value; 2956 return value;
2953 } 2957 }
2954 2958
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3004 value, 3008 value,
3005 attributes); 3009 attributes);
3006 } 3010 }
3007 3011
3008 // Check for accessor in prototype chain removed here in clone. 3012 // Check for accessor in prototype chain removed here in clone.
3009 if (!result.IsFound()) { 3013 if (!result.IsFound()) {
3010 // Neither properties nor transitions found. 3014 // Neither properties nor transitions found.
3011 return AddProperty(name, value, attributes, kNonStrictMode); 3015 return AddProperty(name, value, attributes, kNonStrictMode);
3012 } 3016 }
3013 3017
3014 PropertyDetails details = PropertyDetails(attributes, NORMAL);
3015
3016 // Check of IsReadOnly removed from here in clone. 3018 // Check of IsReadOnly removed from here in clone.
3017 switch (result.type()) { 3019 switch (result.type()) {
3018 case NORMAL: 3020 case NORMAL: {
3021 PropertyDetails details = PropertyDetails(attributes, NORMAL);
3019 return SetNormalizedProperty(name, value, details); 3022 return SetNormalizedProperty(name, value, details);
3023 }
3020 case FIELD: 3024 case FIELD:
3021 return FastPropertyAtPut(result.GetFieldIndex(), value); 3025 return FastPropertyAtPut(result.GetFieldIndex(), value);
3022 case MAP_TRANSITION:
3023 if (attributes == result.GetAttributes()) {
3024 // Only use map transition if the attributes match.
3025 return AddFastPropertyUsingMap(result.GetTransitionMap(),
3026 name,
3027 value);
3028 }
3029 return ConvertDescriptorToField(name, value, attributes);
3030 case CONSTANT_FUNCTION: 3026 case CONSTANT_FUNCTION:
3031 // Only replace the function if necessary. 3027 // Only replace the function if necessary.
3032 if (value == result.GetConstantFunction()) return value; 3028 if (value == result.GetConstantFunction()) return value;
3033 // Preserve the attributes of this existing property. 3029 // Preserve the attributes of this existing property.
3034 attributes = result.GetAttributes(); 3030 attributes = result.GetAttributes();
3035 return ConvertDescriptorToField(name, value, attributes); 3031 return ConvertDescriptorToField(name, value, attributes);
3036 case CALLBACKS: 3032 case CALLBACKS:
3037 case INTERCEPTOR: 3033 case INTERCEPTOR:
3038 // Override callback in clone 3034 // Override callback in clone
3039 return ConvertDescriptorToField(name, value, attributes); 3035 return ConvertDescriptorToField(name, value, attributes);
3040 case CONSTANT_TRANSITION: 3036 case TRANSITION: {
3041 // Replace with a MAP_TRANSITION to a new map with a FIELD, even 3037 Object* transition = result.GetTransitionValue();
3042 // if the value is a function. 3038
3039 if (transition->IsAccessorPair()) {
3040 return ConvertDescriptorToField(name, value, attributes);
3041 }
3042
3043 Map* transition_map = Map::cast(transition);
3044 DescriptorArray* descriptors = transition_map->instance_descriptors();
3045 int descriptor = descriptors->Search(name);
3046 PropertyDetails details = descriptors->GetDetails(descriptor);
3047 ASSERT(details.type() == FIELD || details.type() == CONSTANT_FUNCTION);
3048
3049 if (details.type() == FIELD) {
3050 if (attributes == details.attributes()) {
3051 int field_index = descriptors->GetFieldIndex(descriptor);
3052 return AddFastPropertyUsingMap(transition_map,
3053 name,
3054 value,
3055 field_index);
3056 }
3057 return ConvertDescriptorToField(name, value, attributes);
3058 }
3059
3060 // Was transition to CONSTANT_FUNCTION. Replace with a map transition to a
3061 // new map with a FIELD, even if the value is a function.
3043 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); 3062 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes);
3063 }
3044 case HANDLER: 3064 case HANDLER:
3045 case NONEXISTENT: 3065 case NONEXISTENT:
3046 UNREACHABLE(); 3066 UNREACHABLE();
3047 } 3067 }
3048 UNREACHABLE(); // keep the compiler happy 3068 UNREACHABLE(); // keep the compiler happy
3049 return value; 3069 return value;
3050 } 3070 }
3051 3071
3052 3072
3053 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor( 3073 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3157 case CONSTANT_FUNCTION: 3177 case CONSTANT_FUNCTION:
3158 case CALLBACKS: 3178 case CALLBACKS:
3159 return result->GetAttributes(); 3179 return result->GetAttributes();
3160 case HANDLER: { 3180 case HANDLER: {
3161 return JSProxy::cast(result->proxy())->GetPropertyAttributeWithHandler( 3181 return JSProxy::cast(result->proxy())->GetPropertyAttributeWithHandler(
3162 receiver, name); 3182 receiver, name);
3163 } 3183 }
3164 case INTERCEPTOR: 3184 case INTERCEPTOR:
3165 return result->holder()->GetPropertyAttributeWithInterceptor( 3185 return result->holder()->GetPropertyAttributeWithInterceptor(
3166 JSObject::cast(receiver), name, continue_search); 3186 JSObject::cast(receiver), name, continue_search);
3167 default: 3187 case TRANSITION:
3188 case NONEXISTENT:
3168 UNREACHABLE(); 3189 UNREACHABLE();
3169 } 3190 }
3170 } 3191 }
3171 return ABSENT; 3192 return ABSENT;
3172 } 3193 }
3173 3194
3174 3195
3175 PropertyAttributes JSReceiver::GetLocalPropertyAttribute(String* name) { 3196 PropertyAttributes JSReceiver::GetLocalPropertyAttribute(String* name) {
3176 // Check whether the name is an array index. 3197 // Check whether the name is an array index.
3177 uint32_t index = 0; 3198 uint32_t index = 0;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3314 case FIELD: { 3335 case FIELD: {
3315 PropertyDetails d = 3336 PropertyDetails d =
3316 PropertyDetails(details.attributes(), NORMAL, details.index()); 3337 PropertyDetails(details.attributes(), NORMAL, details.index());
3317 Object* value = FastPropertyAt(descs->GetFieldIndex(i)); 3338 Object* value = FastPropertyAt(descs->GetFieldIndex(i));
3318 MaybeObject* maybe_dictionary = 3339 MaybeObject* maybe_dictionary =
3319 dictionary->Add(descs->GetKey(i), value, d); 3340 dictionary->Add(descs->GetKey(i), value, d);
3320 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; 3341 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
3321 break; 3342 break;
3322 } 3343 }
3323 case CALLBACKS: { 3344 case CALLBACKS: {
3324 if (!descs->IsProperty(i)) break;
3325 Object* value = descs->GetCallbacksObject(i); 3345 Object* value = descs->GetCallbacksObject(i);
3326 if (value->IsAccessorPair()) { 3346 if (value->IsAccessorPair()) {
3327 MaybeObject* maybe_copy = 3347 MaybeObject* maybe_copy =
3328 AccessorPair::cast(value)->CopyWithoutTransitions(); 3348 AccessorPair::cast(value)->CopyWithoutTransitions();
3329 if (!maybe_copy->To(&value)) return maybe_copy; 3349 if (!maybe_copy->To(&value)) return maybe_copy;
3330 } 3350 }
3331 MaybeObject* maybe_dictionary = 3351 MaybeObject* maybe_dictionary =
3332 dictionary->Add(descs->GetKey(i), value, details); 3352 dictionary->Add(descs->GetKey(i), value, details);
3333 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; 3353 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
3334 break; 3354 break;
3335 } 3355 }
3336 case MAP_TRANSITION:
3337 case CONSTANT_TRANSITION:
3338 case INTERCEPTOR: 3356 case INTERCEPTOR:
3339 break; 3357 break;
3340 case HANDLER: 3358 case HANDLER:
3341 case NORMAL: 3359 case NORMAL:
3360 case TRANSITION:
3342 case NONEXISTENT: 3361 case NONEXISTENT:
3343 UNREACHABLE(); 3362 UNREACHABLE();
3344 break; 3363 break;
3345 } 3364 }
3346 } 3365 }
3347 3366
3348 Heap* current_heap = GetHeap(); 3367 Heap* current_heap = GetHeap();
3349 3368
3350 // Copy the next enumeration index from instance descriptor. 3369 // Copy the next enumeration index from instance descriptor.
3351 int index = map_of_this->instance_descriptors()->NextEnumerationIndex(); 3370 int index = map_of_this->instance_descriptors()->NextEnumerationIndex();
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
3671 MaybeObject* JSObject::GetHiddenPropertiesDictionary(bool create_if_absent) { 3690 MaybeObject* JSObject::GetHiddenPropertiesDictionary(bool create_if_absent) {
3672 ASSERT(!IsJSGlobalProxy()); 3691 ASSERT(!IsJSGlobalProxy());
3673 if (HasFastProperties()) { 3692 if (HasFastProperties()) {
3674 // If the object has fast properties, check whether the first slot 3693 // If the object has fast properties, check whether the first slot
3675 // in the descriptor array matches the hidden symbol. Since the 3694 // in the descriptor array matches the hidden symbol. Since the
3676 // hidden symbols hash code is zero (and no other string has hash 3695 // hidden symbols hash code is zero (and no other string has hash
3677 // code zero) it will always occupy the first entry if present. 3696 // code zero) it will always occupy the first entry if present.
3678 DescriptorArray* descriptors = this->map()->instance_descriptors(); 3697 DescriptorArray* descriptors = this->map()->instance_descriptors();
3679 if ((descriptors->number_of_descriptors() > 0) && 3698 if ((descriptors->number_of_descriptors() > 0) &&
3680 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { 3699 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) {
3681 if (descriptors->GetType(0) == FIELD) { 3700 ASSERT(descriptors->GetType(0) == FIELD);
3682 Object* hidden_store = 3701 Object* hidden_store =
3683 this->FastPropertyAt(descriptors->GetFieldIndex(0)); 3702 this->FastPropertyAt(descriptors->GetFieldIndex(0));
3684 return StringDictionary::cast(hidden_store); 3703 return StringDictionary::cast(hidden_store);
3685 } else {
3686 ASSERT(descriptors->GetType(0) == MAP_TRANSITION);
3687 }
3688 } 3704 }
3689 } else { 3705 } else {
3690 PropertyAttributes attributes; 3706 PropertyAttributes attributes;
3691 // You can't install a getter on a property indexed by the hidden symbol, 3707 // You can't install a getter on a property indexed by the hidden symbol,
3692 // so we can be sure that GetLocalPropertyPostInterceptor returns a real 3708 // so we can be sure that GetLocalPropertyPostInterceptor returns a real
3693 // object. 3709 // object.
3694 Object* lookup = 3710 Object* lookup =
3695 GetLocalPropertyPostInterceptor(this, 3711 GetLocalPropertyPostInterceptor(this,
3696 GetHeap()->hidden_symbol(), 3712 GetHeap()->hidden_symbol(),
3697 &attributes)->ToObjectUnchecked(); 3713 &attributes)->ToObjectUnchecked();
(...skipping 22 matching lines...) Expand all
3720 ASSERT(!IsJSGlobalProxy()); 3736 ASSERT(!IsJSGlobalProxy());
3721 ASSERT(HasHiddenProperties()); 3737 ASSERT(HasHiddenProperties());
3722 if (HasFastProperties()) { 3738 if (HasFastProperties()) {
3723 // If the object has fast properties, check whether the first slot 3739 // If the object has fast properties, check whether the first slot
3724 // in the descriptor array matches the hidden symbol. Since the 3740 // in the descriptor array matches the hidden symbol. Since the
3725 // hidden symbols hash code is zero (and no other string has hash 3741 // hidden symbols hash code is zero (and no other string has hash
3726 // code zero) it will always occupy the first entry if present. 3742 // code zero) it will always occupy the first entry if present.
3727 DescriptorArray* descriptors = this->map()->instance_descriptors(); 3743 DescriptorArray* descriptors = this->map()->instance_descriptors();
3728 if ((descriptors->number_of_descriptors() > 0) && 3744 if ((descriptors->number_of_descriptors() > 0) &&
3729 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { 3745 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) {
3730 if (descriptors->GetType(0) == FIELD) { 3746 ASSERT(descriptors->GetType(0) == FIELD);
3731 this->FastPropertyAtPut(descriptors->GetFieldIndex(0), dictionary); 3747 this->FastPropertyAtPut(descriptors->GetFieldIndex(0), dictionary);
3732 return this; 3748 return this;
3733 } else {
3734 ASSERT(descriptors->GetType(0) == MAP_TRANSITION);
3735 }
3736 } 3749 }
3737 } 3750 }
3738 MaybeObject* store_result = 3751 MaybeObject* store_result =
3739 SetPropertyPostInterceptor(GetHeap()->hidden_symbol(), 3752 SetPropertyPostInterceptor(GetHeap()->hidden_symbol(),
3740 dictionary, 3753 dictionary,
3741 DONT_ENUM, 3754 DONT_ENUM,
3742 kNonStrictMode, 3755 kNonStrictMode,
3743 OMIT_EXTENSIBILITY_CHECK); 3756 OMIT_EXTENSIBILITY_CHECK);
3744 if (store_result->IsFailure()) return store_result; 3757 if (store_result->IsFailure()) return store_result;
3745 return this; 3758 return this;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4160 } 4173 }
4161 return true; 4174 return true;
4162 } 4175 }
4163 4176
4164 4177
4165 int Map::NumberOfDescribedProperties(PropertyAttributes filter) { 4178 int Map::NumberOfDescribedProperties(PropertyAttributes filter) {
4166 int result = 0; 4179 int result = 0;
4167 DescriptorArray* descs = instance_descriptors(); 4180 DescriptorArray* descs = instance_descriptors();
4168 for (int i = 0; i < descs->number_of_descriptors(); i++) { 4181 for (int i = 0; i < descs->number_of_descriptors(); i++) {
4169 PropertyDetails details = descs->GetDetails(i); 4182 PropertyDetails details = descs->GetDetails(i);
4170 if (descs->IsProperty(i) && (details.attributes() & filter) == 0) { 4183 if ((details.attributes() & filter) == 0) {
4171 result++; 4184 result++;
4172 } 4185 }
4173 } 4186 }
4174 return result; 4187 return result;
4175 } 4188 }
4176 4189
4177 4190
4178 int Map::PropertyIndexFor(String* name) { 4191 int Map::PropertyIndexFor(String* name) {
4179 DescriptorArray* descs = instance_descriptors(); 4192 DescriptorArray* descs = instance_descriptors();
4180 for (int i = 0; i < descs->number_of_descriptors(); i++) { 4193 for (int i = 0; i < descs->number_of_descriptors(); i++) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
4263 } 4276 }
4264 4277
4265 4278
4266 // Search object and its prototype chain for callback properties. 4279 // Search object and its prototype chain for callback properties.
4267 void JSObject::LookupCallback(String* name, LookupResult* result) { 4280 void JSObject::LookupCallback(String* name, LookupResult* result) {
4268 Heap* heap = GetHeap(); 4281 Heap* heap = GetHeap();
4269 for (Object* current = this; 4282 for (Object* current = this;
4270 current != heap->null_value() && current->IsJSObject(); 4283 current != heap->null_value() && current->IsJSObject();
4271 current = JSObject::cast(current)->GetPrototype()) { 4284 current = JSObject::cast(current)->GetPrototype()) {
4272 JSObject::cast(current)->LocalLookupRealNamedProperty(name, result); 4285 JSObject::cast(current)->LocalLookupRealNamedProperty(name, result);
4286 // TODO(verwaest) clean test
4273 if (result->IsCallbacks()) return; 4287 if (result->IsCallbacks()) return;
4274 } 4288 }
4275 result->NotFound(); 4289 result->NotFound();
4276 } 4290 }
4277 4291
4278 4292
4279 // Try to update an accessor in an elements dictionary. Return true if the 4293 // Try to update an accessor in an elements dictionary. Return true if the
4280 // update succeeded, and false otherwise. 4294 // update succeeded, and false otherwise.
4281 static bool UpdateGetterSetterInDictionary( 4295 static bool UpdateGetterSetterInDictionary(
4282 SeededNumberDictionary* dictionary, 4296 SeededNumberDictionary* dictionary,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4366 } 4380 }
4367 accessors->SetComponents(getter, setter); 4381 accessors->SetComponents(getter, setter);
4368 4382
4369 return SetElementCallback(index, accessors, attributes); 4383 return SetElementCallback(index, accessors, attributes);
4370 } 4384 }
4371 4385
4372 4386
4373 MaybeObject* JSObject::CreateAccessorPairFor(String* name) { 4387 MaybeObject* JSObject::CreateAccessorPairFor(String* name) {
4374 LookupResult result(GetHeap()->isolate()); 4388 LookupResult result(GetHeap()->isolate());
4375 LocalLookupRealNamedProperty(name, &result); 4389 LocalLookupRealNamedProperty(name, &result);
4376 if (result.IsProperty() && result.IsCallbacks()) { 4390 if (result.IsPropertyCallbacks()) {
4377 // Note that the result can actually have IsDontDelete() == true when we 4391 // Note that the result can actually have IsDontDelete() == true when we
4378 // e.g. have to fall back to the slow case while adding a setter after 4392 // e.g. have to fall back to the slow case while adding a setter after
4379 // successfully reusing a map transition for a getter. Nevertheless, this is 4393 // successfully reusing a map transition for a getter. Nevertheless, this is
4380 // OK, because the assertion only holds for the whole addition of both 4394 // OK, because the assertion only holds for the whole addition of both
4381 // accessors, not for the addition of each part. See first comment in 4395 // accessors, not for the addition of each part. See first comment in
4382 // DefinePropertyAccessor below. 4396 // DefinePropertyAccessor below.
4383 Object* obj = result.GetCallbackObject(); 4397 Object* obj = result.GetCallbackObject();
4384 if (obj->IsAccessorPair()) { 4398 if (obj->IsAccessorPair()) {
4385 return AccessorPair::cast(obj)->CopyWithoutTransitions(); 4399 return AccessorPair::cast(obj)->CopyWithoutTransitions();
4386 } 4400 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
4575 { MaybeObject* maybe_accessors2 = heap->AllocateAccessorPair(); 4589 { MaybeObject* maybe_accessors2 = heap->AllocateAccessorPair();
4576 if (!maybe_accessors2->To(&accessors2)) return maybe_accessors2; 4590 if (!maybe_accessors2->To(&accessors2)) return maybe_accessors2;
4577 } 4591 }
4578 accessors2->set(component, accessor); 4592 accessors2->set(component, accessor);
4579 4593
4580 // step 2: create a copy of the descriptors, incl. the new getter/setter pair 4594 // step 2: create a copy of the descriptors, incl. the new getter/setter pair
4581 Map* map1 = obj->map(); 4595 Map* map1 = obj->map();
4582 CallbacksDescriptor callbacks_descr2(name, accessors2, attributes); 4596 CallbacksDescriptor callbacks_descr2(name, accessors2, attributes);
4583 DescriptorArray* descriptors2; 4597 DescriptorArray* descriptors2;
4584 { MaybeObject* maybe_descriptors2 = 4598 { MaybeObject* maybe_descriptors2 =
4585 map1->instance_descriptors()->CopyInsert(&callbacks_descr2, 4599 map1->instance_descriptors()->CopyInsert(&callbacks_descr2);
4586 REMOVE_TRANSITIONS);
4587 if (!maybe_descriptors2->To(&descriptors2)) return maybe_descriptors2; 4600 if (!maybe_descriptors2->To(&descriptors2)) return maybe_descriptors2;
4588 } 4601 }
4589 4602
4590 // step 3: create a new map with the new descriptors 4603 // step 3: create a new map with the new descriptors
4591 Map* map2; 4604 Map* map2;
4592 { MaybeObject* maybe_map2 = map1->CopyDropDescriptors(); 4605 { MaybeObject* maybe_map2 = map1->CopyDropDescriptors();
4593 if (!maybe_map2->To(&map2)) return maybe_map2; 4606 if (!maybe_map2->To(&map2)) return maybe_map2;
4594 } 4607 }
4595 map2->set_instance_descriptors(descriptors2); 4608 map2->set_instance_descriptors(descriptors2);
4596 4609
4597 // step 4: create a new getter/setter pair with a transition to the new map 4610 // step 4: create a new getter/setter pair with a transition to the new map
4598 AccessorPair* accessors1; 4611 AccessorPair* accessors1;
4599 { MaybeObject* maybe_accessors1 = heap->AllocateAccessorPair(); 4612 { MaybeObject* maybe_accessors1 = heap->AllocateAccessorPair();
4600 if (!maybe_accessors1->To(&accessors1)) return maybe_accessors1; 4613 if (!maybe_accessors1->To(&accessors1)) return maybe_accessors1;
4601 } 4614 }
4602 accessors1->set(component, map2); 4615 accessors1->set(component, map2);
4603 4616
4604 // step 5: create a copy of the descriptors, incl. the new getter/setter pair 4617 // step 5: create a copy of the descriptors, incl. the new getter/setter pair
4605 // with the transition 4618 // with the transition
4606 CallbacksDescriptor callbacks_descr1(name, accessors1, attributes); 4619 TransitionArray* new_transitions;
4607 DescriptorArray* descriptors1; 4620 MaybeObject* maybe_new_transitions = map1->AddTransition(name, accessors1);
4608 { MaybeObject* maybe_descriptors1 = 4621 if (!maybe_new_transitions->To(&new_transitions)) {
4609 map1->instance_descriptors()->CopyInsert(&callbacks_descr1, 4622 // We have accomplished the main goal, so return success.
4610 KEEP_TRANSITIONS); 4623 return maybe_new_transitions;
4611 if (!maybe_descriptors1->To(&descriptors1)) return maybe_descriptors1;
4612 } 4624 }
4613 4625
4614 // step 6: everything went well so far, so we make our changes visible 4626 // step 6: everything went well so far, so we make our changes visible
4627 MaybeObject* transition_added = map1->set_transitions(new_transitions);
4628 if (transition_added->IsFailure()) return transition_added;
4629 map2->SetBackPointer(map1);
4615 obj->set_map(map2); 4630 obj->set_map(map2);
4616 map1->set_instance_descriptors(descriptors1);
4617 map2->SetBackPointer(map1);
4618 return obj; 4631 return obj;
4619 } 4632 }
4620 4633
4621 4634
4622 static bool TransitionToSameAccessor(Object* map, 4635 static bool TransitionToSameAccessor(Object* map,
4623 String* name, 4636 String* name,
4624 AccessorComponent component, 4637 AccessorComponent component,
4625 Object* accessor, 4638 Object* accessor,
4626 PropertyAttributes attributes ) { 4639 PropertyAttributes attributes ) {
4627 DescriptorArray* descs = Map::cast(map)->instance_descriptors(); 4640 DescriptorArray* descs = Map::cast(map)->instance_descriptors();
(...skipping 17 matching lines...) Expand all
4645 { MaybeObject* maybe_accessors3 = accessors2->CopyWithoutTransitions(); 4658 { MaybeObject* maybe_accessors3 = accessors2->CopyWithoutTransitions();
4646 if (!maybe_accessors3->To(&accessors3)) return maybe_accessors3; 4659 if (!maybe_accessors3->To(&accessors3)) return maybe_accessors3;
4647 } 4660 }
4648 accessors3->set(component, accessor); 4661 accessors3->set(component, accessor);
4649 4662
4650 // step 2: create a copy of the descriptors, incl. the new getter/setter pair 4663 // step 2: create a copy of the descriptors, incl. the new getter/setter pair
4651 Map* map2 = obj->map(); 4664 Map* map2 = obj->map();
4652 CallbacksDescriptor callbacks_descr3(name, accessors3, attributes); 4665 CallbacksDescriptor callbacks_descr3(name, accessors3, attributes);
4653 DescriptorArray* descriptors3; 4666 DescriptorArray* descriptors3;
4654 { MaybeObject* maybe_descriptors3 = 4667 { MaybeObject* maybe_descriptors3 =
4655 map2->instance_descriptors()->CopyInsert(&callbacks_descr3, 4668 map2->instance_descriptors()->CopyInsert(&callbacks_descr3);
4656 REMOVE_TRANSITIONS);
4657 if (!maybe_descriptors3->To(&descriptors3)) return maybe_descriptors3; 4669 if (!maybe_descriptors3->To(&descriptors3)) return maybe_descriptors3;
4658 } 4670 }
4659 4671
4660 // step 3: create a new map with the new descriptors 4672 // step 3: create a new map with the new descriptors
4661 Map* map3; 4673 Map* map3;
4662 { MaybeObject* maybe_map3 = map2->CopyDropDescriptors(); 4674 { MaybeObject* maybe_map3 = map2->CopyDropDescriptors();
4663 if (!maybe_map3->To(&map3)) return maybe_map3; 4675 if (!maybe_map3->To(&map3)) return maybe_map3;
4664 } 4676 }
4665 map3->set_instance_descriptors(descriptors3); 4677 map3->set_instance_descriptors(descriptors3);
4666 4678
4667 // step 4: everything went well so far, so we make our changes visible 4679 // step 4: add a new transition to the new map
4680 TransitionArray* new_transitions;
4681 MaybeObject* maybe_transitions = map2->AddTransition(name, accessors2);
4682 if (!maybe_transitions->To(&new_transitions)) return maybe_transitions;
4683
4684 // step 5: everything went well so far, so we make our changes visible
4685 MaybeObject* transition_added = map2->set_transitions(new_transitions);
4686 if (transition_added->IsFailure()) return transition_added;
4687
4688 map3->SetBackPointer(map2);
4668 obj->set_map(map3); 4689 obj->set_map(map3);
4669 accessors2->set(component, map3); 4690 accessors2->set(component, map3);
4670 map3->SetBackPointer(map2);
4671 return obj; 4691 return obj;
4672 } 4692 }
4673 4693
4674 4694
4675 MaybeObject* JSObject::DefineFastAccessor(String* name, 4695 MaybeObject* JSObject::DefineFastAccessor(String* name,
4676 AccessorComponent component, 4696 AccessorComponent component,
4677 Object* accessor, 4697 Object* accessor,
4678 PropertyAttributes attributes) { 4698 PropertyAttributes attributes) {
4679 ASSERT(accessor->IsSpecFunction() || accessor->IsUndefined()); 4699 ASSERT(accessor->IsSpecFunction() || accessor->IsUndefined());
4680 LookupResult result(GetIsolate()); 4700 LookupResult result(GetIsolate());
4681 LocalLookup(name, &result); 4701 LocalLookup(name, &result);
4682 4702
4683 // If we have a new property, create a fresh accessor plus a transition to it. 4703 // If we have a new property, create a fresh accessor plus a transition to it.
4684 if (!result.IsFound()) { 4704 if (!result.IsFound()) {
4685 return CreateFreshAccessor(this, name, component, accessor, attributes); 4705 return CreateFreshAccessor(this, name, component, accessor, attributes);
4686 } 4706 }
4687 4707
4688 // If the property is not a JavaScript accessor, fall back to the slow case. 4708 // If the property is not a JavaScript accessor, fall back to the slow case.
4689 if (result.type() != CALLBACKS) return GetHeap()->null_value(); 4709 if (!result.IsCallbacks()) return GetHeap()->null_value();
4710
4690 Object* callback_value = result.GetCallbackObject(); 4711 Object* callback_value = result.GetCallbackObject();
4691 if (!callback_value->IsAccessorPair()) return GetHeap()->null_value(); 4712 if (!callback_value->IsAccessorPair()) return GetHeap()->null_value();
4692 AccessorPair* accessors = AccessorPair::cast(callback_value); 4713 AccessorPair* accessors = AccessorPair::cast(callback_value);
4693 4714
4694 // Follow a callback transition, if there is a fitting one. 4715 // Follow a callback transition, if there is a fitting one.
4695 Object* entry = accessors->get(component); 4716 Object* entry = accessors->get(component);
4696 if (entry->IsMap() && 4717 if (entry->IsMap() &&
4697 TransitionToSameAccessor(entry, name, component, accessor, attributes)) { 4718 TransitionToSameAccessor(entry, name, component, accessor, attributes)) {
4698 set_map(Map::cast(entry)); 4719 set_map(Map::cast(entry));
4699 return this; 4720 return this;
4700 } 4721 }
4701 4722
4702 // When we re-add the same accessor again, there is nothing to do.
4703 if (entry == accessor && result.GetAttributes() == attributes) return this; 4723 if (entry == accessor && result.GetAttributes() == attributes) return this;
4704 4724
4705 // Only the other accessor has been set so far, create a new transition. 4725 // Only the other accessor has been set so far, create a new transition.
4706 if (entry->IsTheHole()) { 4726 if (entry->IsTheHole()) {
4707 return NewCallbackTransition(this, 4727 return NewCallbackTransition(this,
4708 name, 4728 name,
4709 component, 4729 component,
4710 accessor, 4730 accessor,
4711 attributes, 4731 attributes,
4712 accessors); 4732 accessors);
(...skipping 21 matching lines...) Expand all
4734 return JSObject::cast(proto)->DefineAccessor(info); 4754 return JSObject::cast(proto)->DefineAccessor(info);
4735 } 4755 }
4736 4756
4737 // Make sure that the top context does not change when doing callbacks or 4757 // Make sure that the top context does not change when doing callbacks or
4738 // interceptor calls. 4758 // interceptor calls.
4739 AssertNoContextChange ncc; 4759 AssertNoContextChange ncc;
4740 4760
4741 // Try to flatten before operating on the string. 4761 // Try to flatten before operating on the string.
4742 name->TryFlatten(); 4762 name->TryFlatten();
4743 4763
4744 if (!CanSetCallback(name)) { 4764 if (!CanSetCallback(name)) return isolate->heap()->undefined_value();
4745 return isolate->heap()->undefined_value();
4746 }
4747 4765
4748 uint32_t index = 0; 4766 uint32_t index = 0;
4749 bool is_element = name->AsArrayIndex(&index); 4767 bool is_element = name->AsArrayIndex(&index);
4750 4768
4751 if (is_element) { 4769 if (is_element) {
4752 if (IsJSArray()) return isolate->heap()->undefined_value(); 4770 if (IsJSArray()) return isolate->heap()->undefined_value();
4753 4771
4754 // Accessors overwrite previous callbacks (cf. with getters/setters). 4772 // Accessors overwrite previous callbacks (cf. with getters/setters).
4755 switch (GetElementsKind()) { 4773 switch (GetElementsKind()) {
4756 case FAST_SMI_ELEMENTS: 4774 case FAST_SMI_ELEMENTS:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
4836 } 4854 }
4837 } 4855 }
4838 } else { 4856 } else {
4839 for (Object* obj = this; 4857 for (Object* obj = this;
4840 obj != heap->null_value(); 4858 obj != heap->null_value();
4841 obj = JSObject::cast(obj)->GetPrototype()) { 4859 obj = JSObject::cast(obj)->GetPrototype()) {
4842 LookupResult result(heap->isolate()); 4860 LookupResult result(heap->isolate());
4843 JSObject::cast(obj)->LocalLookup(name, &result); 4861 JSObject::cast(obj)->LocalLookup(name, &result);
4844 if (result.IsProperty()) { 4862 if (result.IsProperty()) {
4845 if (result.IsReadOnly()) return heap->undefined_value(); 4863 if (result.IsReadOnly()) return heap->undefined_value();
4846 if (result.IsCallbacks()) { 4864 if (result.IsPropertyCallbacks()) {
4847 Object* obj = result.GetCallbackObject(); 4865 Object* obj = result.GetCallbackObject();
4848 if (obj->IsAccessorPair()) { 4866 if (obj->IsAccessorPair()) {
4849 return AccessorPair::cast(obj)->GetComponent(component); 4867 return AccessorPair::cast(obj)->GetComponent(component);
4850 } 4868 }
4851 } 4869 }
4852 } 4870 }
4853 } 4871 }
4854 } 4872 }
4855 return heap->undefined_value(); 4873 return heap->undefined_value();
4856 } 4874 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4896 Map::cast(result)->set_inobject_properties(inobject_properties()); 4914 Map::cast(result)->set_inobject_properties(inobject_properties());
4897 Map::cast(result)->set_unused_property_fields(unused_property_fields()); 4915 Map::cast(result)->set_unused_property_fields(unused_property_fields());
4898 4916
4899 // If the map has pre-allocated properties always start out with a descriptor 4917 // If the map has pre-allocated properties always start out with a descriptor
4900 // array describing these properties. 4918 // array describing these properties.
4901 if (pre_allocated_property_fields() > 0) { 4919 if (pre_allocated_property_fields() > 0) {
4902 ASSERT(constructor()->IsJSFunction()); 4920 ASSERT(constructor()->IsJSFunction());
4903 JSFunction* ctor = JSFunction::cast(constructor()); 4921 JSFunction* ctor = JSFunction::cast(constructor());
4904 Object* descriptors; 4922 Object* descriptors;
4905 { MaybeObject* maybe_descriptors = 4923 { MaybeObject* maybe_descriptors =
4906 ctor->initial_map()->instance_descriptors()->RemoveTransitions( 4924 ctor->initial_map()->instance_descriptors()->Copy(
4907 DescriptorArray::MAY_BE_SHARED); 4925 DescriptorArray::MAY_BE_SHARED);
4908 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors; 4926 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors;
4909 } 4927 }
4910 Map::cast(result)->set_instance_descriptors( 4928 Map::cast(result)->set_instance_descriptors(
4911 DescriptorArray::cast(descriptors)); 4929 DescriptorArray::cast(descriptors));
4912 Map::cast(result)->set_pre_allocated_property_fields( 4930 Map::cast(result)->set_pre_allocated_property_fields(
4913 pre_allocated_property_fields()); 4931 pre_allocated_property_fields());
4914 } 4932 }
4915 Map::cast(result)->set_bit_field(bit_field()); 4933 Map::cast(result)->set_bit_field(bit_field());
4916 Map::cast(result)->set_bit_field2(bit_field2()); 4934 Map::cast(result)->set_bit_field2(bit_field2());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4959 4977
4960 4978
4961 MaybeObject* Map::CopyDropTransitions( 4979 MaybeObject* Map::CopyDropTransitions(
4962 DescriptorArray::SharedMode shared_mode) { 4980 DescriptorArray::SharedMode shared_mode) {
4963 Object* new_map; 4981 Object* new_map;
4964 { MaybeObject* maybe_new_map = CopyDropDescriptors(); 4982 { MaybeObject* maybe_new_map = CopyDropDescriptors();
4965 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; 4983 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map;
4966 } 4984 }
4967 Object* descriptors; 4985 Object* descriptors;
4968 { MaybeObject* maybe_descriptors = 4986 { MaybeObject* maybe_descriptors =
4969 instance_descriptors()->RemoveTransitions(shared_mode); 4987 instance_descriptors()->Copy(shared_mode);
4970 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors; 4988 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors;
4971 } 4989 }
4972 cast(new_map)->set_instance_descriptors(DescriptorArray::cast(descriptors)); 4990 cast(new_map)->set_instance_descriptors(DescriptorArray::cast(descriptors));
4973 return new_map; 4991 return new_map;
4974 } 4992 }
4975 4993
4976 4994
4977 void Map::UpdateCodeCache(Handle<Map> map, 4995 void Map::UpdateCodeCache(Handle<Map> map,
4978 Handle<String> name, 4996 Handle<String> name,
4979 Handle<Code> code) { 4997 Handle<Code> code) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5023 // RemoveFromCodeCache so the code cache must be there. 5041 // RemoveFromCodeCache so the code cache must be there.
5024 ASSERT(!code_cache()->IsFixedArray()); 5042 ASSERT(!code_cache()->IsFixedArray());
5025 CodeCache::cast(code_cache())->RemoveByIndex(name, code, index); 5043 CodeCache::cast(code_cache())->RemoveByIndex(name, code, index);
5026 } 5044 }
5027 5045
5028 5046
5029 // An iterator over all map transitions in an descriptor array, reusing the map 5047 // An iterator over all map transitions in an descriptor array, reusing the map
5030 // field of the contens array while it is running. 5048 // field of the contens array while it is running.
5031 class IntrusiveMapTransitionIterator { 5049 class IntrusiveMapTransitionIterator {
5032 public: 5050 public:
5033 explicit IntrusiveMapTransitionIterator(DescriptorArray* descriptor_array) 5051 explicit IntrusiveMapTransitionIterator(TransitionArray* transition_array)
5034 : descriptor_array_(descriptor_array) { } 5052 : transition_array_(transition_array) { }
5035 5053
5036 void Start() { 5054 void Start() {
5037 ASSERT(!IsIterating()); 5055 ASSERT(!IsIterating());
5038 if (descriptor_array_->MayContainTransitions()) 5056 *TransitionArrayHeader() = Smi::FromInt(0);
5039 *DescriptorArrayHeader() = Smi::FromInt(0);
5040 } 5057 }
5041 5058
5042 bool IsIterating() { 5059 bool IsIterating() {
5043 return descriptor_array_->MayContainTransitions() && 5060 return (*TransitionArrayHeader())->IsSmi();
5044 (*DescriptorArrayHeader())->IsSmi();
5045 } 5061 }
5046 5062
5047 Map* Next() { 5063 Map* Next() {
5048 ASSERT(IsIterating()); 5064 ASSERT(IsIterating());
5049 // Attention, tricky index manipulation ahead: Two consecutive indices are 5065 // Attention, tricky index manipulation ahead: Two consecutive indices are
5050 // assigned to each descriptor. Most descriptors directly advance to the 5066 // assigned to each descriptor. Most descriptors directly advance to the
5051 // next descriptor by adding 2 to the index. The exceptions are the 5067 // next descriptor by adding 2 to the index. The exceptions are the
5052 // CALLBACKS entries: An even index means we look at its getter, and an odd 5068 // CALLBACKS entries: An even index means we look at its getter, and an odd
5053 // index means we look at its setter. 5069 // index means we look at its setter.
5054 int raw_index = Smi::cast(*DescriptorArrayHeader())->value(); 5070 int raw_index = Smi::cast(*TransitionArrayHeader())->value();
5055 int index = raw_index / 2; 5071 int index = raw_index / 2;
5056 int number_of_descriptors = descriptor_array_->number_of_descriptors(); 5072 int number_of_transitions = transition_array_->number_of_transitions();
5057 while (index < number_of_descriptors) { 5073 while (index < number_of_transitions) {
5058 PropertyDetails details(descriptor_array_->GetDetails(index)); 5074 Object* value = transition_array_->GetValue(index);
5059 switch (details.type()) { 5075 if (value->IsMap()) {
5060 case MAP_TRANSITION: 5076 *TransitionArrayHeader() = Smi::FromInt(raw_index + 2);
5061 case CONSTANT_TRANSITION: 5077 return static_cast<Map*>(value);
5062 // We definitely have a map transition. 5078 } else if (value->IsAccessorPair()) {
5063 *DescriptorArrayHeader() = Smi::FromInt(raw_index + 2); 5079 // We might have a map transition in a getter or in a setter.
5064 return static_cast<Map*>(descriptor_array_->GetValue(index)); 5080 AccessorPair* accessors = static_cast<AccessorPair*>(value);
5065 case CALLBACKS: { 5081 Object* accessor;
5066 // We might have a map transition in a getter or in a setter. 5082 if ((raw_index & 1) == 0) {
5067 AccessorPair* accessors = 5083 accessor = accessors->setter();
5068 static_cast<AccessorPair*>(descriptor_array_->GetValue(index)); 5084 } else {
5069 Object* accessor; 5085 ++index;
5070 if ((raw_index & 1) == 0) { 5086 accessor = accessors->getter();
5071 accessor = accessors->setter();
5072 } else {
5073 ++index;
5074 accessor = accessors->getter();
5075 }
5076 ++raw_index;
5077 if (accessor->IsMap()) {
5078 *DescriptorArrayHeader() = Smi::FromInt(raw_index);
5079 return static_cast<Map*>(accessor);
5080 }
5081 break;
5082 } 5087 }
5083 case NORMAL: 5088 ++raw_index;
5084 case FIELD: 5089 if (accessor->IsMap()) {
5085 case CONSTANT_FUNCTION: 5090 *TransitionArrayHeader() = Smi::FromInt(raw_index);
5086 case HANDLER: 5091 return static_cast<Map*>(accessor);
5087 case INTERCEPTOR: 5092 }
5088 // We definitely have no map transition. 5093 break;
5089 raw_index += 2;
5090 ++index;
5091 break;
5092 case NONEXISTENT:
5093 UNREACHABLE();
5094 break;
5095 } 5094 }
5095 // We definitely have no map transition.
5096 raw_index += 2;
5097 ++index;
5096 } 5098 }
5097 if (index == descriptor_array_->number_of_descriptors()) { 5099
5098 Map* elements_transition = descriptor_array_->elements_transition_map(); 5100 if (index == transition_array_->number_of_transitions() &&
5099 if (elements_transition != NULL) { 5101 transition_array_->HasElementsTransition()) {
5100 *DescriptorArrayHeader() = Smi::FromInt(raw_index + 2); 5102 Map* elements_transition = transition_array_->elements_transition();
5101 return elements_transition; 5103 *TransitionArrayHeader() = Smi::FromInt(raw_index + 2);
5102 } 5104 return elements_transition;
5103 } 5105 }
5104 *DescriptorArrayHeader() = descriptor_array_->GetHeap()->fixed_array_map(); 5106 *TransitionArrayHeader() = transition_array_->GetHeap()->fixed_array_map();
5105 return NULL; 5107 return NULL;
5106 } 5108 }
5107 5109
5108 private: 5110 private:
5109 Object** DescriptorArrayHeader() { 5111 Object** TransitionArrayHeader() {
5110 return HeapObject::RawField(descriptor_array_, DescriptorArray::kMapOffset); 5112 return HeapObject::RawField(transition_array_, TransitionArray::kMapOffset);
5111 } 5113 }
5112 5114
5113 DescriptorArray* descriptor_array_; 5115 TransitionArray* transition_array_;
5114 }; 5116 };
5115 5117
5116 5118
5117 // An iterator over all prototype transitions, reusing the map field of the 5119 // An iterator over all prototype transitions, reusing the map field of the
5118 // underlying array while it is running. 5120 // underlying array while it is running.
5119 class IntrusivePrototypeTransitionIterator { 5121 class IntrusivePrototypeTransitionIterator {
5120 public: 5122 public:
5121 explicit IntrusivePrototypeTransitionIterator(HeapObject* proto_trans) 5123 explicit IntrusivePrototypeTransitionIterator(HeapObject* proto_trans)
5122 : proto_trans_(proto_trans) { } 5124 : proto_trans_(proto_trans) { }
5123 5125
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5203 5205
5204 // Reset the current map's map, returning the parent previously stored in it. 5206 // Reset the current map's map, returning the parent previously stored in it.
5205 TraversableMap* GetAndResetParent() { 5207 TraversableMap* GetAndResetParent() {
5206 TraversableMap* old_parent = static_cast<TraversableMap*>(map()); 5208 TraversableMap* old_parent = static_cast<TraversableMap*>(map());
5207 set_map_no_write_barrier(GetHeap()->meta_map()); 5209 set_map_no_write_barrier(GetHeap()->meta_map());
5208 return old_parent; 5210 return old_parent;
5209 } 5211 }
5210 5212
5211 // Can either be Smi (no instance descriptors), or a descriptor array with the 5213 // Can either be Smi (no instance descriptors), or a descriptor array with the
5212 // header overwritten as a Smi (thus iterating). 5214 // header overwritten as a Smi (thus iterating).
5213 DescriptorArray* MutatedInstanceDescriptors() { 5215 TransitionArray* MutatedTransitions() {
5214 Object* object = 5216 Object* object = *HeapObject::RawField(instance_descriptors(),
5215 *HeapObject::RawField(this, kInstanceDescriptorsOrBitField3Offset); 5217 DescriptorArray::kTransitionsOffset);
5216 if (object->IsSmi()) { 5218 TransitionArray* transition_array = static_cast<TransitionArray*>(object);
5217 return GetHeap()->empty_descriptor_array(); 5219 return transition_array;
5218 } else {
5219 DescriptorArray* descriptor_array =
5220 static_cast<DescriptorArray*>(object);
5221 return descriptor_array;
5222 }
5223 } 5220 }
5224 5221
5225 // Start iterating over this map's children, possibly destroying a FixedArray 5222 // Start iterating over this map's children, possibly destroying a FixedArray
5226 // map (see explanation above). 5223 // map (see explanation above).
5227 void ChildIteratorStart() { 5224 void ChildIteratorStart() {
5228 IntrusiveMapTransitionIterator(instance_descriptors()).Start(); 5225 if (HasTransitionArray()) {
5226 IntrusiveMapTransitionIterator(transitions()).Start();
5227 }
5229 IntrusivePrototypeTransitionIterator( 5228 IntrusivePrototypeTransitionIterator(
5230 unchecked_prototype_transitions()).Start(); 5229 unchecked_prototype_transitions()).Start();
5231 } 5230 }
5232 5231
5233 // If we have an unvisited child map, return that one and advance. If we have 5232 // If we have an unvisited child map, return that one and advance. If we have
5234 // none, return NULL and reset any destroyed FixedArray maps. 5233 // none, return NULL and reset any destroyed FixedArray maps.
5235 TraversableMap* ChildIteratorNext() { 5234 TraversableMap* ChildIteratorNext() {
5236 IntrusivePrototypeTransitionIterator 5235 IntrusivePrototypeTransitionIterator
5237 proto_iterator(unchecked_prototype_transitions()); 5236 proto_iterator(unchecked_prototype_transitions());
5238 if (proto_iterator.IsIterating()) { 5237 if (proto_iterator.IsIterating()) {
5239 Map* next = proto_iterator.Next(); 5238 Map* next = proto_iterator.Next();
5240 if (next != NULL) return static_cast<TraversableMap*>(next); 5239 if (next != NULL) return static_cast<TraversableMap*>(next);
5241 } 5240 }
5242 IntrusiveMapTransitionIterator 5241 if (HasTransitionArray()) {
5243 descriptor_iterator(MutatedInstanceDescriptors()); 5242 IntrusiveMapTransitionIterator
5244 if (descriptor_iterator.IsIterating()) { 5243 transitions_iterator(MutatedTransitions());
5245 Map* next = descriptor_iterator.Next(); 5244 if (transitions_iterator.IsIterating()) {
5246 if (next != NULL) return static_cast<TraversableMap*>(next); 5245 Map* next = transitions_iterator.Next();
5246 if (next != NULL) return static_cast<TraversableMap*>(next);
5247 }
5247 } 5248 }
5248 return NULL; 5249 return NULL;
5249 } 5250 }
5250 }; 5251 };
5251 5252
5252 5253
5253 // Traverse the transition tree in postorder without using the C++ stack by 5254 // Traverse the transition tree in postorder without using the C++ stack by
5254 // doing pointer reversal. 5255 // doing pointer reversal.
5255 void Map::TraverseTransitionTree(TraverseCallback callback, void* data) { 5256 void Map::TraverseTransitionTree(TraverseCallback callback, void* data) {
5256 TraversableMap* current = static_cast<TraversableMap*>(this); 5257 TraversableMap* current = static_cast<TraversableMap*>(this);
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
5865 MaybeObject* maybe_copy = 5866 MaybeObject* maybe_copy =
5866 AccessorPair::cast(value)->CopyWithoutTransitions(); 5867 AccessorPair::cast(value)->CopyWithoutTransitions();
5867 if (!maybe_copy->To(&value)) return maybe_copy; 5868 if (!maybe_copy->To(&value)) return maybe_copy;
5868 } 5869 }
5869 Descriptor desc(src->GetKey(src_index), value, details); 5870 Descriptor desc(src->GetKey(src_index), value, details);
5870 Set(dst_index, &desc, witness); 5871 Set(dst_index, &desc, witness);
5871 return this; 5872 return this;
5872 } 5873 }
5873 5874
5874 5875
5875 MaybeObject* DescriptorArray::CopyInsert(Descriptor* descriptor, 5876 MaybeObject* DescriptorArray::CopyInsert(Descriptor* descriptor) {
5876 TransitionFlag transition_flag) {
5877 // Transitions are only kept when inserting another transition.
5878 // This precondition is not required by this function's implementation, but
5879 // is currently required by the semantics of maps, so we check it.
5880 // Conversely, we filter after replacing, so replacing a transition and
5881 // removing all other transitions is not supported.
5882 bool remove_transitions = transition_flag == REMOVE_TRANSITIONS;
5883 ASSERT(remove_transitions == !descriptor->ContainsTransition());
5884
5885 // Ensure the key is a symbol. 5877 // Ensure the key is a symbol.
5886 { MaybeObject* maybe_result = descriptor->KeyToSymbol(); 5878 { MaybeObject* maybe_result = descriptor->KeyToSymbol();
5887 if (maybe_result->IsFailure()) return maybe_result; 5879 if (maybe_result->IsFailure()) return maybe_result;
5888 } 5880 }
5889 5881
5890 int new_size = 0; 5882 int new_size = number_of_descriptors();
5891 for (int i = 0; i < number_of_descriptors(); i++) {
5892 if (remove_transitions && IsTransitionOnly(i)) continue;
5893 new_size++;
5894 }
5895 5883
5896 // If key is in descriptor, we replace it in-place when filtering. 5884 // If key is in descriptor, we replace it in-place when filtering.
5897 // Count a null descriptor for key as inserted, not replaced. 5885 // Count a null descriptor for key as inserted, not replaced.
5898 int index = Search(descriptor->GetKey()); 5886 int index = SearchWithCache(descriptor->GetKey());
5899 const bool replacing = (index != kNotFound); 5887 const bool replacing = (index != kNotFound);
5900 bool keep_enumeration_index = false; 5888 bool keep_enumeration_index = false;
5901 if (!replacing) { 5889 if (replacing) {
5902 ++new_size;
5903 } else if (!IsTransitionOnly(index)) {
5904 // We are replacing an existing descriptor. We keep the enumeration index 5890 // We are replacing an existing descriptor. We keep the enumeration index
5905 // of a visible property. 5891 // of a visible property.
5906 keep_enumeration_index = true; 5892 keep_enumeration_index = true;
5907 } else if (remove_transitions) { 5893 } else {
5908 // Replaced descriptor has been counted as removed if it is a transition
5909 // that will be replaced. Adjust count in this case.
5910 ++new_size; 5894 ++new_size;
5911 } 5895 }
5912 5896
5913 DescriptorArray* new_descriptors; 5897 DescriptorArray* new_descriptors;
5914 { SharedMode mode = remove_transitions ? MAY_BE_SHARED : CANNOT_BE_SHARED; 5898 { MaybeObject* maybe_result = Allocate(new_size, MAY_BE_SHARED);
5915 MaybeObject* maybe_result = Allocate(new_size, mode);
5916 if (!maybe_result->To(&new_descriptors)) return maybe_result; 5899 if (!maybe_result->To(&new_descriptors)) return maybe_result;
5917 } 5900 }
5918 5901
5919 DescriptorArray::WhitenessWitness witness(new_descriptors); 5902 DescriptorArray::WhitenessWitness witness(new_descriptors);
5920 5903
5921 // Set the enumeration index in the descriptors and set the enumeration index 5904 // Set the enumeration index in the descriptors and set the enumeration index
5922 // in the result. 5905 // in the result.
5923 int enumeration_index = NextEnumerationIndex(); 5906 int enumeration_index = NextEnumerationIndex();
5924 if (!descriptor->ContainsTransition()) { 5907 if (keep_enumeration_index) {
5925 if (keep_enumeration_index) { 5908 descriptor->SetEnumerationIndex(GetDetails(index).index());
5926 descriptor->SetEnumerationIndex(GetDetails(index).index()); 5909 } else {
5927 } else { 5910 descriptor->SetEnumerationIndex(enumeration_index);
5928 descriptor->SetEnumerationIndex(enumeration_index); 5911 ++enumeration_index;
5929 ++enumeration_index;
5930 }
5931 }
5932 Map* old_elements_transition = elements_transition_map();
5933 if ((!remove_transitions) && (old_elements_transition != NULL)) {
5934 new_descriptors->set_elements_transition_map(old_elements_transition);
5935 } 5912 }
5936 new_descriptors->SetNextEnumerationIndex(enumeration_index); 5913 new_descriptors->SetNextEnumerationIndex(enumeration_index);
5937 5914
5938 // Copy the descriptors, filtering out transitions and null descriptors, 5915 // Copy the descriptors, filtering out transitions and null descriptors,
5939 // and inserting or replacing a descriptor. 5916 // and inserting or replacing a descriptor.
5940 int to_index = 0; 5917 int to_index = 0;
5941 int insertion_index = -1; 5918 int insertion_index = -1;
5942 int from_index = 0; 5919 int from_index = 0;
5943 while (from_index < number_of_descriptors()) { 5920 while (from_index < number_of_descriptors()) {
5944 if (insertion_index < 0 && 5921 if (insertion_index < 0 &&
5945 InsertionPointFound(GetKey(from_index), descriptor->GetKey())) { 5922 InsertionPointFound(GetKey(from_index), descriptor->GetKey())) {
5946 insertion_index = to_index++; 5923 insertion_index = to_index++;
5947 if (replacing) from_index++; 5924 if (replacing) from_index++;
5948 } else { 5925 } else {
5949 if (!(remove_transitions && IsTransitionOnly(from_index))) { 5926 MaybeObject* copy_result =
5950 MaybeObject* copy_result = 5927 new_descriptors->CopyFrom(to_index++, this, from_index, witness);
5951 new_descriptors->CopyFrom(to_index++, this, from_index, witness); 5928 if (copy_result->IsFailure()) return copy_result;
5952 if (copy_result->IsFailure()) return copy_result;
5953 }
5954 from_index++; 5929 from_index++;
5955 } 5930 }
5956 } 5931 }
5957 if (insertion_index < 0) insertion_index = to_index++; 5932 if (insertion_index < 0) insertion_index = to_index++;
5958 5933
5959 ASSERT(insertion_index < new_descriptors->number_of_descriptors()); 5934 ASSERT(insertion_index < new_descriptors->number_of_descriptors());
5960 new_descriptors->Set(insertion_index, descriptor, witness); 5935 new_descriptors->Set(insertion_index, descriptor, witness);
5961 5936
5962 ASSERT(to_index == new_descriptors->number_of_descriptors()); 5937 ASSERT(to_index == new_descriptors->number_of_descriptors());
5963 SLOW_ASSERT(new_descriptors->IsSortedNoDuplicates()); 5938 SLOW_ASSERT(new_descriptors->IsSortedNoDuplicates());
5964 5939
5965 return new_descriptors; 5940 return new_descriptors;
5966 } 5941 }
5967 5942
5968 5943
5969 MaybeObject* DescriptorArray::RemoveTransitions(SharedMode shared_mode) { 5944 MaybeObject* DescriptorArray::Copy(SharedMode shared_mode) {
5970 // Allocate the new descriptor array. 5945 // Allocate the new descriptor array.
5971 int new_number_of_descriptors = 0; 5946 int number_of_descriptors = this->number_of_descriptors();
5972 for (int i = 0; i < number_of_descriptors(); i++) {
5973 if (IsProperty(i)) new_number_of_descriptors++;
5974 }
5975 DescriptorArray* new_descriptors; 5947 DescriptorArray* new_descriptors;
5976 { MaybeObject* maybe_result = Allocate(new_number_of_descriptors, 5948 { MaybeObject* maybe_result = Allocate(number_of_descriptors,
5977 shared_mode); 5949 shared_mode);
5978 if (!maybe_result->To(&new_descriptors)) return maybe_result; 5950 if (!maybe_result->To(&new_descriptors)) return maybe_result;
5979 } 5951 }
5980 5952
5981 // Copy the content. 5953 // Copy the content.
5982 DescriptorArray::WhitenessWitness witness(new_descriptors); 5954 DescriptorArray::WhitenessWitness witness(new_descriptors);
5983 int next_descriptor = 0; 5955 for (int i = 0; i < number_of_descriptors; i++) {
5984 for (int i = 0; i < number_of_descriptors(); i++) { 5956 MaybeObject* copy_result =
5985 if (IsProperty(i)) { 5957 new_descriptors->CopyFrom(i, this, i, witness);
5986 MaybeObject* copy_result = 5958 if (copy_result->IsFailure()) return copy_result;
5987 new_descriptors->CopyFrom(next_descriptor++, this, i, witness);
5988 if (copy_result->IsFailure()) return copy_result;
5989 }
5990 } 5959 }
5991 ASSERT(next_descriptor == new_descriptors->number_of_descriptors());
5992 new_descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); 5960 new_descriptors->SetNextEnumerationIndex(NextEnumerationIndex());
5993
5994 return new_descriptors; 5961 return new_descriptors;
5995 } 5962 }
5996 5963
5997 // We need the whiteness witness since sort will reshuffle the entries in the 5964 // We need the whiteness witness since sort will reshuffle the entries in the
5998 // descriptor array. If the descriptor array were to be black, the shuffling 5965 // descriptor array. If the descriptor array were to be black, the shuffling
5999 // would move a slot that was already recorded as pointing into an evacuation 5966 // would move a slot that was already recorded as pointing into an evacuation
6000 // candidate. This would result in missing updates upon evacuation. 5967 // candidate. This would result in missing updates upon evacuation.
6001 void DescriptorArray::SortUnchecked(const WhitenessWitness& witness) { 5968 void DescriptorArray::SortUnchecked(const WhitenessWitness& witness) {
6002 // In-place heap sort. 5969 // In-place heap sort.
6003 int len = number_of_descriptors(); 5970 int len = number_of_descriptors();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6050 } 6017 }
6051 } 6018 }
6052 6019
6053 6020
6054 void DescriptorArray::Sort(const WhitenessWitness& witness) { 6021 void DescriptorArray::Sort(const WhitenessWitness& witness) {
6055 SortUnchecked(witness); 6022 SortUnchecked(witness);
6056 SLOW_ASSERT(IsSortedNoDuplicates()); 6023 SLOW_ASSERT(IsSortedNoDuplicates());
6057 } 6024 }
6058 6025
6059 6026
6060 int DescriptorArray::BinarySearch(String* name, int low, int high) {
6061 uint32_t hash = name->Hash();
6062 int limit = high;
6063
6064 ASSERT(low <= high);
6065
6066 while (low != high) {
6067 int mid = (low + high) / 2;
6068 String* mid_name = GetKey(mid);
6069 uint32_t mid_hash = mid_name->Hash();
6070
6071 if (mid_hash >= hash) {
6072 high = mid;
6073 } else {
6074 low = mid + 1;
6075 }
6076 }
6077
6078 for (; low <= limit && GetKey(low)->Hash() == hash; ++low) {
6079 if (GetKey(low)->Equals(name)) return low;
6080 }
6081
6082 return kNotFound;
6083 }
6084
6085
6086 int DescriptorArray::LinearSearch(SearchMode mode, String* name, int len) {
6087 uint32_t hash = name->Hash();
6088 for (int number = 0; number < len; number++) {
6089 String* entry = GetKey(number);
6090 if (mode == EXPECT_SORTED && entry->Hash() > hash) break;
6091 if (name->Equals(entry)) return number;
6092 }
6093 return kNotFound;
6094 }
6095
6096
6097 MaybeObject* AccessorPair::CopyWithoutTransitions() { 6027 MaybeObject* AccessorPair::CopyWithoutTransitions() {
6098 Heap* heap = GetHeap(); 6028 Heap* heap = GetHeap();
6099 AccessorPair* copy; 6029 AccessorPair* copy;
6100 { MaybeObject* maybe_copy = heap->AllocateAccessorPair(); 6030 { MaybeObject* maybe_copy = heap->AllocateAccessorPair();
6101 if (!maybe_copy->To(&copy)) return maybe_copy; 6031 if (!maybe_copy->To(&copy)) return maybe_copy;
6102 } 6032 }
6103 copy->set_getter(getter()->IsMap() ? heap->the_hole_value() : getter()); 6033 copy->set_getter(getter()->IsMap() ? heap->the_hole_value() : getter());
6104 copy->set_setter(setter()->IsMap() ? heap->the_hole_value() : setter()); 6034 copy->set_setter(setter()->IsMap() ? heap->the_hole_value() : setter());
6105 return copy; 6035 return copy;
6106 } 6036 }
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
7329 7259
7330 7260
7331 void String::PrintOn(FILE* file) { 7261 void String::PrintOn(FILE* file) {
7332 int length = this->length(); 7262 int length = this->length();
7333 for (int i = 0; i < length; i++) { 7263 for (int i = 0; i < length; i++) {
7334 fprintf(file, "%c", Get(i)); 7264 fprintf(file, "%c", Get(i));
7335 } 7265 }
7336 } 7266 }
7337 7267
7338 7268
7339 // Clear a possible back pointer in case the transition leads to a dead map.
7340 // Return true in case a back pointer has been cleared and false otherwise.
7341 static bool ClearBackPointer(Heap* heap, Object* target) {
7342 ASSERT(target->IsMap());
7343 Map* map = Map::cast(target);
7344 if (Marking::MarkBitFrom(map).Get()) return false;
7345 map->SetBackPointer(heap->undefined_value(), SKIP_WRITE_BARRIER);
7346 return true;
7347 }
7348
7349
7350 // This function should only be called from within the GC, since it uses 7269 // This function should only be called from within the GC, since it uses
7351 // IncrementLiveBytesFromGC. If called from anywhere else, this results in an 7270 // IncrementLiveBytesFromGC. If called from anywhere else, this results in an
7352 // inconsistent live-bytes count. 7271 // inconsistent live-bytes count.
7353 static void RightTrimFixedArray(Heap* heap, FixedArray* elms, int to_trim) { 7272 static void RightTrimFixedArray(Heap* heap, FixedArray* elms, int to_trim) {
7354 ASSERT(elms->map() != HEAP->fixed_cow_array_map()); 7273 ASSERT(elms->map() != HEAP->fixed_cow_array_map());
7355 // For now this trick is only applied to fixed arrays in new and paged space. 7274 // For now this trick is only applied to fixed arrays in new and paged space.
7356 // In large object space the object's start must coincide with chunk 7275 // In large object space the object's start must coincide with chunk
7357 // and thus the trick is just not applicable. 7276 // and thus the trick is just not applicable.
7358 ASSERT(!HEAP->lo_space()->Contains(elms)); 7277 ASSERT(!HEAP->lo_space()->Contains(elms));
7359 7278
(...skipping 20 matching lines...) Expand all
7380 7299
7381 elms->set_length(len - to_trim); 7300 elms->set_length(len - to_trim);
7382 7301
7383 // Maintain marking consistency for IncrementalMarking. 7302 // Maintain marking consistency for IncrementalMarking.
7384 if (Marking::IsBlack(Marking::MarkBitFrom(elms))) { 7303 if (Marking::IsBlack(Marking::MarkBitFrom(elms))) {
7385 MemoryChunk::IncrementLiveBytesFromGC(elms->address(), -size_delta); 7304 MemoryChunk::IncrementLiveBytesFromGC(elms->address(), -size_delta);
7386 } 7305 }
7387 } 7306 }
7388 7307
7389 7308
7390 // If the descriptor describes a transition to a dead map, the back pointer 7309 // Clear a possible back pointer in case the transition leads to a dead map.
7391 // of this map is cleared and we return true. Otherwise we return false. 7310 // Return true in case a back pointer has been cleared and false otherwise.
7392 static bool ClearNonLiveTransitionsFromDescriptor(Heap* heap, 7311 static bool ClearBackPointer(Heap* heap, Object* target) {
7393 DescriptorArray* d, 7312 ASSERT(target->IsMap());
7394 int descriptor_index) { 7313 Map* map = Map::cast(target);
7395 // If the pair (value, details) is a map transition, check if the target is 7314 if (Marking::MarkBitFrom(map).Get()) return false;
7396 // live. If not, null the descriptor. Also drop the back pointer for that 7315 map->SetBackPointer(heap->undefined_value(), SKIP_WRITE_BARRIER);
7397 // map transition, so that this map is not reached again by following a back 7316 return true;
7398 // pointer from that non-live map. 7317 }
7399 PropertyDetails details(d->GetDetails(descriptor_index)); 7318
7400 switch (details.type()) { 7319
7401 case MAP_TRANSITION: 7320 static bool ClearAccessorComponent(Heap* heap,
7402 case CONSTANT_TRANSITION: 7321 AccessorPair* accessors,
7403 return ClearBackPointer(heap, d->GetValue(descriptor_index)); 7322 AccessorComponent component) {
7404 case CALLBACKS: { 7323 Object* component_value = accessors->get(component);
7405 Object* object = d->GetValue(descriptor_index); 7324 if (!component_value->IsMap()) return true;
7406 if (object->IsAccessorPair()) { 7325 if (ClearBackPointer(heap, component_value)) {
7407 bool cleared = true; 7326 accessors->set(component, heap->the_hole_value());
7408 AccessorPair* accessors = AccessorPair::cast(object); 7327 return true;
7409 Object* getter = accessors->getter(); 7328 }
7410 if (getter->IsMap()) { 7329 return false;
7411 if (ClearBackPointer(heap, getter)) { 7330 }
7412 accessors->set_getter(heap->the_hole_value()); 7331
7413 } else { 7332
7414 cleared = false; 7333 static bool ClearNonLiveTransition(Heap* heap,
7415 } 7334 TransitionArray* t,
7416 } else if (!getter->IsTheHole()) { 7335 int transition_index) {
7417 cleared = false; 7336 // If the value is a map, check if the target is live. If not, clear the
7418 } 7337 // transition. Also drop the back pointer for that map transition, so that
7419 Object* setter = accessors->setter(); 7338 // this map is not reached again by following a back pointer from that
7420 if (setter->IsMap()) { 7339 // non-live map.
7421 if (ClearBackPointer(heap, setter)) { 7340 Object* value = t->GetValue(transition_index);
7422 accessors->set_setter(heap->the_hole_value()); 7341 if (value->IsMap()) {
7423 } else { 7342 return ClearBackPointer(heap, t->GetValue(transition_index));
7424 cleared = false; 7343 } else if (value->IsAccessorPair()) {
7425 } 7344 AccessorPair* accessors = AccessorPair::cast(value);
7426 } else if (!setter->IsTheHole()) { 7345 bool getter = ClearAccessorComponent(heap, accessors, ACCESSOR_GETTER);
7427 cleared = false; 7346 bool setter = ClearAccessorComponent(heap, accessors, ACCESSOR_SETTER);
7428 } 7347 return getter && setter;
7429 return cleared;
7430 }
7431 return false;
7432 }
7433 case NORMAL:
7434 case FIELD:
7435 case CONSTANT_FUNCTION:
7436 case HANDLER:
7437 case INTERCEPTOR:
7438 return false;
7439 case NONEXISTENT:
7440 break;
7441 } 7348 }
7442 UNREACHABLE(); 7349 UNREACHABLE();
7443 return true; 7350 return true;
7444 } 7351 }
7445 7352
7446 7353
7447 // TODO(mstarzinger): This method should be moved into MarkCompactCollector, 7354 // TODO(mstarzinger): This method should be moved into MarkCompactCollector,
7448 // because it cannot be called from outside the GC and we already have methods 7355 // because it cannot be called from outside the GC and we already have methods
7449 // depending on the transitions layout in the GC anyways. 7356 // depending on the transitions layout in the GC anyways.
7450 void Map::ClearNonLiveTransitions(Heap* heap) { 7357 void Map::ClearNonLiveTransitions(Heap* heap) {
7451 Object* array = *RawField(this, Map::kInstanceDescriptorsOrBitField3Offset); 7358 TransitionArray* t = transitions();
7452 // If there are no descriptors to be cleared, return. 7359 // If there are no transitions to be cleared, return.
7453 // TODO(verwaest) Should be an assert, otherwise back pointers are not 7360 // TODO(verwaest) Should be an assert, otherwise back pointers are not
7454 // properly cleared. 7361 // properly cleared.
7455 if (array->IsSmi()) return; 7362 if (t == NULL) return;
7456 DescriptorArray* d = DescriptorArray::cast(array);
7457 7363
7458 int descriptor_index = 0; 7364 int transition_index = 0;
7365
7459 // Compact all live descriptors to the left. 7366 // Compact all live descriptors to the left.
7460 for (int i = 0; i < d->number_of_descriptors(); ++i) { 7367 for (int i = 0; i < t->number_of_transitions(); ++i) {
7461 if (!ClearNonLiveTransitionsFromDescriptor(heap, d, i)) { 7368 if (!ClearNonLiveTransition(heap, t, i)) {
7462 if (i != descriptor_index) { 7369 if (i != transition_index) {
7463 String* key = d->GetKey(i); 7370 String* key = t->GetKey(i);
7464 Object* value = d->GetValue(i); 7371 Object* value = t->GetValue(i);
7465 d->SetKeyUnchecked(heap, descriptor_index, key); 7372 t->SetKeyUnchecked(heap, transition_index, key);
7466 d->SetDetailsUnchecked(descriptor_index, d->GetDetails(i).AsSmi()); 7373 t->SetValueUnchecked(heap, transition_index, value);
7467 d->SetValueUnchecked(heap, descriptor_index, value);
7468 MarkCompactCollector* collector = heap->mark_compact_collector(); 7374 MarkCompactCollector* collector = heap->mark_compact_collector();
7469 Object** key_slot = d->GetKeySlot(descriptor_index); 7375 Object** key_slot = t->GetKeySlot(transition_index);
7470 collector->RecordSlot(key_slot, key_slot, key); 7376 collector->RecordSlot(key_slot, key_slot, key);
7471 if (value->IsHeapObject()) { 7377 Object** value_slot = t->GetValueSlot(transition_index);
7472 Object** value_slot = d->GetValueSlot(descriptor_index); 7378 collector->RecordSlot(value_slot, value_slot, value);
7473 collector->RecordSlot(value_slot, value_slot, value);
7474 }
7475 } 7379 }
7476 descriptor_index++; 7380 transition_index++;
7477 } 7381 }
7478 } 7382 }
7479 7383
7480 Map* elements_transition = d->elements_transition_map(); 7384 if (t->HasElementsTransition() &&
7481 if (elements_transition != NULL && 7385 ClearBackPointer(heap, t->elements_transition())) {
7482 ClearBackPointer(heap, elements_transition)) { 7386 t->ClearElementsTransition();
7483 elements_transition = NULL;
7484 d->ClearElementsTransition();
7485 } else { 7387 } else {
7486 // If there are no descriptors to be cleared, return. 7388 // If there are no transitions to be cleared, return.
7487 // TODO(verwaest) Should be an assert, otherwise back pointers are not 7389 // TODO(verwaest) Should be an assert, otherwise back pointers are not
7488 // properly cleared. 7390 // properly cleared.
7489 if (descriptor_index == d->number_of_descriptors()) return; 7391 if (transition_index == t->number_of_transitions()) return;
7490 } 7392 }
7491 7393
7492 // If the final descriptor array does not contain any live descriptors, remove 7394 // If the final transition array does not contain any live transitions, remove
7493 // the descriptor array from the map. 7395 // the transition array from the map.
7494 if (descriptor_index == 0 && elements_transition == NULL) { 7396 if (transition_index == 0 && !t->HasElementsTransition()) {
7495 ClearDescriptorArray(); 7397 return ClearTransitions();
7496 return;
7497 } 7398 }
7498 7399
7499 int trim = d->number_of_descriptors() - descriptor_index; 7400 int trim = t->number_of_transitions() - transition_index;
7500 if (trim > 0) { 7401 if (trim > 0) {
7501 RightTrimFixedArray(heap, d, trim * DescriptorArray::kDescriptorSize); 7402 RightTrimFixedArray(heap, t, trim * TransitionArray::kTransitionSize);
7502 } 7403 }
7503 } 7404 }
7504 7405
7505 7406
7506 int Map::Hash() { 7407 int Map::Hash() {
7507 // For performance reasons we only hash the 3 most variable fields of a map: 7408 // For performance reasons we only hash the 3 most variable fields of a map:
7508 // constructor, prototype and bit_field2. 7409 // constructor, prototype and bit_field2.
7509 7410
7510 // Shift away the tag. 7411 // Shift away the tag.
7511 int hash = (static_cast<uint32_t>( 7412 int hash = (static_cast<uint32_t>(
(...skipping 3174 matching lines...) Expand 10 before | Expand all | Expand 10 after
10686 } 10587 }
10687 10588
10688 10589
10689 // Fill in the names of local properties into the supplied storage. The main 10590 // Fill in the names of local properties into the supplied storage. The main
10690 // purpose of this function is to provide reflection information for the object 10591 // purpose of this function is to provide reflection information for the object
10691 // mirrors. 10592 // mirrors.
10692 void JSObject::GetLocalPropertyNames(FixedArray* storage, int index) { 10593 void JSObject::GetLocalPropertyNames(FixedArray* storage, int index) {
10693 ASSERT(storage->length() >= (NumberOfLocalProperties() - index)); 10594 ASSERT(storage->length() >= (NumberOfLocalProperties() - index));
10694 if (HasFastProperties()) { 10595 if (HasFastProperties()) {
10695 DescriptorArray* descs = map()->instance_descriptors(); 10596 DescriptorArray* descs = map()->instance_descriptors();
10597 ASSERT(storage->length() >= index + descs->number_of_descriptors());
10696 for (int i = 0; i < descs->number_of_descriptors(); i++) { 10598 for (int i = 0; i < descs->number_of_descriptors(); i++) {
10697 if (descs->IsProperty(i)) storage->set(index++, descs->GetKey(i)); 10599 storage->set(index + i, descs->GetKey(i));
10698 } 10600 }
10699 ASSERT(storage->length() >= index);
10700 } else { 10601 } else {
10701 property_dictionary()->CopyKeysTo(storage, 10602 property_dictionary()->CopyKeysTo(storage,
10702 index, 10603 index,
10703 StringDictionary::UNSORTED); 10604 StringDictionary::UNSORTED);
10704 } 10605 }
10705 } 10606 }
10706 10607
10707 10608
10708 int JSObject::NumberOfLocalElements(PropertyAttributes filter) { 10609 int JSObject::NumberOfLocalElements(PropertyAttributes filter) {
10709 return GetLocalElementKeys(NULL, filter); 10610 return GetLocalElementKeys(NULL, filter);
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
11317 set(index, key); 11218 set(index, key);
11318 return entry; 11219 return entry;
11319 } 11220 }
11320 ASSERT(element->IsTheHole() || !String::cast(element)->Equals(key)); 11221 ASSERT(element->IsTheHole() || !String::cast(element)->Equals(key));
11321 entry = NextProbe(entry, count++, capacity); 11222 entry = NextProbe(entry, count++, capacity);
11322 } 11223 }
11323 return kNotFound; 11224 return kNotFound;
11324 } 11225 }
11325 11226
11326 11227
11327 bool StringDictionary::ContainsTransition(int entry) {
11328 switch (DetailsAt(entry).type()) {
11329 case MAP_TRANSITION:
11330 case CONSTANT_TRANSITION:
11331 return true;
11332 case CALLBACKS: {
11333 Object* value = ValueAt(entry);
11334 if (!value->IsAccessorPair()) return false;
11335 AccessorPair* accessors = AccessorPair::cast(value);
11336 return accessors->getter()->IsMap() || accessors->setter()->IsMap();
11337 }
11338 case NORMAL:
11339 case FIELD:
11340 case CONSTANT_FUNCTION:
11341 case HANDLER:
11342 case INTERCEPTOR:
11343 return false;
11344 case NONEXISTENT:
11345 UNREACHABLE();
11346 break;
11347 }
11348 UNREACHABLE(); // Keep the compiler happy.
11349 return false;
11350 }
11351
11352
11353 template<typename Shape, typename Key> 11228 template<typename Shape, typename Key>
11354 MaybeObject* HashTable<Shape, Key>::Rehash(HashTable* new_table, Key key) { 11229 MaybeObject* HashTable<Shape, Key>::Rehash(HashTable* new_table, Key key) {
11355 ASSERT(NumberOfElements() < new_table->Capacity()); 11230 ASSERT(NumberOfElements() < new_table->Capacity());
11356 11231
11357 AssertNoAllocation no_gc; 11232 AssertNoAllocation no_gc;
11358 WriteBarrierMode mode = new_table->GetWriteBarrierMode(no_gc); 11233 WriteBarrierMode mode = new_table->GetWriteBarrierMode(no_gc);
11359 11234
11360 // Copy prefix to new array. 11235 // Copy prefix to new array.
11361 for (int i = kPrefixStartIndex; 11236 for (int i = kPrefixStartIndex;
11362 i < kPrefixStartIndex + Shape::kPrefixSize; 11237 i < kPrefixStartIndex + Shape::kPrefixSize;
(...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after
13377 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13252 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13378 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13253 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13379 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13254 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13380 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13255 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13381 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13256 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13382 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13257 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13383 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13258 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13384 } 13259 }
13385 13260
13386 } } // namespace v8::internal 13261 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | src/transitions-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698