[heap,cctest] Fix CodeRange tests that use AllocateRawMemory directly.
authormlippautz <mlippautz@chromium.org>
Tue, 1 Sep 2015 18:39:13 +0000 (11:39 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 1 Sep 2015 18:39:32 +0000 (18:39 +0000)
* Enforce invariants on the way.
* Unmark flaky CodeRange test.

BUG=v8:4141
BUG=v8:3005
LOG=N

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

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

src/base/platform/platform-linux.cc
src/base/platform/platform.h
src/heap/spaces.cc
test/cctest/cctest.status
test/cctest/test-alloc.cc
test/cctest/test-spaces.cc

index 874c6dbc31b9b3bdd6cd285b5fcbfa7ff528cf8d..e2c321c07f09074aed4a49c0503b8e848c33ebbb 100644 (file)
@@ -310,16 +310,19 @@ void VirtualMemory::Reset() {
 
 
 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
+  CHECK(InVM(address, size));
   return CommitRegion(address, size, is_executable);
 }
 
 
 bool VirtualMemory::Uncommit(void* address, size_t size) {
+  CHECK(InVM(address, size));
   return UncommitRegion(address, size);
 }
 
 
 bool VirtualMemory::Guard(void* address) {
+  CHECK(InVM(address, OS::CommitPageSize()));
   OS::Guard(address, OS::CommitPageSize());
   return true;
 }
index 23ed123e66b51ee853d007da460f7b5d9e112ba4..aa30519506d691b8df57969aec2a8bddfe981831 100644 (file)
@@ -272,6 +272,7 @@ class OS {
   DISALLOW_IMPLICIT_CONSTRUCTORS(OS);
 };
 
+
 // Represents and controls an area of reserved memory.
 // Control of the reserved memory can be assigned to another VirtualMemory
 // object by assignment or copy-contructing. This removes the reserved memory
@@ -329,6 +330,7 @@ class VirtualMemory {
     // inside the allocated region.
     void* address = address_;
     size_t size = size_;
+    CHECK(InVM(address, size));
     Reset();
     bool result = ReleaseRegion(address, size);
     USE(result);
@@ -360,6 +362,13 @@ class VirtualMemory {
   static bool HasLazyCommits();
 
  private:
+  bool InVM(void* address, size_t size) {
+    return (reinterpret_cast<intptr_t>(address_) <=
+            reinterpret_cast<intptr_t>(address)) &&
+           (reinterpret_cast<intptr_t>(address_) + size_ >=
+            reinterpret_cast<intptr_t>(address) + size);
+  }
+
   void* address_;  // Start address of the virtual memory.
   size_t size_;  // Size of the virtual memory.
 };
index 8658fe0030c21db65497b1c22f98461816f9db41..a85e9fca16b4e6e2b4ffcfb9904a0c49bb3ce599 100644 (file)
@@ -202,7 +202,10 @@ bool CodeRange::GetNextAllocationBlock(size_t requested) {
 Address CodeRange::AllocateRawMemory(const size_t requested_size,
                                      const size_t commit_size,
                                      size_t* allocated) {
-  DCHECK(commit_size <= requested_size);
+  // request_size includes guards while committed_size does not. Make sure
+  // callers know about the invariant.
+  CHECK_LE(commit_size,
+           requested_size - 2 * MemoryAllocator::CodePageGuardSize());
   FreeBlock current;
   if (!ReserveBlock(requested_size, &current)) {
     *allocated = 0;
@@ -636,7 +639,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
                  CodePageGuardSize();
 
     // Check executable memory limit.
-    if (size_executable_ + chunk_size > capacity_executable_) {
+    if ((size_executable_ + chunk_size) > capacity_executable_) {
       LOG(isolate_, StringEvent("MemoryAllocator::AllocateRawMemory",
                                 "V8 Executable Allocation capacity exceeded"));
       return NULL;
index d5e75ef323052b1bbf489c091f5e11ddedcb0326..718a65aed92af1610003705830e92bfad4f70a5b 100644 (file)
 ##############################################################################
 ['system == windows', {
 
-  # BUG(3005).
-  'test-alloc/CodeRange': [PASS, FAIL],
-
   # BUG(3331). Fails on windows.
   'test-heap/NoWeakHashTableLeakWithIncrementalMarking': [SKIP],
 
index d8000fde2046fb818fa591783a17e94ae22213ad..1ac0adde0f78cc65e75930387580f59a0227cbd7 100644 (file)
@@ -224,9 +224,12 @@ TEST(CodeRange) {
           (Page::kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) +
           Pseudorandom() % 5000 + 1;
       size_t allocated = 0;
-      Address base = code_range.AllocateRawMemory(requested,
-                                                  requested,
-                                                  &allocated);
+
+      // The request size has to be at least 2 code guard pages larger than the
+      // actual commit size.
+      Address base = code_range.AllocateRawMemory(
+          requested, requested - (2 * MemoryAllocator::CodePageGuardSize()),
+          &allocated);
       CHECK(base != NULL);
       blocks.Add(::Block(base, static_cast<int>(allocated)));
       current_allocated += static_cast<int>(allocated);
index 292b27fd00cad41a8057f10bf98c8e31d7b0ed03..a744bb79a7d4658acd5209158b021a4095d8c48e 100644 (file)
@@ -222,16 +222,23 @@ TEST(Regress3540) {
           v8::internal::MemoryAllocator::CodePageAreaSize())) {
     return;
   }
+
   Address address;
   size_t size;
+  size_t request_size = code_range_size - 2 * pageSize;
   address = code_range->AllocateRawMemory(
-      code_range_size - 2 * pageSize, code_range_size - 2 * pageSize, &size);
+      request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()),
+      &size);
   CHECK(address != NULL);
+
   Address null_address;
   size_t null_size;
+  request_size = code_range_size - pageSize;
   null_address = code_range->AllocateRawMemory(
-      code_range_size - pageSize, code_range_size - pageSize, &null_size);
+      request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()),
+      &null_size);
   CHECK(null_address == NULL);
+
   code_range->FreeRawMemory(address, size);
   delete code_range;
   memory_allocator->TearDown();