OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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 FixedArray* 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(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 Loading... |
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 return maybe_new_transitions; |
1587 { MaybeObject* maybe_r = old_descriptors->CopyInsert(&d, KEEP_TRANSITIONS); | |
1588 if (!maybe_r->ToObject(&r)) return maybe_r; | |
1589 } | 1585 } |
1590 old_descriptors = DescriptorArray::cast(r); | |
1591 } | 1586 } |
1592 | 1587 |
1593 if (map()->unused_property_fields() == 0) { | 1588 if (map()->unused_property_fields() == 0) { |
1594 if (TooManyFastProperties(properties()->length(), store_mode)) { | 1589 if (TooManyFastProperties(properties()->length(), store_mode)) { |
1595 Object* obj; | 1590 Object* obj; |
1596 { MaybeObject* maybe_obj = | 1591 { MaybeObject* maybe_obj = |
1597 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); | 1592 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); |
1598 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 1593 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
1599 } | 1594 } |
1600 return AddSlowProperty(name, value, attributes); | 1595 return AddSlowProperty(name, value, attributes); |
1601 } | 1596 } |
1602 // Make room for the new value | 1597 // Make room for the new value |
1603 Object* values; | 1598 Object* values; |
1604 { MaybeObject* maybe_values = | 1599 { MaybeObject* maybe_values = |
1605 properties()->CopySize(properties()->length() + kFieldsAdded); | 1600 properties()->CopySize(properties()->length() + kFieldsAdded); |
1606 if (!maybe_values->ToObject(&values)) return maybe_values; | 1601 if (!maybe_values->ToObject(&values)) return maybe_values; |
1607 } | 1602 } |
1608 set_properties(FixedArray::cast(values)); | 1603 set_properties(FixedArray::cast(values)); |
1609 new_map->set_unused_property_fields(kFieldsAdded - 1); | 1604 new_map->set_unused_property_fields(kFieldsAdded - 1); |
1610 } else { | 1605 } else { |
1611 new_map->set_unused_property_fields(map()->unused_property_fields() - 1); | 1606 new_map->set_unused_property_fields(map()->unused_property_fields() - 1); |
1612 } | 1607 } |
1613 // We have now allocated all the necessary objects. | 1608 // 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) { | 1609 if (allow_map_transition) { |
1616 map()->set_instance_descriptors(old_descriptors); | 1610 MaybeObject* transition_added = map()->set_transitions(new_transitions); |
| 1611 if (transition_added->IsFailure()) return transition_added; |
1617 } | 1612 } |
| 1613 new_map->set_instance_descriptors(new_descriptors); |
1618 new_map->SetBackPointer(map()); | 1614 new_map->SetBackPointer(map()); |
1619 new_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); | |
1620 set_map(new_map); | 1615 set_map(new_map); |
1621 return FastPropertyAtPut(index, value); | 1616 return FastPropertyAtPut(index, value); |
1622 } | 1617 } |
1623 | 1618 |
1624 | 1619 |
1625 MaybeObject* JSObject::AddConstantFunctionProperty( | 1620 MaybeObject* JSObject::AddConstantFunctionProperty( |
1626 String* name, | 1621 String* name, |
1627 JSFunction* function, | 1622 JSFunction* function, |
1628 PropertyAttributes attributes) { | 1623 PropertyAttributes attributes) { |
1629 // Allocate new instance descriptors with (name, function) added | 1624 // Allocate new instance descriptors with (name, function) added |
1630 ConstantFunctionDescriptor d(name, function, attributes); | 1625 ConstantFunctionDescriptor d(name, function, attributes); |
1631 Object* new_descriptors; | 1626 DescriptorArray* new_descriptors; |
1632 { MaybeObject* maybe_new_descriptors = | 1627 { MaybeObject* maybe_new_descriptors = |
1633 map()->instance_descriptors()->CopyInsert(&d, REMOVE_TRANSITIONS); | 1628 map()->instance_descriptors()->CopyInsert(&d); |
1634 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { | 1629 if (!maybe_new_descriptors->To(&new_descriptors)) { |
1635 return maybe_new_descriptors; | 1630 return maybe_new_descriptors; |
1636 } | 1631 } |
1637 } | 1632 } |
1638 | 1633 |
1639 // Allocate a new map for the object. | 1634 // Allocate a new map for the object. |
1640 Object* new_map; | 1635 Map* new_map; |
1641 { MaybeObject* maybe_new_map = map()->CopyDropDescriptors(); | 1636 { MaybeObject* maybe_new_map = map()->CopyDropDescriptors(); |
1642 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; | 1637 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
1643 } | 1638 } |
1644 | 1639 |
1645 DescriptorArray* descriptors = DescriptorArray::cast(new_descriptors); | 1640 new_map->set_instance_descriptors(new_descriptors); |
1646 Map::cast(new_map)->set_instance_descriptors(descriptors); | |
1647 Map* old_map = map(); | 1641 Map* old_map = map(); |
1648 set_map(Map::cast(new_map)); | 1642 set_map(new_map); |
1649 | 1643 |
1650 // If the old map is the global object map (from new Object()), | 1644 // If the old map is the global object map (from new Object()), |
1651 // then transitions are not added to it, so we are done. | 1645 // then transitions are not added to it, so we are done. |
1652 Heap* heap = GetHeap(); | 1646 Heap* heap = GetHeap(); |
1653 if (old_map == heap->isolate()->context()->global_context()-> | 1647 if (old_map == heap->isolate()->context()->global_context()-> |
1654 object_function()->map()) { | 1648 object_function()->map()) { |
1655 return function; | 1649 return function; |
1656 } | 1650 } |
1657 | 1651 |
1658 // Do not add CONSTANT_TRANSITIONS to global objects | 1652 // Do not add constant transitions to global objects |
1659 if (IsGlobalObject()) { | 1653 if (IsGlobalObject()) { |
1660 return function; | 1654 return function; |
1661 } | 1655 } |
1662 | 1656 |
1663 // Add a CONSTANT_TRANSITION descriptor to the old map, | 1657 // Add a constant transition to the old map, so future assignments to this |
1664 // so future assignments to this property on other objects | 1658 // property on other objects of the same type will create a normal field, not |
1665 // of the same type will create a normal field, not a constant function. | 1659 // a constant function. Don't do this for special properties, with non-trival |
1666 // Don't do this for special properties, with non-trival attributes. | 1660 // attributes. |
1667 if (attributes != NONE) { | 1661 if (attributes != NONE) { |
1668 return function; | 1662 return function; |
1669 } | 1663 } |
1670 ConstTransitionDescriptor mark(name, Map::cast(new_map)); | 1664 |
1671 { MaybeObject* maybe_new_descriptors = | 1665 TransitionArray* new_transitions; |
1672 old_map->instance_descriptors()->CopyInsert(&mark, KEEP_TRANSITIONS); | 1666 { MaybeObject* maybe_new_transitions = |
1673 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { | 1667 old_map->AddTransition(name, new_map); |
| 1668 if (!maybe_new_transitions->To(&new_transitions)) { |
1674 // We have accomplished the main goal, so return success. | 1669 // We have accomplished the main goal, so return success. |
1675 return function; | 1670 return function; |
1676 } | 1671 } |
1677 } | 1672 } |
1678 old_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); | |
1679 Map::cast(new_map)->SetBackPointer(old_map); | |
1680 | 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 } |
| 1680 |
| 1681 new_map->SetBackPointer(old_map); |
1681 return function; | 1682 return function; |
1682 } | 1683 } |
1683 | 1684 |
1684 | 1685 |
1685 // Add property in slow mode | 1686 // Add property in slow mode |
1686 MaybeObject* JSObject::AddSlowProperty(String* name, | 1687 MaybeObject* JSObject::AddSlowProperty(String* name, |
1687 Object* value, | 1688 Object* value, |
1688 PropertyAttributes attributes) { | 1689 PropertyAttributes attributes) { |
1689 ASSERT(!HasFastProperties()); | 1690 ASSERT(!HasFastProperties()); |
1690 StringDictionary* dict = property_dictionary(); | 1691 StringDictionary* dict = property_dictionary(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1791 | 1792 |
1792 | 1793 |
1793 MaybeObject* JSObject::ReplaceSlowProperty(String* name, | 1794 MaybeObject* JSObject::ReplaceSlowProperty(String* name, |
1794 Object* value, | 1795 Object* value, |
1795 PropertyAttributes attributes) { | 1796 PropertyAttributes attributes) { |
1796 StringDictionary* dictionary = property_dictionary(); | 1797 StringDictionary* dictionary = property_dictionary(); |
1797 int old_index = dictionary->FindEntry(name); | 1798 int old_index = dictionary->FindEntry(name); |
1798 int new_enumeration_index = 0; // 0 means "Use the next available index." | 1799 int new_enumeration_index = 0; // 0 means "Use the next available index." |
1799 if (old_index != -1) { | 1800 if (old_index != -1) { |
1800 // All calls to ReplaceSlowProperty have had all transitions removed. | 1801 // All calls to ReplaceSlowProperty have had all transitions removed. |
1801 ASSERT(!dictionary->ContainsTransition(old_index)); | |
1802 new_enumeration_index = dictionary->DetailsAt(old_index).index(); | 1802 new_enumeration_index = dictionary->DetailsAt(old_index).index(); |
1803 } | 1803 } |
1804 | 1804 |
1805 PropertyDetails new_details(attributes, NORMAL, new_enumeration_index); | 1805 PropertyDetails new_details(attributes, NORMAL, new_enumeration_index); |
1806 return SetNormalizedProperty(name, value, new_details); | 1806 return SetNormalizedProperty(name, value, new_details); |
1807 } | 1807 } |
1808 | 1808 |
1809 | 1809 |
1810 MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition( | 1810 MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition( |
1811 String* name, | 1811 String* name, |
1812 Object* new_value, | 1812 Object* new_value, |
1813 PropertyAttributes attributes) { | 1813 PropertyAttributes attributes) { |
1814 Map* old_map = map(); | 1814 Map* old_map = map(); |
1815 Object* result; | 1815 Object* result; |
| 1816 |
1816 { MaybeObject* maybe_result = | 1817 { MaybeObject* maybe_result = |
1817 ConvertDescriptorToField(name, new_value, attributes); | 1818 ConvertDescriptorToField(name, new_value, attributes); |
1818 if (!maybe_result->ToObject(&result)) return maybe_result; | 1819 if (!maybe_result->To(&result)) return maybe_result; |
1819 } | 1820 } |
| 1821 |
1820 // If we get to this point we have succeeded - do not return failure | 1822 // If we get to this point we have succeeded - do not return failure |
1821 // after this point. Later stuff is optional. | 1823 // after this point. Later stuff is optional. |
1822 if (!HasFastProperties()) { | 1824 if (!HasFastProperties()) { |
1823 return result; | 1825 return result; |
1824 } | 1826 } |
| 1827 |
1825 // Do not add transitions to the map of "new Object()". | 1828 // Do not add transitions to the map of "new Object()". |
1826 if (map() == GetIsolate()->context()->global_context()-> | 1829 if (map() == GetIsolate()->context()->global_context()-> |
1827 object_function()->map()) { | 1830 object_function()->map()) { |
1828 return result; | 1831 return result; |
1829 } | 1832 } |
1830 | 1833 |
1831 MapTransitionDescriptor transition(name, | 1834 TransitionArray* new_transitions; |
1832 map(), | 1835 { MaybeObject* maybe_new_transitions = old_map->AddTransition(name, map()); |
1833 attributes); | 1836 if (!maybe_new_transitions->To(&new_transitions)) { |
1834 Object* new_descriptors; | 1837 // We have accomplished the main goal, so return success. |
1835 { MaybeObject* maybe_new_descriptors = old_map->instance_descriptors()-> | 1838 return result; |
1836 CopyInsert(&transition, KEEP_TRANSITIONS); | |
1837 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { | |
1838 return result; // Yes, return _result_. | |
1839 } | 1839 } |
1840 } | 1840 } |
1841 old_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); | 1841 |
1842 map()->SetBackPointer(old_map); | 1842 { MaybeObject* transition_added = old_map->set_transitions(new_transitions); |
| 1843 // Return success if failure since we accomplished the main goal. Otherwise |
| 1844 // also set backpointer. |
| 1845 if (!transition_added->IsFailure()) { |
| 1846 map()->SetBackPointer(old_map); |
| 1847 } |
| 1848 } |
| 1849 |
1843 return result; | 1850 return result; |
1844 } | 1851 } |
1845 | 1852 |
1846 | 1853 |
1847 MaybeObject* JSObject::ConvertDescriptorToField(String* name, | 1854 MaybeObject* JSObject::ConvertDescriptorToField(String* name, |
1848 Object* new_value, | 1855 Object* new_value, |
1849 PropertyAttributes attributes) { | 1856 PropertyAttributes attributes) { |
1850 if (map()->unused_property_fields() == 0 && | 1857 if (map()->unused_property_fields() == 0 && |
1851 TooManyFastProperties(properties()->length(), MAY_BE_STORE_FROM_KEYED)) { | 1858 TooManyFastProperties(properties()->length(), MAY_BE_STORE_FROM_KEYED)) { |
1852 Object* obj; | 1859 Object* obj; |
1853 { MaybeObject* maybe_obj = | 1860 { MaybeObject* maybe_obj = |
1854 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); | 1861 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); |
1855 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 1862 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
1856 } | 1863 } |
1857 return ReplaceSlowProperty(name, new_value, attributes); | 1864 return ReplaceSlowProperty(name, new_value, attributes); |
1858 } | 1865 } |
1859 | 1866 |
1860 int index = map()->NextFreePropertyIndex(); | 1867 int index = map()->NextFreePropertyIndex(); |
1861 FieldDescriptor new_field(name, index, attributes); | 1868 FieldDescriptor new_field(name, index, attributes); |
1862 // Make a new DescriptorArray replacing an entry with FieldDescriptor. | 1869 // Make a new DescriptorArray replacing an entry with FieldDescriptor. |
1863 Object* descriptors_unchecked; | 1870 Object* descriptors_unchecked; |
1864 { MaybeObject* maybe_descriptors_unchecked = map()->instance_descriptors()-> | 1871 { MaybeObject* maybe_descriptors_unchecked = |
1865 CopyInsert(&new_field, REMOVE_TRANSITIONS); | 1872 map()->instance_descriptors()->CopyInsert(&new_field); |
1866 if (!maybe_descriptors_unchecked->ToObject(&descriptors_unchecked)) { | 1873 if (!maybe_descriptors_unchecked->ToObject(&descriptors_unchecked)) { |
1867 return maybe_descriptors_unchecked; | 1874 return maybe_descriptors_unchecked; |
1868 } | 1875 } |
1869 } | 1876 } |
1870 DescriptorArray* new_descriptors = | 1877 DescriptorArray* new_descriptors = |
1871 DescriptorArray::cast(descriptors_unchecked); | 1878 DescriptorArray::cast(descriptors_unchecked); |
1872 | 1879 |
1873 // Make a new map for the object. | 1880 // Make a new map for the object. |
1874 Object* new_map_unchecked; | 1881 Object* new_map_unchecked; |
1875 { MaybeObject* maybe_new_map_unchecked = map()->CopyDropDescriptors(); | 1882 { MaybeObject* maybe_new_map_unchecked = map()->CopyDropDescriptors(); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 case CALLBACKS: { | 2156 case CALLBACKS: { |
2150 if (!FLAG_es5_readonly && result.IsReadOnly()) break; | 2157 if (!FLAG_es5_readonly && result.IsReadOnly()) break; |
2151 *done = true; | 2158 *done = true; |
2152 return SetPropertyWithCallback(result.GetCallbackObject(), | 2159 return SetPropertyWithCallback(result.GetCallbackObject(), |
2153 name, value, result.holder(), strict_mode); | 2160 name, value, result.holder(), strict_mode); |
2154 } | 2161 } |
2155 case HANDLER: { | 2162 case HANDLER: { |
2156 return result.proxy()->SetPropertyViaPrototypesWithHandler( | 2163 return result.proxy()->SetPropertyViaPrototypesWithHandler( |
2157 this, name, value, attributes, strict_mode, done); | 2164 this, name, value, attributes, strict_mode, done); |
2158 } | 2165 } |
2159 case MAP_TRANSITION: | 2166 case TRANSITION: |
2160 case CONSTANT_TRANSITION: | |
2161 break; | |
2162 case NONEXISTENT: | 2167 case NONEXISTENT: |
2163 UNREACHABLE(); | 2168 UNREACHABLE(); |
2164 break; | 2169 break; |
2165 } | 2170 } |
2166 } | 2171 } |
2167 | 2172 |
2168 // If we get here with *done true, we have encountered a read-only property. | 2173 // If we get here with *done true, we have encountered a read-only property. |
2169 if (!FLAG_es5_readonly) *done = false; | 2174 if (!FLAG_es5_readonly) *done = false; |
2170 if (*done) { | 2175 if (*done) { |
2171 if (strict_mode == kNonStrictMode) return value; | 2176 if (strict_mode == kNonStrictMode) return value; |
2172 Handle<Object> args[] = { Handle<Object>(name), Handle<Object>(this)}; | 2177 Handle<Object> args[] = { Handle<Object>(name), Handle<Object>(this)}; |
2173 return isolate->Throw(*isolate->factory()->NewTypeError( | 2178 return isolate->Throw(*isolate->factory()->NewTypeError( |
2174 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)))); | 2179 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)))); |
2175 } | 2180 } |
2176 return heap->the_hole_value(); | 2181 return heap->the_hole_value(); |
2177 } | 2182 } |
2178 | 2183 |
2179 | 2184 |
2180 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { | 2185 void Map::LookupDescriptor(JSObject* holder, |
2181 DescriptorArray* descriptors = map()->instance_descriptors(); | 2186 String* name, |
| 2187 LookupResult* result) { |
| 2188 DescriptorArray* descriptors = this->instance_descriptors(); |
2182 int number = descriptors->SearchWithCache(name); | 2189 int number = descriptors->SearchWithCache(name); |
2183 if (number != DescriptorArray::kNotFound) { | 2190 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); | 2191 result->DescriptorResult(holder, descriptors->GetDetails(number), number); |
2204 } else { | 2192 } else { |
2205 result->NotFound(); | 2193 result->NotFound(); |
2206 } | 2194 } |
2207 } | 2195 } |
2208 | 2196 |
2209 | 2197 |
| 2198 void Map::LookupTransition(JSObject* holder, |
| 2199 String* name, |
| 2200 LookupResult* result) { |
| 2201 if (HasTransitionArray()) { |
| 2202 TransitionArray* transition_array = transitions(); |
| 2203 int number = transition_array->Search(name); |
| 2204 if (number != TransitionArray::kNotFound) { |
| 2205 return result->TransitionResult(holder, number); |
| 2206 } |
| 2207 } |
| 2208 result->NotFound(); |
| 2209 } |
| 2210 |
| 2211 |
| 2212 void Map::LookupTransitionOrDescriptor(JSObject* holder, |
| 2213 String* name, |
| 2214 LookupResult* result) { |
| 2215 // AccessorPairs containing both a Descriptor and a Transition are shared |
| 2216 // between the DescriptorArray and the Transition array. This is why looking |
| 2217 // up the AccessorPair solely in the DescriptorArray works. |
| 2218 // TODO(verwaest) This should be implemented differently so the |
| 2219 // DescriptorArray is free of transitions; and so we can freely share it. |
| 2220 this->LookupDescriptor(holder, name, result); |
| 2221 if (result->IsFound()) return; |
| 2222 this->LookupTransition(holder, name, result); |
| 2223 } |
| 2224 |
| 2225 |
2210 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { | 2226 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { |
2211 ASSERT(!map.is_null()); | 2227 ASSERT(!map.is_null()); |
2212 for (int i = 0; i < maps->length(); ++i) { | 2228 for (int i = 0; i < maps->length(); ++i) { |
2213 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; | 2229 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; |
2214 } | 2230 } |
2215 return false; | 2231 return false; |
2216 } | 2232 } |
2217 | 2233 |
2218 | 2234 |
2219 template <class T> | 2235 template <class T> |
(...skipping 29 matching lines...) Expand all Loading... |
2249 static Map* FindClosestElementsTransition(Map* map, ElementsKind to_kind) { | 2265 static Map* FindClosestElementsTransition(Map* map, ElementsKind to_kind) { |
2250 Map* current_map = map; | 2266 Map* current_map = map; |
2251 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind()); | 2267 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind()); |
2252 int to_index = IsFastElementsKind(to_kind) | 2268 int to_index = IsFastElementsKind(to_kind) |
2253 ? GetSequenceIndexFromFastElementsKind(to_kind) | 2269 ? GetSequenceIndexFromFastElementsKind(to_kind) |
2254 : GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND); | 2270 : GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND); |
2255 | 2271 |
2256 ASSERT(index <= to_index); | 2272 ASSERT(index <= to_index); |
2257 | 2273 |
2258 for (; index < to_index; ++index) { | 2274 for (; index < to_index; ++index) { |
| 2275 if (!current_map->HasElementsTransition()) return current_map; |
| 2276 current_map = current_map->elements_transition_map(); |
| 2277 } |
| 2278 if (!IsFastElementsKind(to_kind) && current_map->HasElementsTransition()) { |
2259 Map* next_map = current_map->elements_transition_map(); | 2279 Map* next_map = current_map->elements_transition_map(); |
2260 if (next_map == NULL) { | 2280 if (next_map->elements_kind() == to_kind) return next_map; |
2261 return current_map; | |
2262 } | |
2263 current_map = next_map; | |
2264 } | 2281 } |
2265 if (!IsFastElementsKind(to_kind)) { | 2282 ASSERT(IsFastElementsKind(to_kind) |
2266 Map* next_map = current_map->elements_transition_map(); | 2283 ? current_map->elements_kind() == to_kind |
2267 if (next_map != NULL && next_map->elements_kind() == to_kind) { | 2284 : 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; | 2285 return current_map; |
2275 } | 2286 } |
2276 | 2287 |
2277 | 2288 |
2278 Map* Map::LookupElementsTransitionMap(ElementsKind to_kind) { | 2289 Map* Map::LookupElementsTransitionMap(ElementsKind to_kind) { |
2279 Map* to_map = FindClosestElementsTransition(this, to_kind); | 2290 Map* to_map = FindClosestElementsTransition(this, to_kind); |
2280 if (to_map->elements_kind() == to_kind) return to_map; | 2291 if (to_map->elements_kind() == to_kind) return to_map; |
2281 return NULL; | 2292 return NULL; |
2282 } | 2293 } |
2283 | 2294 |
2284 | 2295 |
2285 MaybeObject* Map::CreateNextElementsTransition(ElementsKind next_kind) { | 2296 MaybeObject* Map::CreateNextElementsTransition(ElementsKind next_kind) { |
2286 ASSERT(elements_transition_map() == NULL || | 2297 ASSERT(!HasElementsTransition() || |
2287 ((elements_transition_map()->elements_kind() == DICTIONARY_ELEMENTS || | 2298 ((elements_transition_map()->elements_kind() == DICTIONARY_ELEMENTS || |
2288 IsExternalArrayElementsKind( | 2299 IsExternalArrayElementsKind( |
2289 elements_transition_map()->elements_kind())) && | 2300 elements_transition_map()->elements_kind())) && |
2290 (next_kind == DICTIONARY_ELEMENTS || | 2301 (next_kind == DICTIONARY_ELEMENTS || |
2291 IsExternalArrayElementsKind(next_kind)))); | 2302 IsExternalArrayElementsKind(next_kind)))); |
2292 ASSERT(!IsFastElementsKind(next_kind) || | 2303 ASSERT(!IsFastElementsKind(next_kind) || |
2293 IsMoreGeneralElementsKindTransition(elements_kind(), next_kind)); | 2304 IsMoreGeneralElementsKindTransition(elements_kind(), next_kind)); |
2294 ASSERT(next_kind != elements_kind()); | 2305 ASSERT(next_kind != elements_kind()); |
2295 | 2306 |
2296 Map* next_map; | 2307 Map* next_map; |
2297 MaybeObject* maybe_next_map = | 2308 { MaybeObject* maybe_next_map = |
2298 this->CopyDropTransitions(DescriptorArray::CANNOT_BE_SHARED); | 2309 this->CopyDropTransitions(DescriptorArray::CANNOT_BE_SHARED); |
2299 if (!maybe_next_map->To(&next_map)) return maybe_next_map; | 2310 if (!maybe_next_map->To(&next_map)) return maybe_next_map; |
| 2311 } |
| 2312 |
| 2313 { MaybeObject* added_elements = this->set_elements_transition_map(next_map); |
| 2314 if (added_elements->IsFailure()) return added_elements; |
| 2315 } |
2300 | 2316 |
2301 next_map->set_elements_kind(next_kind); | 2317 next_map->set_elements_kind(next_kind); |
2302 next_map->SetBackPointer(this); | 2318 next_map->SetBackPointer(this); |
2303 this->set_elements_transition_map(next_map); | |
2304 return next_map; | 2319 return next_map; |
2305 } | 2320 } |
2306 | 2321 |
2307 | 2322 |
2308 static MaybeObject* AddMissingElementsTransitions(Map* map, | 2323 static MaybeObject* AddMissingElementsTransitions(Map* map, |
2309 ElementsKind to_kind) { | 2324 ElementsKind to_kind) { |
2310 ASSERT(IsFastElementsKind(map->elements_kind())); | 2325 ASSERT(IsFastElementsKind(map->elements_kind())); |
2311 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind()); | 2326 int index = GetSequenceIndexFromFastElementsKind(map->elements_kind()); |
2312 int to_index = IsFastElementsKind(to_kind) | 2327 int to_index = IsFastElementsKind(to_kind) |
2313 ? GetSequenceIndexFromFastElementsKind(to_kind) | 2328 ? GetSequenceIndexFromFastElementsKind(to_kind) |
(...skipping 25 matching lines...) Expand all Loading... |
2339 | 2354 |
2340 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, | 2355 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, |
2341 ElementsKind to_kind) { | 2356 ElementsKind to_kind) { |
2342 Isolate* isolate = object->GetIsolate(); | 2357 Isolate* isolate = object->GetIsolate(); |
2343 CALL_HEAP_FUNCTION(isolate, | 2358 CALL_HEAP_FUNCTION(isolate, |
2344 object->GetElementsTransitionMap(isolate, to_kind), | 2359 object->GetElementsTransitionMap(isolate, to_kind), |
2345 Map); | 2360 Map); |
2346 } | 2361 } |
2347 | 2362 |
2348 | 2363 |
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) { | 2364 MaybeObject* JSObject::GetElementsTransitionMapSlow(ElementsKind to_kind) { |
2366 Map* start_map = map(); | 2365 Map* start_map = map(); |
2367 ElementsKind from_kind = start_map->elements_kind(); | 2366 ElementsKind from_kind = start_map->elements_kind(); |
2368 | 2367 |
2369 if (from_kind == to_kind) { | 2368 if (from_kind == to_kind) { |
2370 return start_map; | 2369 return start_map; |
2371 } | 2370 } |
2372 | 2371 |
2373 Context* global_context = GetIsolate()->context()->global_context(); | 2372 Context* global_context = GetIsolate()->context()->global_context(); |
2374 bool allow_store_transition = | 2373 bool allow_store_transition = |
(...skipping 14 matching lines...) Expand all Loading... |
2389 if (!allow_store_transition) { | 2388 if (!allow_store_transition) { |
2390 // Create a new free-floating map only if we are not allowed to store it. | 2389 // Create a new free-floating map only if we are not allowed to store it. |
2391 Map* new_map = NULL; | 2390 Map* new_map = NULL; |
2392 MaybeObject* maybe_new_map = | 2391 MaybeObject* maybe_new_map = |
2393 start_map->CopyDropTransitions(DescriptorArray::MAY_BE_SHARED); | 2392 start_map->CopyDropTransitions(DescriptorArray::MAY_BE_SHARED); |
2394 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 2393 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
2395 new_map->set_elements_kind(to_kind); | 2394 new_map->set_elements_kind(to_kind); |
2396 return new_map; | 2395 return new_map; |
2397 } | 2396 } |
2398 | 2397 |
2399 EnsureMayContainTransitions(start_map); | |
2400 Map* closest_map = FindClosestElementsTransition(start_map, to_kind); | 2398 Map* closest_map = FindClosestElementsTransition(start_map, to_kind); |
2401 | 2399 |
2402 if (closest_map->elements_kind() == to_kind) { | 2400 if (closest_map->elements_kind() == to_kind) { |
2403 return closest_map; | 2401 return closest_map; |
2404 } | 2402 } |
2405 | 2403 |
2406 return AddMissingElementsTransitions(closest_map, to_kind); | 2404 return AddMissingElementsTransitions(closest_map, to_kind); |
2407 } | 2405 } |
2408 | 2406 |
2409 | 2407 |
2410 void JSObject::LocalLookupRealNamedProperty(String* name, | 2408 void JSObject::LocalLookupRealNamedProperty(String* name, |
2411 LookupResult* result) { | 2409 LookupResult* result) { |
2412 if (IsJSGlobalProxy()) { | 2410 if (IsJSGlobalProxy()) { |
2413 Object* proto = GetPrototype(); | 2411 Object* proto = GetPrototype(); |
2414 if (proto->IsNull()) return result->NotFound(); | 2412 if (proto->IsNull()) return result->NotFound(); |
2415 ASSERT(proto->IsJSGlobalObject()); | 2413 ASSERT(proto->IsJSGlobalObject()); |
2416 // A GlobalProxy's prototype should always be a proper JSObject. | 2414 // A GlobalProxy's prototype should always be a proper JSObject. |
2417 return JSObject::cast(proto)->LocalLookupRealNamedProperty(name, result); | 2415 return JSObject::cast(proto)->LocalLookupRealNamedProperty(name, result); |
2418 } | 2416 } |
2419 | 2417 |
2420 if (HasFastProperties()) { | 2418 if (HasFastProperties()) { |
2421 LookupInDescriptor(name, result); | 2419 map()->LookupTransitionOrDescriptor(this, name, result); |
2422 if (result->IsFound()) { | 2420 // 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. | 2421 // types because LocalLookupRealNamedProperty is used when setting |
2424 // We return all of these result types because | 2422 // properties where map transitions are handled. |
2425 // LocalLookupRealNamedProperty is used when setting properties | 2423 ASSERT(!result->IsFound() || |
2426 // where map transitions and null descriptors are handled. | 2424 (result->holder() == this && result->IsFastPropertyType())); |
2427 ASSERT(result->holder() == this && result->IsFastPropertyType()); | 2425 // Disallow caching for uninitialized constants. These can only |
2428 // Disallow caching for uninitialized constants. These can only | 2426 // occur as fields. |
2429 // occur as fields. | 2427 if (result->IsField() && |
2430 if (result->IsField() && | 2428 result->IsReadOnly() && |
2431 result->IsReadOnly() && | 2429 FastPropertyAt(result->GetFieldIndex())->IsTheHole()) { |
2432 FastPropertyAt(result->GetFieldIndex())->IsTheHole()) { | 2430 result->DisallowCaching(); |
2433 result->DisallowCaching(); | 2431 } |
| 2432 return; |
| 2433 } |
| 2434 |
| 2435 int entry = property_dictionary()->FindEntry(name); |
| 2436 if (entry != StringDictionary::kNotFound) { |
| 2437 Object* value = property_dictionary()->ValueAt(entry); |
| 2438 if (IsGlobalObject()) { |
| 2439 PropertyDetails d = property_dictionary()->DetailsAt(entry); |
| 2440 if (d.IsDeleted()) { |
| 2441 result->NotFound(); |
| 2442 return; |
2434 } | 2443 } |
2435 return; | 2444 value = JSGlobalPropertyCell::cast(value)->value(); |
2436 } | 2445 } |
2437 } else { | 2446 // Make sure to disallow caching for uninitialized constants |
2438 int entry = property_dictionary()->FindEntry(name); | 2447 // found in the dictionary-mode objects. |
2439 if (entry != StringDictionary::kNotFound) { | 2448 if (value->IsTheHole()) result->DisallowCaching(); |
2440 Object* value = property_dictionary()->ValueAt(entry); | 2449 result->DictionaryResult(this, entry); |
2441 if (IsGlobalObject()) { | 2450 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 } | 2451 } |
| 2452 |
2456 result->NotFound(); | 2453 result->NotFound(); |
2457 } | 2454 } |
2458 | 2455 |
2459 | 2456 |
2460 void JSObject::LookupRealNamedProperty(String* name, LookupResult* result) { | 2457 void JSObject::LookupRealNamedProperty(String* name, LookupResult* result) { |
2461 LocalLookupRealNamedProperty(name, result); | 2458 LocalLookupRealNamedProperty(name, result); |
2462 if (result->IsProperty()) return; | 2459 if (result->IsProperty()) return; |
2463 | 2460 |
2464 LookupRealNamedPropertyInPrototypes(name, result); | 2461 LookupRealNamedPropertyInPrototypes(name, result); |
2465 } | 2462 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2872 bool done = false; | 2869 bool done = false; |
2873 MaybeObject* result_object = | 2870 MaybeObject* result_object = |
2874 SetPropertyViaPrototypes(name, value, attributes, strict_mode, &done); | 2871 SetPropertyViaPrototypes(name, value, attributes, strict_mode, &done); |
2875 if (done) return result_object; | 2872 if (done) return result_object; |
2876 } | 2873 } |
2877 | 2874 |
2878 if (!result->IsFound()) { | 2875 if (!result->IsFound()) { |
2879 // Neither properties nor transitions found. | 2876 // Neither properties nor transitions found. |
2880 return AddProperty(name, value, attributes, strict_mode, store_mode); | 2877 return AddProperty(name, value, attributes, strict_mode, store_mode); |
2881 } | 2878 } |
2882 if (result->IsReadOnly() && result->IsProperty()) { | 2879 if (result->IsProperty() && result->IsReadOnly()) { |
2883 if (strict_mode == kStrictMode) { | 2880 if (strict_mode == kStrictMode) { |
2884 Handle<JSObject> self(this); | 2881 Handle<JSObject> self(this); |
2885 Handle<String> hname(name); | 2882 Handle<String> hname(name); |
2886 Handle<Object> args[] = { hname, self }; | 2883 Handle<Object> args[] = { hname, self }; |
2887 return heap->isolate()->Throw(*heap->isolate()->factory()->NewTypeError( | 2884 return heap->isolate()->Throw(*heap->isolate()->factory()->NewTypeError( |
2888 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)))); | 2885 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)))); |
2889 } else { | 2886 } else { |
2890 return value; | 2887 return value; |
2891 } | 2888 } |
2892 } | 2889 } |
| 2890 |
2893 // This is a real property that is not read-only, or it is a | 2891 // 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. | 2892 // transition or null descriptor and there are no setters in the prototypes. |
2895 switch (result->type()) { | 2893 switch (result->type()) { |
2896 case NORMAL: | 2894 case NORMAL: |
2897 return SetNormalizedProperty(result, value); | 2895 return SetNormalizedProperty(result, value); |
2898 case FIELD: | 2896 case FIELD: |
2899 return FastPropertyAtPut(result->GetFieldIndex(), value); | 2897 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: | 2898 case CONSTANT_FUNCTION: |
2909 // Only replace the function if necessary. | 2899 // Only replace the function if necessary. |
2910 if (value == result->GetConstantFunction()) return value; | 2900 if (value == result->GetConstantFunction()) return value; |
2911 // Preserve the attributes of this existing property. | 2901 // Preserve the attributes of this existing property. |
2912 attributes = result->GetAttributes(); | 2902 attributes = result->GetAttributes(); |
2913 return ConvertDescriptorToField(name, value, attributes); | 2903 return ConvertDescriptorToField(name, value, attributes); |
2914 case CALLBACKS: { | 2904 case CALLBACKS: { |
2915 Object* callback_object = result->GetCallbackObject(); | 2905 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, | 2906 return SetPropertyWithCallback(callback_object, |
2921 name, | 2907 name, |
2922 value, | 2908 value, |
2923 result->holder(), | 2909 result->holder(), |
2924 strict_mode); | 2910 strict_mode); |
2925 } | 2911 } |
2926 case INTERCEPTOR: | 2912 case INTERCEPTOR: |
2927 return SetPropertyWithInterceptor(name, value, attributes, strict_mode); | 2913 return SetPropertyWithInterceptor(name, value, attributes, strict_mode); |
2928 case CONSTANT_TRANSITION: { | 2914 case TRANSITION: { |
| 2915 Object* transition = result->GetTransitionValue(); |
| 2916 |
| 2917 if (transition->IsAccessorPair()) { |
| 2918 if (!AccessorPair::cast(transition)->ContainsAccessor()) { |
| 2919 return ConvertDescriptorToField(name, value, attributes); |
| 2920 } |
| 2921 return SetPropertyWithCallback(transition, |
| 2922 name, |
| 2923 value, |
| 2924 result->holder(), |
| 2925 strict_mode); |
| 2926 } |
| 2927 |
| 2928 Map* transition_map = Map::cast(transition); |
| 2929 DescriptorArray* descriptors = transition_map->instance_descriptors(); |
| 2930 int descriptor = descriptors->SearchWithCache(name); |
| 2931 PropertyDetails details = descriptors->GetDetails(descriptor); |
| 2932 ASSERT(details.type() == FIELD || details.type() == CONSTANT_FUNCTION); |
| 2933 |
| 2934 if (details.type() == FIELD) { |
| 2935 if (attributes == details.attributes()) { |
| 2936 int field_index = descriptors->GetFieldIndex(descriptor); |
| 2937 return AddFastPropertyUsingMap(transition_map, |
| 2938 name, |
| 2939 value, |
| 2940 field_index); |
| 2941 } |
| 2942 return ConvertDescriptorToField(name, value, attributes); |
| 2943 } |
| 2944 |
| 2945 // Is transition to CONSTANT_FUNCTION. |
| 2946 Object* constant_function = descriptors->GetValue(descriptor); |
2929 // If the same constant function is being added we can simply | 2947 // If the same constant function is being added we can simply |
2930 // transition to the target map. | 2948 // transition to the target map. |
2931 Map* target_map = result->GetTransitionMap(); | 2949 if (constant_function == value) { |
2932 DescriptorArray* target_descriptors = target_map->instance_descriptors(); | 2950 set_map(transition_map); |
2933 int number = target_descriptors->SearchWithCache(name); | 2951 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 } | 2952 } |
2942 // Otherwise, replace with a MAP_TRANSITION to a new map with a | 2953 // Otherwise, replace with a map transition to a new map with a FIELD, |
2943 // FIELD, even if the value is a constant function. | 2954 // even if the value is a constant function. |
2944 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); | 2955 return ConvertDescriptorToFieldAndMapTransition( |
| 2956 name, value, attributes); |
2945 } | 2957 } |
2946 case HANDLER: | 2958 case HANDLER: |
2947 case NONEXISTENT: | 2959 case NONEXISTENT: |
2948 UNREACHABLE(); | 2960 UNREACHABLE(); |
2949 return value; | 2961 return value; |
2950 } | 2962 } |
2951 UNREACHABLE(); // keep the compiler happy | 2963 UNREACHABLE(); // keep the compiler happy |
2952 return value; | 2964 return value; |
2953 } | 2965 } |
2954 | 2966 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3004 value, | 3016 value, |
3005 attributes); | 3017 attributes); |
3006 } | 3018 } |
3007 | 3019 |
3008 // Check for accessor in prototype chain removed here in clone. | 3020 // Check for accessor in prototype chain removed here in clone. |
3009 if (!result.IsFound()) { | 3021 if (!result.IsFound()) { |
3010 // Neither properties nor transitions found. | 3022 // Neither properties nor transitions found. |
3011 return AddProperty(name, value, attributes, kNonStrictMode); | 3023 return AddProperty(name, value, attributes, kNonStrictMode); |
3012 } | 3024 } |
3013 | 3025 |
3014 PropertyDetails details = PropertyDetails(attributes, NORMAL); | |
3015 | |
3016 // Check of IsReadOnly removed from here in clone. | 3026 // Check of IsReadOnly removed from here in clone. |
3017 switch (result.type()) { | 3027 switch (result.type()) { |
3018 case NORMAL: | 3028 case NORMAL: { |
| 3029 PropertyDetails details = PropertyDetails(attributes, NORMAL); |
3019 return SetNormalizedProperty(name, value, details); | 3030 return SetNormalizedProperty(name, value, details); |
| 3031 } |
3020 case FIELD: | 3032 case FIELD: |
3021 return FastPropertyAtPut(result.GetFieldIndex(), value); | 3033 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: | 3034 case CONSTANT_FUNCTION: |
3031 // Only replace the function if necessary. | 3035 // Only replace the function if necessary. |
3032 if (value == result.GetConstantFunction()) return value; | 3036 if (value == result.GetConstantFunction()) return value; |
3033 // Preserve the attributes of this existing property. | 3037 // Preserve the attributes of this existing property. |
3034 attributes = result.GetAttributes(); | 3038 attributes = result.GetAttributes(); |
3035 return ConvertDescriptorToField(name, value, attributes); | 3039 return ConvertDescriptorToField(name, value, attributes); |
3036 case CALLBACKS: | 3040 case CALLBACKS: |
3037 case INTERCEPTOR: | 3041 case INTERCEPTOR: |
3038 // Override callback in clone | 3042 // Override callback in clone |
3039 return ConvertDescriptorToField(name, value, attributes); | 3043 return ConvertDescriptorToField(name, value, attributes); |
3040 case CONSTANT_TRANSITION: | 3044 case TRANSITION: { |
3041 // Replace with a MAP_TRANSITION to a new map with a FIELD, even | 3045 Object* transition = result.GetTransitionValue(); |
3042 // if the value is a function. | 3046 |
| 3047 if (transition->IsAccessorPair()) { |
| 3048 return ConvertDescriptorToField(name, value, attributes); |
| 3049 } |
| 3050 |
| 3051 Map* transition_map = Map::cast(transition); |
| 3052 DescriptorArray* descriptors = transition_map->instance_descriptors(); |
| 3053 int descriptor = descriptors->Search(name); |
| 3054 PropertyDetails details = descriptors->GetDetails(descriptor); |
| 3055 ASSERT(details.type() == FIELD || details.type() == CONSTANT_FUNCTION); |
| 3056 |
| 3057 if (details.type() == FIELD) { |
| 3058 if (attributes == details.attributes()) { |
| 3059 int field_index = descriptors->GetFieldIndex(descriptor); |
| 3060 return AddFastPropertyUsingMap(transition_map, |
| 3061 name, |
| 3062 value, |
| 3063 field_index); |
| 3064 } |
| 3065 return ConvertDescriptorToField(name, value, attributes); |
| 3066 } |
| 3067 |
| 3068 // Was transition to CONSTANT_FUNCTION. Replace with a map transition to a |
| 3069 // new map with a FIELD, even if the value is a function. |
3043 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); | 3070 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); |
| 3071 } |
3044 case HANDLER: | 3072 case HANDLER: |
3045 case NONEXISTENT: | 3073 case NONEXISTENT: |
3046 UNREACHABLE(); | 3074 UNREACHABLE(); |
3047 } | 3075 } |
3048 UNREACHABLE(); // keep the compiler happy | 3076 UNREACHABLE(); // keep the compiler happy |
3049 return value; | 3077 return value; |
3050 } | 3078 } |
3051 | 3079 |
3052 | 3080 |
3053 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor( | 3081 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor( |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3157 case CONSTANT_FUNCTION: | 3185 case CONSTANT_FUNCTION: |
3158 case CALLBACKS: | 3186 case CALLBACKS: |
3159 return result->GetAttributes(); | 3187 return result->GetAttributes(); |
3160 case HANDLER: { | 3188 case HANDLER: { |
3161 return JSProxy::cast(result->proxy())->GetPropertyAttributeWithHandler( | 3189 return JSProxy::cast(result->proxy())->GetPropertyAttributeWithHandler( |
3162 receiver, name); | 3190 receiver, name); |
3163 } | 3191 } |
3164 case INTERCEPTOR: | 3192 case INTERCEPTOR: |
3165 return result->holder()->GetPropertyAttributeWithInterceptor( | 3193 return result->holder()->GetPropertyAttributeWithInterceptor( |
3166 JSObject::cast(receiver), name, continue_search); | 3194 JSObject::cast(receiver), name, continue_search); |
3167 default: | 3195 case TRANSITION: |
| 3196 case NONEXISTENT: |
3168 UNREACHABLE(); | 3197 UNREACHABLE(); |
3169 } | 3198 } |
3170 } | 3199 } |
3171 return ABSENT; | 3200 return ABSENT; |
3172 } | 3201 } |
3173 | 3202 |
3174 | 3203 |
3175 PropertyAttributes JSReceiver::GetLocalPropertyAttribute(String* name) { | 3204 PropertyAttributes JSReceiver::GetLocalPropertyAttribute(String* name) { |
3176 // Check whether the name is an array index. | 3205 // Check whether the name is an array index. |
3177 uint32_t index = 0; | 3206 uint32_t index = 0; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3314 case FIELD: { | 3343 case FIELD: { |
3315 PropertyDetails d = | 3344 PropertyDetails d = |
3316 PropertyDetails(details.attributes(), NORMAL, details.index()); | 3345 PropertyDetails(details.attributes(), NORMAL, details.index()); |
3317 Object* value = FastPropertyAt(descs->GetFieldIndex(i)); | 3346 Object* value = FastPropertyAt(descs->GetFieldIndex(i)); |
3318 MaybeObject* maybe_dictionary = | 3347 MaybeObject* maybe_dictionary = |
3319 dictionary->Add(descs->GetKey(i), value, d); | 3348 dictionary->Add(descs->GetKey(i), value, d); |
3320 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; | 3349 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; |
3321 break; | 3350 break; |
3322 } | 3351 } |
3323 case CALLBACKS: { | 3352 case CALLBACKS: { |
3324 if (!descs->IsProperty(i)) break; | |
3325 Object* value = descs->GetCallbacksObject(i); | 3353 Object* value = descs->GetCallbacksObject(i); |
3326 if (value->IsAccessorPair()) { | 3354 if (value->IsAccessorPair()) { |
3327 MaybeObject* maybe_copy = | 3355 MaybeObject* maybe_copy = |
3328 AccessorPair::cast(value)->CopyWithoutTransitions(); | 3356 AccessorPair::cast(value)->CopyWithoutTransitions(); |
3329 if (!maybe_copy->To(&value)) return maybe_copy; | 3357 if (!maybe_copy->To(&value)) return maybe_copy; |
3330 } | 3358 } |
3331 MaybeObject* maybe_dictionary = | 3359 MaybeObject* maybe_dictionary = |
3332 dictionary->Add(descs->GetKey(i), value, details); | 3360 dictionary->Add(descs->GetKey(i), value, details); |
3333 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; | 3361 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; |
3334 break; | 3362 break; |
3335 } | 3363 } |
3336 case MAP_TRANSITION: | |
3337 case CONSTANT_TRANSITION: | |
3338 case INTERCEPTOR: | 3364 case INTERCEPTOR: |
3339 break; | 3365 break; |
3340 case HANDLER: | 3366 case HANDLER: |
3341 case NORMAL: | 3367 case NORMAL: |
| 3368 case TRANSITION: |
3342 case NONEXISTENT: | 3369 case NONEXISTENT: |
3343 UNREACHABLE(); | 3370 UNREACHABLE(); |
3344 break; | 3371 break; |
3345 } | 3372 } |
3346 } | 3373 } |
3347 | 3374 |
3348 Heap* current_heap = GetHeap(); | 3375 Heap* current_heap = GetHeap(); |
3349 | 3376 |
3350 // Copy the next enumeration index from instance descriptor. | 3377 // Copy the next enumeration index from instance descriptor. |
3351 int index = map_of_this->instance_descriptors()->NextEnumerationIndex(); | 3378 int index = map_of_this->instance_descriptors()->NextEnumerationIndex(); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3671 MaybeObject* JSObject::GetHiddenPropertiesDictionary(bool create_if_absent) { | 3698 MaybeObject* JSObject::GetHiddenPropertiesDictionary(bool create_if_absent) { |
3672 ASSERT(!IsJSGlobalProxy()); | 3699 ASSERT(!IsJSGlobalProxy()); |
3673 if (HasFastProperties()) { | 3700 if (HasFastProperties()) { |
3674 // If the object has fast properties, check whether the first slot | 3701 // If the object has fast properties, check whether the first slot |
3675 // in the descriptor array matches the hidden symbol. Since the | 3702 // in the descriptor array matches the hidden symbol. Since the |
3676 // hidden symbols hash code is zero (and no other string has hash | 3703 // hidden symbols hash code is zero (and no other string has hash |
3677 // code zero) it will always occupy the first entry if present. | 3704 // code zero) it will always occupy the first entry if present. |
3678 DescriptorArray* descriptors = this->map()->instance_descriptors(); | 3705 DescriptorArray* descriptors = this->map()->instance_descriptors(); |
3679 if ((descriptors->number_of_descriptors() > 0) && | 3706 if ((descriptors->number_of_descriptors() > 0) && |
3680 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { | 3707 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { |
3681 if (descriptors->GetType(0) == FIELD) { | 3708 ASSERT(descriptors->GetType(0) == FIELD); |
3682 Object* hidden_store = | 3709 Object* hidden_store = |
3683 this->FastPropertyAt(descriptors->GetFieldIndex(0)); | 3710 this->FastPropertyAt(descriptors->GetFieldIndex(0)); |
3684 return StringDictionary::cast(hidden_store); | 3711 return StringDictionary::cast(hidden_store); |
3685 } else { | |
3686 ASSERT(descriptors->GetType(0) == MAP_TRANSITION); | |
3687 } | |
3688 } | 3712 } |
3689 } else { | 3713 } else { |
3690 PropertyAttributes attributes; | 3714 PropertyAttributes attributes; |
3691 // You can't install a getter on a property indexed by the hidden symbol, | 3715 // 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 | 3716 // so we can be sure that GetLocalPropertyPostInterceptor returns a real |
3693 // object. | 3717 // object. |
3694 Object* lookup = | 3718 Object* lookup = |
3695 GetLocalPropertyPostInterceptor(this, | 3719 GetLocalPropertyPostInterceptor(this, |
3696 GetHeap()->hidden_symbol(), | 3720 GetHeap()->hidden_symbol(), |
3697 &attributes)->ToObjectUnchecked(); | 3721 &attributes)->ToObjectUnchecked(); |
(...skipping 22 matching lines...) Expand all Loading... |
3720 ASSERT(!IsJSGlobalProxy()); | 3744 ASSERT(!IsJSGlobalProxy()); |
3721 ASSERT(HasHiddenProperties()); | 3745 ASSERT(HasHiddenProperties()); |
3722 if (HasFastProperties()) { | 3746 if (HasFastProperties()) { |
3723 // If the object has fast properties, check whether the first slot | 3747 // If the object has fast properties, check whether the first slot |
3724 // in the descriptor array matches the hidden symbol. Since the | 3748 // in the descriptor array matches the hidden symbol. Since the |
3725 // hidden symbols hash code is zero (and no other string has hash | 3749 // hidden symbols hash code is zero (and no other string has hash |
3726 // code zero) it will always occupy the first entry if present. | 3750 // code zero) it will always occupy the first entry if present. |
3727 DescriptorArray* descriptors = this->map()->instance_descriptors(); | 3751 DescriptorArray* descriptors = this->map()->instance_descriptors(); |
3728 if ((descriptors->number_of_descriptors() > 0) && | 3752 if ((descriptors->number_of_descriptors() > 0) && |
3729 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { | 3753 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { |
3730 if (descriptors->GetType(0) == FIELD) { | 3754 ASSERT(descriptors->GetType(0) == FIELD); |
3731 this->FastPropertyAtPut(descriptors->GetFieldIndex(0), dictionary); | 3755 this->FastPropertyAtPut(descriptors->GetFieldIndex(0), dictionary); |
3732 return this; | 3756 return this; |
3733 } else { | |
3734 ASSERT(descriptors->GetType(0) == MAP_TRANSITION); | |
3735 } | |
3736 } | 3757 } |
3737 } | 3758 } |
3738 MaybeObject* store_result = | 3759 MaybeObject* store_result = |
3739 SetPropertyPostInterceptor(GetHeap()->hidden_symbol(), | 3760 SetPropertyPostInterceptor(GetHeap()->hidden_symbol(), |
3740 dictionary, | 3761 dictionary, |
3741 DONT_ENUM, | 3762 DONT_ENUM, |
3742 kNonStrictMode, | 3763 kNonStrictMode, |
3743 OMIT_EXTENSIBILITY_CHECK); | 3764 OMIT_EXTENSIBILITY_CHECK); |
3744 if (store_result->IsFailure()) return store_result; | 3765 if (store_result->IsFailure()) return store_result; |
3745 return this; | 3766 return this; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4160 } | 4181 } |
4161 return true; | 4182 return true; |
4162 } | 4183 } |
4163 | 4184 |
4164 | 4185 |
4165 int Map::NumberOfDescribedProperties(PropertyAttributes filter) { | 4186 int Map::NumberOfDescribedProperties(PropertyAttributes filter) { |
4166 int result = 0; | 4187 int result = 0; |
4167 DescriptorArray* descs = instance_descriptors(); | 4188 DescriptorArray* descs = instance_descriptors(); |
4168 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 4189 for (int i = 0; i < descs->number_of_descriptors(); i++) { |
4169 PropertyDetails details = descs->GetDetails(i); | 4190 PropertyDetails details = descs->GetDetails(i); |
4170 if (descs->IsProperty(i) && (details.attributes() & filter) == 0) { | 4191 if ((details.attributes() & filter) == 0) { |
4171 result++; | 4192 result++; |
4172 } | 4193 } |
4173 } | 4194 } |
4174 return result; | 4195 return result; |
4175 } | 4196 } |
4176 | 4197 |
4177 | 4198 |
4178 int Map::PropertyIndexFor(String* name) { | 4199 int Map::PropertyIndexFor(String* name) { |
4179 DescriptorArray* descs = instance_descriptors(); | 4200 DescriptorArray* descs = instance_descriptors(); |
4180 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 4201 for (int i = 0; i < descs->number_of_descriptors(); i++) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4366 } | 4387 } |
4367 accessors->SetComponents(getter, setter); | 4388 accessors->SetComponents(getter, setter); |
4368 | 4389 |
4369 return SetElementCallback(index, accessors, attributes); | 4390 return SetElementCallback(index, accessors, attributes); |
4370 } | 4391 } |
4371 | 4392 |
4372 | 4393 |
4373 MaybeObject* JSObject::CreateAccessorPairFor(String* name) { | 4394 MaybeObject* JSObject::CreateAccessorPairFor(String* name) { |
4374 LookupResult result(GetHeap()->isolate()); | 4395 LookupResult result(GetHeap()->isolate()); |
4375 LocalLookupRealNamedProperty(name, &result); | 4396 LocalLookupRealNamedProperty(name, &result); |
4376 if (result.IsProperty() && result.IsCallbacks()) { | 4397 if (result.IsPropertyCallbacks()) { |
4377 // Note that the result can actually have IsDontDelete() == true when we | 4398 // 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 | 4399 // 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 | 4400 // successfully reusing a map transition for a getter. Nevertheless, this is |
4380 // OK, because the assertion only holds for the whole addition of both | 4401 // 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 | 4402 // accessors, not for the addition of each part. See first comment in |
4382 // DefinePropertyAccessor below. | 4403 // DefinePropertyAccessor below. |
4383 Object* obj = result.GetCallbackObject(); | 4404 Object* obj = result.GetCallbackObject(); |
4384 if (obj->IsAccessorPair()) { | 4405 if (obj->IsAccessorPair()) { |
4385 return AccessorPair::cast(obj)->CopyWithoutTransitions(); | 4406 return AccessorPair::cast(obj)->CopyWithoutTransitions(); |
4386 } | 4407 } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4575 { MaybeObject* maybe_accessors2 = heap->AllocateAccessorPair(); | 4596 { MaybeObject* maybe_accessors2 = heap->AllocateAccessorPair(); |
4576 if (!maybe_accessors2->To(&accessors2)) return maybe_accessors2; | 4597 if (!maybe_accessors2->To(&accessors2)) return maybe_accessors2; |
4577 } | 4598 } |
4578 accessors2->set(component, accessor); | 4599 accessors2->set(component, accessor); |
4579 | 4600 |
4580 // step 2: create a copy of the descriptors, incl. the new getter/setter pair | 4601 // step 2: create a copy of the descriptors, incl. the new getter/setter pair |
4581 Map* map1 = obj->map(); | 4602 Map* map1 = obj->map(); |
4582 CallbacksDescriptor callbacks_descr2(name, accessors2, attributes); | 4603 CallbacksDescriptor callbacks_descr2(name, accessors2, attributes); |
4583 DescriptorArray* descriptors2; | 4604 DescriptorArray* descriptors2; |
4584 { MaybeObject* maybe_descriptors2 = | 4605 { MaybeObject* maybe_descriptors2 = |
4585 map1->instance_descriptors()->CopyInsert(&callbacks_descr2, | 4606 map1->instance_descriptors()->CopyInsert(&callbacks_descr2); |
4586 REMOVE_TRANSITIONS); | |
4587 if (!maybe_descriptors2->To(&descriptors2)) return maybe_descriptors2; | 4607 if (!maybe_descriptors2->To(&descriptors2)) return maybe_descriptors2; |
4588 } | 4608 } |
4589 | 4609 |
4590 // step 3: create a new map with the new descriptors | 4610 // step 3: create a new map with the new descriptors |
4591 Map* map2; | 4611 Map* map2; |
4592 { MaybeObject* maybe_map2 = map1->CopyDropDescriptors(); | 4612 { MaybeObject* maybe_map2 = map1->CopyDropDescriptors(); |
4593 if (!maybe_map2->To(&map2)) return maybe_map2; | 4613 if (!maybe_map2->To(&map2)) return maybe_map2; |
4594 } | 4614 } |
4595 map2->set_instance_descriptors(descriptors2); | 4615 map2->set_instance_descriptors(descriptors2); |
4596 | 4616 |
4597 // step 4: create a new getter/setter pair with a transition to the new map | 4617 // step 4: create a new getter/setter pair with a transition to the new map |
4598 AccessorPair* accessors1; | 4618 AccessorPair* accessors1; |
4599 { MaybeObject* maybe_accessors1 = heap->AllocateAccessorPair(); | 4619 { MaybeObject* maybe_accessors1 = heap->AllocateAccessorPair(); |
4600 if (!maybe_accessors1->To(&accessors1)) return maybe_accessors1; | 4620 if (!maybe_accessors1->To(&accessors1)) return maybe_accessors1; |
4601 } | 4621 } |
4602 accessors1->set(component, map2); | 4622 accessors1->set(component, map2); |
4603 | 4623 |
4604 // step 5: create a copy of the descriptors, incl. the new getter/setter pair | 4624 // step 5: create a copy of the descriptors, incl. the new getter/setter pair |
4605 // with the transition | 4625 // with the transition |
4606 CallbacksDescriptor callbacks_descr1(name, accessors1, attributes); | 4626 TransitionArray* new_transitions; |
4607 DescriptorArray* descriptors1; | 4627 { MaybeObject* maybe_new_transitions = map1->AddTransition(name, accessors1); |
4608 { MaybeObject* maybe_descriptors1 = | 4628 if (!maybe_new_transitions->To(&new_transitions)) { |
4609 map1->instance_descriptors()->CopyInsert(&callbacks_descr1, | 4629 return maybe_new_transitions; |
4610 KEEP_TRANSITIONS); | 4630 } |
4611 if (!maybe_descriptors1->To(&descriptors1)) return maybe_descriptors1; | |
4612 } | 4631 } |
4613 | 4632 |
4614 // step 6: everything went well so far, so we make our changes visible | 4633 // step 6: everything went well so far, so we make our changes visible |
| 4634 { MaybeObject* transition_added = map1->set_transitions(new_transitions); |
| 4635 if (transition_added->IsFailure()) return transition_added; |
| 4636 } |
| 4637 |
| 4638 map2->SetBackPointer(map1); |
4615 obj->set_map(map2); | 4639 obj->set_map(map2); |
4616 map1->set_instance_descriptors(descriptors1); | |
4617 map2->SetBackPointer(map1); | |
4618 return obj; | 4640 return obj; |
4619 } | 4641 } |
4620 | 4642 |
4621 | 4643 |
4622 static bool TransitionToSameAccessor(Object* map, | 4644 static bool TransitionToSameAccessor(Object* map, |
4623 String* name, | 4645 String* name, |
4624 AccessorComponent component, | 4646 AccessorComponent component, |
4625 Object* accessor, | 4647 Object* accessor, |
4626 PropertyAttributes attributes ) { | 4648 PropertyAttributes attributes ) { |
4627 DescriptorArray* descs = Map::cast(map)->instance_descriptors(); | 4649 DescriptorArray* descs = Map::cast(map)->instance_descriptors(); |
(...skipping 17 matching lines...) Expand all Loading... |
4645 { MaybeObject* maybe_accessors3 = accessors2->CopyWithoutTransitions(); | 4667 { MaybeObject* maybe_accessors3 = accessors2->CopyWithoutTransitions(); |
4646 if (!maybe_accessors3->To(&accessors3)) return maybe_accessors3; | 4668 if (!maybe_accessors3->To(&accessors3)) return maybe_accessors3; |
4647 } | 4669 } |
4648 accessors3->set(component, accessor); | 4670 accessors3->set(component, accessor); |
4649 | 4671 |
4650 // step 2: create a copy of the descriptors, incl. the new getter/setter pair | 4672 // step 2: create a copy of the descriptors, incl. the new getter/setter pair |
4651 Map* map2 = obj->map(); | 4673 Map* map2 = obj->map(); |
4652 CallbacksDescriptor callbacks_descr3(name, accessors3, attributes); | 4674 CallbacksDescriptor callbacks_descr3(name, accessors3, attributes); |
4653 DescriptorArray* descriptors3; | 4675 DescriptorArray* descriptors3; |
4654 { MaybeObject* maybe_descriptors3 = | 4676 { MaybeObject* maybe_descriptors3 = |
4655 map2->instance_descriptors()->CopyInsert(&callbacks_descr3, | 4677 map2->instance_descriptors()->CopyInsert(&callbacks_descr3); |
4656 REMOVE_TRANSITIONS); | |
4657 if (!maybe_descriptors3->To(&descriptors3)) return maybe_descriptors3; | 4678 if (!maybe_descriptors3->To(&descriptors3)) return maybe_descriptors3; |
4658 } | 4679 } |
4659 | 4680 |
4660 // step 3: create a new map with the new descriptors | 4681 // step 3: create a new map with the new descriptors |
4661 Map* map3; | 4682 Map* map3; |
4662 { MaybeObject* maybe_map3 = map2->CopyDropDescriptors(); | 4683 { MaybeObject* maybe_map3 = map2->CopyDropDescriptors(); |
4663 if (!maybe_map3->To(&map3)) return maybe_map3; | 4684 if (!maybe_map3->To(&map3)) return maybe_map3; |
4664 } | 4685 } |
4665 map3->set_instance_descriptors(descriptors3); | 4686 map3->set_instance_descriptors(descriptors3); |
4666 | 4687 |
4667 // step 4: everything went well so far, so we make our changes visible | 4688 // step 4: add a new transition to the new map |
| 4689 TransitionArray* new_transitions; |
| 4690 { MaybeObject* maybe_transitions = map2->AddTransition(name, accessors2); |
| 4691 if (!maybe_transitions->To(&new_transitions)) return maybe_transitions; |
| 4692 } |
| 4693 |
| 4694 // step 5: everything went well so far, so we make our changes visible |
| 4695 { MaybeObject* transition_added = map2->set_transitions(new_transitions); |
| 4696 if (transition_added->IsFailure()) return transition_added; |
| 4697 } |
| 4698 |
| 4699 map3->SetBackPointer(map2); |
4668 obj->set_map(map3); | 4700 obj->set_map(map3); |
4669 accessors2->set(component, map3); | 4701 accessors2->set(component, map3); |
4670 map3->SetBackPointer(map2); | |
4671 return obj; | 4702 return obj; |
4672 } | 4703 } |
4673 | 4704 |
4674 | 4705 |
4675 MaybeObject* JSObject::DefineFastAccessor(String* name, | 4706 MaybeObject* JSObject::DefineFastAccessor(String* name, |
4676 AccessorComponent component, | 4707 AccessorComponent component, |
4677 Object* accessor, | 4708 Object* accessor, |
4678 PropertyAttributes attributes) { | 4709 PropertyAttributes attributes) { |
4679 ASSERT(accessor->IsSpecFunction() || accessor->IsUndefined()); | 4710 ASSERT(accessor->IsSpecFunction() || accessor->IsUndefined()); |
4680 LookupResult result(GetIsolate()); | 4711 LookupResult result(GetIsolate()); |
4681 LocalLookup(name, &result); | 4712 LocalLookup(name, &result); |
4682 | 4713 |
4683 // If we have a new property, create a fresh accessor plus a transition to it. | 4714 // If we have a new property, create a fresh accessor plus a transition to it. |
4684 if (!result.IsFound()) { | 4715 if (!result.IsFound()) { |
4685 return CreateFreshAccessor(this, name, component, accessor, attributes); | 4716 return CreateFreshAccessor(this, name, component, accessor, attributes); |
4686 } | 4717 } |
4687 | 4718 |
4688 // If the property is not a JavaScript accessor, fall back to the slow case. | 4719 // If the property is not a JavaScript accessor, fall back to the slow case. |
4689 if (result.type() != CALLBACKS) return GetHeap()->null_value(); | 4720 if (!result.IsCallbacks()) return GetHeap()->null_value(); |
| 4721 |
4690 Object* callback_value = result.GetCallbackObject(); | 4722 Object* callback_value = result.GetCallbackObject(); |
4691 if (!callback_value->IsAccessorPair()) return GetHeap()->null_value(); | 4723 if (!callback_value->IsAccessorPair()) return GetHeap()->null_value(); |
4692 AccessorPair* accessors = AccessorPair::cast(callback_value); | 4724 AccessorPair* accessors = AccessorPair::cast(callback_value); |
4693 | 4725 |
4694 // Follow a callback transition, if there is a fitting one. | 4726 // Follow a callback transition, if there is a fitting one. |
4695 Object* entry = accessors->get(component); | 4727 Object* entry = accessors->get(component); |
4696 if (entry->IsMap() && | 4728 if (entry->IsMap() && |
4697 TransitionToSameAccessor(entry, name, component, accessor, attributes)) { | 4729 TransitionToSameAccessor(entry, name, component, accessor, attributes)) { |
4698 set_map(Map::cast(entry)); | 4730 set_map(Map::cast(entry)); |
4699 return this; | 4731 return this; |
4700 } | 4732 } |
4701 | 4733 |
4702 // When we re-add the same accessor again, there is nothing to do. | |
4703 if (entry == accessor && result.GetAttributes() == attributes) return this; | 4734 if (entry == accessor && result.GetAttributes() == attributes) return this; |
4704 | 4735 |
4705 // Only the other accessor has been set so far, create a new transition. | 4736 // Only the other accessor has been set so far, create a new transition. |
4706 if (entry->IsTheHole()) { | 4737 if (entry->IsTheHole()) { |
4707 return NewCallbackTransition(this, | 4738 return NewCallbackTransition(this, |
4708 name, | 4739 name, |
4709 component, | 4740 component, |
4710 accessor, | 4741 accessor, |
4711 attributes, | 4742 attributes, |
4712 accessors); | 4743 accessors); |
(...skipping 21 matching lines...) Expand all Loading... |
4734 return JSObject::cast(proto)->DefineAccessor(info); | 4765 return JSObject::cast(proto)->DefineAccessor(info); |
4735 } | 4766 } |
4736 | 4767 |
4737 // Make sure that the top context does not change when doing callbacks or | 4768 // Make sure that the top context does not change when doing callbacks or |
4738 // interceptor calls. | 4769 // interceptor calls. |
4739 AssertNoContextChange ncc; | 4770 AssertNoContextChange ncc; |
4740 | 4771 |
4741 // Try to flatten before operating on the string. | 4772 // Try to flatten before operating on the string. |
4742 name->TryFlatten(); | 4773 name->TryFlatten(); |
4743 | 4774 |
4744 if (!CanSetCallback(name)) { | 4775 if (!CanSetCallback(name)) return isolate->heap()->undefined_value(); |
4745 return isolate->heap()->undefined_value(); | |
4746 } | |
4747 | 4776 |
4748 uint32_t index = 0; | 4777 uint32_t index = 0; |
4749 bool is_element = name->AsArrayIndex(&index); | 4778 bool is_element = name->AsArrayIndex(&index); |
4750 | 4779 |
4751 if (is_element) { | 4780 if (is_element) { |
4752 if (IsJSArray()) return isolate->heap()->undefined_value(); | 4781 if (IsJSArray()) return isolate->heap()->undefined_value(); |
4753 | 4782 |
4754 // Accessors overwrite previous callbacks (cf. with getters/setters). | 4783 // Accessors overwrite previous callbacks (cf. with getters/setters). |
4755 switch (GetElementsKind()) { | 4784 switch (GetElementsKind()) { |
4756 case FAST_SMI_ELEMENTS: | 4785 case FAST_SMI_ELEMENTS: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4836 } | 4865 } |
4837 } | 4866 } |
4838 } else { | 4867 } else { |
4839 for (Object* obj = this; | 4868 for (Object* obj = this; |
4840 obj != heap->null_value(); | 4869 obj != heap->null_value(); |
4841 obj = JSObject::cast(obj)->GetPrototype()) { | 4870 obj = JSObject::cast(obj)->GetPrototype()) { |
4842 LookupResult result(heap->isolate()); | 4871 LookupResult result(heap->isolate()); |
4843 JSObject::cast(obj)->LocalLookup(name, &result); | 4872 JSObject::cast(obj)->LocalLookup(name, &result); |
4844 if (result.IsProperty()) { | 4873 if (result.IsProperty()) { |
4845 if (result.IsReadOnly()) return heap->undefined_value(); | 4874 if (result.IsReadOnly()) return heap->undefined_value(); |
4846 if (result.IsCallbacks()) { | 4875 if (result.IsPropertyCallbacks()) { |
4847 Object* obj = result.GetCallbackObject(); | 4876 Object* obj = result.GetCallbackObject(); |
4848 if (obj->IsAccessorPair()) { | 4877 if (obj->IsAccessorPair()) { |
4849 return AccessorPair::cast(obj)->GetComponent(component); | 4878 return AccessorPair::cast(obj)->GetComponent(component); |
4850 } | 4879 } |
4851 } | 4880 } |
4852 } | 4881 } |
4853 } | 4882 } |
4854 } | 4883 } |
4855 return heap->undefined_value(); | 4884 return heap->undefined_value(); |
4856 } | 4885 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4896 Map::cast(result)->set_inobject_properties(inobject_properties()); | 4925 Map::cast(result)->set_inobject_properties(inobject_properties()); |
4897 Map::cast(result)->set_unused_property_fields(unused_property_fields()); | 4926 Map::cast(result)->set_unused_property_fields(unused_property_fields()); |
4898 | 4927 |
4899 // If the map has pre-allocated properties always start out with a descriptor | 4928 // If the map has pre-allocated properties always start out with a descriptor |
4900 // array describing these properties. | 4929 // array describing these properties. |
4901 if (pre_allocated_property_fields() > 0) { | 4930 if (pre_allocated_property_fields() > 0) { |
4902 ASSERT(constructor()->IsJSFunction()); | 4931 ASSERT(constructor()->IsJSFunction()); |
4903 JSFunction* ctor = JSFunction::cast(constructor()); | 4932 JSFunction* ctor = JSFunction::cast(constructor()); |
4904 Object* descriptors; | 4933 Object* descriptors; |
4905 { MaybeObject* maybe_descriptors = | 4934 { MaybeObject* maybe_descriptors = |
4906 ctor->initial_map()->instance_descriptors()->RemoveTransitions( | 4935 ctor->initial_map()->instance_descriptors()->Copy( |
4907 DescriptorArray::MAY_BE_SHARED); | 4936 DescriptorArray::MAY_BE_SHARED); |
4908 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors; | 4937 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors; |
4909 } | 4938 } |
4910 Map::cast(result)->set_instance_descriptors( | 4939 Map::cast(result)->set_instance_descriptors( |
4911 DescriptorArray::cast(descriptors)); | 4940 DescriptorArray::cast(descriptors)); |
4912 Map::cast(result)->set_pre_allocated_property_fields( | 4941 Map::cast(result)->set_pre_allocated_property_fields( |
4913 pre_allocated_property_fields()); | 4942 pre_allocated_property_fields()); |
4914 } | 4943 } |
4915 Map::cast(result)->set_bit_field(bit_field()); | 4944 Map::cast(result)->set_bit_field(bit_field()); |
4916 Map::cast(result)->set_bit_field2(bit_field2()); | 4945 Map::cast(result)->set_bit_field2(bit_field2()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4959 | 4988 |
4960 | 4989 |
4961 MaybeObject* Map::CopyDropTransitions( | 4990 MaybeObject* Map::CopyDropTransitions( |
4962 DescriptorArray::SharedMode shared_mode) { | 4991 DescriptorArray::SharedMode shared_mode) { |
4963 Object* new_map; | 4992 Object* new_map; |
4964 { MaybeObject* maybe_new_map = CopyDropDescriptors(); | 4993 { MaybeObject* maybe_new_map = CopyDropDescriptors(); |
4965 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; | 4994 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; |
4966 } | 4995 } |
4967 Object* descriptors; | 4996 Object* descriptors; |
4968 { MaybeObject* maybe_descriptors = | 4997 { MaybeObject* maybe_descriptors = |
4969 instance_descriptors()->RemoveTransitions(shared_mode); | 4998 instance_descriptors()->Copy(shared_mode); |
4970 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors; | 4999 if (!maybe_descriptors->ToObject(&descriptors)) return maybe_descriptors; |
4971 } | 5000 } |
4972 cast(new_map)->set_instance_descriptors(DescriptorArray::cast(descriptors)); | 5001 cast(new_map)->set_instance_descriptors(DescriptorArray::cast(descriptors)); |
4973 return new_map; | 5002 return new_map; |
4974 } | 5003 } |
4975 | 5004 |
4976 | 5005 |
4977 void Map::UpdateCodeCache(Handle<Map> map, | 5006 void Map::UpdateCodeCache(Handle<Map> map, |
4978 Handle<String> name, | 5007 Handle<String> name, |
4979 Handle<Code> code) { | 5008 Handle<Code> code) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5023 // RemoveFromCodeCache so the code cache must be there. | 5052 // RemoveFromCodeCache so the code cache must be there. |
5024 ASSERT(!code_cache()->IsFixedArray()); | 5053 ASSERT(!code_cache()->IsFixedArray()); |
5025 CodeCache::cast(code_cache())->RemoveByIndex(name, code, index); | 5054 CodeCache::cast(code_cache())->RemoveByIndex(name, code, index); |
5026 } | 5055 } |
5027 | 5056 |
5028 | 5057 |
5029 // An iterator over all map transitions in an descriptor array, reusing the map | 5058 // An iterator over all map transitions in an descriptor array, reusing the map |
5030 // field of the contens array while it is running. | 5059 // field of the contens array while it is running. |
5031 class IntrusiveMapTransitionIterator { | 5060 class IntrusiveMapTransitionIterator { |
5032 public: | 5061 public: |
5033 explicit IntrusiveMapTransitionIterator(DescriptorArray* descriptor_array) | 5062 explicit IntrusiveMapTransitionIterator(TransitionArray* transition_array) |
5034 : descriptor_array_(descriptor_array) { } | 5063 : transition_array_(transition_array) { } |
5035 | 5064 |
5036 void Start() { | 5065 void Start() { |
5037 ASSERT(!IsIterating()); | 5066 ASSERT(!IsIterating()); |
5038 if (descriptor_array_->MayContainTransitions()) | 5067 *TransitionArrayHeader() = Smi::FromInt(0); |
5039 *DescriptorArrayHeader() = Smi::FromInt(0); | |
5040 } | 5068 } |
5041 | 5069 |
5042 bool IsIterating() { | 5070 bool IsIterating() { |
5043 return descriptor_array_->MayContainTransitions() && | 5071 return (*TransitionArrayHeader())->IsSmi(); |
5044 (*DescriptorArrayHeader())->IsSmi(); | |
5045 } | 5072 } |
5046 | 5073 |
5047 Map* Next() { | 5074 Map* Next() { |
5048 ASSERT(IsIterating()); | 5075 ASSERT(IsIterating()); |
5049 // Attention, tricky index manipulation ahead: Two consecutive indices are | 5076 // Attention, tricky index manipulation ahead: Two consecutive indices are |
5050 // assigned to each descriptor. Most descriptors directly advance to the | 5077 // assigned to each descriptor. Most descriptors directly advance to the |
5051 // next descriptor by adding 2 to the index. The exceptions are the | 5078 // 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 | 5079 // CALLBACKS entries: An even index means we look at its getter, and an odd |
5053 // index means we look at its setter. | 5080 // index means we look at its setter. |
5054 int raw_index = Smi::cast(*DescriptorArrayHeader())->value(); | 5081 int raw_index = Smi::cast(*TransitionArrayHeader())->value(); |
5055 int index = raw_index / 2; | 5082 int index = raw_index / 2; |
5056 int number_of_descriptors = descriptor_array_->number_of_descriptors(); | 5083 int number_of_transitions = transition_array_->number_of_transitions(); |
5057 while (index < number_of_descriptors) { | 5084 while (index < number_of_transitions) { |
5058 PropertyDetails details(descriptor_array_->GetDetails(index)); | 5085 Object* value = transition_array_->GetValue(index); |
5059 switch (details.type()) { | 5086 |
5060 case MAP_TRANSITION: | 5087 if (value->IsMap()) { |
5061 case CONSTANT_TRANSITION: | 5088 *TransitionArrayHeader() = Smi::FromInt(raw_index + 2); |
5062 // We definitely have a map transition. | 5089 return static_cast<Map*>(value); |
5063 *DescriptorArrayHeader() = Smi::FromInt(raw_index + 2); | 5090 } |
5064 return static_cast<Map*>(descriptor_array_->GetValue(index)); | 5091 |
5065 case CALLBACKS: { | 5092 ASSERT(value->IsAccessorPair()); |
5066 // We might have a map transition in a getter or in a setter. | 5093 |
5067 AccessorPair* accessors = | 5094 // We might have a map transition in a getter or in a setter. |
5068 static_cast<AccessorPair*>(descriptor_array_->GetValue(index)); | 5095 AccessorPair* accessors = static_cast<AccessorPair*>(value); |
5069 Object* accessor; | 5096 Object* accessor; |
5070 if ((raw_index & 1) == 0) { | 5097 if ((raw_index & 1) == 0) { |
5071 accessor = accessors->setter(); | 5098 accessor = accessors->setter(); |
5072 } else { | 5099 } else { |
5073 ++index; | 5100 ++index; |
5074 accessor = accessors->getter(); | 5101 accessor = accessors->getter(); |
5075 } | 5102 } |
5076 ++raw_index; | 5103 ++raw_index; |
5077 if (accessor->IsMap()) { | 5104 if (accessor->IsMap()) { |
5078 *DescriptorArrayHeader() = Smi::FromInt(raw_index); | 5105 *TransitionArrayHeader() = Smi::FromInt(raw_index); |
5079 return static_cast<Map*>(accessor); | 5106 return static_cast<Map*>(accessor); |
5080 } | |
5081 break; | |
5082 } | |
5083 case NORMAL: | |
5084 case FIELD: | |
5085 case CONSTANT_FUNCTION: | |
5086 case HANDLER: | |
5087 case INTERCEPTOR: | |
5088 // We definitely have no map transition. | |
5089 raw_index += 2; | |
5090 ++index; | |
5091 break; | |
5092 case NONEXISTENT: | |
5093 UNREACHABLE(); | |
5094 break; | |
5095 } | 5107 } |
5096 } | 5108 } |
5097 if (index == descriptor_array_->number_of_descriptors()) { | 5109 |
5098 Map* elements_transition = descriptor_array_->elements_transition_map(); | 5110 if (index == transition_array_->number_of_transitions() && |
5099 if (elements_transition != NULL) { | 5111 transition_array_->HasElementsTransition()) { |
5100 *DescriptorArrayHeader() = Smi::FromInt(raw_index + 2); | 5112 Map* elements_transition = transition_array_->elements_transition(); |
5101 return elements_transition; | 5113 *TransitionArrayHeader() = Smi::FromInt(raw_index + 2); |
5102 } | 5114 return elements_transition; |
5103 } | 5115 } |
5104 *DescriptorArrayHeader() = descriptor_array_->GetHeap()->fixed_array_map(); | 5116 *TransitionArrayHeader() = transition_array_->GetHeap()->fixed_array_map(); |
5105 return NULL; | 5117 return NULL; |
5106 } | 5118 } |
5107 | 5119 |
5108 private: | 5120 private: |
5109 Object** DescriptorArrayHeader() { | 5121 Object** TransitionArrayHeader() { |
5110 return HeapObject::RawField(descriptor_array_, DescriptorArray::kMapOffset); | 5122 return HeapObject::RawField(transition_array_, TransitionArray::kMapOffset); |
5111 } | 5123 } |
5112 | 5124 |
5113 DescriptorArray* descriptor_array_; | 5125 TransitionArray* transition_array_; |
5114 }; | 5126 }; |
5115 | 5127 |
5116 | 5128 |
5117 // An iterator over all prototype transitions, reusing the map field of the | 5129 // An iterator over all prototype transitions, reusing the map field of the |
5118 // underlying array while it is running. | 5130 // underlying array while it is running. |
5119 class IntrusivePrototypeTransitionIterator { | 5131 class IntrusivePrototypeTransitionIterator { |
5120 public: | 5132 public: |
5121 explicit IntrusivePrototypeTransitionIterator(HeapObject* proto_trans) | 5133 explicit IntrusivePrototypeTransitionIterator(HeapObject* proto_trans) |
5122 : proto_trans_(proto_trans) { } | 5134 : proto_trans_(proto_trans) { } |
5123 | 5135 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5203 | 5215 |
5204 // Reset the current map's map, returning the parent previously stored in it. | 5216 // Reset the current map's map, returning the parent previously stored in it. |
5205 TraversableMap* GetAndResetParent() { | 5217 TraversableMap* GetAndResetParent() { |
5206 TraversableMap* old_parent = static_cast<TraversableMap*>(map()); | 5218 TraversableMap* old_parent = static_cast<TraversableMap*>(map()); |
5207 set_map_no_write_barrier(GetHeap()->meta_map()); | 5219 set_map_no_write_barrier(GetHeap()->meta_map()); |
5208 return old_parent; | 5220 return old_parent; |
5209 } | 5221 } |
5210 | 5222 |
5211 // Can either be Smi (no instance descriptors), or a descriptor array with the | 5223 // Can either be Smi (no instance descriptors), or a descriptor array with the |
5212 // header overwritten as a Smi (thus iterating). | 5224 // header overwritten as a Smi (thus iterating). |
5213 DescriptorArray* MutatedInstanceDescriptors() { | 5225 TransitionArray* MutatedTransitions() { |
5214 Object* object = | 5226 Object* object = *HeapObject::RawField(instance_descriptors(), |
5215 *HeapObject::RawField(this, kInstanceDescriptorsOrBitField3Offset); | 5227 DescriptorArray::kTransitionsOffset); |
5216 if (object->IsSmi()) { | 5228 TransitionArray* transition_array = static_cast<TransitionArray*>(object); |
5217 return GetHeap()->empty_descriptor_array(); | 5229 return transition_array; |
5218 } else { | |
5219 DescriptorArray* descriptor_array = | |
5220 static_cast<DescriptorArray*>(object); | |
5221 return descriptor_array; | |
5222 } | |
5223 } | 5230 } |
5224 | 5231 |
5225 // Start iterating over this map's children, possibly destroying a FixedArray | 5232 // Start iterating over this map's children, possibly destroying a FixedArray |
5226 // map (see explanation above). | 5233 // map (see explanation above). |
5227 void ChildIteratorStart() { | 5234 void ChildIteratorStart() { |
5228 IntrusiveMapTransitionIterator(instance_descriptors()).Start(); | 5235 if (HasTransitionArray()) { |
| 5236 IntrusiveMapTransitionIterator(transitions()).Start(); |
| 5237 } |
5229 IntrusivePrototypeTransitionIterator( | 5238 IntrusivePrototypeTransitionIterator( |
5230 unchecked_prototype_transitions()).Start(); | 5239 unchecked_prototype_transitions()).Start(); |
5231 } | 5240 } |
5232 | 5241 |
5233 // If we have an unvisited child map, return that one and advance. If we have | 5242 // 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. | 5243 // none, return NULL and reset any destroyed FixedArray maps. |
5235 TraversableMap* ChildIteratorNext() { | 5244 TraversableMap* ChildIteratorNext() { |
5236 IntrusivePrototypeTransitionIterator | 5245 IntrusivePrototypeTransitionIterator |
5237 proto_iterator(unchecked_prototype_transitions()); | 5246 proto_iterator(unchecked_prototype_transitions()); |
5238 if (proto_iterator.IsIterating()) { | 5247 if (proto_iterator.IsIterating()) { |
5239 Map* next = proto_iterator.Next(); | 5248 Map* next = proto_iterator.Next(); |
5240 if (next != NULL) return static_cast<TraversableMap*>(next); | 5249 if (next != NULL) return static_cast<TraversableMap*>(next); |
5241 } | 5250 } |
5242 IntrusiveMapTransitionIterator | 5251 if (HasTransitionArray()) { |
5243 descriptor_iterator(MutatedInstanceDescriptors()); | 5252 IntrusiveMapTransitionIterator |
5244 if (descriptor_iterator.IsIterating()) { | 5253 transitions_iterator(MutatedTransitions()); |
5245 Map* next = descriptor_iterator.Next(); | 5254 if (transitions_iterator.IsIterating()) { |
5246 if (next != NULL) return static_cast<TraversableMap*>(next); | 5255 Map* next = transitions_iterator.Next(); |
| 5256 if (next != NULL) return static_cast<TraversableMap*>(next); |
| 5257 } |
5247 } | 5258 } |
5248 return NULL; | 5259 return NULL; |
5249 } | 5260 } |
5250 }; | 5261 }; |
5251 | 5262 |
5252 | 5263 |
5253 // Traverse the transition tree in postorder without using the C++ stack by | 5264 // Traverse the transition tree in postorder without using the C++ stack by |
5254 // doing pointer reversal. | 5265 // doing pointer reversal. |
5255 void Map::TraverseTransitionTree(TraverseCallback callback, void* data) { | 5266 void Map::TraverseTransitionTree(TraverseCallback callback, void* data) { |
5256 TraversableMap* current = static_cast<TraversableMap*>(this); | 5267 TraversableMap* current = static_cast<TraversableMap*>(this); |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5865 MaybeObject* maybe_copy = | 5876 MaybeObject* maybe_copy = |
5866 AccessorPair::cast(value)->CopyWithoutTransitions(); | 5877 AccessorPair::cast(value)->CopyWithoutTransitions(); |
5867 if (!maybe_copy->To(&value)) return maybe_copy; | 5878 if (!maybe_copy->To(&value)) return maybe_copy; |
5868 } | 5879 } |
5869 Descriptor desc(src->GetKey(src_index), value, details); | 5880 Descriptor desc(src->GetKey(src_index), value, details); |
5870 Set(dst_index, &desc, witness); | 5881 Set(dst_index, &desc, witness); |
5871 return this; | 5882 return this; |
5872 } | 5883 } |
5873 | 5884 |
5874 | 5885 |
5875 MaybeObject* DescriptorArray::CopyInsert(Descriptor* descriptor, | 5886 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. | 5887 // Ensure the key is a symbol. |
5886 { MaybeObject* maybe_result = descriptor->KeyToSymbol(); | 5888 { MaybeObject* maybe_result = descriptor->KeyToSymbol(); |
5887 if (maybe_result->IsFailure()) return maybe_result; | 5889 if (maybe_result->IsFailure()) return maybe_result; |
5888 } | 5890 } |
5889 | 5891 |
5890 int new_size = 0; | 5892 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 | 5893 |
5896 // If key is in descriptor, we replace it in-place when filtering. | 5894 // If key is in descriptor, we replace it in-place when filtering. |
5897 // Count a null descriptor for key as inserted, not replaced. | 5895 // Count a null descriptor for key as inserted, not replaced. |
5898 int index = Search(descriptor->GetKey()); | 5896 int index = SearchWithCache(descriptor->GetKey()); |
5899 const bool replacing = (index != kNotFound); | 5897 const bool replacing = (index != kNotFound); |
5900 bool keep_enumeration_index = false; | 5898 bool keep_enumeration_index = false; |
5901 if (!replacing) { | 5899 if (replacing) { |
5902 ++new_size; | |
5903 } else if (!IsTransitionOnly(index)) { | |
5904 // We are replacing an existing descriptor. We keep the enumeration index | 5900 // We are replacing an existing descriptor. We keep the enumeration index |
5905 // of a visible property. | 5901 // of a visible property. |
5906 keep_enumeration_index = true; | 5902 keep_enumeration_index = true; |
5907 } else if (remove_transitions) { | 5903 } 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; | 5904 ++new_size; |
5911 } | 5905 } |
5912 | 5906 |
5913 DescriptorArray* new_descriptors; | 5907 DescriptorArray* new_descriptors; |
5914 { SharedMode mode = remove_transitions ? MAY_BE_SHARED : CANNOT_BE_SHARED; | 5908 { 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; | 5909 if (!maybe_result->To(&new_descriptors)) return maybe_result; |
5917 } | 5910 } |
5918 | 5911 |
5919 DescriptorArray::WhitenessWitness witness(new_descriptors); | 5912 FixedArray::WhitenessWitness witness(new_descriptors); |
5920 | 5913 |
5921 // Set the enumeration index in the descriptors and set the enumeration index | 5914 // Set the enumeration index in the descriptors and set the enumeration index |
5922 // in the result. | 5915 // in the result. |
5923 int enumeration_index = NextEnumerationIndex(); | 5916 int enumeration_index = NextEnumerationIndex(); |
5924 if (!descriptor->ContainsTransition()) { | 5917 if (keep_enumeration_index) { |
5925 if (keep_enumeration_index) { | 5918 descriptor->SetEnumerationIndex(GetDetails(index).index()); |
5926 descriptor->SetEnumerationIndex(GetDetails(index).index()); | 5919 } else { |
5927 } else { | 5920 descriptor->SetEnumerationIndex(enumeration_index); |
5928 descriptor->SetEnumerationIndex(enumeration_index); | 5921 ++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 } | 5922 } |
5936 new_descriptors->SetNextEnumerationIndex(enumeration_index); | 5923 new_descriptors->SetNextEnumerationIndex(enumeration_index); |
5937 | 5924 |
5938 // Copy the descriptors, filtering out transitions and null descriptors, | 5925 // Copy the descriptors, inserting or replacing a descriptor. |
5939 // and inserting or replacing a descriptor. | |
5940 int to_index = 0; | 5926 int to_index = 0; |
5941 int insertion_index = -1; | 5927 int insertion_index = -1; |
5942 int from_index = 0; | 5928 int from_index = 0; |
5943 while (from_index < number_of_descriptors()) { | 5929 while (from_index < number_of_descriptors()) { |
5944 if (insertion_index < 0 && | 5930 if (insertion_index < 0 && |
5945 InsertionPointFound(GetKey(from_index), descriptor->GetKey())) { | 5931 InsertionPointFound(GetKey(from_index), descriptor->GetKey())) { |
5946 insertion_index = to_index++; | 5932 insertion_index = to_index++; |
5947 if (replacing) from_index++; | 5933 if (replacing) from_index++; |
5948 } else { | 5934 } else { |
5949 if (!(remove_transitions && IsTransitionOnly(from_index))) { | 5935 MaybeObject* copy_result = |
5950 MaybeObject* copy_result = | 5936 new_descriptors->CopyFrom(to_index++, this, from_index, witness); |
5951 new_descriptors->CopyFrom(to_index++, this, from_index, witness); | 5937 if (copy_result->IsFailure()) return copy_result; |
5952 if (copy_result->IsFailure()) return copy_result; | |
5953 } | |
5954 from_index++; | 5938 from_index++; |
5955 } | 5939 } |
5956 } | 5940 } |
5957 if (insertion_index < 0) insertion_index = to_index++; | 5941 if (insertion_index < 0) insertion_index = to_index++; |
5958 | 5942 |
5959 ASSERT(insertion_index < new_descriptors->number_of_descriptors()); | 5943 ASSERT(insertion_index < new_descriptors->number_of_descriptors()); |
5960 new_descriptors->Set(insertion_index, descriptor, witness); | 5944 new_descriptors->Set(insertion_index, descriptor, witness); |
5961 | 5945 |
5962 ASSERT(to_index == new_descriptors->number_of_descriptors()); | 5946 ASSERT(to_index == new_descriptors->number_of_descriptors()); |
5963 SLOW_ASSERT(new_descriptors->IsSortedNoDuplicates()); | 5947 SLOW_ASSERT(new_descriptors->IsSortedNoDuplicates()); |
5964 | 5948 |
5965 return new_descriptors; | 5949 return new_descriptors; |
5966 } | 5950 } |
5967 | 5951 |
5968 | 5952 |
5969 MaybeObject* DescriptorArray::RemoveTransitions(SharedMode shared_mode) { | 5953 MaybeObject* DescriptorArray::Copy(SharedMode shared_mode) { |
5970 // Allocate the new descriptor array. | 5954 // Allocate the new descriptor array. |
5971 int new_number_of_descriptors = 0; | 5955 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; | 5956 DescriptorArray* new_descriptors; |
5976 { MaybeObject* maybe_result = Allocate(new_number_of_descriptors, | 5957 { MaybeObject* maybe_result = Allocate(number_of_descriptors, |
5977 shared_mode); | 5958 shared_mode); |
5978 if (!maybe_result->To(&new_descriptors)) return maybe_result; | 5959 if (!maybe_result->To(&new_descriptors)) return maybe_result; |
5979 } | 5960 } |
5980 | 5961 |
5981 // Copy the content. | 5962 // Copy the content. |
5982 DescriptorArray::WhitenessWitness witness(new_descriptors); | 5963 if (number_of_descriptors > 0) { |
5983 int next_descriptor = 0; | 5964 FixedArray::WhitenessWitness witness(new_descriptors); |
5984 for (int i = 0; i < number_of_descriptors(); i++) { | 5965 for (int i = 0; i < number_of_descriptors; i++) { |
5985 if (IsProperty(i)) { | |
5986 MaybeObject* copy_result = | 5966 MaybeObject* copy_result = |
5987 new_descriptors->CopyFrom(next_descriptor++, this, i, witness); | 5967 new_descriptors->CopyFrom(i, this, i, witness); |
5988 if (copy_result->IsFailure()) return copy_result; | 5968 if (copy_result->IsFailure()) return copy_result; |
5989 } | 5969 } |
5990 } | 5970 } |
5991 ASSERT(next_descriptor == new_descriptors->number_of_descriptors()); | |
5992 new_descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); | 5971 new_descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); |
5993 | |
5994 return new_descriptors; | 5972 return new_descriptors; |
5995 } | 5973 } |
5996 | 5974 |
5997 // We need the whiteness witness since sort will reshuffle the entries in the | 5975 // 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 | 5976 // 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 | 5977 // would move a slot that was already recorded as pointing into an evacuation |
6000 // candidate. This would result in missing updates upon evacuation. | 5978 // candidate. This would result in missing updates upon evacuation. |
6001 void DescriptorArray::SortUnchecked(const WhitenessWitness& witness) { | 5979 void DescriptorArray::SortUnchecked(const WhitenessWitness& witness) { |
6002 // In-place heap sort. | 5980 // In-place heap sort. |
6003 int len = number_of_descriptors(); | 5981 int len = number_of_descriptors(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6050 } | 6028 } |
6051 } | 6029 } |
6052 | 6030 |
6053 | 6031 |
6054 void DescriptorArray::Sort(const WhitenessWitness& witness) { | 6032 void DescriptorArray::Sort(const WhitenessWitness& witness) { |
6055 SortUnchecked(witness); | 6033 SortUnchecked(witness); |
6056 SLOW_ASSERT(IsSortedNoDuplicates()); | 6034 SLOW_ASSERT(IsSortedNoDuplicates()); |
6057 } | 6035 } |
6058 | 6036 |
6059 | 6037 |
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() { | 6038 MaybeObject* AccessorPair::CopyWithoutTransitions() { |
6098 Heap* heap = GetHeap(); | 6039 Heap* heap = GetHeap(); |
6099 AccessorPair* copy; | 6040 AccessorPair* copy; |
6100 { MaybeObject* maybe_copy = heap->AllocateAccessorPair(); | 6041 { MaybeObject* maybe_copy = heap->AllocateAccessorPair(); |
6101 if (!maybe_copy->To(©)) return maybe_copy; | 6042 if (!maybe_copy->To(©)) return maybe_copy; |
6102 } | 6043 } |
6103 copy->set_getter(getter()->IsMap() ? heap->the_hole_value() : getter()); | 6044 copy->set_getter(getter()->IsMap() ? heap->the_hole_value() : getter()); |
6104 copy->set_setter(setter()->IsMap() ? heap->the_hole_value() : setter()); | 6045 copy->set_setter(setter()->IsMap() ? heap->the_hole_value() : setter()); |
6105 return copy; | 6046 return copy; |
6106 } | 6047 } |
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7329 | 7270 |
7330 | 7271 |
7331 void String::PrintOn(FILE* file) { | 7272 void String::PrintOn(FILE* file) { |
7332 int length = this->length(); | 7273 int length = this->length(); |
7333 for (int i = 0; i < length; i++) { | 7274 for (int i = 0; i < length; i++) { |
7334 fprintf(file, "%c", Get(i)); | 7275 fprintf(file, "%c", Get(i)); |
7335 } | 7276 } |
7336 } | 7277 } |
7337 | 7278 |
7338 | 7279 |
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 | 7280 // This function should only be called from within the GC, since it uses |
7351 // IncrementLiveBytesFromGC. If called from anywhere else, this results in an | 7281 // IncrementLiveBytesFromGC. If called from anywhere else, this results in an |
7352 // inconsistent live-bytes count. | 7282 // inconsistent live-bytes count. |
7353 static void RightTrimFixedArray(Heap* heap, FixedArray* elms, int to_trim) { | 7283 static void RightTrimFixedArray(Heap* heap, FixedArray* elms, int to_trim) { |
7354 ASSERT(elms->map() != HEAP->fixed_cow_array_map()); | 7284 ASSERT(elms->map() != HEAP->fixed_cow_array_map()); |
7355 // For now this trick is only applied to fixed arrays in new and paged space. | 7285 // 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 | 7286 // In large object space the object's start must coincide with chunk |
7357 // and thus the trick is just not applicable. | 7287 // and thus the trick is just not applicable. |
7358 ASSERT(!HEAP->lo_space()->Contains(elms)); | 7288 ASSERT(!HEAP->lo_space()->Contains(elms)); |
7359 | 7289 |
(...skipping 20 matching lines...) Expand all Loading... |
7380 | 7310 |
7381 elms->set_length(len - to_trim); | 7311 elms->set_length(len - to_trim); |
7382 | 7312 |
7383 // Maintain marking consistency for IncrementalMarking. | 7313 // Maintain marking consistency for IncrementalMarking. |
7384 if (Marking::IsBlack(Marking::MarkBitFrom(elms))) { | 7314 if (Marking::IsBlack(Marking::MarkBitFrom(elms))) { |
7385 MemoryChunk::IncrementLiveBytesFromGC(elms->address(), -size_delta); | 7315 MemoryChunk::IncrementLiveBytesFromGC(elms->address(), -size_delta); |
7386 } | 7316 } |
7387 } | 7317 } |
7388 | 7318 |
7389 | 7319 |
7390 // If the descriptor describes a transition to a dead map, the back pointer | 7320 // 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. | 7321 // Return true in case a back pointer has been cleared and false otherwise. |
7392 static bool ClearNonLiveTransitionsFromDescriptor(Heap* heap, | 7322 static bool ClearBackPointer(Heap* heap, Object* target) { |
7393 DescriptorArray* d, | 7323 ASSERT(target->IsMap()); |
7394 int descriptor_index) { | 7324 Map* map = Map::cast(target); |
7395 // If the pair (value, details) is a map transition, check if the target is | 7325 if (Marking::MarkBitFrom(map).Get()) return false; |
7396 // live. If not, null the descriptor. Also drop the back pointer for that | 7326 map->SetBackPointer(heap->undefined_value(), SKIP_WRITE_BARRIER); |
7397 // map transition, so that this map is not reached again by following a back | 7327 return true; |
7398 // pointer from that non-live map. | 7328 } |
7399 PropertyDetails details(d->GetDetails(descriptor_index)); | 7329 |
7400 switch (details.type()) { | 7330 |
7401 case MAP_TRANSITION: | 7331 static bool ClearAccessorComponent(Heap* heap, |
7402 case CONSTANT_TRANSITION: | 7332 AccessorPair* accessors, |
7403 return ClearBackPointer(heap, d->GetValue(descriptor_index)); | 7333 AccessorComponent component) { |
7404 case CALLBACKS: { | 7334 Object* component_value = accessors->get(component); |
7405 Object* object = d->GetValue(descriptor_index); | 7335 if (!component_value->IsMap()) return true; |
7406 if (object->IsAccessorPair()) { | 7336 if (ClearBackPointer(heap, component_value)) { |
7407 bool cleared = true; | 7337 accessors->set(component, heap->the_hole_value()); |
7408 AccessorPair* accessors = AccessorPair::cast(object); | 7338 return true; |
7409 Object* getter = accessors->getter(); | |
7410 if (getter->IsMap()) { | |
7411 if (ClearBackPointer(heap, getter)) { | |
7412 accessors->set_getter(heap->the_hole_value()); | |
7413 } else { | |
7414 cleared = false; | |
7415 } | |
7416 } else if (!getter->IsTheHole()) { | |
7417 cleared = false; | |
7418 } | |
7419 Object* setter = accessors->setter(); | |
7420 if (setter->IsMap()) { | |
7421 if (ClearBackPointer(heap, setter)) { | |
7422 accessors->set_setter(heap->the_hole_value()); | |
7423 } else { | |
7424 cleared = false; | |
7425 } | |
7426 } else if (!setter->IsTheHole()) { | |
7427 cleared = false; | |
7428 } | |
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 } | 7339 } |
7442 UNREACHABLE(); | 7340 return false; |
7443 return true; | 7341 } |
| 7342 |
| 7343 |
| 7344 static bool ClearNonLiveTransition(Heap* heap, |
| 7345 TransitionArray* t, |
| 7346 int transition_index) { |
| 7347 // If the value is a map, check if the target is live. If not, clear the |
| 7348 // transition. Also drop the back pointer for that map transition, so that |
| 7349 // this map is not reached again by following a back pointer from that |
| 7350 // non-live map. |
| 7351 Object* value = t->GetValue(transition_index); |
| 7352 if (value->IsMap()) { |
| 7353 return ClearBackPointer(heap, t->GetValue(transition_index)); |
| 7354 } |
| 7355 |
| 7356 ASSERT(value->IsAccessorPair()); |
| 7357 |
| 7358 AccessorPair* accessors = AccessorPair::cast(value); |
| 7359 bool getter = ClearAccessorComponent(heap, accessors, ACCESSOR_GETTER); |
| 7360 bool setter = ClearAccessorComponent(heap, accessors, ACCESSOR_SETTER); |
| 7361 return getter && setter; |
7444 } | 7362 } |
7445 | 7363 |
7446 | 7364 |
7447 // TODO(mstarzinger): This method should be moved into MarkCompactCollector, | 7365 // TODO(mstarzinger): This method should be moved into MarkCompactCollector, |
7448 // because it cannot be called from outside the GC and we already have methods | 7366 // because it cannot be called from outside the GC and we already have methods |
7449 // depending on the transitions layout in the GC anyways. | 7367 // depending on the transitions layout in the GC anyways. |
7450 void Map::ClearNonLiveTransitions(Heap* heap) { | 7368 void Map::ClearNonLiveTransitions(Heap* heap) { |
7451 Object* array = *RawField(this, Map::kInstanceDescriptorsOrBitField3Offset); | 7369 TransitionArray* t = transitions(); |
7452 // If there are no descriptors to be cleared, return. | 7370 // If there are no transitions to be cleared, return. |
7453 // TODO(verwaest) Should be an assert, otherwise back pointers are not | 7371 // TODO(verwaest) Should be an assert, otherwise back pointers are not |
7454 // properly cleared. | 7372 // properly cleared. |
7455 if (array->IsSmi()) return; | 7373 if (t == NULL) return; |
7456 DescriptorArray* d = DescriptorArray::cast(array); | |
7457 | 7374 |
7458 int descriptor_index = 0; | 7375 int transition_index = 0; |
| 7376 |
7459 // Compact all live descriptors to the left. | 7377 // Compact all live descriptors to the left. |
7460 for (int i = 0; i < d->number_of_descriptors(); ++i) { | 7378 for (int i = 0; i < t->number_of_transitions(); ++i) { |
7461 if (!ClearNonLiveTransitionsFromDescriptor(heap, d, i)) { | 7379 if (!ClearNonLiveTransition(heap, t, i)) { |
7462 if (i != descriptor_index) { | 7380 if (i != transition_index) { |
7463 String* key = d->GetKey(i); | 7381 String* key = t->GetKey(i); |
7464 Object* value = d->GetValue(i); | 7382 Object* value = t->GetValue(i); |
7465 d->SetKeyUnchecked(heap, descriptor_index, key); | 7383 t->SetKey(transition_index, key); |
7466 d->SetDetailsUnchecked(descriptor_index, d->GetDetails(i).AsSmi()); | 7384 t->SetValue(transition_index, value); |
7467 d->SetValueUnchecked(heap, descriptor_index, value); | |
7468 MarkCompactCollector* collector = heap->mark_compact_collector(); | 7385 MarkCompactCollector* collector = heap->mark_compact_collector(); |
7469 Object** key_slot = d->GetKeySlot(descriptor_index); | 7386 Object** key_slot = t->GetKeySlot(transition_index); |
7470 collector->RecordSlot(key_slot, key_slot, key); | 7387 collector->RecordSlot(key_slot, key_slot, key); |
7471 if (value->IsHeapObject()) { | 7388 Object** value_slot = t->GetValueSlot(transition_index); |
7472 Object** value_slot = d->GetValueSlot(descriptor_index); | 7389 collector->RecordSlot(value_slot, value_slot, value); |
7473 collector->RecordSlot(value_slot, value_slot, value); | |
7474 } | |
7475 } | 7390 } |
7476 descriptor_index++; | 7391 transition_index++; |
7477 } | 7392 } |
7478 } | 7393 } |
7479 | 7394 |
7480 Map* elements_transition = d->elements_transition_map(); | 7395 if (t->HasElementsTransition() && |
7481 if (elements_transition != NULL && | 7396 ClearBackPointer(heap, t->elements_transition())) { |
7482 ClearBackPointer(heap, elements_transition)) { | 7397 t->ClearElementsTransition(); |
7483 elements_transition = NULL; | |
7484 d->ClearElementsTransition(); | |
7485 } else { | 7398 } else { |
7486 // If there are no descriptors to be cleared, return. | 7399 // If there are no transitions to be cleared, return. |
7487 // TODO(verwaest) Should be an assert, otherwise back pointers are not | 7400 // TODO(verwaest) Should be an assert, otherwise back pointers are not |
7488 // properly cleared. | 7401 // properly cleared. |
7489 if (descriptor_index == d->number_of_descriptors()) return; | 7402 if (transition_index == t->number_of_transitions()) return; |
7490 } | 7403 } |
7491 | 7404 |
7492 // If the final descriptor array does not contain any live descriptors, remove | 7405 // If the final transition array does not contain any live transitions, remove |
7493 // the descriptor array from the map. | 7406 // the transition array from the map. |
7494 if (descriptor_index == 0 && elements_transition == NULL) { | 7407 if (transition_index == 0 && !t->HasElementsTransition()) { |
7495 ClearDescriptorArray(); | 7408 return ClearTransitions(); |
7496 return; | |
7497 } | 7409 } |
7498 | 7410 |
7499 int trim = d->number_of_descriptors() - descriptor_index; | 7411 int trim = t->number_of_transitions() - transition_index; |
7500 if (trim > 0) { | 7412 if (trim > 0) { |
7501 RightTrimFixedArray(heap, d, trim * DescriptorArray::kDescriptorSize); | 7413 RightTrimFixedArray(heap, t, trim * TransitionArray::kTransitionSize); |
7502 } | 7414 } |
7503 } | 7415 } |
7504 | 7416 |
7505 | 7417 |
7506 int Map::Hash() { | 7418 int Map::Hash() { |
7507 // For performance reasons we only hash the 3 most variable fields of a map: | 7419 // For performance reasons we only hash the 3 most variable fields of a map: |
7508 // constructor, prototype and bit_field2. | 7420 // constructor, prototype and bit_field2. |
7509 | 7421 |
7510 // Shift away the tag. | 7422 // Shift away the tag. |
7511 int hash = (static_cast<uint32_t>( | 7423 int hash = (static_cast<uint32_t>( |
(...skipping 3174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10686 } | 10598 } |
10687 | 10599 |
10688 | 10600 |
10689 // Fill in the names of local properties into the supplied storage. The main | 10601 // 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 | 10602 // purpose of this function is to provide reflection information for the object |
10691 // mirrors. | 10603 // mirrors. |
10692 void JSObject::GetLocalPropertyNames(FixedArray* storage, int index) { | 10604 void JSObject::GetLocalPropertyNames(FixedArray* storage, int index) { |
10693 ASSERT(storage->length() >= (NumberOfLocalProperties() - index)); | 10605 ASSERT(storage->length() >= (NumberOfLocalProperties() - index)); |
10694 if (HasFastProperties()) { | 10606 if (HasFastProperties()) { |
10695 DescriptorArray* descs = map()->instance_descriptors(); | 10607 DescriptorArray* descs = map()->instance_descriptors(); |
| 10608 ASSERT(storage->length() >= index + descs->number_of_descriptors()); |
10696 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 10609 for (int i = 0; i < descs->number_of_descriptors(); i++) { |
10697 if (descs->IsProperty(i)) storage->set(index++, descs->GetKey(i)); | 10610 storage->set(index + i, descs->GetKey(i)); |
10698 } | 10611 } |
10699 ASSERT(storage->length() >= index); | |
10700 } else { | 10612 } else { |
10701 property_dictionary()->CopyKeysTo(storage, | 10613 property_dictionary()->CopyKeysTo(storage, |
10702 index, | 10614 index, |
10703 StringDictionary::UNSORTED); | 10615 StringDictionary::UNSORTED); |
10704 } | 10616 } |
10705 } | 10617 } |
10706 | 10618 |
10707 | 10619 |
10708 int JSObject::NumberOfLocalElements(PropertyAttributes filter) { | 10620 int JSObject::NumberOfLocalElements(PropertyAttributes filter) { |
10709 return GetLocalElementKeys(NULL, filter); | 10621 return GetLocalElementKeys(NULL, filter); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11317 set(index, key); | 11229 set(index, key); |
11318 return entry; | 11230 return entry; |
11319 } | 11231 } |
11320 ASSERT(element->IsTheHole() || !String::cast(element)->Equals(key)); | 11232 ASSERT(element->IsTheHole() || !String::cast(element)->Equals(key)); |
11321 entry = NextProbe(entry, count++, capacity); | 11233 entry = NextProbe(entry, count++, capacity); |
11322 } | 11234 } |
11323 return kNotFound; | 11235 return kNotFound; |
11324 } | 11236 } |
11325 | 11237 |
11326 | 11238 |
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> | 11239 template<typename Shape, typename Key> |
11354 MaybeObject* HashTable<Shape, Key>::Rehash(HashTable* new_table, Key key) { | 11240 MaybeObject* HashTable<Shape, Key>::Rehash(HashTable* new_table, Key key) { |
11355 ASSERT(NumberOfElements() < new_table->Capacity()); | 11241 ASSERT(NumberOfElements() < new_table->Capacity()); |
11356 | 11242 |
11357 AssertNoAllocation no_gc; | 11243 AssertNoAllocation no_gc; |
11358 WriteBarrierMode mode = new_table->GetWriteBarrierMode(no_gc); | 11244 WriteBarrierMode mode = new_table->GetWriteBarrierMode(no_gc); |
11359 | 11245 |
11360 // Copy prefix to new array. | 11246 // Copy prefix to new array. |
11361 for (int i = kPrefixStartIndex; | 11247 for (int i = kPrefixStartIndex; |
11362 i < kPrefixStartIndex + Shape::kPrefixSize; | 11248 i < kPrefixStartIndex + Shape::kPrefixSize; |
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12779 // Allocate the instance descriptor. | 12665 // Allocate the instance descriptor. |
12780 DescriptorArray* descriptors; | 12666 DescriptorArray* descriptors; |
12781 { MaybeObject* maybe_descriptors = | 12667 { MaybeObject* maybe_descriptors = |
12782 DescriptorArray::Allocate(instance_descriptor_length, | 12668 DescriptorArray::Allocate(instance_descriptor_length, |
12783 DescriptorArray::MAY_BE_SHARED); | 12669 DescriptorArray::MAY_BE_SHARED); |
12784 if (!maybe_descriptors->To<DescriptorArray>(&descriptors)) { | 12670 if (!maybe_descriptors->To<DescriptorArray>(&descriptors)) { |
12785 return maybe_descriptors; | 12671 return maybe_descriptors; |
12786 } | 12672 } |
12787 } | 12673 } |
12788 | 12674 |
12789 DescriptorArray::WhitenessWitness witness(descriptors); | 12675 FixedArray::WhitenessWitness witness(descriptors); |
12790 | 12676 |
12791 int inobject_props = obj->map()->inobject_properties(); | 12677 int inobject_props = obj->map()->inobject_properties(); |
12792 int number_of_allocated_fields = | 12678 int number_of_allocated_fields = |
12793 number_of_fields + unused_property_fields - inobject_props; | 12679 number_of_fields + unused_property_fields - inobject_props; |
12794 if (number_of_allocated_fields < 0) { | 12680 if (number_of_allocated_fields < 0) { |
12795 // There is enough inobject space for all fields (including unused). | 12681 // There is enough inobject space for all fields (including unused). |
12796 number_of_allocated_fields = 0; | 12682 number_of_allocated_fields = 0; |
12797 unused_property_fields = inobject_props - number_of_fields; | 12683 unused_property_fields = inobject_props - number_of_fields; |
12798 } | 12684 } |
12799 | 12685 |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13377 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13263 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13378 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13264 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13379 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13265 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13380 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13266 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13381 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13267 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13382 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13268 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13383 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13269 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13384 } | 13270 } |
13385 | 13271 |
13386 } } // namespace v8::internal | 13272 } } // namespace v8::internal |
OLD | NEW |