From aade11ede098bf689a51d1b6e6b8396d199d364c Mon Sep 17 00:00:00 2001 From: "verwaest@chromium.org" Date: Wed, 6 Aug 2014 17:48:31 +0000 Subject: [PATCH] We should never allocate a 0-sized buffer, so never grow from 0. BUG= R=ishell@chromium.org Review URL: https://codereview.chromium.org/446933003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22947 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/assembler-arm.cc | 4 +--- src/arm64/assembler-arm64.cc | 4 +--- src/assembler.cc | 13 ++++--------- src/ia32/assembler-ia32.cc | 7 ++----- src/lithium.cc | 3 +-- src/x64/assembler-x64.cc | 7 ++----- 6 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/arm/assembler-arm.cc b/src/arm/assembler-arm.cc index 1c690a8..1a2f5d6 100644 --- a/src/arm/assembler-arm.cc +++ b/src/arm/assembler-arm.cc @@ -3202,9 +3202,7 @@ void Assembler::GrowBuffer() { // Compute new buffer size. CodeDesc desc; // the new buffer - if (buffer_size_ == 0) { - desc.buffer_size = kMinimalBufferSize; - } else if (buffer_size_ < 1*MB) { + if (buffer_size_ < 1 * MB) { desc.buffer_size = 2*buffer_size_; } else { desc.buffer_size = buffer_size_ + 1*MB; diff --git a/src/arm64/assembler-arm64.cc b/src/arm64/assembler-arm64.cc index a51b22a..dc2d587 100644 --- a/src/arm64/assembler-arm64.cc +++ b/src/arm64/assembler-arm64.cc @@ -2771,9 +2771,7 @@ void Assembler::GrowBuffer() { // Compute new buffer size. CodeDesc desc; // the new buffer - if (buffer_size_ == 0) { - desc.buffer_size = kMinimalBufferSize; - } else if (buffer_size_ < 1 * MB) { + if (buffer_size_ < 1 * MB) { desc.buffer_size = 2 * buffer_size_; } else { desc.buffer_size = buffer_size_ + 1 * MB; diff --git a/src/assembler.cc b/src/assembler.cc index c35c81c..2374634 100644 --- a/src/assembler.cc +++ b/src/assembler.cc @@ -134,15 +134,10 @@ AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) if (FLAG_mask_constants_with_cookie && isolate != NULL) { jit_cookie_ = isolate->random_number_generator()->NextInt(); } - if (buffer == NULL) { - // Do our own buffer management. - buffer = NewArray(buffer_size); - own_buffer_ = true; - } else { - // Use externally provided buffer instead. - DCHECK(buffer_size > 0); - own_buffer_ = false; - } + own_buffer_ = buffer == NULL; + if (buffer_size == 0) buffer_size = kMinimalBufferSize; + DCHECK(buffer_size > 0); + if (own_buffer_) buffer = NewArray(buffer_size); buffer_ = static_cast(buffer); buffer_size_ = buffer_size; diff --git a/src/ia32/assembler-ia32.cc b/src/ia32/assembler-ia32.cc index 43f49d8..d8cd59c 100644 --- a/src/ia32/assembler-ia32.cc +++ b/src/ia32/assembler-ia32.cc @@ -2497,11 +2497,8 @@ void Assembler::GrowBuffer() { // Compute new buffer size. CodeDesc desc; // the new buffer - if (buffer_size_ == 0) { - desc.buffer_size = kMinimalBufferSize; - } else { - desc.buffer_size = 2*buffer_size_; - } + desc.buffer_size = 2 * buffer_size_; + // Some internal data structures overflow for very large buffers, // they must ensure that kMaximalBufferSize is not too large. if ((desc.buffer_size > kMaximalBufferSize) || diff --git a/src/lithium.cc b/src/lithium.cc index 01d7866..a8d4d22 100644 --- a/src/lithium.cc +++ b/src/lithium.cc @@ -457,8 +457,7 @@ LChunk* LChunk::NewChunk(HGraph* graph) { Handle LChunk::Codegen() { - MacroAssembler assembler(info()->isolate(), NULL, - Assembler::kMinimalBufferSize); + MacroAssembler assembler(info()->isolate(), NULL, 0); LOG_CODE_EVENT(info()->isolate(), CodeStartLinePosInfoRecordEvent( assembler.positions_recorder())); diff --git a/src/x64/assembler-x64.cc b/src/x64/assembler-x64.cc index f8f323f..d13c21f 100644 --- a/src/x64/assembler-x64.cc +++ b/src/x64/assembler-x64.cc @@ -331,11 +331,8 @@ void Assembler::GrowBuffer() { // Compute new buffer size. CodeDesc desc; // the new buffer - if (buffer_size_ == 0) { - desc.buffer_size = kMinimalBufferSize; - } else { - desc.buffer_size = 2*buffer_size_; - } + desc.buffer_size = 2 * buffer_size_; + // Some internal data structures overflow for very large buffers, // they must ensure that kMaximalBufferSize is not too large. if ((desc.buffer_size > kMaximalBufferSize) || -- 2.7.4