Commit 2c17f158 authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap] Extend mutex guards for CodeRange.

Previously the mutex only guarded free_list_. The extension covers also
allocation_list_.

BUG=chromium:524425
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#30748}
parent 54bab695
...@@ -163,28 +163,24 @@ bool CodeRange::GetNextAllocationBlock(size_t requested) { ...@@ -163,28 +163,24 @@ bool CodeRange::GetNextAllocationBlock(size_t requested) {
} }
} }
{ // Sort and merge the free blocks on the free list and the allocation list.
base::LockGuard<base::Mutex> free_list_lock_guard(&free_list_mutex_); free_list_.AddAll(allocation_list_);
allocation_list_.Clear();
// Sort and merge the free blocks on the free list and the allocation list. free_list_.Sort(&CompareFreeBlockAddress);
free_list_.AddAll(allocation_list_); for (int i = 0; i < free_list_.length();) {
allocation_list_.Clear(); FreeBlock merged = free_list_[i];
free_list_.Sort(&CompareFreeBlockAddress); i++;
for (int i = 0; i < free_list_.length();) { // Add adjacent free blocks to the current merged block.
FreeBlock merged = free_list_[i]; while (i < free_list_.length() &&
free_list_[i].start == merged.start + merged.size) {
merged.size += free_list_[i].size;
i++; i++;
// Add adjacent free blocks to the current merged block.
while (i < free_list_.length() &&
free_list_[i].start == merged.start + merged.size) {
merged.size += free_list_[i].size;
i++;
}
if (merged.size > 0) {
allocation_list_.Add(merged);
}
} }
free_list_.Clear(); if (merged.size > 0) {
allocation_list_.Add(merged);
}
} }
free_list_.Clear();
for (current_allocation_block_index_ = 0; for (current_allocation_block_index_ = 0;
current_allocation_block_index_ < allocation_list_.length(); current_allocation_block_index_ < allocation_list_.length();
...@@ -236,7 +232,7 @@ bool CodeRange::UncommitRawMemory(Address start, size_t length) { ...@@ -236,7 +232,7 @@ bool CodeRange::UncommitRawMemory(Address start, size_t length) {
void CodeRange::FreeRawMemory(Address address, size_t length) { void CodeRange::FreeRawMemory(Address address, size_t length) {
DCHECK(IsAddressAligned(address, MemoryChunk::kAlignment)); DCHECK(IsAddressAligned(address, MemoryChunk::kAlignment));
base::LockGuard<base::Mutex> free_list_lock_guard(&free_list_mutex_); base::LockGuard<base::Mutex> guard(&code_range_mutex_);
free_list_.Add(FreeBlock(address, length)); free_list_.Add(FreeBlock(address, length));
code_range_->Uncommit(address, length); code_range_->Uncommit(address, length);
} }
...@@ -245,13 +241,14 @@ void CodeRange::FreeRawMemory(Address address, size_t length) { ...@@ -245,13 +241,14 @@ void CodeRange::FreeRawMemory(Address address, size_t length) {
void CodeRange::TearDown() { void CodeRange::TearDown() {
delete code_range_; // Frees all memory in the virtual memory range. delete code_range_; // Frees all memory in the virtual memory range.
code_range_ = NULL; code_range_ = NULL;
base::LockGuard<base::Mutex> free_list_lock_guard(&free_list_mutex_); base::LockGuard<base::Mutex> guard(&code_range_mutex_);
free_list_.Free(); free_list_.Free();
allocation_list_.Free(); allocation_list_.Free();
} }
bool CodeRange::ReserveBlock(const size_t requested_size, FreeBlock* block) { bool CodeRange::ReserveBlock(const size_t requested_size, FreeBlock* block) {
base::LockGuard<base::Mutex> guard(&code_range_mutex_);
DCHECK(allocation_list_.length() == 0 || DCHECK(allocation_list_.length() == 0 ||
current_allocation_block_index_ < allocation_list_.length()); current_allocation_block_index_ < allocation_list_.length());
if (allocation_list_.length() == 0 || if (allocation_list_.length() == 0 ||
...@@ -274,7 +271,7 @@ bool CodeRange::ReserveBlock(const size_t requested_size, FreeBlock* block) { ...@@ -274,7 +271,7 @@ bool CodeRange::ReserveBlock(const size_t requested_size, FreeBlock* block) {
void CodeRange::ReleaseBlock(const FreeBlock* block) { void CodeRange::ReleaseBlock(const FreeBlock* block) {
base::LockGuard<base::Mutex> free_list_lock_guard(&free_list_mutex_); base::LockGuard<base::Mutex> guard(&code_range_mutex_);
free_list_.Add(*block); free_list_.Add(*block);
} }
......
...@@ -1013,9 +1013,9 @@ class CodeRange { ...@@ -1013,9 +1013,9 @@ class CodeRange {
size_t size; size_t size;
}; };
// All access to free_list_ require to take the free_list_mutex_. GC threads // The global mutex guards free_list_ and allocation_list_ as GC threads may
// may access the free_list_ concurrently to the main thread. // access both lists concurrently to the main thread.
base::Mutex free_list_mutex_; base::Mutex code_range_mutex_;
// Freed blocks of memory are added to the free list. When the allocation // Freed blocks of memory are added to the free list. When the allocation
// list is exhausted, the free list is sorted and merged to make the new // list is exhausted, the free list is sorted and merged to make the new
......
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