OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 4643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4654 int unused_property_fields) { | 4654 int unused_property_fields) { |
4655 if (object->HasFastProperties()) return; | 4655 if (object->HasFastProperties()) return; |
4656 ASSERT(!object->IsGlobalObject()); | 4656 ASSERT(!object->IsGlobalObject()); |
4657 CALL_HEAP_FUNCTION_VOID( | 4657 CALL_HEAP_FUNCTION_VOID( |
4658 object->GetIsolate(), | 4658 object->GetIsolate(), |
4659 object->property_dictionary()->TransformPropertiesToFastFor( | 4659 object->property_dictionary()->TransformPropertiesToFastFor( |
4660 *object, unused_property_fields)); | 4660 *object, unused_property_fields)); |
4661 } | 4661 } |
4662 | 4662 |
4663 | 4663 |
4664 static MUST_USE_RESULT MaybeObject* CopyFastElementsToDictionary( | 4664 static |
4665 Isolate* isolate, | 4665 MUST_USE_RESULT Handle<SeededNumberDictionary> CopyFastElementsToDictionary( |
Toon Verwaest
2014/03/21 12:01:15
Remove the MUST_USE_RESULT annotation.
Igor Sheludko
2014/03/21 12:05:46
Done.
| |
4666 FixedArrayBase* array, | 4666 Handle<FixedArrayBase> array, |
4667 int length, | 4667 int length, |
4668 SeededNumberDictionary* dictionary) { | 4668 Handle<SeededNumberDictionary> dictionary) { |
4669 Heap* heap = isolate->heap(); | 4669 Isolate* isolate = array->GetIsolate(); |
4670 Factory* factory = isolate->factory(); | |
4670 bool has_double_elements = array->IsFixedDoubleArray(); | 4671 bool has_double_elements = array->IsFixedDoubleArray(); |
4671 for (int i = 0; i < length; i++) { | 4672 for (int i = 0; i < length; i++) { |
4672 Object* value = NULL; | 4673 Handle<Object> value; |
4673 if (has_double_elements) { | 4674 if (has_double_elements) { |
4674 FixedDoubleArray* double_array = FixedDoubleArray::cast(array); | 4675 Handle<FixedDoubleArray> double_array = |
4676 Handle<FixedDoubleArray>::cast(array); | |
4675 if (double_array->is_the_hole(i)) { | 4677 if (double_array->is_the_hole(i)) { |
4676 value = isolate->heap()->the_hole_value(); | 4678 value = factory->the_hole_value(); |
4677 } else { | 4679 } else { |
4678 // Objects must be allocated in the old object space, since the | 4680 // Objects must be allocated in the old object space, since the |
4679 // overall number of HeapNumbers needed for the conversion might | 4681 // overall number of HeapNumbers needed for the conversion might |
4680 // exceed the capacity of new space, and we would fail repeatedly | 4682 // exceed the capacity of new space, and we would fail repeatedly |
Toon Verwaest
2014/03/21 12:02:49
Remove comment and TENURED flag below, that's not
Igor Sheludko
2014/03/21 12:05:46
Done.
| |
4681 // trying to convert the FixedDoubleArray. | 4683 // trying to convert the FixedDoubleArray. |
4682 MaybeObject* maybe_value_object = | 4684 value = factory->NewHeapNumber(double_array->get_scalar(i), TENURED); |
4683 heap->AllocateHeapNumber(double_array->get_scalar(i), TENURED); | |
4684 if (!maybe_value_object->ToObject(&value)) return maybe_value_object; | |
4685 } | 4685 } |
4686 } else { | 4686 } else { |
4687 value = FixedArray::cast(array)->get(i); | 4687 value = handle(Handle<FixedArray>::cast(array)->get(i), isolate); |
4688 } | 4688 } |
4689 if (!value->IsTheHole()) { | 4689 if (!value->IsTheHole()) { |
4690 PropertyDetails details = PropertyDetails(NONE, NORMAL, 0); | 4690 PropertyDetails details = PropertyDetails(NONE, NORMAL, 0); |
4691 MaybeObject* maybe_result = | 4691 dictionary = |
4692 dictionary->AddNumberEntry(i, value, details); | 4692 SeededNumberDictionary::AddNumberEntry(dictionary, i, value, details); |
4693 if (!maybe_result->To(&dictionary)) return maybe_result; | |
4694 } | 4693 } |
4695 } | 4694 } |
4696 return dictionary; | 4695 return dictionary; |
4697 } | 4696 } |
4698 | 4697 |
4699 | 4698 |
4700 static Handle<SeededNumberDictionary> CopyFastElementsToDictionary( | |
4701 Handle<FixedArrayBase> array, | |
4702 int length, | |
4703 Handle<SeededNumberDictionary> dict) { | |
4704 Isolate* isolate = array->GetIsolate(); | |
4705 CALL_HEAP_FUNCTION(isolate, | |
4706 CopyFastElementsToDictionary( | |
4707 isolate, *array, length, *dict), | |
4708 SeededNumberDictionary); | |
4709 } | |
4710 | |
4711 | |
4712 Handle<SeededNumberDictionary> JSObject::NormalizeElements( | 4699 Handle<SeededNumberDictionary> JSObject::NormalizeElements( |
4713 Handle<JSObject> object) { | 4700 Handle<JSObject> object) { |
4714 CALL_HEAP_FUNCTION(object->GetIsolate(), | 4701 ASSERT(!object->HasExternalArrayElements()); |
4715 object->NormalizeElements(), | 4702 Isolate* isolate = object->GetIsolate(); |
4716 SeededNumberDictionary); | 4703 Factory* factory = isolate->factory(); |
4717 } | |
4718 | |
4719 | |
4720 MaybeObject* JSObject::NormalizeElements() { | |
4721 ASSERT(!HasExternalArrayElements()); | |
4722 | 4704 |
4723 // Find the backing store. | 4705 // Find the backing store. |
4724 FixedArrayBase* array = FixedArrayBase::cast(elements()); | 4706 Handle<FixedArrayBase> array(FixedArrayBase::cast(object->elements())); |
4725 Map* old_map = array->map(); | |
4726 bool is_arguments = | 4707 bool is_arguments = |
4727 (old_map == old_map->GetHeap()->sloppy_arguments_elements_map()); | 4708 (array->map() == isolate->heap()->sloppy_arguments_elements_map()); |
4728 if (is_arguments) { | 4709 if (is_arguments) { |
4729 array = FixedArrayBase::cast(FixedArray::cast(array)->get(1)); | 4710 array = handle(FixedArrayBase::cast( |
4711 Handle<FixedArray>::cast(array)->get(1))); | |
4730 } | 4712 } |
4731 if (array->IsDictionary()) return array; | 4713 if (array->IsDictionary()) return Handle<SeededNumberDictionary>::cast(array); |
4732 | 4714 |
4733 ASSERT(HasFastSmiOrObjectElements() || | 4715 ASSERT(object->HasFastSmiOrObjectElements() || |
4734 HasFastDoubleElements() || | 4716 object->HasFastDoubleElements() || |
4735 HasFastArgumentsElements()); | 4717 object->HasFastArgumentsElements()); |
4736 // Compute the effective length and allocate a new backing store. | 4718 // Compute the effective length and allocate a new backing store. |
4737 int length = IsJSArray() | 4719 int length = object->IsJSArray() |
4738 ? Smi::cast(JSArray::cast(this)->length())->value() | 4720 ? Smi::cast(Handle<JSArray>::cast(object)->length())->value() |
4739 : array->length(); | 4721 : array->length(); |
4740 int old_capacity = 0; | 4722 int old_capacity = 0; |
4741 int used_elements = 0; | 4723 int used_elements = 0; |
4742 GetElementsCapacityAndUsage(&old_capacity, &used_elements); | 4724 object->GetElementsCapacityAndUsage(&old_capacity, &used_elements); |
4743 SeededNumberDictionary* dictionary; | 4725 Handle<SeededNumberDictionary> dictionary = |
4744 MaybeObject* maybe_dictionary = | 4726 factory->NewSeededNumberDictionary(used_elements); |
4745 SeededNumberDictionary::Allocate(GetHeap(), used_elements); | |
4746 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; | |
4747 | 4727 |
4748 maybe_dictionary = CopyFastElementsToDictionary( | 4728 dictionary = CopyFastElementsToDictionary(array, length, dictionary); |
4749 GetIsolate(), array, length, dictionary); | |
4750 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; | |
4751 | 4729 |
4752 // Switch to using the dictionary as the backing storage for elements. | 4730 // Switch to using the dictionary as the backing storage for elements. |
4753 if (is_arguments) { | 4731 if (is_arguments) { |
4754 FixedArray::cast(elements())->set(1, dictionary); | 4732 FixedArray::cast(object->elements())->set(1, *dictionary); |
4755 } else { | 4733 } else { |
4756 // Set the new map first to satify the elements type assert in | 4734 // Set the new map first to satify the elements type assert in |
4757 // set_elements(). | 4735 // set_elements(). |
4758 Map* new_map; | 4736 Handle<Map> new_map = |
4759 MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(), | 4737 JSObject::GetElementsTransitionMap(object, DICTIONARY_ELEMENTS); |
4760 DICTIONARY_ELEMENTS); | 4738 |
4761 if (!maybe->To(&new_map)) return maybe; | 4739 JSObject::MigrateToMap(object, new_map); |
4762 // TODO(verwaest): Replace by MigrateToMap. | 4740 object->set_elements(*dictionary); |
4763 set_map(new_map); | |
4764 set_elements(dictionary); | |
4765 } | 4741 } |
4766 | 4742 |
4767 old_map->GetHeap()->isolate()->counters()->elements_to_dictionary()-> | 4743 isolate->counters()->elements_to_dictionary()->Increment(); |
4768 Increment(); | |
4769 | 4744 |
4770 #ifdef DEBUG | 4745 #ifdef DEBUG |
4771 if (FLAG_trace_normalization) { | 4746 if (FLAG_trace_normalization) { |
4772 PrintF("Object elements have been normalized:\n"); | 4747 PrintF("Object elements have been normalized:\n"); |
4773 Print(); | 4748 object->Print(); |
4774 } | 4749 } |
4775 #endif | 4750 #endif |
4776 | 4751 |
4777 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); | 4752 ASSERT(object->HasDictionaryElements() || |
4753 object->HasDictionaryArgumentsElements()); | |
4778 return dictionary; | 4754 return dictionary; |
4779 } | 4755 } |
4780 | 4756 |
4781 | 4757 |
4782 Smi* JSReceiver::GenerateIdentityHash() { | 4758 Smi* JSReceiver::GenerateIdentityHash() { |
4783 Isolate* isolate = GetIsolate(); | 4759 Isolate* isolate = GetIsolate(); |
4784 | 4760 |
4785 int hash_value; | 4761 int hash_value; |
4786 int attempts = 0; | 4762 int attempts = 0; |
4787 do { | 4763 do { |
(...skipping 11675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16463 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16439 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16464 static const char* error_messages_[] = { | 16440 static const char* error_messages_[] = { |
16465 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16441 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16466 }; | 16442 }; |
16467 #undef ERROR_MESSAGES_TEXTS | 16443 #undef ERROR_MESSAGES_TEXTS |
16468 return error_messages_[reason]; | 16444 return error_messages_[reason]; |
16469 } | 16445 } |
16470 | 16446 |
16471 | 16447 |
16472 } } // namespace v8::internal | 16448 } } // namespace v8::internal |
OLD | NEW |