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

Side by Side Diff: runtime/vm/heap.cc

Issue 2609643002: 1. Avoid potential dead lock due to lock-order-inversion (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/pages.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/heap.h" 5 #include "vm/heap.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/flags.h" 9 #include "vm/flags.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { 80 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
81 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 81 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
82 uword addr = old_space_.TryAllocate(size, type); 82 uword addr = old_space_.TryAllocate(size, type);
83 if (addr != 0) { 83 if (addr != 0) {
84 return addr; 84 return addr;
85 } 85 }
86 // If we are in the process of running a sweep, wait for the sweeper to free 86 // If we are in the process of running a sweep, wait for the sweeper to free
87 // memory. 87 // memory.
88 Thread* thread = Thread::Current(); 88 Thread* thread = Thread::Current();
89 if (thread->CanCollectGarbage()) { 89 if (thread->CanCollectGarbage()) {
90 { 90 {
Vyacheslav Egorov (Google) 2016/12/31 11:09:48 this block of code is repeated twice - maybe make
siva 2017/01/05 19:06:10 Done.
91 // Wait for any GC tasks that are in progress.
91 MonitorLocker ml(old_space_.tasks_lock()); 92 MonitorLocker ml(old_space_.tasks_lock());
92 addr = old_space_.TryAllocate(size, type); 93 while (old_space_.tasks() > 0) {
93 while ((addr == 0) && (old_space_.tasks() > 0)) {
94 ml.WaitWithSafepointCheck(thread); 94 ml.WaitWithSafepointCheck(thread);
95 addr = old_space_.TryAllocate(size, type);
96 } 95 }
97 } 96 }
97 addr = old_space_.TryAllocate(size, type);
98 if (addr != 0) { 98 if (addr != 0) {
99 return addr; 99 return addr;
100 } 100 }
101 // All GC tasks finished without allocating successfully. Run a full GC. 101 // All GC tasks finished without allocating successfully. Run a full GC.
102 CollectAllGarbage(); 102 CollectAllGarbage();
103 addr = old_space_.TryAllocate(size, type); 103 addr = old_space_.TryAllocate(size, type);
104 if (addr != 0) { 104 if (addr != 0) {
105 return addr; 105 return addr;
106 } 106 }
107 // Wait for all of the concurrent tasks to finish before giving up. 107 // Wait for all of the concurrent tasks to finish before giving up.
108 { 108 {
109 MonitorLocker ml(old_space_.tasks_lock()); 109 MonitorLocker ml(old_space_.tasks_lock());
110 addr = old_space_.TryAllocate(size, type); 110 while (old_space_.tasks() > 0) {
111 while ((addr == 0) && (old_space_.tasks() > 0)) {
112 ml.WaitWithSafepointCheck(thread); 111 ml.WaitWithSafepointCheck(thread);
113 addr = old_space_.TryAllocate(size, type);
114 } 112 }
115 } 113 }
114 addr = old_space_.TryAllocate(size, type);
116 if (addr != 0) { 115 if (addr != 0) {
117 return addr; 116 return addr;
118 } 117 }
119 // Force growth before attempting another synchronous GC. 118 // Force growth before attempting another synchronous GC.
120 addr = old_space_.TryAllocate(size, type, PageSpace::kForceGrowth); 119 addr = old_space_.TryAllocate(size, type, PageSpace::kForceGrowth);
121 if (addr != 0) { 120 if (addr != 0) {
122 return addr; 121 return addr;
123 } 122 }
124 // Before throwing an out-of-memory error try a synchronous GC. 123 // Before throwing an out-of-memory error try a synchronous GC.
125 CollectAllGarbage(); 124 CollectAllGarbage();
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 Dart::vm_isolate()->heap()->WriteProtect(false); 842 Dart::vm_isolate()->heap()->WriteProtect(false);
844 } 843 }
845 844
846 845
847 WritableVMIsolateScope::~WritableVMIsolateScope() { 846 WritableVMIsolateScope::~WritableVMIsolateScope() {
848 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); 847 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0);
849 Dart::vm_isolate()->heap()->WriteProtect(true); 848 Dart::vm_isolate()->heap()->WriteProtect(true);
850 } 849 }
851 850
852 } // namespace dart 851 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/pages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698