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

Side by Side Diff: src/objects.cc

Issue 206343002: JSObject::NormalizeElements() handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 CALL_HEAP_FUNCTION(object->GetIsolate(), 4714 ASSERT(!object->HasExternalArrayElements());
4715 object->NormalizeElements(), 4715 Isolate* isolate = object->GetIsolate();
4716 SeededNumberDictionary); 4716 Factory* factory = isolate->factory();
4717 }
4718
4719
4720 MaybeObject* JSObject::NormalizeElements() {
4721 ASSERT(!HasExternalArrayElements());
4722 4717
4723 // Find the backing store. 4718 // Find the backing store.
4724 FixedArrayBase* array = FixedArrayBase::cast(elements()); 4719 Handle<FixedArrayBase> array(FixedArrayBase::cast(object->elements()));
4725 Map* old_map = array->map();
4726 bool is_arguments = 4720 bool is_arguments =
4727 (old_map == old_map->GetHeap()->sloppy_arguments_elements_map()); 4721 (array->map() == isolate->heap()->sloppy_arguments_elements_map());
4728 if (is_arguments) { 4722 if (is_arguments) {
4729 array = FixedArrayBase::cast(FixedArray::cast(array)->get(1)); 4723 array = handle(FixedArrayBase::cast(
4724 Handle<FixedArray>::cast(array)->get(1)));
4730 } 4725 }
4731 if (array->IsDictionary()) return array; 4726 if (array->IsDictionary()) return Handle<SeededNumberDictionary>::cast(array);
4732 4727
4733 ASSERT(HasFastSmiOrObjectElements() || 4728 ASSERT(object->HasFastSmiOrObjectElements() ||
4734 HasFastDoubleElements() || 4729 object->HasFastDoubleElements() ||
4735 HasFastArgumentsElements()); 4730 object->HasFastArgumentsElements());
4736 // Compute the effective length and allocate a new backing store. 4731 // Compute the effective length and allocate a new backing store.
4737 int length = IsJSArray() 4732 int length = object->IsJSArray()
4738 ? Smi::cast(JSArray::cast(this)->length())->value() 4733 ? Smi::cast(Handle<JSArray>::cast(object)->length())->value()
4739 : array->length(); 4734 : array->length();
4740 int old_capacity = 0; 4735 int old_capacity = 0;
4741 int used_elements = 0; 4736 int used_elements = 0;
4742 GetElementsCapacityAndUsage(&old_capacity, &used_elements); 4737 object->GetElementsCapacityAndUsage(&old_capacity, &used_elements);
4743 SeededNumberDictionary* dictionary; 4738 Handle<SeededNumberDictionary> dictionary =
4744 MaybeObject* maybe_dictionary = 4739 factory->NewSeededNumberDictionary(used_elements);
4745 SeededNumberDictionary::Allocate(GetHeap(), used_elements);
4746 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
4747 4740
4748 maybe_dictionary = CopyFastElementsToDictionary( 4741 dictionary = CopyFastElementsToDictionary(array, length, dictionary);
4749 GetIsolate(), array, length, dictionary);
4750 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
4751 4742
4752 // Switch to using the dictionary as the backing storage for elements. 4743 // Switch to using the dictionary as the backing storage for elements.
4753 if (is_arguments) { 4744 if (is_arguments) {
4754 FixedArray::cast(elements())->set(1, dictionary); 4745 FixedArray::cast(object->elements())->set(1, *dictionary);
4755 } else { 4746 } else {
4756 // Set the new map first to satify the elements type assert in 4747 // Set the new map first to satify the elements type assert in
4757 // set_elements(). 4748 // set_elements().
4758 Map* new_map; 4749 Handle<Map> new_map =
4759 MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(), 4750 JSObject::GetElementsTransitionMap(object, DICTIONARY_ELEMENTS);
4760 DICTIONARY_ELEMENTS); 4751
4761 if (!maybe->To(&new_map)) return maybe; 4752 JSObject::MigrateToMap(object, new_map);
4762 // TODO(verwaest): Replace by MigrateToMap. 4753 object->set_elements(*dictionary);
4763 set_map(new_map);
4764 set_elements(dictionary);
4765 } 4754 }
4766 4755
4767 old_map->GetHeap()->isolate()->counters()->elements_to_dictionary()-> 4756 isolate->counters()->elements_to_dictionary()->Increment();
4768 Increment();
4769 4757
4770 #ifdef DEBUG 4758 #ifdef DEBUG
4771 if (FLAG_trace_normalization) { 4759 if (FLAG_trace_normalization) {
4772 PrintF("Object elements have been normalized:\n"); 4760 PrintF("Object elements have been normalized:\n");
4773 Print(); 4761 object->Print();
4774 } 4762 }
4775 #endif 4763 #endif
4776 4764
4777 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); 4765 ASSERT(object->HasDictionaryElements() ||
4766 object->HasDictionaryArgumentsElements());
4778 return dictionary; 4767 return dictionary;
4779 } 4768 }
4780 4769
4781 4770
4782 Smi* JSReceiver::GenerateIdentityHash() { 4771 Smi* JSReceiver::GenerateIdentityHash() {
4783 Isolate* isolate = GetIsolate(); 4772 Isolate* isolate = GetIsolate();
4784 4773
4785 int hash_value; 4774 int hash_value;
4786 int attempts = 0; 4775 int attempts = 0;
4787 do { 4776 do {
(...skipping 11679 matching lines...) Expand 10 before | Expand all | Expand 10 after
16467 #define ERROR_MESSAGES_TEXTS(C, T) T, 16456 #define ERROR_MESSAGES_TEXTS(C, T) T,
16468 static const char* error_messages_[] = { 16457 static const char* error_messages_[] = {
16469 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16458 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16470 }; 16459 };
16471 #undef ERROR_MESSAGES_TEXTS 16460 #undef ERROR_MESSAGES_TEXTS
16472 return error_messages_[reason]; 16461 return error_messages_[reason];
16473 } 16462 }
16474 16463
16475 16464
16476 } } // namespace v8::internal 16465 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698