Commit 8cf79873 authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap, deoptimizer] Use proper right trim instead of manually trimming

Failing to do so results in out-of-date marking information, because live bytes
is not properly adjusted.

This CL adds support for right trimming ByteArray and properly DCHECKs that we
do not left trim  ByteArray (as we already do for FixedTypedArrayBase).

BUG=

Review URL: https://codereview.chromium.org/1577263003

Cr-Commit-Position: refs/heads/master@{#33252}
parent 995c9fe3
...@@ -3117,6 +3117,7 @@ void Heap::AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode) { ...@@ -3117,6 +3117,7 @@ void Heap::AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode) {
FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object, FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object,
int elements_to_trim) { int elements_to_trim) {
DCHECK(!object->IsFixedTypedArrayBase()); DCHECK(!object->IsFixedTypedArrayBase());
DCHECK(!object->IsByteArray());
const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize;
const int bytes_to_trim = elements_to_trim * element_size; const int bytes_to_trim = elements_to_trim * element_size;
Map* map = object->map(); Map* map = object->map();
...@@ -3173,7 +3174,8 @@ template void Heap::RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>( ...@@ -3173,7 +3174,8 @@ template void Heap::RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(
template<Heap::InvocationMode mode> template<Heap::InvocationMode mode>
void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) { void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) {
const int len = object->length(); const int len = object->length();
DCHECK(elements_to_trim < len); DCHECK_LE(elements_to_trim, len);
DCHECK_GE(elements_to_trim, 0);
int bytes_to_trim; int bytes_to_trim;
if (object->IsFixedTypedArrayBase()) { if (object->IsFixedTypedArrayBase()) {
...@@ -3181,12 +3183,17 @@ void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) { ...@@ -3181,12 +3183,17 @@ void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) {
bytes_to_trim = bytes_to_trim =
FixedTypedArrayBase::TypedArraySize(type, len) - FixedTypedArrayBase::TypedArraySize(type, len) -
FixedTypedArrayBase::TypedArraySize(type, len - elements_to_trim); FixedTypedArrayBase::TypedArraySize(type, len - elements_to_trim);
} else if (object->IsByteArray()) {
int new_size = ByteArray::SizeFor(len - elements_to_trim);
bytes_to_trim = ByteArray::SizeFor(len) - new_size;
DCHECK_GE(bytes_to_trim, 0);
} else { } else {
const int element_size = const int element_size =
object->IsFixedArray() ? kPointerSize : kDoubleSize; object->IsFixedArray() ? kPointerSize : kDoubleSize;
bytes_to_trim = elements_to_trim * element_size; bytes_to_trim = elements_to_trim * element_size;
} }
// For now this trick is only applied to objects in new and paged space. // For now this trick is only applied to objects in new and paged space.
DCHECK(object->map() != fixed_cow_array_map()); DCHECK(object->map() != fixed_cow_array_map());
......
...@@ -157,18 +157,15 @@ void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { ...@@ -157,18 +157,15 @@ void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) {
} }
// Move the relocation info to the beginning of the byte array. // Move the relocation info to the beginning of the byte array.
int new_reloc_size = reloc_end_address - reloc_info_writer.pos(); const int new_reloc_length = reloc_end_address - reloc_info_writer.pos();
MemMove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_size); MemMove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_length);
// The relocation info is in place, update the size. // Right trim the relocation info to free up remaining space.
reloc_info->set_length(new_reloc_size); const int delta = reloc_info->length() - new_reloc_length;
if (delta > 0) {
// Handle the junk part after the new relocation info. We will create isolate->heap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(
// a non-live object in the extra space at the end of the former reloc info. reloc_info, delta);
Address junk_address = reloc_info->address() + reloc_info->Size(); }
DCHECK(junk_address <= reloc_end_address);
isolate->heap()->CreateFillerObjectAt(junk_address,
reloc_end_address - junk_address);
} }
......
...@@ -157,18 +157,15 @@ void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { ...@@ -157,18 +157,15 @@ void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) {
} }
// Move the relocation info to the beginning of the byte array. // Move the relocation info to the beginning of the byte array.
int new_reloc_size = reloc_end_address - reloc_info_writer.pos(); const int new_reloc_length = reloc_end_address - reloc_info_writer.pos();
MemMove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_size); MemMove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_length);
// The relocation info is in place, update the size. // Right trim the relocation info to free up remaining space.
reloc_info->set_length(new_reloc_size); const int delta = reloc_info->length() - new_reloc_length;
if (delta > 0) {
// Handle the junk part after the new relocation info. We will create isolate->heap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(
// a non-live object in the extra space at the end of the former reloc info. reloc_info, delta);
Address junk_address = reloc_info->address() + reloc_info->Size(); }
DCHECK(junk_address <= reloc_end_address);
isolate->heap()->CreateFillerObjectAt(junk_address,
reloc_end_address - junk_address);
} }
......
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