Commit 18842238 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap] Clear recorded slots for trimmed strings and preparse data

Currently string and preparse data trimming code creates filler object
without clearing the slots in the trimmed area. This currently works
because the slots are overwritten by filler/free space map.

This CL explicitly clears the slots and makes the code more robust.

Bug: v8:9454
Change-Id: I20ad8a210eb17932e46be5df4b42389955b5e5eb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1778023Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63481}
parent baed90dc
...@@ -627,7 +627,7 @@ void SharedFunctionInfo::ClearPreparseData() { ...@@ -627,7 +627,7 @@ void SharedFunctionInfo::ClearPreparseData() {
data.address() + UncompiledDataWithoutPreparseData::kSize, data.address() + UncompiledDataWithoutPreparseData::kSize,
UncompiledDataWithPreparseData::kSize - UncompiledDataWithPreparseData::kSize -
UncompiledDataWithoutPreparseData::kSize, UncompiledDataWithoutPreparseData::kSize,
ClearRecordedSlots::kNo); ClearRecordedSlots::kYes);
// Ensure that the clear was successful. // Ensure that the clear was successful.
DCHECK(HasUncompiledDataWithoutPreparseData()); DCHECK(HasUncompiledDataWithoutPreparseData());
......
...@@ -110,6 +110,8 @@ void String::MakeThin(Isolate* isolate, String internalized) { ...@@ -110,6 +110,8 @@ void String::MakeThin(Isolate* isolate, String internalized) {
} }
} }
bool has_pointers = StringShape(*this).IsIndirect();
int old_size = this->Size(); int old_size = this->Size();
isolate->heap()->NotifyObjectLayoutChange(*this, old_size, no_gc); isolate->heap()->NotifyObjectLayoutChange(*this, old_size, no_gc);
bool one_byte = internalized.IsOneByteRepresentation(); bool one_byte = internalized.IsOneByteRepresentation();
...@@ -123,7 +125,9 @@ void String::MakeThin(Isolate* isolate, String internalized) { ...@@ -123,7 +125,9 @@ void String::MakeThin(Isolate* isolate, String internalized) {
int size_delta = old_size - ThinString::kSize; int size_delta = old_size - ThinString::kSize;
if (size_delta != 0) { if (size_delta != 0) {
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
heap->CreateFillerObjectAt(thin_end, size_delta, ClearRecordedSlots::kNo); heap->CreateFillerObjectAt(
thin_end, size_delta,
has_pointers ? ClearRecordedSlots::kYes : ClearRecordedSlots::kNo);
} }
} }
...@@ -178,7 +182,8 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) { ...@@ -178,7 +182,8 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) {
// Byte size of the external String object. // Byte size of the external String object.
int new_size = this->SizeFromMap(new_map); int new_size = this->SizeFromMap(new_map);
isolate->heap()->CreateFillerObjectAt( isolate->heap()->CreateFillerObjectAt(
this->address() + new_size, size - new_size, ClearRecordedSlots::kNo); this->address() + new_size, size - new_size,
has_pointers ? ClearRecordedSlots::kYes : ClearRecordedSlots::kNo);
if (has_pointers) { if (has_pointers) {
isolate->heap()->ClearRecordedSlotRange(this->address(), isolate->heap()->ClearRecordedSlotRange(this->address(),
this->address() + new_size); this->address() + new_size);
...@@ -250,7 +255,8 @@ bool String::MakeExternal(v8::String::ExternalOneByteStringResource* resource) { ...@@ -250,7 +255,8 @@ bool String::MakeExternal(v8::String::ExternalOneByteStringResource* resource) {
// Byte size of the external String object. // Byte size of the external String object.
int new_size = this->SizeFromMap(new_map); int new_size = this->SizeFromMap(new_map);
isolate->heap()->CreateFillerObjectAt( isolate->heap()->CreateFillerObjectAt(
this->address() + new_size, size - new_size, ClearRecordedSlots::kNo); this->address() + new_size, size - new_size,
has_pointers ? ClearRecordedSlots::kYes : ClearRecordedSlots::kNo);
if (has_pointers) { if (has_pointers) {
isolate->heap()->ClearRecordedSlotRange(this->address(), isolate->heap()->ClearRecordedSlotRange(this->address(),
this->address() + new_size); this->address() + new_size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment