Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 7608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7619 if ((field & kIsNotArrayIndexMask) != 0) return false; | 7619 if ((field & kIsNotArrayIndexMask) != 0) return false; |
| 7620 // Isolate the array index form the full hash field. | 7620 // Isolate the array index form the full hash field. |
| 7621 *index = (kArrayIndexHashMask & field) >> kHashShift; | 7621 *index = (kArrayIndexHashMask & field) >> kHashShift; |
| 7622 return true; | 7622 return true; |
| 7623 } else { | 7623 } else { |
| 7624 return ComputeArrayIndex(index); | 7624 return ComputeArrayIndex(index); |
| 7625 } | 7625 } |
| 7626 } | 7626 } |
| 7627 | 7627 |
| 7628 | 7628 |
| 7629 String* SeqString::Truncate(int new_length) { | 7629 void SeqString::Truncate(int new_length) { |
| 7630 Heap* heap = GetHeap(); | 7630 ASSERT_LT(0, new_length); |
|
Hannes Payer (out of office)
2013/03/21 12:48:30
new_length = 0 should be possible
| |
| 7631 if (new_length <= 0) return heap->empty_string(); | |
| 7632 | 7631 |
| 7633 int string_size, allocated_string_size; | 7632 int new_size, old_size; |
| 7634 int old_length = length(); | 7633 int old_length = length(); |
| 7635 if (old_length <= new_length) return this; | 7634 if (old_length <= new_length) return; |
| 7636 | 7635 |
| 7637 if (IsSeqOneByteString()) { | 7636 if (IsSeqOneByteString()) { |
| 7638 allocated_string_size = SeqOneByteString::SizeFor(old_length); | 7637 old_size = SeqOneByteString::SizeFor(old_length); |
| 7639 string_size = SeqOneByteString::SizeFor(new_length); | 7638 new_size = SeqOneByteString::SizeFor(new_length); |
| 7640 } else { | 7639 } else { |
| 7641 allocated_string_size = SeqTwoByteString::SizeFor(old_length); | 7640 old_size = SeqTwoByteString::SizeFor(old_length); |
| 7642 string_size = SeqTwoByteString::SizeFor(new_length); | 7641 new_size = SeqTwoByteString::SizeFor(new_length); |
| 7643 } | 7642 } |
| 7644 | 7643 |
| 7645 int delta = allocated_string_size - string_size; | 7644 int delta = old_size - new_size; |
| 7646 set_length(new_length); | 7645 set_length(new_length); |
| 7647 | 7646 |
| 7648 // String sizes are pointer size aligned, so that we can use filler objects | 7647 Address start_of_string = address(); |
| 7649 // that are a multiple of pointer size. | 7648 ASSERT_OBJECT_ALIGNED(start_of_string); |
| 7650 Address end_of_string = address() + string_size; | 7649 ASSERT_OBJECT_ALIGNED(start_of_string + new_size); |
| 7651 heap->CreateFillerObjectAt(end_of_string, delta); | 7650 |
| 7651 Heap* heap = GetHeap(); | |
| 7652 if (heap->InNewSpace(start_of_string) && | |
| 7653 heap->new_space()->allocation_info_.top == start_of_string + old_size) { | |
| 7654 // Last allocated object in new space. Simply lower allocation top. | |
| 7655 heap->new_space()->allocation_info_.top = start_of_string + new_size; | |
|
Hannes Payer (out of office)
2013/03/21 12:48:30
I think you also want to adjust MemoryChunk::Incre
Yang
2013/03/21 14:18:34
I'm doing this summarily below.
| |
| 7656 } else { | |
| 7657 // String sizes are pointer size aligned, so that we can use filler objects | |
| 7658 // that are a multiple of pointer size. | |
| 7659 heap->CreateFillerObjectAt(start_of_string + new_size, delta); | |
|
Hannes Payer (out of office)
2013/03/21 12:48:30
Do we also have to adjust MemoryChunk::IncrementL
Yang
2013/03/21 14:18:34
I'm doing this summarily below.
| |
| 7660 } | |
| 7661 | |
| 7652 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { | 7662 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { |
| 7653 MemoryChunk::IncrementLiveBytesFromMutator(address(), -delta); | 7663 MemoryChunk::IncrementLiveBytesFromMutator(start_of_string, -delta); |
| 7654 } | 7664 } |
| 7655 return this; | |
| 7656 } | 7665 } |
| 7657 | 7666 |
| 7658 | 7667 |
| 7659 AllocationSiteInfo* AllocationSiteInfo::FindForJSObject(JSObject* object) { | 7668 AllocationSiteInfo* AllocationSiteInfo::FindForJSObject(JSObject* object) { |
| 7660 // Currently, AllocationSiteInfo objects are only allocated immediately | 7669 // Currently, AllocationSiteInfo objects are only allocated immediately |
| 7661 // after JSArrays in NewSpace, and detecting whether a JSArray has one | 7670 // after JSArrays in NewSpace, and detecting whether a JSArray has one |
| 7662 // involves carefully checking the object immediately after the JSArray | 7671 // involves carefully checking the object immediately after the JSArray |
| 7663 // (if there is one) to see if it's an AllocationSiteInfo. | 7672 // (if there is one) to see if it's an AllocationSiteInfo. |
| 7664 if (FLAG_track_allocation_sites && object->GetHeap()->InNewSpace(object)) { | 7673 if (FLAG_track_allocation_sites && object->GetHeap()->InNewSpace(object)) { |
| 7665 Address ptr_end = (reinterpret_cast<Address>(object) - kHeapObjectTag) + | 7674 Address ptr_end = (reinterpret_cast<Address>(object) - kHeapObjectTag) + |
| (...skipping 6660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14326 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 14335 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
| 14327 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 14336 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
| 14328 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 14337 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
| 14329 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 14338 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
| 14330 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 14339 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
| 14331 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 14340 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
| 14332 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 14341 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
| 14333 } | 14342 } |
| 14334 | 14343 |
| 14335 } } // namespace v8::internal | 14344 } } // namespace v8::internal |
| OLD | NEW |