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

Side by Side Diff: src/objects.cc

Issue 7298004: Do a backing store sparseness check on fast element delete. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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 | « no previous file | 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 3013 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 Heap* heap = GetHeap(); 3024 Heap* heap = GetHeap();
3025 FixedArray* backing_store = FixedArray::cast(elements()); 3025 FixedArray* backing_store = FixedArray::cast(elements());
3026 if (backing_store->map() == heap->non_strict_arguments_elements_map()) { 3026 if (backing_store->map() == heap->non_strict_arguments_elements_map()) {
3027 backing_store = FixedArray::cast(backing_store->get(1)); 3027 backing_store = FixedArray::cast(backing_store->get(1));
3028 } else { 3028 } else {
3029 Object* writable; 3029 Object* writable;
3030 MaybeObject* maybe = EnsureWritableFastElements(); 3030 MaybeObject* maybe = EnsureWritableFastElements();
3031 if (!maybe->ToObject(&writable)) return maybe; 3031 if (!maybe->ToObject(&writable)) return maybe;
3032 backing_store = FixedArray::cast(writable); 3032 backing_store = FixedArray::cast(writable);
3033 } 3033 }
3034 int length = IsJSArray() 3034 uint32_t length = static_cast<uint32_t>(
3035 IsJSArray()
3035 ? Smi::cast(JSArray::cast(this)->length())->value() 3036 ? Smi::cast(JSArray::cast(this)->length())->value()
3036 : backing_store->length(); 3037 : backing_store->length());
3037 if (index < static_cast<uint32_t>(length)) { 3038 if (index < length) {
3038 backing_store->set_the_hole(index); 3039 backing_store->set_the_hole(index);
3040 // If an old space backing store is larger than a certain size and
3041 // has too few used values, normalize it.
3042 // To avoid doing the check on every delete we require at least
3043 // one adjacent hole to the value being deleted.
3044 Object* hole = heap->the_hole_value();
3045 const int kMinLengthForSparsenessCheck = 64;
3046 if (backing_store->length() >= kMinLengthForSparsenessCheck &&
3047 !heap->InNewSpace(backing_store) &&
3048 ((index > 0 && backing_store->get(index - 1) == hole) ||
3049 (index + 1 < length && backing_store->get(index + 1) == hole))) {
3050 int num_used = 0;
3051 for (int i = 0; i < backing_store->length(); ++i) {
3052 if (backing_store->get(i) != hole) ++num_used;
Vyacheslav Egorov (Chromium) 2011/07/01 12:25:58 You can have an early exit from the loop if num_us
Vitaly Repeshko 2011/07/01 13:05:02 Good idea. Done.
3053 }
3054 if (4 * num_used <= backing_store->length()) {
3055 MaybeObject* result = NormalizeElements();
3056 if (result->IsFailure()) return result;
3057 }
3058 }
3039 } 3059 }
3040 return heap->true_value(); 3060 return heap->true_value();
3041 } 3061 }
3042 3062
3043 3063
3044 MaybeObject* JSObject::DeleteDictionaryElement(uint32_t index, 3064 MaybeObject* JSObject::DeleteDictionaryElement(uint32_t index,
3045 DeleteMode mode) { 3065 DeleteMode mode) {
3046 Isolate* isolate = GetIsolate(); 3066 Isolate* isolate = GetIsolate();
3047 Heap* heap = isolate->heap(); 3067 Heap* heap = isolate->heap();
3048 FixedArray* backing_store = FixedArray::cast(elements()); 3068 FixedArray* backing_store = FixedArray::cast(elements());
(...skipping 8587 matching lines...) Expand 10 before | Expand all | Expand 10 after
11636 if (break_point_objects()->IsUndefined()) return 0; 11656 if (break_point_objects()->IsUndefined()) return 0;
11637 // Single beak point. 11657 // Single beak point.
11638 if (!break_point_objects()->IsFixedArray()) return 1; 11658 if (!break_point_objects()->IsFixedArray()) return 1;
11639 // Multiple break points. 11659 // Multiple break points.
11640 return FixedArray::cast(break_point_objects())->length(); 11660 return FixedArray::cast(break_point_objects())->length();
11641 } 11661 }
11642 #endif 11662 #endif
11643 11663
11644 11664
11645 } } // namespace v8::internal 11665 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698