Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: runtime/vm/heap.cc

Issue 2609643002: 1. Avoid potential dead lock due to lock-order-inversion (Closed)
Patch Set: Address code review changes. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/heap.cc
diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc
index da9e6790dab711e48223c9b4c9528e6d4d02be9b..fce8cfee29dffcbfe1c5d2f6604112e8b6e2ac12 100644
--- a/runtime/vm/heap.cc
+++ b/runtime/vm/heap.cc
@@ -87,14 +87,9 @@ uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
// memory.
Thread* thread = Thread::Current();
if (thread->CanCollectGarbage()) {
- {
- MonitorLocker ml(old_space_.tasks_lock());
- addr = old_space_.TryAllocate(size, type);
- while ((addr == 0) && (old_space_.tasks() > 0)) {
- ml.WaitWithSafepointCheck(thread);
- addr = old_space_.TryAllocate(size, type);
- }
- }
+ // Wait for any GC tasks that are in progress.
+ WaitForSweeperTasks(thread);
+ addr = old_space_.TryAllocate(size, type);
if (addr != 0) {
return addr;
}
@@ -105,14 +100,8 @@ uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
return addr;
}
// Wait for all of the concurrent tasks to finish before giving up.
- {
- MonitorLocker ml(old_space_.tasks_lock());
- addr = old_space_.TryAllocate(size, type);
- while ((addr == 0) && (old_space_.tasks() > 0)) {
- ml.WaitWithSafepointCheck(thread);
- addr = old_space_.TryAllocate(size, type);
- }
- }
+ WaitForSweeperTasks(thread);
+ addr = old_space_.TryAllocate(size, type);
if (addr != 0) {
return addr;
}
@@ -123,12 +112,7 @@ uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
}
// Before throwing an out-of-memory error try a synchronous GC.
CollectAllGarbage();
- {
- MonitorLocker ml(old_space_.tasks_lock());
- while (old_space_.tasks() > 0) {
- ml.WaitWithSafepointCheck(thread);
- }
- }
+ WaitForSweeperTasks(thread);
}
addr = old_space_.TryAllocate(size, type, PageSpace::kForceGrowth);
if (addr != 0) {
@@ -445,17 +429,12 @@ void Heap::CollectAllGarbage() {
}
-#if defined(DEBUG)
-void Heap::WaitForSweeperTasks() {
- Thread* thread = Thread::Current();
- {
- MonitorLocker ml(old_space_.tasks_lock());
- while (old_space_.tasks() > 0) {
- ml.WaitWithSafepointCheck(thread);
- }
+void Heap::WaitForSweeperTasks(Thread* thread) {
+ MonitorLocker ml(old_space_.tasks_lock());
+ while (old_space_.tasks() > 0) {
+ ml.WaitWithSafepointCheck(thread);
}
}
-#endif
void Heap::UpdateGlobalMaxUsed() {
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698