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 4693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4704 Isolate* isolate = array->GetIsolate(); | 4704 Isolate* isolate = array->GetIsolate(); |
4705 CALL_HEAP_FUNCTION(isolate, | 4705 CALL_HEAP_FUNCTION(isolate, |
4706 CopyFastElementsToDictionary( | 4706 CopyFastElementsToDictionary( |
4707 isolate, *array, length, *dict), | 4707 isolate, *array, length, *dict), |
4708 SeededNumberDictionary); | 4708 SeededNumberDictionary); |
4709 } | 4709 } |
4710 | 4710 |
4711 | 4711 |
4712 Handle<SeededNumberDictionary> JSObject::NormalizeElements( | 4712 Handle<SeededNumberDictionary> JSObject::NormalizeElements( |
4713 Handle<JSObject> object) { | 4713 Handle<JSObject> object) { |
4714 ASSERT(!object->HasExternalArrayElements()); | 4714 CALL_HEAP_FUNCTION(object->GetIsolate(), |
4715 Isolate* isolate = object->GetIsolate(); | 4715 object->NormalizeElements(), |
4716 Factory* factory = isolate->factory(); | 4716 SeededNumberDictionary); |
| 4717 } |
| 4718 |
| 4719 |
| 4720 MaybeObject* JSObject::NormalizeElements() { |
| 4721 ASSERT(!HasExternalArrayElements()); |
4717 | 4722 |
4718 // Find the backing store. | 4723 // Find the backing store. |
4719 Handle<FixedArrayBase> array(FixedArrayBase::cast(object->elements())); | 4724 FixedArrayBase* array = FixedArrayBase::cast(elements()); |
| 4725 Map* old_map = array->map(); |
4720 bool is_arguments = | 4726 bool is_arguments = |
4721 (array->map() == isolate->heap()->sloppy_arguments_elements_map()); | 4727 (old_map == old_map->GetHeap()->sloppy_arguments_elements_map()); |
4722 if (is_arguments) { | 4728 if (is_arguments) { |
4723 array = handle(FixedArrayBase::cast( | 4729 array = FixedArrayBase::cast(FixedArray::cast(array)->get(1)); |
4724 Handle<FixedArray>::cast(array)->get(1))); | |
4725 } | 4730 } |
4726 if (array->IsDictionary()) return Handle<SeededNumberDictionary>::cast(array); | 4731 if (array->IsDictionary()) return array; |
4727 | 4732 |
4728 ASSERT(object->HasFastSmiOrObjectElements() || | 4733 ASSERT(HasFastSmiOrObjectElements() || |
4729 object->HasFastDoubleElements() || | 4734 HasFastDoubleElements() || |
4730 object->HasFastArgumentsElements()); | 4735 HasFastArgumentsElements()); |
4731 // Compute the effective length and allocate a new backing store. | 4736 // Compute the effective length and allocate a new backing store. |
4732 int length = object->IsJSArray() | 4737 int length = IsJSArray() |
4733 ? Smi::cast(Handle<JSArray>::cast(object)->length())->value() | 4738 ? Smi::cast(JSArray::cast(this)->length())->value() |
4734 : array->length(); | 4739 : array->length(); |
4735 int old_capacity = 0; | 4740 int old_capacity = 0; |
4736 int used_elements = 0; | 4741 int used_elements = 0; |
4737 object->GetElementsCapacityAndUsage(&old_capacity, &used_elements); | 4742 GetElementsCapacityAndUsage(&old_capacity, &used_elements); |
4738 Handle<SeededNumberDictionary> dictionary = | 4743 SeededNumberDictionary* dictionary; |
4739 factory->NewSeededNumberDictionary(used_elements); | 4744 MaybeObject* maybe_dictionary = |
| 4745 SeededNumberDictionary::Allocate(GetHeap(), used_elements); |
| 4746 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; |
4740 | 4747 |
4741 dictionary = CopyFastElementsToDictionary(array, length, dictionary); | 4748 maybe_dictionary = CopyFastElementsToDictionary( |
| 4749 GetIsolate(), array, length, dictionary); |
| 4750 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; |
4742 | 4751 |
4743 // Switch to using the dictionary as the backing storage for elements. | 4752 // Switch to using the dictionary as the backing storage for elements. |
4744 if (is_arguments) { | 4753 if (is_arguments) { |
4745 FixedArray::cast(object->elements())->set(1, *dictionary); | 4754 FixedArray::cast(elements())->set(1, dictionary); |
4746 } else { | 4755 } else { |
4747 // Set the new map first to satify the elements type assert in | 4756 // Set the new map first to satify the elements type assert in |
4748 // set_elements(). | 4757 // set_elements(). |
4749 Handle<Map> new_map = | 4758 Map* new_map; |
4750 JSObject::GetElementsTransitionMap(object, DICTIONARY_ELEMENTS); | 4759 MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(), |
4751 | 4760 DICTIONARY_ELEMENTS); |
4752 JSObject::MigrateToMap(object, new_map); | 4761 if (!maybe->To(&new_map)) return maybe; |
4753 object->set_elements(*dictionary); | 4762 // TODO(verwaest): Replace by MigrateToMap. |
| 4763 set_map(new_map); |
| 4764 set_elements(dictionary); |
4754 } | 4765 } |
4755 | 4766 |
4756 isolate->counters()->elements_to_dictionary()->Increment(); | 4767 old_map->GetHeap()->isolate()->counters()->elements_to_dictionary()-> |
| 4768 Increment(); |
4757 | 4769 |
4758 #ifdef DEBUG | 4770 #ifdef DEBUG |
4759 if (FLAG_trace_normalization) { | 4771 if (FLAG_trace_normalization) { |
4760 PrintF("Object elements have been normalized:\n"); | 4772 PrintF("Object elements have been normalized:\n"); |
4761 object->Print(); | 4773 Print(); |
4762 } | 4774 } |
4763 #endif | 4775 #endif |
4764 | 4776 |
4765 ASSERT(object->HasDictionaryElements() || | 4777 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); |
4766 object->HasDictionaryArgumentsElements()); | |
4767 return dictionary; | 4778 return dictionary; |
4768 } | 4779 } |
4769 | 4780 |
4770 | 4781 |
4771 Smi* JSReceiver::GenerateIdentityHash() { | 4782 Smi* JSReceiver::GenerateIdentityHash() { |
4772 Isolate* isolate = GetIsolate(); | 4783 Isolate* isolate = GetIsolate(); |
4773 | 4784 |
4774 int hash_value; | 4785 int hash_value; |
4775 int attempts = 0; | 4786 int attempts = 0; |
4776 do { | 4787 do { |
(...skipping 11675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16452 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16463 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16453 static const char* error_messages_[] = { | 16464 static const char* error_messages_[] = { |
16454 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16465 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16455 }; | 16466 }; |
16456 #undef ERROR_MESSAGES_TEXTS | 16467 #undef ERROR_MESSAGES_TEXTS |
16457 return error_messages_[reason]; | 16468 return error_messages_[reason]; |
16458 } | 16469 } |
16459 | 16470 |
16460 | 16471 |
16461 } } // namespace v8::internal | 16472 } } // namespace v8::internal |
OLD | NEW |