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

Side by Side Diff: src/objects.cc

Issue 12440061: Improve SeqString::Truncate for latest allocated strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: renamed according to suggestion Created 7 years, 9 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/objects.h ('k') | src/runtime.cc » ('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 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
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 Handle<String> SeqString::Truncate(Handle<SeqString> string, int new_length) {
7630 Heap* heap = GetHeap(); 7630 int new_size, old_size;
7631 if (new_length <= 0) return heap->empty_string(); 7631 int old_length = string->length();
7632 if (old_length <= new_length) return string;
7632 7633
7633 int string_size, allocated_string_size; 7634 if (string->IsSeqOneByteString()) {
7634 int old_length = length(); 7635 old_size = SeqOneByteString::SizeFor(old_length);
7635 if (old_length <= new_length) return this; 7636 new_size = SeqOneByteString::SizeFor(new_length);
7636
7637 if (IsSeqOneByteString()) {
7638 allocated_string_size = SeqOneByteString::SizeFor(old_length);
7639 string_size = SeqOneByteString::SizeFor(new_length);
7640 } else { 7637 } else {
7641 allocated_string_size = SeqTwoByteString::SizeFor(old_length); 7638 ASSERT(string->IsSeqTwoByteString());
7642 string_size = SeqTwoByteString::SizeFor(new_length); 7639 old_size = SeqTwoByteString::SizeFor(old_length);
7640 new_size = SeqTwoByteString::SizeFor(new_length);
7643 } 7641 }
7644 7642
7645 int delta = allocated_string_size - string_size; 7643 int delta = old_size - new_size;
7646 set_length(new_length); 7644 string->set_length(new_length);
7647 7645
7648 // String sizes are pointer size aligned, so that we can use filler objects 7646 Address start_of_string = string->address();
7649 // that are a multiple of pointer size. 7647 ASSERT_OBJECT_ALIGNED(start_of_string);
7650 Address end_of_string = address() + string_size; 7648 ASSERT_OBJECT_ALIGNED(start_of_string + new_size);
7651 heap->CreateFillerObjectAt(end_of_string, delta); 7649
7652 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { 7650 Heap* heap = string->GetHeap();
7653 MemoryChunk::IncrementLiveBytesFromMutator(address(), -delta); 7651 NewSpace* newspace = heap->new_space();
7652 if (newspace->Contains(start_of_string) &&
7653 newspace->top() == start_of_string + old_size) {
7654 // Last allocated object in new space. Simply lower allocation top.
7655 *(newspace->allocation_top_address()) = start_of_string + new_size;
7656 } else {
7657 // 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);
7654 } 7660 }
7655 return this; 7661 if (Marking::IsBlack(Marking::MarkBitFrom(start_of_string))) {
7662 MemoryChunk::IncrementLiveBytesFromMutator(start_of_string, -delta);
7663 }
7664
7665
7666 if (new_length == 0) return heap->isolate()->factory()->empty_string();
7667 return string;
7656 } 7668 }
7657 7669
7658 7670
7659 AllocationSiteInfo* AllocationSiteInfo::FindForJSObject(JSObject* object) { 7671 AllocationSiteInfo* AllocationSiteInfo::FindForJSObject(JSObject* object) {
7660 // Currently, AllocationSiteInfo objects are only allocated immediately 7672 // Currently, AllocationSiteInfo objects are only allocated immediately
7661 // after JSArrays in NewSpace, and detecting whether a JSArray has one 7673 // after JSArrays in NewSpace, and detecting whether a JSArray has one
7662 // involves carefully checking the object immediately after the JSArray 7674 // involves carefully checking the object immediately after the JSArray
7663 // (if there is one) to see if it's an AllocationSiteInfo. 7675 // (if there is one) to see if it's an AllocationSiteInfo.
7664 if (FLAG_track_allocation_sites && object->GetHeap()->InNewSpace(object)) { 7676 if (FLAG_track_allocation_sites && object->GetHeap()->InNewSpace(object)) {
7665 Address ptr_end = (reinterpret_cast<Address>(object) - kHeapObjectTag) + 7677 Address ptr_end = (reinterpret_cast<Address>(object) - kHeapObjectTag) +
(...skipping 6660 matching lines...) Expand 10 before | Expand all | Expand 10 after
14326 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 14338 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
14327 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 14339 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
14328 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 14340 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
14329 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 14341 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
14330 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 14342 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
14331 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 14343 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
14332 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 14344 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
14333 } 14345 }
14334 14346
14335 } } // namespace v8::internal 14347 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698