| OLD | NEW | 
|---|
| 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 15 matching lines...) Expand all  Loading... | 
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 27 | 27 | 
| 28 #include "v8.h" | 28 #include "v8.h" | 
| 29 | 29 | 
| 30 #include "api.h" | 30 #include "api.h" | 
| 31 #include "arguments.h" | 31 #include "arguments.h" | 
| 32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" | 
| 33 #include "builtins.h" | 33 #include "builtins.h" | 
| 34 #include "gdb-jit.h" | 34 #include "gdb-jit.h" | 
| 35 #include "ic-inl.h" | 35 #include "ic-inl.h" | 
|  | 36 #include "mark-compact.h" | 
| 36 #include "vm-state-inl.h" | 37 #include "vm-state-inl.h" | 
| 37 | 38 | 
| 38 namespace v8 { | 39 namespace v8 { | 
| 39 namespace internal { | 40 namespace internal { | 
| 40 | 41 | 
| 41 namespace { | 42 namespace { | 
| 42 | 43 | 
| 43 // Arguments object passed to C++ builtins. | 44 // Arguments object passed to C++ builtins. | 
| 44 template <BuiltinExtraArguments extra_args> | 45 template <BuiltinExtraArguments extra_args> | 
| 45 class BuiltinArguments : public Arguments { | 46 class BuiltinArguments : public Arguments { | 
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 288   ASSERT(dst != src);  // Use MoveElements instead. | 289   ASSERT(dst != src);  // Use MoveElements instead. | 
| 289   ASSERT(dst->map() != HEAP->fixed_cow_array_map()); | 290   ASSERT(dst->map() != HEAP->fixed_cow_array_map()); | 
| 290   ASSERT(len > 0); | 291   ASSERT(len > 0); | 
| 291   CopyWords(dst->data_start() + dst_index, | 292   CopyWords(dst->data_start() + dst_index, | 
| 292             src->data_start() + src_index, | 293             src->data_start() + src_index, | 
| 293             len); | 294             len); | 
| 294   WriteBarrierMode mode = dst->GetWriteBarrierMode(*no_gc); | 295   WriteBarrierMode mode = dst->GetWriteBarrierMode(*no_gc); | 
| 295   if (mode == UPDATE_WRITE_BARRIER) { | 296   if (mode == UPDATE_WRITE_BARRIER) { | 
| 296     heap->RecordWrites(dst->address(), dst->OffsetOfElementAt(dst_index), len); | 297     heap->RecordWrites(dst->address(), dst->OffsetOfElementAt(dst_index), len); | 
| 297   } | 298   } | 
|  | 299   heap->incremental_marking()->RecordWrites(dst); | 
| 298 } | 300 } | 
| 299 | 301 | 
| 300 | 302 | 
| 301 static void MoveElements(Heap* heap, | 303 static void MoveElements(Heap* heap, | 
| 302                          AssertNoAllocation* no_gc, | 304                          AssertNoAllocation* no_gc, | 
| 303                          FixedArray* dst, | 305                          FixedArray* dst, | 
| 304                          int dst_index, | 306                          int dst_index, | 
| 305                          FixedArray* src, | 307                          FixedArray* src, | 
| 306                          int src_index, | 308                          int src_index, | 
| 307                          int len) { | 309                          int len) { | 
| 308   ASSERT(dst->map() != HEAP->fixed_cow_array_map()); | 310   ASSERT(dst->map() != HEAP->fixed_cow_array_map()); | 
| 309   memmove(dst->data_start() + dst_index, | 311   memmove(dst->data_start() + dst_index, | 
| 310           src->data_start() + src_index, | 312           src->data_start() + src_index, | 
| 311           len * kPointerSize); | 313           len * kPointerSize); | 
| 312   WriteBarrierMode mode = dst->GetWriteBarrierMode(*no_gc); | 314   WriteBarrierMode mode = dst->GetWriteBarrierMode(*no_gc); | 
| 313   if (mode == UPDATE_WRITE_BARRIER) { | 315   if (mode == UPDATE_WRITE_BARRIER) { | 
| 314     heap->RecordWrites(dst->address(), dst->OffsetOfElementAt(dst_index), len); | 316     heap->RecordWrites(dst->address(), dst->OffsetOfElementAt(dst_index), len); | 
| 315   } | 317   } | 
|  | 318   heap->incremental_marking()->RecordWrites(dst); | 
| 316 } | 319 } | 
| 317 | 320 | 
| 318 | 321 | 
| 319 static void FillWithHoles(Heap* heap, FixedArray* dst, int from, int to) { | 322 static void FillWithHoles(Heap* heap, FixedArray* dst, int from, int to) { | 
| 320   ASSERT(dst->map() != heap->fixed_cow_array_map()); | 323   ASSERT(dst->map() != heap->fixed_cow_array_map()); | 
| 321   MemsetPointer(dst->data_start() + from, heap->the_hole_value(), to - from); | 324   MemsetPointer(dst->data_start() + from, heap->the_hole_value(), to - from); | 
| 322 } | 325 } | 
| 323 | 326 | 
| 324 | 327 | 
| 325 static FixedArray* LeftTrimFixedArray(Heap* heap, | 328 static FixedArray* LeftTrimFixedArray(Heap* heap, | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 351     } | 354     } | 
| 352   } | 355   } | 
| 353   // Technically in new space this write might be omitted (except for | 356   // Technically in new space this write might be omitted (except for | 
| 354   // debug mode which iterates through the heap), but to play safer | 357   // debug mode which iterates through the heap), but to play safer | 
| 355   // we still do it. | 358   // we still do it. | 
| 356   heap->CreateFillerObjectAt(elms->address(), to_trim * kPointerSize); | 359   heap->CreateFillerObjectAt(elms->address(), to_trim * kPointerSize); | 
| 357 | 360 | 
| 358   former_start[to_trim] = heap->fixed_array_map(); | 361   former_start[to_trim] = heap->fixed_array_map(); | 
| 359   former_start[to_trim + 1] = Smi::FromInt(len - to_trim); | 362   former_start[to_trim + 1] = Smi::FromInt(len - to_trim); | 
| 360 | 363 | 
|  | 364   // Maintain marking consistency for HeapObjectIterator and | 
|  | 365   // IncrementalMarking. | 
|  | 366   int size_delta = to_trim * kPointerSize; | 
|  | 367   if (heap->marking()->TransferMark(elms->address(), | 
|  | 368                                     elms->address() + size_delta)) { | 
|  | 369     MemoryChunk::IncrementLiveBytes(elms->address(), -size_delta); | 
|  | 370   } | 
|  | 371 | 
| 361   return FixedArray::cast(HeapObject::FromAddress( | 372   return FixedArray::cast(HeapObject::FromAddress( | 
| 362       elms->address() + to_trim * kPointerSize)); | 373       elms->address() + to_trim * kPointerSize)); | 
| 363 } | 374 } | 
| 364 | 375 | 
| 365 | 376 | 
| 366 static bool ArrayPrototypeHasNoElements(Heap* heap, | 377 static bool ArrayPrototypeHasNoElements(Heap* heap, | 
| 367                                         Context* global_context, | 378                                         Context* global_context, | 
| 368                                         JSObject* array_proto) { | 379                                         JSObject* array_proto) { | 
| 369   // This method depends on non writability of Object and Array prototype | 380   // This method depends on non writability of Object and Array prototype | 
| 370   // fields. | 381   // fields. | 
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 544   int len = Smi::cast(array->length())->value(); | 555   int len = Smi::cast(array->length())->value(); | 
| 545   if (len == 0) return heap->undefined_value(); | 556   if (len == 0) return heap->undefined_value(); | 
| 546 | 557 | 
| 547   // Get first element | 558   // Get first element | 
| 548   Object* first = elms->get(0); | 559   Object* first = elms->get(0); | 
| 549   if (first->IsTheHole()) { | 560   if (first->IsTheHole()) { | 
| 550     first = heap->undefined_value(); | 561     first = heap->undefined_value(); | 
| 551   } | 562   } | 
| 552 | 563 | 
| 553   if (!heap->lo_space()->Contains(elms)) { | 564   if (!heap->lo_space()->Contains(elms)) { | 
| 554     // As elms still in the same space they used to be, | 565     array->set_elements(LeftTrimFixedArray(heap, elms, 1)); | 
| 555     // there is no need to update region dirty mark. |  | 
| 556     array->set_elements(LeftTrimFixedArray(heap, elms, 1), SKIP_WRITE_BARRIER); |  | 
| 557   } else { | 566   } else { | 
| 558     // Shift the elements. | 567     // Shift the elements. | 
| 559     AssertNoAllocation no_gc; | 568     AssertNoAllocation no_gc; | 
| 560     MoveElements(heap, &no_gc, elms, 0, elms, 1, len - 1); | 569     MoveElements(heap, &no_gc, elms, 0, elms, 1, len - 1); | 
| 561     elms->set(len - 1, heap->the_hole_value()); | 570     elms->set(len - 1, heap->the_hole_value()); | 
| 562   } | 571   } | 
| 563 | 572 | 
| 564   // Set the length. | 573   // Set the length. | 
| 565   array->set_length(Smi::FromInt(len - 1)); | 574   array->set_length(Smi::FromInt(len - 1)); | 
| 566 | 575 | 
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 835           (len - actual_delete_count - actual_start)); | 844           (len - actual_delete_count - actual_start)); | 
| 836     if (trim_array) { | 845     if (trim_array) { | 
| 837       const int delta = actual_delete_count - item_count; | 846       const int delta = actual_delete_count - item_count; | 
| 838 | 847 | 
| 839       if (actual_start > 0) { | 848       if (actual_start > 0) { | 
| 840         AssertNoAllocation no_gc; | 849         AssertNoAllocation no_gc; | 
| 841         MoveElements(heap, &no_gc, elms, delta, elms, 0, actual_start); | 850         MoveElements(heap, &no_gc, elms, delta, elms, 0, actual_start); | 
| 842       } | 851       } | 
| 843 | 852 | 
| 844       elms = LeftTrimFixedArray(heap, elms, delta); | 853       elms = LeftTrimFixedArray(heap, elms, delta); | 
| 845       array->set_elements(elms, SKIP_WRITE_BARRIER); | 854       array->set_elements(elms); | 
| 846     } else { | 855     } else { | 
| 847       AssertNoAllocation no_gc; | 856       AssertNoAllocation no_gc; | 
| 848       MoveElements(heap, &no_gc, | 857       MoveElements(heap, &no_gc, | 
| 849                    elms, actual_start + item_count, | 858                    elms, actual_start + item_count, | 
| 850                    elms, actual_start + actual_delete_count, | 859                    elms, actual_start + actual_delete_count, | 
| 851                    (len - actual_delete_count - actual_start)); | 860                    (len - actual_delete_count - actual_start)); | 
| 852       FillWithHoles(heap, elms, new_length, len); | 861       FillWithHoles(heap, elms, new_length, len); | 
| 853     } | 862     } | 
| 854   } else if (item_count > actual_delete_count) { | 863   } else if (item_count > actual_delete_count) { | 
| 855     // Currently fixed arrays cannot grow too big, so | 864     // Currently fixed arrays cannot grow too big, so | 
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1704   return Handle<Code>(code_address);                        \ | 1713   return Handle<Code>(code_address);                        \ | 
| 1705 } | 1714 } | 
| 1706 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1715 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 
| 1707 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1716 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 
| 1708 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1717 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 
| 1709 #undef DEFINE_BUILTIN_ACCESSOR_C | 1718 #undef DEFINE_BUILTIN_ACCESSOR_C | 
| 1710 #undef DEFINE_BUILTIN_ACCESSOR_A | 1719 #undef DEFINE_BUILTIN_ACCESSOR_A | 
| 1711 | 1720 | 
| 1712 | 1721 | 
| 1713 } }  // namespace v8::internal | 1722 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|