OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 new_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); | 1633 new_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); |
1634 set_map(new_map); | 1634 set_map(new_map); |
1635 return FastPropertyAtPut(index, value); | 1635 return FastPropertyAtPut(index, value); |
1636 } | 1636 } |
1637 | 1637 |
1638 | 1638 |
1639 MaybeObject* JSObject::AddConstantFunctionProperty( | 1639 MaybeObject* JSObject::AddConstantFunctionProperty( |
1640 String* name, | 1640 String* name, |
1641 JSFunction* function, | 1641 JSFunction* function, |
1642 PropertyAttributes attributes) { | 1642 PropertyAttributes attributes) { |
1643 ASSERT(!GetHeap()->InNewSpace(function)); | |
1644 | |
1645 // Allocate new instance descriptors with (name, function) added | 1643 // Allocate new instance descriptors with (name, function) added |
1646 ConstantFunctionDescriptor d(name, function, attributes); | 1644 ConstantFunctionDescriptor d(name, function, attributes); |
1647 Object* new_descriptors; | 1645 Object* new_descriptors; |
1648 { MaybeObject* maybe_new_descriptors = | 1646 { MaybeObject* maybe_new_descriptors = |
1649 map()->instance_descriptors()->CopyInsert(&d, REMOVE_TRANSITIONS); | 1647 map()->instance_descriptors()->CopyInsert(&d, REMOVE_TRANSITIONS); |
1650 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { | 1648 if (!maybe_new_descriptors->ToObject(&new_descriptors)) { |
1651 return maybe_new_descriptors; | 1649 return maybe_new_descriptors; |
1652 } | 1650 } |
1653 } | 1651 } |
1654 | 1652 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 Handle<Object> args[1] = {Handle<String>(name)}; | 1747 Handle<Object> args[1] = {Handle<String>(name)}; |
1750 return heap->isolate()->Throw( | 1748 return heap->isolate()->Throw( |
1751 *FACTORY->NewTypeError("object_not_extensible", | 1749 *FACTORY->NewTypeError("object_not_extensible", |
1752 HandleVector(args, 1))); | 1750 HandleVector(args, 1))); |
1753 } | 1751 } |
1754 } | 1752 } |
1755 if (HasFastProperties()) { | 1753 if (HasFastProperties()) { |
1756 // Ensure the descriptor array does not get too big. | 1754 // Ensure the descriptor array does not get too big. |
1757 if (map_of_this->instance_descriptors()->number_of_descriptors() < | 1755 if (map_of_this->instance_descriptors()->number_of_descriptors() < |
1758 DescriptorArray::kMaxNumberOfDescriptors) { | 1756 DescriptorArray::kMaxNumberOfDescriptors) { |
1759 if (value->IsJSFunction() && !heap->InNewSpace(value)) { | 1757 if (value->IsJSFunction()) { |
1760 return AddConstantFunctionProperty(name, | 1758 return AddConstantFunctionProperty(name, |
1761 JSFunction::cast(value), | 1759 JSFunction::cast(value), |
1762 attributes); | 1760 attributes); |
1763 } else { | 1761 } else { |
1764 return AddFastProperty(name, value, attributes); | 1762 return AddFastProperty(name, value, attributes); |
1765 } | 1763 } |
1766 } else { | 1764 } else { |
1767 // Normalize the object to prevent very large instance descriptors. | 1765 // Normalize the object to prevent very large instance descriptors. |
1768 // This eliminates unwanted N^2 allocation and lookup behavior. | 1766 // This eliminates unwanted N^2 allocation and lookup behavior. |
1769 Object* obj; | 1767 Object* obj; |
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2988 case CONSTANT_TRANSITION: { | 2986 case CONSTANT_TRANSITION: { |
2989 // If the same constant function is being added we can simply | 2987 // If the same constant function is being added we can simply |
2990 // transition to the target map. | 2988 // transition to the target map. |
2991 Map* target_map = result->GetTransitionMap(); | 2989 Map* target_map = result->GetTransitionMap(); |
2992 DescriptorArray* target_descriptors = target_map->instance_descriptors(); | 2990 DescriptorArray* target_descriptors = target_map->instance_descriptors(); |
2993 int number = target_descriptors->SearchWithCache(name); | 2991 int number = target_descriptors->SearchWithCache(name); |
2994 ASSERT(number != DescriptorArray::kNotFound); | 2992 ASSERT(number != DescriptorArray::kNotFound); |
2995 ASSERT(target_descriptors->GetType(number) == CONSTANT_FUNCTION); | 2993 ASSERT(target_descriptors->GetType(number) == CONSTANT_FUNCTION); |
2996 JSFunction* function = | 2994 JSFunction* function = |
2997 JSFunction::cast(target_descriptors->GetValue(number)); | 2995 JSFunction::cast(target_descriptors->GetValue(number)); |
2998 ASSERT(!HEAP->InNewSpace(function)); | |
2999 if (value == function) { | 2996 if (value == function) { |
3000 set_map(target_map); | 2997 set_map(target_map); |
3001 return value; | 2998 return value; |
3002 } | 2999 } |
3003 // Otherwise, replace with a MAP_TRANSITION to a new map with a | 3000 // Otherwise, replace with a MAP_TRANSITION to a new map with a |
3004 // FIELD, even if the value is a constant function. | 3001 // FIELD, even if the value is a constant function. |
3005 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); | 3002 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); |
3006 } | 3003 } |
3007 case NULL_DESCRIPTOR: | 3004 case NULL_DESCRIPTOR: |
3008 case ELEMENTS_TRANSITION: | 3005 case ELEMENTS_TRANSITION: |
(...skipping 2619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5628 int child_index = 2 * parent_index + 1; | 5625 int child_index = 2 * parent_index + 1; |
5629 uint32_t child_hash = GetKey(child_index)->Hash(); | 5626 uint32_t child_hash = GetKey(child_index)->Hash(); |
5630 if (child_index + 1 < len) { | 5627 if (child_index + 1 < len) { |
5631 uint32_t right_child_hash = GetKey(child_index + 1)->Hash(); | 5628 uint32_t right_child_hash = GetKey(child_index + 1)->Hash(); |
5632 if (right_child_hash > child_hash) { | 5629 if (right_child_hash > child_hash) { |
5633 child_index++; | 5630 child_index++; |
5634 child_hash = right_child_hash; | 5631 child_hash = right_child_hash; |
5635 } | 5632 } |
5636 } | 5633 } |
5637 if (child_hash <= parent_hash) break; | 5634 if (child_hash <= parent_hash) break; |
5638 NoWriteBarrierSwapDescriptors(parent_index, child_index); | 5635 NoIncrementalWriteBarrierSwapDescriptors(parent_index, child_index); |
5639 // Now element at child_index could be < its children. | 5636 // Now element at child_index could be < its children. |
5640 parent_index = child_index; // parent_hash remains correct. | 5637 parent_index = child_index; // parent_hash remains correct. |
5641 } | 5638 } |
5642 } | 5639 } |
5643 | 5640 |
5644 // Extract elements and create sorted array. | 5641 // Extract elements and create sorted array. |
5645 for (int i = len - 1; i > 0; --i) { | 5642 for (int i = len - 1; i > 0; --i) { |
5646 // Put max element at the back of the array. | 5643 // Put max element at the back of the array. |
5647 NoWriteBarrierSwapDescriptors(0, i); | 5644 NoIncrementalWriteBarrierSwapDescriptors(0, i); |
5648 // Shift down the new top element. | 5645 // Shift down the new top element. |
5649 int parent_index = 0; | 5646 int parent_index = 0; |
5650 const uint32_t parent_hash = GetKey(parent_index)->Hash(); | 5647 const uint32_t parent_hash = GetKey(parent_index)->Hash(); |
5651 const int max_parent_index = (i / 2) - 1; | 5648 const int max_parent_index = (i / 2) - 1; |
5652 while (parent_index <= max_parent_index) { | 5649 while (parent_index <= max_parent_index) { |
5653 int child_index = parent_index * 2 + 1; | 5650 int child_index = parent_index * 2 + 1; |
5654 uint32_t child_hash = GetKey(child_index)->Hash(); | 5651 uint32_t child_hash = GetKey(child_index)->Hash(); |
5655 if (child_index + 1 < i) { | 5652 if (child_index + 1 < i) { |
5656 uint32_t right_child_hash = GetKey(child_index + 1)->Hash(); | 5653 uint32_t right_child_hash = GetKey(child_index + 1)->Hash(); |
5657 if (right_child_hash > child_hash) { | 5654 if (right_child_hash > child_hash) { |
5658 child_index++; | 5655 child_index++; |
5659 child_hash = right_child_hash; | 5656 child_hash = right_child_hash; |
5660 } | 5657 } |
5661 } | 5658 } |
5662 if (child_hash <= parent_hash) break; | 5659 if (child_hash <= parent_hash) break; |
5663 NoWriteBarrierSwapDescriptors(parent_index, child_index); | 5660 NoIncrementalWriteBarrierSwapDescriptors(parent_index, child_index); |
5664 parent_index = child_index; | 5661 parent_index = child_index; |
5665 } | 5662 } |
5666 } | 5663 } |
5667 } | 5664 } |
5668 | 5665 |
5669 | 5666 |
5670 void DescriptorArray::Sort(const WhitenessWitness& witness) { | 5667 void DescriptorArray::Sort(const WhitenessWitness& witness) { |
5671 SortUnchecked(witness); | 5668 SortUnchecked(witness); |
5672 SLOW_ASSERT(IsSortedNoDuplicates()); | 5669 SLOW_ASSERT(IsSortedNoDuplicates()); |
5673 } | 5670 } |
(...skipping 6838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12512 if (break_point_objects()->IsUndefined()) return 0; | 12509 if (break_point_objects()->IsUndefined()) return 0; |
12513 // Single break point. | 12510 // Single break point. |
12514 if (!break_point_objects()->IsFixedArray()) return 1; | 12511 if (!break_point_objects()->IsFixedArray()) return 1; |
12515 // Multiple break points. | 12512 // Multiple break points. |
12516 return FixedArray::cast(break_point_objects())->length(); | 12513 return FixedArray::cast(break_point_objects())->length(); |
12517 } | 12514 } |
12518 #endif // ENABLE_DEBUGGER_SUPPORT | 12515 #endif // ENABLE_DEBUGGER_SUPPORT |
12519 | 12516 |
12520 | 12517 |
12521 } } // namespace v8::internal | 12518 } } // namespace v8::internal |
OLD | NEW |