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

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

Issue 1541073002: Implement safepointing of threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 4 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
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return addr; 88 return addr;
89 } 89 }
90 90
91 91
92 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { 92 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
93 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 93 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
94 uword addr = old_space_.TryAllocate(size, type); 94 uword addr = old_space_.TryAllocate(size, type);
95 if (addr != 0) { 95 if (addr != 0) {
96 return addr; 96 return addr;
97 } 97 }
98 // If we are in the process of running a sweep wait for the sweeper to free 98 // If we are in the process of running a sweep wait for the sweeper to free
zra 2016/01/08 23:32:07 sweep, wait
siva 2016/01/12 21:26:22 Done.
99 // memory. 99 // memory.
100 Thread* thread = Thread::Current();
100 { 101 {
101 MonitorLocker ml(old_space_.tasks_lock()); 102 MonitorLocker ml(old_space_.tasks_lock());
102 addr = old_space_.TryAllocate(size, type); 103 addr = old_space_.TryAllocate(size, type);
103 while ((addr == 0) && (old_space_.tasks() > 0)) { 104 while ((addr == 0) && (old_space_.tasks() > 0)) {
104 ml.Wait(); 105 ml.WaitWithSafepointCheck(thread);
105 addr = old_space_.TryAllocate(size, type); 106 addr = old_space_.TryAllocate(size, type);
106 } 107 }
107 } 108 }
108 if (addr != 0) { 109 if (addr != 0) {
109 return addr; 110 return addr;
110 } 111 }
111 // All GC tasks finished without allocating successfully. Run a full GC. 112 // All GC tasks finished without allocating successfully. Run a full GC.
112 CollectAllGarbage(); 113 CollectAllGarbage();
113 addr = old_space_.TryAllocate(size, type); 114 addr = old_space_.TryAllocate(size, type);
114 if (addr != 0) { 115 if (addr != 0) {
115 return addr; 116 return addr;
116 } 117 }
117 // Wait for all of the concurrent tasks to finish before giving up. 118 // Wait for all of the concurrent tasks to finish before giving up.
118 { 119 {
119 MonitorLocker ml(old_space_.tasks_lock()); 120 MonitorLocker ml(old_space_.tasks_lock());
120 addr = old_space_.TryAllocate(size, type); 121 addr = old_space_.TryAllocate(size, type);
121 while ((addr == 0) && (old_space_.tasks() > 0)) { 122 while ((addr == 0) && (old_space_.tasks() > 0)) {
122 ml.Wait(); 123 ml.WaitWithSafepointCheck(thread);
123 addr = old_space_.TryAllocate(size, type); 124 addr = old_space_.TryAllocate(size, type);
124 } 125 }
125 } 126 }
126 if (addr != 0) { 127 if (addr != 0) {
127 return addr; 128 return addr;
128 } 129 }
129 // Force growth before attempting a synchronous GC. 130 // Force growth before attempting a synchronous GC.
130 addr = old_space_.TryAllocate(size, type, PageSpace::kForceGrowth); 131 addr = old_space_.TryAllocate(size, type, PageSpace::kForceGrowth);
131 if (addr != 0) { 132 if (addr != 0) {
132 return addr; 133 return addr;
133 } 134 }
134 // Before throwing an out-of-memory error try a synchronous GC. 135 // Before throwing an out-of-memory error try a synchronous GC.
135 CollectAllGarbage(); 136 CollectAllGarbage();
136 { 137 {
137 MonitorLocker ml(old_space_.tasks_lock()); 138 MonitorLocker ml(old_space_.tasks_lock());
138 while (old_space_.tasks() > 0) { 139 while (old_space_.tasks() > 0) {
139 ml.Wait(); 140 ml.WaitWithSafepointCheck(thread);
140 } 141 }
141 } 142 }
142 addr = old_space_.TryAllocate(size, type, PageSpace::kForceGrowth); 143 addr = old_space_.TryAllocate(size, type, PageSpace::kForceGrowth);
143 if (addr != 0) { 144 if (addr != 0) {
144 return addr; 145 return addr;
145 } 146 }
146 // Give up allocating this object. 147 // Give up allocating this object.
147 OS::PrintErr( 148 OS::PrintErr(
148 "Exhausted heap space, trying to allocate %" Pd " bytes.\n", size); 149 "Exhausted heap space, trying to allocate %" Pd " bytes.\n", size);
149 return 0; 150 return 0;
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 Dart::vm_isolate()->heap()->WriteProtect(false, include_code_pages_); 808 Dart::vm_isolate()->heap()->WriteProtect(false, include_code_pages_);
808 } 809 }
809 810
810 811
811 WritableVMIsolateScope::~WritableVMIsolateScope() { 812 WritableVMIsolateScope::~WritableVMIsolateScope() {
812 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); 813 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0);
813 Dart::vm_isolate()->heap()->WriteProtect(true, include_code_pages_); 814 Dart::vm_isolate()->heap()->WriteProtect(true, include_code_pages_);
814 } 815 }
815 816
816 } // namespace dart 817 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698