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

Side by Side Diff: src/objects.cc

Issue 29353003: [Object.observe] Don't force normalization of elements for observed objects (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: KeyedStoreIC Created 7 years, 1 month 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
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 5609 matching lines...) Expand 10 before | Expand all | Expand 10 after
5620 return object; 5620 return object;
5621 } 5621 }
5622 5622
5623 5623
5624 void JSObject::SetObserved(Handle<JSObject> object) { 5624 void JSObject::SetObserved(Handle<JSObject> object) {
5625 Isolate* isolate = object->GetIsolate(); 5625 Isolate* isolate = object->GetIsolate();
5626 5626
5627 if (object->map()->is_observed()) 5627 if (object->map()->is_observed())
5628 return; 5628 return;
5629 5629
5630 if (!object->HasExternalArrayElements()) {
5631 // Go to dictionary mode, so that we don't skip map checks.
5632 NormalizeElements(object);
5633 ASSERT(!object->HasFastElements());
5634 }
5635
5636 LookupResult result(isolate); 5630 LookupResult result(isolate);
5637 object->map()->LookupTransition(*object, 5631 object->map()->LookupTransition(*object,
5638 isolate->heap()->observed_symbol(), 5632 isolate->heap()->observed_symbol(),
5639 &result); 5633 &result);
5640 5634
5641 Handle<Map> new_map; 5635 Handle<Map> new_map;
5642 if (result.IsTransition()) { 5636 if (result.IsTransition()) {
5643 new_map = handle(result.GetTransitionTarget()); 5637 new_map = handle(result.GetTransitionTarget());
5644 ASSERT(new_map->is_observed()); 5638 ASSERT(new_map->is_observed());
5645 } else if (object->map()->CanHaveMoreTransitions()) { 5639 } else if (object->map()->CanHaveMoreTransitions()) {
5646 new_map = Map::CopyForObserved(handle(object->map())); 5640 new_map = Map::CopyForObserved(handle(object->map()));
5647 } else { 5641 } else {
5648 new_map = Map::Copy(handle(object->map())); 5642 new_map = Map::Copy(handle(object->map()));
5649 new_map->set_is_observed(true); 5643 new_map->set_is_observed();
5650 } 5644 }
5651 object->set_map(*new_map); 5645 object->set_map(*new_map);
5652 } 5646 }
5653 5647
5654 5648
5655 Handle<JSObject> JSObject::Copy(Handle<JSObject> object, 5649 Handle<JSObject> JSObject::Copy(Handle<JSObject> object,
5656 Handle<AllocationSite> site) { 5650 Handle<AllocationSite> site) {
5657 Isolate* isolate = object->GetIsolate(); 5651 Isolate* isolate = object->GetIsolate();
5658 CALL_HEAP_FUNCTION(isolate, 5652 CALL_HEAP_FUNCTION(isolate,
5659 isolate->heap()->CopyJSObject(*object, *site), JSObject); 5653 isolate->heap()->CopyJSObject(*object, *site), JSObject);
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
6944 } else { 6938 } else {
6945 new_map = Map::Copy(map); 6939 new_map = Map::Copy(map);
6946 } 6940 }
6947 6941
6948 Handle<TransitionArray> transitions = 6942 Handle<TransitionArray> transitions =
6949 Map::AddTransition(map, isolate->factory()->observed_symbol(), new_map, 6943 Map::AddTransition(map, isolate->factory()->observed_symbol(), new_map,
6950 FULL_TRANSITION); 6944 FULL_TRANSITION);
6951 6945
6952 map->set_transitions(*transitions); 6946 map->set_transitions(*transitions);
6953 6947
6954 new_map->set_is_observed(true); 6948 new_map->set_is_observed();
6955 6949
6956 if (map->owns_descriptors()) { 6950 if (map->owns_descriptors()) {
6957 new_map->InitializeDescriptors(map->instance_descriptors()); 6951 new_map->InitializeDescriptors(map->instance_descriptors());
6958 map->set_owns_descriptors(false); 6952 map->set_owns_descriptors(false);
6959 } 6953 }
6960 6954
6961 new_map->SetBackPointer(*map); 6955 new_map->SetBackPointer(*map);
6962 return new_map; 6956 return new_map;
6963 } 6957 }
6964 6958
(...skipping 4164 matching lines...) Expand 10 before | Expand all | Expand 10 after
11129 #endif // ENABLE_DISASSEMBLER 11123 #endif // ENABLE_DISASSEMBLER
11130 11124
11131 11125
11132 MaybeObject* JSObject::SetFastElementsCapacityAndLength( 11126 MaybeObject* JSObject::SetFastElementsCapacityAndLength(
11133 int capacity, 11127 int capacity,
11134 int length, 11128 int length,
11135 SetFastElementsCapacitySmiMode smi_mode) { 11129 SetFastElementsCapacitySmiMode smi_mode) {
11136 Heap* heap = GetHeap(); 11130 Heap* heap = GetHeap();
11137 // We should never end in here with a pixel or external array. 11131 // We should never end in here with a pixel or external array.
11138 ASSERT(!HasExternalArrayElements()); 11132 ASSERT(!HasExternalArrayElements());
11139 ASSERT(!map()->is_observed());
11140 11133
11141 // Allocate a new fast elements backing store. 11134 // Allocate a new fast elements backing store.
11142 FixedArray* new_elements; 11135 FixedArray* new_elements;
11143 MaybeObject* maybe = heap->AllocateUninitializedFixedArray(capacity); 11136 MaybeObject* maybe = heap->AllocateUninitializedFixedArray(capacity);
11144 if (!maybe->To(&new_elements)) return maybe; 11137 if (!maybe->To(&new_elements)) return maybe;
11145 11138
11146 ElementsKind elements_kind = GetElementsKind(); 11139 ElementsKind elements_kind = GetElementsKind();
11147 ElementsKind new_elements_kind; 11140 ElementsKind new_elements_kind;
11148 // The resized array has FAST_*_SMI_ELEMENTS if the capacity mode forces it, 11141 // The resized array has FAST_*_SMI_ELEMENTS if the capacity mode forces it,
11149 // or if it's allowed and the old elements array contained only SMIs. 11142 // or if it's allowed and the old elements array contained only SMIs.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
11214 11207
11215 return false; 11208 return false;
11216 } 11209 }
11217 11210
11218 MaybeObject* JSObject::SetFastDoubleElementsCapacityAndLength( 11211 MaybeObject* JSObject::SetFastDoubleElementsCapacityAndLength(
11219 int capacity, 11212 int capacity,
11220 int length) { 11213 int length) {
11221 Heap* heap = GetHeap(); 11214 Heap* heap = GetHeap();
11222 // We should never end in here with a pixel or external array. 11215 // We should never end in here with a pixel or external array.
11223 ASSERT(!HasExternalArrayElements()); 11216 ASSERT(!HasExternalArrayElements());
11224 ASSERT(!map()->is_observed());
11225 11217
11226 FixedArrayBase* elems; 11218 FixedArrayBase* elems;
11227 { MaybeObject* maybe_obj = 11219 { MaybeObject* maybe_obj =
11228 heap->AllocateUninitializedFixedDoubleArray(capacity); 11220 heap->AllocateUninitializedFixedDoubleArray(capacity);
11229 if (!maybe_obj->To(&elems)) return maybe_obj; 11221 if (!maybe_obj->To(&elems)) return maybe_obj;
11230 } 11222 }
11231 11223
11232 ElementsKind elements_kind = GetElementsKind(); 11224 ElementsKind elements_kind = GetElementsKind();
11233 ElementsKind new_elements_kind = elements_kind; 11225 ElementsKind new_elements_kind = elements_kind;
11234 if (IsHoleyElementsKind(elements_kind)) { 11226 if (IsHoleyElementsKind(elements_kind)) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
11363 List<uint32_t> indices; 11355 List<uint32_t> indices;
11364 List<Handle<Object> > old_values; 11356 List<Handle<Object> > old_values;
11365 Handle<Object> old_length_handle(self->length(), isolate); 11357 Handle<Object> old_length_handle(self->length(), isolate);
11366 Handle<Object> new_length_handle(len, isolate); 11358 Handle<Object> new_length_handle(len, isolate);
11367 uint32_t old_length = 0; 11359 uint32_t old_length = 0;
11368 CHECK(old_length_handle->ToArrayIndex(&old_length)); 11360 CHECK(old_length_handle->ToArrayIndex(&old_length));
11369 uint32_t new_length = 0; 11361 uint32_t new_length = 0;
11370 if (!new_length_handle->ToArrayIndex(&new_length)) 11362 if (!new_length_handle->ToArrayIndex(&new_length))
11371 return Failure::InternalError(); 11363 return Failure::InternalError();
11372 11364
11365 // TODO(adamk): The below used to be true but is no longer.
11373 // Observed arrays should always be in dictionary mode; 11366 // Observed arrays should always be in dictionary mode;
11374 // if they were in fast mode, the below is slower than necessary 11367 // if they were in fast mode, the below is slower than necessary
11375 // as it iterates over the array backing store multiple times. 11368 // as it iterates over the array backing store multiple times.
11376 ASSERT(self->HasDictionaryElements());
11377 static const PropertyAttributes kNoAttrFilter = NONE; 11369 static const PropertyAttributes kNoAttrFilter = NONE;
11378 int num_elements = self->NumberOfLocalElements(kNoAttrFilter); 11370 int num_elements = self->NumberOfLocalElements(kNoAttrFilter);
11379 if (num_elements > 0) { 11371 if (num_elements > 0) {
11380 if (old_length == static_cast<uint32_t>(num_elements)) { 11372 if (old_length == static_cast<uint32_t>(num_elements)) {
11381 // Simple case for arrays without holes. 11373 // Simple case for arrays without holes.
11382 for (uint32_t i = old_length - 1; i + 1 > new_length; --i) { 11374 for (uint32_t i = old_length - 1; i + 1 > new_length; --i) {
11383 if (!GetOldValue(isolate, self, i, &old_values, &indices)) break; 11375 if (!GetOldValue(isolate, self, i, &old_values, &indices)) break;
11384 } 11376 }
11385 } else { 11377 } else {
11386 // For sparse arrays, only iterate over existing elements. 11378 // For sparse arrays, only iterate over existing elements.
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
12763 ElementsKindToString(to_kind)); 12755 ElementsKindToString(to_kind));
12764 } 12756 }
12765 site->set_transition_info(Smi::FromInt(to_kind)); 12757 site->set_transition_info(Smi::FromInt(to_kind));
12766 } 12758 }
12767 } 12759 }
12768 return this; 12760 return this;
12769 } 12761 }
12770 12762
12771 12763
12772 MaybeObject* JSObject::TransitionElementsKind(ElementsKind to_kind) { 12764 MaybeObject* JSObject::TransitionElementsKind(ElementsKind to_kind) {
12773 ASSERT(!map()->is_observed());
12774 ElementsKind from_kind = map()->elements_kind(); 12765 ElementsKind from_kind = map()->elements_kind();
12775 12766
12776 if (IsFastHoleyElementsKind(from_kind)) { 12767 if (IsFastHoleyElementsKind(from_kind)) {
12777 to_kind = GetHoleyElementsKind(to_kind); 12768 to_kind = GetHoleyElementsKind(to_kind);
12778 } 12769 }
12779 12770
12780 if (from_kind == to_kind) return this; 12771 if (from_kind == to_kind) return this;
12781 12772
12782 MaybeObject* maybe_failure = UpdateAllocationSite(to_kind); 12773 MaybeObject* maybe_failure = UpdateAllocationSite(to_kind);
12783 if (maybe_failure->IsFailure()) return maybe_failure; 12774 if (maybe_failure->IsFailure()) return maybe_failure;
(...skipping 3612 matching lines...) Expand 10 before | Expand all | Expand 10 after
16396 #define ERROR_MESSAGES_TEXTS(C, T) T, 16387 #define ERROR_MESSAGES_TEXTS(C, T) T,
16397 static const char* error_messages_[] = { 16388 static const char* error_messages_[] = {
16398 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16389 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16399 }; 16390 };
16400 #undef ERROR_MESSAGES_TEXTS 16391 #undef ERROR_MESSAGES_TEXTS
16401 return error_messages_[reason]; 16392 return error_messages_[reason];
16402 } 16393 }
16403 16394
16404 16395
16405 } } // namespace v8::internal 16396 } } // namespace v8::internal
OLDNEW
« src/arm/ic-arm.cc ('K') | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698