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

Side by Side Diff: src/builtins.cc

Issue 3143032: We can use the array trim trick in old paged space as well as (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 4 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 299
300 300
301 static void FillWithHoles(FixedArray* dst, int from, int to) { 301 static void FillWithHoles(FixedArray* dst, int from, int to) {
302 ASSERT(dst->map() != Heap::fixed_cow_array_map()); 302 ASSERT(dst->map() != Heap::fixed_cow_array_map());
303 MemsetPointer(dst->data_start() + from, Heap::the_hole_value(), to - from); 303 MemsetPointer(dst->data_start() + from, Heap::the_hole_value(), to - from);
304 } 304 }
305 305
306 306
307 static FixedArray* LeftTrimFixedArray(FixedArray* elms, int to_trim) { 307 static FixedArray* LeftTrimFixedArray(FixedArray* elms, int to_trim) {
308 ASSERT(elms->map() != Heap::fixed_cow_array_map()); 308 ASSERT(elms->map() != Heap::fixed_cow_array_map());
309 // For now this trick is only applied to fixed arrays in new space. 309 // For now this trick is only applied to fixed arrays in new and paged space.
310 // In large object space the object's start must coincide with chunk 310 // In large object space the object's start must coincide with chunk
311 // and thus the trick is just not applicable. 311 // and thus the trick is just not applicable.
312 // In old space we do not use this trick to avoid dealing with 312 ASSERT(!Heap::lo_space()->Contains(elms));
313 // region dirty marks.
314 ASSERT(Heap::new_space()->Contains(elms));
315 313
316 STATIC_ASSERT(FixedArray::kMapOffset == 0); 314 STATIC_ASSERT(FixedArray::kMapOffset == 0);
317 STATIC_ASSERT(FixedArray::kLengthOffset == kPointerSize); 315 STATIC_ASSERT(FixedArray::kLengthOffset == kPointerSize);
318 STATIC_ASSERT(FixedArray::kHeaderSize == 2 * kPointerSize); 316 STATIC_ASSERT(FixedArray::kHeaderSize == 2 * kPointerSize);
319 317
320 Object** former_start = HeapObject::RawField(elms, 0); 318 Object** former_start = HeapObject::RawField(elms, 0);
321 319
322 const int len = elms->length(); 320 const int len = elms->length();
323 321
322 if (to_trim > FixedArray::kHeaderSize / kPointerSize &&
323 !Heap::new_space()->Contains(elms)) {
324 // If we are doing a big trim in old space then we zap the space that was
325 // formerly part of the array so that the GC (aided by the card-based
326 // remembered set) won't find pointers to new-space there.
327 Object** zap = reinterpret_cast<Object**>(elms->address());
328 for (int i = 0; i < to_trim; i++) {
antonm 2010/08/20 11:50:30 you may save one store here as elms->address() wou
329 *zap++ = Smi::FromInt(0);
330 }
331 }
324 // Technically in new space this write might be omitted (except for 332 // Technically in new space this write might be omitted (except for
325 // debug mode which iterates through the heap), but to play safer 333 // debug mode which iterates through the heap), but to play safer
326 // we still do it. 334 // we still do it.
327 Heap::CreateFillerObjectAt(elms->address(), to_trim * kPointerSize); 335 Heap::CreateFillerObjectAt(elms->address(), to_trim * kPointerSize);
328 336
329 former_start[to_trim] = Heap::fixed_array_map(); 337 former_start[to_trim] = Heap::fixed_array_map();
330 former_start[to_trim + 1] = Smi::FromInt(len - to_trim); 338 former_start[to_trim + 1] = Smi::FromInt(len - to_trim);
331 339
332 ASSERT_EQ(elms->address() + to_trim * kPointerSize, 340 return FixedArray::cast(HeapObject::FromAddress(
333 (elms + to_trim * kPointerSize)->address()); 341 elms->address() + to_trim * kPointerSize));
334 return elms + to_trim * kPointerSize;
335 } 342 }
336 343
337 344
338 static bool ArrayPrototypeHasNoElements(Context* global_context, 345 static bool ArrayPrototypeHasNoElements(Context* global_context,
339 JSObject* array_proto) { 346 JSObject* array_proto) {
340 // This method depends on non writability of Object and Array prototype 347 // This method depends on non writability of Object and Array prototype
341 // fields. 348 // fields.
342 if (array_proto->elements() != Heap::empty_fixed_array()) return false; 349 if (array_proto->elements() != Heap::empty_fixed_array()) return false;
343 // Hidden prototype 350 // Hidden prototype
344 array_proto = JSObject::cast(array_proto->GetPrototype()); 351 array_proto = JSObject::cast(array_proto->GetPrototype());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 497
491 int len = Smi::cast(array->length())->value(); 498 int len = Smi::cast(array->length())->value();
492 if (len == 0) return Heap::undefined_value(); 499 if (len == 0) return Heap::undefined_value();
493 500
494 // Get first element 501 // Get first element
495 Object* first = elms->get(0); 502 Object* first = elms->get(0);
496 if (first->IsTheHole()) { 503 if (first->IsTheHole()) {
497 first = Heap::undefined_value(); 504 first = Heap::undefined_value();
498 } 505 }
499 506
500 if (Heap::new_space()->Contains(elms)) { 507 if (!Heap::lo_space()->Contains(elms)) {
501 // As elms still in the same space they used to be (new space), 508 // As elms still in the same space they used to be,
502 // there is no need to update region dirty mark. 509 // there is no need to update region dirty mark.
503 array->set_elements(LeftTrimFixedArray(elms, 1), SKIP_WRITE_BARRIER); 510 array->set_elements(LeftTrimFixedArray(elms, 1), SKIP_WRITE_BARRIER);
504 } else { 511 } else {
505 // Shift the elements. 512 // Shift the elements.
506 AssertNoAllocation no_gc; 513 AssertNoAllocation no_gc;
507 MoveElements(&no_gc, elms, 0, elms, 1, len - 1); 514 MoveElements(&no_gc, elms, 0, elms, 1, len - 1);
508 elms->set(len - 1, Heap::the_hole_value()); 515 elms->set(len - 1, Heap::the_hole_value());
509 } 516 }
510 517
511 // Set the length. 518 // Set the length.
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 // Set the length. 724 // Set the length.
718 result_array->set_length(Smi::FromInt(actual_delete_count)); 725 result_array->set_length(Smi::FromInt(actual_delete_count));
719 } 726 }
720 727
721 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; 728 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0;
722 729
723 int new_length = len - actual_delete_count + item_count; 730 int new_length = len - actual_delete_count + item_count;
724 731
725 if (item_count < actual_delete_count) { 732 if (item_count < actual_delete_count) {
726 // Shrink the array. 733 // Shrink the array.
727 const bool trim_array = Heap::new_space()->Contains(elms) && 734 const bool trim_array = !Heap::lo_space()->Contains(elms) &&
728 ((actual_start + item_count) < 735 ((actual_start + item_count) <
729 (len - actual_delete_count - actual_start)); 736 (len - actual_delete_count - actual_start));
730 if (trim_array) { 737 if (trim_array) {
731 const int delta = actual_delete_count - item_count; 738 const int delta = actual_delete_count - item_count;
732 739
733 if (actual_start > 0) { 740 if (actual_start > 0) {
734 Object** start = elms->data_start(); 741 Object** start = elms->data_start();
735 memmove(start + delta, start, actual_start * kPointerSize); 742 memmove(start + delta, start, actual_start * kPointerSize);
736 } 743 }
737 744
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 if (entry->contains(pc)) { 1534 if (entry->contains(pc)) {
1528 return names_[i]; 1535 return names_[i];
1529 } 1536 }
1530 } 1537 }
1531 } 1538 }
1532 return NULL; 1539 return NULL;
1533 } 1540 }
1534 1541
1535 1542
1536 } } // namespace v8::internal 1543 } } // 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