const size_t commit_size,
size_t* allocated) {
DCHECK(commit_size <= requested_size);
- DCHECK(current_allocation_block_index_ < allocation_list_.length());
- if (requested_size > allocation_list_[current_allocation_block_index_].size) {
+ DCHECK(allocation_list_.length() == 0 ||
+ current_allocation_block_index_ < allocation_list_.length());
+ if (allocation_list_.length() == 0 ||
+ requested_size > allocation_list_[current_allocation_block_index_].size) {
// Find an allocation block large enough.
if (!GetNextAllocationBlock(requested_size)) return NULL;
}
allocation_list_[current_allocation_block_index_].size -= *allocated;
if (*allocated == current.size) {
// This block is used up, get the next one.
- if (!GetNextAllocationBlock(0)) return NULL;
+ GetNextAllocationBlock(0);
}
return current.start;
}
}
+TEST(Regress3540) {
+ Isolate* isolate = CcTest::i_isolate();
+ isolate->InitializeLoggingAndCounters();
+ Heap* heap = isolate->heap();
+ CHECK(heap->ConfigureHeapDefault());
+ MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
+ CHECK(
+ memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize()));
+ TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator);
+ CodeRange* code_range = new CodeRange(isolate);
+ const size_t code_range_size = 4 * MB;
+ if (!code_range->SetUp(code_range_size)) return;
+ size_t allocated_size;
+ Address result;
+ for (int i = 0; i < 5; i++) {
+ result = code_range->AllocateRawMemory(
+ code_range_size - MB, code_range_size - MB, &allocated_size);
+ CHECK((result != NULL) == (i == 0));
+ }
+}
+
+
static unsigned int Pseudorandom() {
static uint32_t lo = 2345;
lo = 18273 * (lo & 0xFFFFF) + (lo >> 16);