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

Side by Side Diff: src/elements.cc

Issue 219103002: Make sure when we shrink an object that we store a filler first into the free memory before updatin… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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/builtins.cc ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 // Check whether the backing store should be shrunk. 996 // Check whether the backing store should be shrunk.
997 if (length <= old_capacity) { 997 if (length <= old_capacity) {
998 if (array->HasFastSmiOrObjectElements()) { 998 if (array->HasFastSmiOrObjectElements()) {
999 backing_store = JSObject::EnsureWritableFastElements(array); 999 backing_store = JSObject::EnsureWritableFastElements(array);
1000 } 1000 }
1001 if (2 * length <= old_capacity) { 1001 if (2 * length <= old_capacity) {
1002 // If more than half the elements won't be used, trim the array. 1002 // If more than half the elements won't be used, trim the array.
1003 if (length == 0) { 1003 if (length == 0) {
1004 array->initialize_elements(); 1004 array->initialize_elements();
1005 } else { 1005 } else {
1006 backing_store->set_length(length); 1006 int filler_size = (old_capacity - length) * ElementSize;
1007 Address filler_start = backing_store->address() + 1007 Address filler_start = backing_store->address() +
1008 BackingStore::OffsetOfElementAt(length); 1008 BackingStore::OffsetOfElementAt(length);
1009 int filler_size = (old_capacity - length) * ElementSize;
1010 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size); 1009 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size);
1010
1011 // We are storing the new length using release store after creating a
1012 // filler for the left-over space to avoid races with the sweeper
1013 // thread.
1014 backing_store->synchronized_set_length(length);
1011 } 1015 }
1012 } else { 1016 } else {
1013 // Otherwise, fill the unused tail with holes. 1017 // Otherwise, fill the unused tail with holes.
1014 int old_length = FastD2IChecked(array->length()->Number()); 1018 int old_length = FastD2IChecked(array->length()->Number());
1015 for (int i = length; i < old_length; i++) { 1019 for (int i = length; i < old_length; i++) {
1016 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); 1020 Handle<BackingStore>::cast(backing_store)->set_the_hole(i);
1017 } 1021 }
1018 } 1022 }
1019 return length_object; 1023 return length_object;
1020 } 1024 }
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 UNREACHABLE(); 2082 UNREACHABLE();
2079 break; 2083 break;
2080 } 2084 }
2081 2085
2082 array->set_elements(*elms); 2086 array->set_elements(*elms);
2083 array->set_length(Smi::FromInt(number_of_elements)); 2087 array->set_length(Smi::FromInt(number_of_elements));
2084 return array; 2088 return array;
2085 } 2089 }
2086 2090
2087 } } // namespace v8::internal 2091 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/builtins.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698