Commit 944e7f09 authored by ulan@chromium.org's avatar ulan@chromium.org

Do GC if CodeRange fails to allocate a block.

BUG=305878
LOG=Y
R=bmeurer@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21869 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5bbc92de
...@@ -158,12 +158,12 @@ int CodeRange::CompareFreeBlockAddress(const FreeBlock* left, ...@@ -158,12 +158,12 @@ int CodeRange::CompareFreeBlockAddress(const FreeBlock* left,
} }
void CodeRange::GetNextAllocationBlock(size_t requested) { bool CodeRange::GetNextAllocationBlock(size_t requested) {
for (current_allocation_block_index_++; for (current_allocation_block_index_++;
current_allocation_block_index_ < allocation_list_.length(); current_allocation_block_index_ < allocation_list_.length();
current_allocation_block_index_++) { current_allocation_block_index_++) {
if (requested <= allocation_list_[current_allocation_block_index_].size) { if (requested <= allocation_list_[current_allocation_block_index_].size) {
return; // Found a large enough allocation block. return true; // Found a large enough allocation block.
} }
} }
...@@ -190,12 +190,12 @@ void CodeRange::GetNextAllocationBlock(size_t requested) { ...@@ -190,12 +190,12 @@ void CodeRange::GetNextAllocationBlock(size_t requested) {
current_allocation_block_index_ < allocation_list_.length(); current_allocation_block_index_ < allocation_list_.length();
current_allocation_block_index_++) { current_allocation_block_index_++) {
if (requested <= allocation_list_[current_allocation_block_index_].size) { if (requested <= allocation_list_[current_allocation_block_index_].size) {
return; // Found a large enough allocation block. return true; // Found a large enough allocation block.
} }
} }
// Code range is full or too fragmented. // Code range is full or too fragmented.
V8::FatalProcessOutOfMemory("CodeRange::GetNextAllocationBlock"); return false;
} }
...@@ -205,9 +205,8 @@ Address CodeRange::AllocateRawMemory(const size_t requested_size, ...@@ -205,9 +205,8 @@ Address CodeRange::AllocateRawMemory(const size_t requested_size,
ASSERT(commit_size <= requested_size); ASSERT(commit_size <= requested_size);
ASSERT(current_allocation_block_index_ < allocation_list_.length()); ASSERT(current_allocation_block_index_ < allocation_list_.length());
if (requested_size > allocation_list_[current_allocation_block_index_].size) { if (requested_size > allocation_list_[current_allocation_block_index_].size) {
// Find an allocation block large enough. This function call may // Find an allocation block large enough.
// call V8::FatalProcessOutOfMemory if it cannot find a large enough block. if (!GetNextAllocationBlock(requested_size)) return NULL;
GetNextAllocationBlock(requested_size);
} }
// Commit the requested memory at the start of the current allocation block. // Commit the requested memory at the start of the current allocation block.
size_t aligned_requested = RoundUp(requested_size, MemoryChunk::kAlignment); size_t aligned_requested = RoundUp(requested_size, MemoryChunk::kAlignment);
...@@ -230,7 +229,8 @@ Address CodeRange::AllocateRawMemory(const size_t requested_size, ...@@ -230,7 +229,8 @@ Address CodeRange::AllocateRawMemory(const size_t requested_size,
allocation_list_[current_allocation_block_index_].start += *allocated; allocation_list_[current_allocation_block_index_].start += *allocated;
allocation_list_[current_allocation_block_index_].size -= *allocated; allocation_list_[current_allocation_block_index_].size -= *allocated;
if (*allocated == current.size) { if (*allocated == current.size) {
GetNextAllocationBlock(0); // This block is used up, get the next one. // This block is used up, get the next one.
if (!GetNextAllocationBlock(0)) return NULL;
} }
return current.start; return current.start;
} }
......
...@@ -985,8 +985,8 @@ class CodeRange { ...@@ -985,8 +985,8 @@ class CodeRange {
// Finds a block on the allocation list that contains at least the // Finds a block on the allocation list that contains at least the
// requested amount of memory. If none is found, sorts and merges // requested amount of memory. If none is found, sorts and merges
// the existing free memory blocks, and searches again. // the existing free memory blocks, and searches again.
// If none can be found, terminates V8 with FatalProcessOutOfMemory. // If none can be found, returns false.
void GetNextAllocationBlock(size_t requested); bool GetNextAllocationBlock(size_t requested);
// Compares the start addresses of two free blocks. // Compares the start addresses of two free blocks.
static int CompareFreeBlockAddress(const FreeBlock* left, static int CompareFreeBlockAddress(const FreeBlock* left,
const FreeBlock* right); const FreeBlock* right);
......
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