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

Side by Side Diff: vm/pages.cc

Issue 8962006: - Honor max_capacity even for large page allocation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « vm/pages.h ('k') | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/pages.h" 5 #include "vm/pages.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/gc_marker.h" 8 #include "vm/gc_marker.h"
9 #include "vm/gc_sweeper.h" 9 #include "vm/gc_sweeper.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 is_executable_(is_executable), 62 is_executable_(is_executable),
63 sweeping_(false) { } 63 sweeping_(false) { }
64 64
65 65
66 PageSpace::~PageSpace() { 66 PageSpace::~PageSpace() {
67 FreePages(pages_); 67 FreePages(pages_);
68 FreePages(large_pages_); 68 FreePages(large_pages_);
69 } 69 }
70 70
71 71
72 intptr_t PageSpace::LargePageSizeFor(intptr_t size) {
73 intptr_t page_size = Utils::RoundUp(size + sizeof(HeapPage),
74 VirtualMemory::PageSize());
75 return page_size;
76 }
77
78
72 void PageSpace::AllocatePage() { 79 void PageSpace::AllocatePage() {
73 HeapPage* page = HeapPage::Allocate(kPageSize, is_executable_); 80 HeapPage* page = HeapPage::Allocate(kPageSize, is_executable_);
74 if (pages_ == NULL) { 81 if (pages_ == NULL) {
75 pages_ = page; 82 pages_ = page;
76 } else { 83 } else {
77 pages_tail_->set_next(page); 84 pages_tail_->set_next(page);
78 } 85 }
79 pages_tail_ = page; 86 pages_tail_ = page;
80 capacity_ += kPageSize; 87 capacity_ += kPageSize;
81 } 88 }
82 89
83 90
84 HeapPage* PageSpace::AllocateLargePage(intptr_t size) { 91 HeapPage* PageSpace::AllocateLargePage(intptr_t size) {
85 intptr_t page_size = Utils::RoundUp(size + sizeof(HeapPage), 92 intptr_t page_size = LargePageSizeFor(size);
86 VirtualMemory::PageSize());
87 HeapPage* page = HeapPage::Allocate(page_size, is_executable_); 93 HeapPage* page = HeapPage::Allocate(page_size, is_executable_);
88 page->set_next(large_pages_); 94 page->set_next(large_pages_);
89 large_pages_ = page; 95 large_pages_ = page;
90 capacity_ += page_size; 96 capacity_ += page_size;
91 return page; 97 return page;
92 } 98 }
93 99
94 100
95 void PageSpace::FreeLargePage(HeapPage* page, HeapPage* previous_page) { 101 void PageSpace::FreeLargePage(HeapPage* page, HeapPage* previous_page) {
96 capacity_ -= page->memory_->size(); 102 capacity_ -= page->memory_->size();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 135 }
130 136
131 137
132 uword PageSpace::TryAllocate(intptr_t size) { 138 uword PageSpace::TryAllocate(intptr_t size) {
133 ASSERT(size >= kObjectAlignment); 139 ASSERT(size >= kObjectAlignment);
134 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 140 ASSERT(Utils::IsAligned(size, kObjectAlignment));
135 uword result = 0; 141 uword result = 0;
136 if (size < kAllocatablePageSize) { 142 if (size < kAllocatablePageSize) {
137 result = TryBumpAllocate(size); 143 result = TryBumpAllocate(size);
138 if (result == 0) { 144 if (result == 0) {
139 if (capacity_ < max_capacity_) { 145 if (CanIncreaseCapacity(kPageSize)) {
140 AllocatePage(); 146 AllocatePage();
141 result = TryBumpAllocate(size); 147 result = TryBumpAllocate(size);
142 ASSERT(result != 0); 148 ASSERT(result != 0);
143 } 149 }
144 } 150 }
145 } else { 151 } else {
146 // Large page allocation. 152 // Large page allocation.
147 HeapPage* page = AllocateLargePage(size); 153 intptr_t page_size = LargePageSizeFor(size);
148 if (page != NULL) { 154 if (page_size < size) {
149 result = page->top(); 155 // On overflow we fail to allocate.
150 page->set_top(result + size); 156 return 0;
157 }
158 if (CanIncreaseCapacity(page_size)) {
159 HeapPage* page = AllocateLargePage(size);
160 if (page != NULL) {
161 result = page->top();
162 page->set_top(result + size);
163 }
151 } 164 }
152 } 165 }
153 if (result != 0) { 166 if (result != 0) {
154 in_use_ += size; 167 in_use_ += size;
155 } 168 }
156 return result; 169 return result;
157 } 170 }
158 171
159 172
160 bool PageSpace::Contains(uword addr) const { 173 bool PageSpace::Contains(uword addr) const {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 OS::PrintErr(" done.\n"); 272 OS::PrintErr(" done.\n");
260 } 273 }
261 274
262 count_++; 275 count_++;
263 // Done, reset the marker. 276 // Done, reset the marker.
264 ASSERT(sweeping_); 277 ASSERT(sweeping_);
265 sweeping_ = false; 278 sweeping_ = false;
266 } 279 }
267 280
268 } // namespace dart 281 } // namespace dart
OLDNEW
« no previous file with comments | « vm/pages.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698