MIPS64: Fix memory allocation when code range is used for LO space only.
authordusan.milosavljevic <dusan.milosavljevic@imgtec.com>
Fri, 12 Jun 2015 11:42:06 +0000 (04:42 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 12 Jun 2015 11:42:15 +0000 (11:42 +0000)
Allocation must respect requested reserve size, not requested commit area size.

Additionally fix check failures in debug mode for mips64.
After CL: https://codereview.chromium.org/1147503002/
memory for large code objects is allocated from code range,
memory for regular code objects is allocated normally.

TEST=cctest/test-spaces/MemoryChunk
BUG=

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

Cr-Commit-Position: refs/heads/master@{#28995}

src/factory.cc
src/heap/heap.cc
src/heap/spaces.cc

index 755f1983706f4775b6ca0dd2ad715d4e8d36759f..b1619d447691ce6ec000b7c16d8b1783f4def6f3 100644 (file)
@@ -1443,9 +1443,9 @@ Handle<Code> Factory::NewCode(const CodeDesc& desc,
   int obj_size = Code::SizeFor(body_size);
 
   Handle<Code> code = NewCodeRaw(obj_size, immovable);
-  DCHECK(isolate()->code_range() == NULL ||
-         !isolate()->code_range()->valid() ||
-         isolate()->code_range()->contains(code->address()));
+  DCHECK(isolate()->code_range() == NULL || !isolate()->code_range()->valid() ||
+         isolate()->code_range()->contains(code->address()) ||
+         obj_size <= isolate()->heap()->code_space()->AreaSize());
 
   // The code object has not been fully initialized yet.  We rely on the
   // fact that no allocation will happen from this point on.
index 6425224fc0558b5d0eda69729ad717aeef973a5f..f4d3f734677818a921d5c8b4404cc46a4da57e6e 100644 (file)
@@ -3937,7 +3937,8 @@ AllocationResult Heap::AllocateCode(int object_size, bool immovable) {
   Code* code = Code::cast(result);
   DCHECK(IsAligned(bit_cast<intptr_t>(code->address()), kCodeAlignment));
   DCHECK(isolate_->code_range() == NULL || !isolate_->code_range()->valid() ||
-         isolate_->code_range()->contains(code->address()));
+         isolate_->code_range()->contains(code->address()) ||
+         object_size <= code_space()->AreaSize());
   code->set_gc_metadata(Smi::FromInt(0));
   code->set_ic_age(global_ic_age_);
   return code;
@@ -3962,7 +3963,8 @@ AllocationResult Heap::CopyCode(Code* code) {
   // Relocate the copy.
   DCHECK(IsAligned(bit_cast<intptr_t>(new_code->address()), kCodeAlignment));
   DCHECK(isolate_->code_range() == NULL || !isolate_->code_range()->valid() ||
-         isolate_->code_range()->contains(code->address()));
+         isolate_->code_range()->contains(code->address()) ||
+         obj_size <= code_space()->AreaSize());
   new_code->Relocate(new_addr - old_addr);
   return new_code;
 }
@@ -4008,7 +4010,9 @@ AllocationResult Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
   // Relocate the copy.
   DCHECK(IsAligned(bit_cast<intptr_t>(new_code->address()), kCodeAlignment));
   DCHECK(isolate_->code_range() == NULL || !isolate_->code_range()->valid() ||
-         isolate_->code_range()->contains(code->address()));
+         isolate_->code_range()->contains(code->address()) ||
+         new_obj_size <= code_space()->AreaSize());
+
   new_code->Relocate(new_addr - old_addr);
 
 #ifdef VERIFY_HEAP
index c5f1a556f8469a9abbf676af206e2f118b6fd7be..0806b2565da68f802c9b06041efd8fe9858312dc 100644 (file)
@@ -362,7 +362,8 @@ void MemoryAllocator::FreeMemory(base::VirtualMemory* reservation,
          !isolate_->code_range()->contains(
              static_cast<Address>(reservation->address())));
   DCHECK(executable == NOT_EXECUTABLE || isolate_->code_range() == NULL ||
-         !isolate_->code_range()->valid());
+         !isolate_->code_range()->valid() || size <= Page::kPageSize);
+
   reservation->Release();
 }
 
@@ -656,7 +657,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
     // Use code range only for large object space on mips64 to keep address
     // range within 256-MB memory region.
     if (isolate_->code_range() != NULL && isolate_->code_range()->valid() &&
-        commit_area_size > CodePageAreaSize()) {
+        reserve_area_size > CodePageAreaSize()) {
 #else
     if (isolate_->code_range() != NULL && isolate_->code_range()->valid()) {
 #endif