| OLD | NEW |
| 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/pages.h" | 5 #include "vm/pages.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/compiler_stats.h" | 8 #include "vm/compiler_stats.h" |
| 9 #include "vm/gc_marker.h" | 9 #include "vm/gc_marker.h" |
| 10 #include "vm/gc_sweeper.h" | 10 #include "vm/gc_sweeper.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 result->next_ = NULL; | 55 result->next_ = NULL; |
| 56 result->executable_ = is_executable; | 56 result->executable_ = is_executable; |
| 57 return result; | 57 return result; |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 HeapPage* HeapPage::Allocate(intptr_t size_in_words, PageType type) { | 61 HeapPage* HeapPage::Allocate(intptr_t size_in_words, PageType type) { |
| 62 VirtualMemory* memory = | 62 VirtualMemory* memory = |
| 63 VerifiedMemory::Reserve(size_in_words << kWordSizeLog2); | 63 VerifiedMemory::Reserve(size_in_words << kWordSizeLog2); |
| 64 if (memory == NULL) { | 64 if (memory == NULL) { |
| 65 FATAL1("Out of memory while allocating %" Pd " words.\n", | 65 return NULL; |
| 66 size_in_words); | |
| 67 } | 66 } |
| 68 return Initialize(memory, type); | 67 return Initialize(memory, type); |
| 69 } | 68 } |
| 70 | 69 |
| 71 | 70 |
| 72 void HeapPage::Deallocate() { | 71 void HeapPage::Deallocate() { |
| 73 // The memory for this object will become unavailable after the delete below. | 72 // The memory for this object will become unavailable after the delete below. |
| 74 delete memory_; | 73 delete memory_; |
| 75 } | 74 } |
| 76 | 75 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 175 |
| 177 intptr_t PageSpace::LargePageSizeInWordsFor(intptr_t size) { | 176 intptr_t PageSpace::LargePageSizeInWordsFor(intptr_t size) { |
| 178 intptr_t page_size = Utils::RoundUp(size + HeapPage::ObjectStartOffset(), | 177 intptr_t page_size = Utils::RoundUp(size + HeapPage::ObjectStartOffset(), |
| 179 VirtualMemory::PageSize()); | 178 VirtualMemory::PageSize()); |
| 180 return page_size >> kWordSizeLog2; | 179 return page_size >> kWordSizeLog2; |
| 181 } | 180 } |
| 182 | 181 |
| 183 | 182 |
| 184 HeapPage* PageSpace::AllocatePage(HeapPage::PageType type) { | 183 HeapPage* PageSpace::AllocatePage(HeapPage::PageType type) { |
| 185 HeapPage* page = HeapPage::Allocate(kPageSizeInWords, type); | 184 HeapPage* page = HeapPage::Allocate(kPageSizeInWords, type); |
| 185 if (page == NULL) { |
| 186 return NULL; |
| 187 } |
| 186 | 188 |
| 187 bool is_exec = (type == HeapPage::kExecutable); | 189 bool is_exec = (type == HeapPage::kExecutable); |
| 188 | 190 |
| 189 MutexLocker ml(pages_lock_); | 191 MutexLocker ml(pages_lock_); |
| 190 if (!is_exec) { | 192 if (!is_exec) { |
| 191 if (pages_ == NULL) { | 193 if (pages_ == NULL) { |
| 192 pages_ = page; | 194 pages_ = page; |
| 193 } else { | 195 } else { |
| 194 pages_tail_->set_next(page); | 196 pages_tail_->set_next(page); |
| 195 } | 197 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 210 } | 212 } |
| 211 IncreaseCapacityInWordsLocked(kPageSizeInWords); | 213 IncreaseCapacityInWordsLocked(kPageSizeInWords); |
| 212 page->set_object_end(page->memory_->end()); | 214 page->set_object_end(page->memory_->end()); |
| 213 return page; | 215 return page; |
| 214 } | 216 } |
| 215 | 217 |
| 216 | 218 |
| 217 HeapPage* PageSpace::AllocateLargePage(intptr_t size, HeapPage::PageType type) { | 219 HeapPage* PageSpace::AllocateLargePage(intptr_t size, HeapPage::PageType type) { |
| 218 intptr_t page_size_in_words = LargePageSizeInWordsFor(size); | 220 intptr_t page_size_in_words = LargePageSizeInWordsFor(size); |
| 219 HeapPage* page = HeapPage::Allocate(page_size_in_words, type); | 221 HeapPage* page = HeapPage::Allocate(page_size_in_words, type); |
| 222 if (page == NULL) { |
| 223 return NULL; |
| 224 } |
| 220 page->set_next(large_pages_); | 225 page->set_next(large_pages_); |
| 221 large_pages_ = page; | 226 large_pages_ = page; |
| 222 IncreaseCapacityInWords(page_size_in_words); | 227 IncreaseCapacityInWords(page_size_in_words); |
| 223 // Only one object in this page (at least until String::MakeExternal or | 228 // Only one object in this page (at least until String::MakeExternal or |
| 224 // Array::MakeArray is called). | 229 // Array::MakeArray is called). |
| 225 page->set_object_end(page->object_start() + size); | 230 page->set_object_end(page->object_start() + size); |
| 226 return page; | 231 return page; |
| 227 } | 232 } |
| 228 | 233 |
| 229 | 234 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 ASSERT(size < kAllocatablePageSize); | 310 ASSERT(size < kAllocatablePageSize); |
| 306 uword result = 0; | 311 uword result = 0; |
| 307 SpaceUsage after_allocation = GetCurrentUsage(); | 312 SpaceUsage after_allocation = GetCurrentUsage(); |
| 308 after_allocation.used_in_words += size >> kWordSizeLog2; | 313 after_allocation.used_in_words += size >> kWordSizeLog2; |
| 309 // Can we grow by one page? | 314 // Can we grow by one page? |
| 310 after_allocation.capacity_in_words += kPageSizeInWords; | 315 after_allocation.capacity_in_words += kPageSizeInWords; |
| 311 if ((growth_policy == kForceGrowth || | 316 if ((growth_policy == kForceGrowth || |
| 312 !page_space_controller_.NeedsGarbageCollection(after_allocation)) && | 317 !page_space_controller_.NeedsGarbageCollection(after_allocation)) && |
| 313 CanIncreaseCapacityInWords(kPageSizeInWords)) { | 318 CanIncreaseCapacityInWords(kPageSizeInWords)) { |
| 314 HeapPage* page = AllocatePage(type); | 319 HeapPage* page = AllocatePage(type); |
| 315 ASSERT(page != NULL); | 320 if (page == NULL) { |
| 321 return 0; |
| 322 } |
| 316 // Start of the newly allocated page is the allocated object. | 323 // Start of the newly allocated page is the allocated object. |
| 317 result = page->object_start(); | 324 result = page->object_start(); |
| 318 // Note: usage_.capacity_in_words is increased by AllocatePage. | 325 // Note: usage_.capacity_in_words is increased by AllocatePage. |
| 319 usage_.used_in_words += size >> kWordSizeLog2; | 326 usage_.used_in_words += size >> kWordSizeLog2; |
| 320 // Enqueue the remainder in the free list. | 327 // Enqueue the remainder in the free list. |
| 321 uword free_start = result + size; | 328 uword free_start = result + size; |
| 322 intptr_t free_size = page->object_end() - free_start; | 329 intptr_t free_size = page->object_end() - free_start; |
| 323 if (free_size > 0) { | 330 if (free_size > 0) { |
| 324 if (is_locked) { | 331 if (is_locked) { |
| 325 freelist_[type].FreeLocked(free_start, free_size); | 332 freelist_[type].FreeLocked(free_start, free_size); |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 return 0; | 1115 return 0; |
| 1109 } else { | 1116 } else { |
| 1110 ASSERT(total_time >= gc_time); | 1117 ASSERT(total_time >= gc_time); |
| 1111 int result = static_cast<int>((static_cast<double>(gc_time) / | 1118 int result = static_cast<int>((static_cast<double>(gc_time) / |
| 1112 static_cast<double>(total_time)) * 100); | 1119 static_cast<double>(total_time)) * 100); |
| 1113 return result; | 1120 return result; |
| 1114 } | 1121 } |
| 1115 } | 1122 } |
| 1116 | 1123 |
| 1117 } // namespace dart | 1124 } // namespace dart |
| OLD | NEW |