Commit 277795e2 authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap,cctest] Fix CodeRange tests that use AllocateRawMemory directly.

* 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}
parent 196d6aee
...@@ -310,16 +310,19 @@ void VirtualMemory::Reset() { ...@@ -310,16 +310,19 @@ void VirtualMemory::Reset() {
bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
CHECK(InVM(address, size));
return CommitRegion(address, size, is_executable); return CommitRegion(address, size, is_executable);
} }
bool VirtualMemory::Uncommit(void* address, size_t size) { bool VirtualMemory::Uncommit(void* address, size_t size) {
CHECK(InVM(address, size));
return UncommitRegion(address, size); return UncommitRegion(address, size);
} }
bool VirtualMemory::Guard(void* address) { bool VirtualMemory::Guard(void* address) {
CHECK(InVM(address, OS::CommitPageSize()));
OS::Guard(address, OS::CommitPageSize()); OS::Guard(address, OS::CommitPageSize());
return true; return true;
} }
......
...@@ -272,6 +272,7 @@ class OS { ...@@ -272,6 +272,7 @@ class OS {
DISALLOW_IMPLICIT_CONSTRUCTORS(OS); DISALLOW_IMPLICIT_CONSTRUCTORS(OS);
}; };
// Represents and controls an area of reserved memory. // Represents and controls an area of reserved memory.
// Control of the reserved memory can be assigned to another VirtualMemory // Control of the reserved memory can be assigned to another VirtualMemory
// object by assignment or copy-contructing. This removes the reserved memory // object by assignment or copy-contructing. This removes the reserved memory
...@@ -329,6 +330,7 @@ class VirtualMemory { ...@@ -329,6 +330,7 @@ class VirtualMemory {
// inside the allocated region. // inside the allocated region.
void* address = address_; void* address = address_;
size_t size = size_; size_t size = size_;
CHECK(InVM(address, size));
Reset(); Reset();
bool result = ReleaseRegion(address, size); bool result = ReleaseRegion(address, size);
USE(result); USE(result);
...@@ -360,6 +362,13 @@ class VirtualMemory { ...@@ -360,6 +362,13 @@ class VirtualMemory {
static bool HasLazyCommits(); static bool HasLazyCommits();
private: 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. void* address_; // Start address of the virtual memory.
size_t size_; // Size of the virtual memory. size_t size_; // Size of the virtual memory.
}; };
......
...@@ -202,7 +202,10 @@ bool CodeRange::GetNextAllocationBlock(size_t requested) { ...@@ -202,7 +202,10 @@ bool CodeRange::GetNextAllocationBlock(size_t requested) {
Address CodeRange::AllocateRawMemory(const size_t requested_size, Address CodeRange::AllocateRawMemory(const size_t requested_size,
const size_t commit_size, const size_t commit_size,
size_t* allocated) { 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; FreeBlock current;
if (!ReserveBlock(requested_size, &current)) { if (!ReserveBlock(requested_size, &current)) {
*allocated = 0; *allocated = 0;
...@@ -636,7 +639,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size, ...@@ -636,7 +639,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
CodePageGuardSize(); CodePageGuardSize();
// Check executable memory limit. // Check executable memory limit.
if (size_executable_ + chunk_size > capacity_executable_) { if ((size_executable_ + chunk_size) > capacity_executable_) {
LOG(isolate_, StringEvent("MemoryAllocator::AllocateRawMemory", LOG(isolate_, StringEvent("MemoryAllocator::AllocateRawMemory",
"V8 Executable Allocation capacity exceeded")); "V8 Executable Allocation capacity exceeded"));
return NULL; return NULL;
......
...@@ -211,9 +211,6 @@ ...@@ -211,9 +211,6 @@
############################################################################## ##############################################################################
['system == windows', { ['system == windows', {
# BUG(3005).
'test-alloc/CodeRange': [PASS, FAIL],
# BUG(3331). Fails on windows. # BUG(3331). Fails on windows.
'test-heap/NoWeakHashTableLeakWithIncrementalMarking': [SKIP], 'test-heap/NoWeakHashTableLeakWithIncrementalMarking': [SKIP],
......
...@@ -224,8 +224,11 @@ TEST(CodeRange) { ...@@ -224,8 +224,11 @@ TEST(CodeRange) {
(Page::kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) + (Page::kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) +
Pseudorandom() % 5000 + 1; Pseudorandom() % 5000 + 1;
size_t allocated = 0; size_t allocated = 0;
Address base = code_range.AllocateRawMemory(requested,
requested, // 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); &allocated);
CHECK(base != NULL); CHECK(base != NULL);
blocks.Add(::Block(base, static_cast<int>(allocated))); blocks.Add(::Block(base, static_cast<int>(allocated)));
......
...@@ -222,16 +222,23 @@ TEST(Regress3540) { ...@@ -222,16 +222,23 @@ TEST(Regress3540) {
v8::internal::MemoryAllocator::CodePageAreaSize())) { v8::internal::MemoryAllocator::CodePageAreaSize())) {
return; return;
} }
Address address; Address address;
size_t size; size_t size;
size_t request_size = code_range_size - 2 * pageSize;
address = code_range->AllocateRawMemory( 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); CHECK(address != NULL);
Address null_address; Address null_address;
size_t null_size; size_t null_size;
request_size = code_range_size - pageSize;
null_address = code_range->AllocateRawMemory( 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); CHECK(null_address == NULL);
code_range->FreeRawMemory(address, size); code_range->FreeRawMemory(address, size);
delete code_range; delete code_range;
memory_allocator->TearDown(); memory_allocator->TearDown();
......
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