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

Side by Side Diff: src/objects.cc

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