| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } else { | 108 } else { |
| 109 prot = VirtualMemory::kReadOnly; | 109 prot = VirtualMemory::kReadOnly; |
| 110 } | 110 } |
| 111 } else { | 111 } else { |
| 112 if (executable_) { | 112 if (executable_) { |
| 113 prot = VirtualMemory::kReadWriteExecute; | 113 prot = VirtualMemory::kReadWriteExecute; |
| 114 } else { | 114 } else { |
| 115 prot = VirtualMemory::kReadWrite; | 115 prot = VirtualMemory::kReadWrite; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 memory_->Protect(prot); | 118 bool status = memory_->Protect(prot); |
| 119 ASSERT(status); |
| 119 } | 120 } |
| 120 | 121 |
| 121 | 122 |
| 122 PageSpace::PageSpace(Heap* heap, intptr_t max_capacity_in_words) | 123 PageSpace::PageSpace(Heap* heap, intptr_t max_capacity_in_words) |
| 123 : freelist_(), | 124 : freelist_(), |
| 124 heap_(heap), | 125 heap_(heap), |
| 125 pages_(NULL), | 126 pages_(NULL), |
| 126 pages_tail_(NULL), | 127 pages_tail_(NULL), |
| 127 large_pages_(NULL), | 128 large_pages_(NULL), |
| 128 max_capacity_in_words_(max_capacity_in_words), | 129 max_capacity_in_words_(max_capacity_in_words), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 146 VirtualMemory::PageSize()); | 147 VirtualMemory::PageSize()); |
| 147 return page_size >> kWordSizeLog2; | 148 return page_size >> kWordSizeLog2; |
| 148 } | 149 } |
| 149 | 150 |
| 150 | 151 |
| 151 HeapPage* PageSpace::AllocatePage(HeapPage::PageType type) { | 152 HeapPage* PageSpace::AllocatePage(HeapPage::PageType type) { |
| 152 HeapPage* page = HeapPage::Allocate(kPageSizeInWords, type); | 153 HeapPage* page = HeapPage::Allocate(kPageSizeInWords, type); |
| 153 if (pages_ == NULL) { | 154 if (pages_ == NULL) { |
| 154 pages_ = page; | 155 pages_ = page; |
| 155 } else { | 156 } else { |
| 157 const bool is_protected = (pages_tail_->type() == HeapPage::kExecutable); |
| 158 if (is_protected) { |
| 159 pages_tail_->WriteProtect(false); |
| 160 } |
| 156 pages_tail_->set_next(page); | 161 pages_tail_->set_next(page); |
| 162 if (is_protected) { |
| 163 pages_tail_->WriteProtect(true); |
| 164 } |
| 157 } | 165 } |
| 158 pages_tail_ = page; | 166 pages_tail_ = page; |
| 159 capacity_in_words_ += kPageSizeInWords; | 167 capacity_in_words_ += kPageSizeInWords; |
| 160 page->set_object_end(page->memory_->end()); | 168 page->set_object_end(page->memory_->end()); |
| 161 return page; | 169 return page; |
| 162 } | 170 } |
| 163 | 171 |
| 164 | 172 |
| 165 HeapPage* PageSpace::AllocateLargePage(intptr_t size, HeapPage::PageType type) { | 173 HeapPage* PageSpace::AllocateLargePage(intptr_t size, HeapPage::PageType type) { |
| 166 intptr_t page_size_in_words = LargePageSizeInWordsFor(size); | 174 intptr_t page_size_in_words = LargePageSizeInWordsFor(size); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 220 } |
| 213 | 221 |
| 214 | 222 |
| 215 uword PageSpace::TryAllocate(intptr_t size, | 223 uword PageSpace::TryAllocate(intptr_t size, |
| 216 HeapPage::PageType type, | 224 HeapPage::PageType type, |
| 217 GrowthPolicy growth_policy) { | 225 GrowthPolicy growth_policy) { |
| 218 ASSERT(size >= kObjectAlignment); | 226 ASSERT(size >= kObjectAlignment); |
| 219 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 227 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| 220 uword result = 0; | 228 uword result = 0; |
| 221 if (size < kAllocatablePageSize) { | 229 if (size < kAllocatablePageSize) { |
| 222 result = freelist_[type].TryAllocate(size); | 230 const bool is_protected = (type == HeapPage::kExecutable); |
| 231 result = freelist_[type].TryAllocate(size, is_protected); |
| 223 if ((result == 0) && | 232 if ((result == 0) && |
| 224 (page_space_controller_.CanGrowPageSpace(size) || | 233 (page_space_controller_.CanGrowPageSpace(size) || |
| 225 growth_policy == kForceGrowth) && | 234 growth_policy == kForceGrowth) && |
| 226 CanIncreaseCapacityInWords(kPageSizeInWords)) { | 235 CanIncreaseCapacityInWords(kPageSizeInWords)) { |
| 227 HeapPage* page = AllocatePage(type); | 236 HeapPage* page = AllocatePage(type); |
| 228 ASSERT(page != NULL); | 237 ASSERT(page != NULL); |
| 229 // Start of the newly allocated page is the allocated object. | 238 // Start of the newly allocated page is the allocated object. |
| 230 result = page->object_start(); | 239 result = page->object_start(); |
| 231 // Enqueue the remainder in the free list. | 240 // Enqueue the remainder in the free list. |
| 232 uword free_start = result + size; | 241 uword free_start = result + size; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 434 } |
| 426 | 435 |
| 427 if (FLAG_verify_before_gc) { | 436 if (FLAG_verify_before_gc) { |
| 428 OS::PrintErr("Verifying before MarkSweep..."); | 437 OS::PrintErr("Verifying before MarkSweep..."); |
| 429 heap_->Verify(); | 438 heap_->Verify(); |
| 430 OS::PrintErr(" done.\n"); | 439 OS::PrintErr(" done.\n"); |
| 431 } | 440 } |
| 432 | 441 |
| 433 const int64_t start = OS::GetCurrentTimeMicros(); | 442 const int64_t start = OS::GetCurrentTimeMicros(); |
| 434 | 443 |
| 444 // Make code pages writable. |
| 445 HeapPage* current_page = pages_; |
| 446 while (current_page != NULL) { |
| 447 if (current_page->type() == HeapPage::kExecutable) { |
| 448 current_page->WriteProtect(false); |
| 449 } |
| 450 current_page = current_page->next(); |
| 451 } |
| 452 current_page = large_pages_; |
| 453 while (current_page != NULL) { |
| 454 if (current_page->type() == HeapPage::kExecutable) { |
| 455 current_page->WriteProtect(false); |
| 456 } |
| 457 current_page = current_page->next(); |
| 458 } |
| 459 |
| 435 // Mark all reachable old-gen objects. | 460 // Mark all reachable old-gen objects. |
| 436 bool collect_code = FLAG_collect_code && ShouldCollectCode(); | 461 bool collect_code = FLAG_collect_code && ShouldCollectCode(); |
| 437 GCMarker marker(heap_); | 462 GCMarker marker(heap_); |
| 438 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); | 463 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); |
| 439 | 464 |
| 440 int64_t mid1 = OS::GetCurrentTimeMicros(); | 465 int64_t mid1 = OS::GetCurrentTimeMicros(); |
| 441 | 466 |
| 442 // Reset the bump allocation page to unused. | 467 // Reset the bump allocation page to unused. |
| 443 // Reset the freelists and setup sweeping. | 468 // Reset the freelists and setup sweeping. |
| 444 freelist_[HeapPage::kData].Reset(); | 469 freelist_[HeapPage::kData].Reset(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 474 if (page_in_use == 0) { | 499 if (page_in_use == 0) { |
| 475 FreeLargePage(page, prev_page); | 500 FreeLargePage(page, prev_page); |
| 476 } else { | 501 } else { |
| 477 used_in_words += (page_in_use >> kWordSizeLog2); | 502 used_in_words += (page_in_use >> kWordSizeLog2); |
| 478 prev_page = page; | 503 prev_page = page; |
| 479 } | 504 } |
| 480 // Advance to the next page. | 505 // Advance to the next page. |
| 481 page = next_page; | 506 page = next_page; |
| 482 } | 507 } |
| 483 | 508 |
| 509 // Make code pages read-only. |
| 510 current_page = pages_; |
| 511 while (current_page != NULL) { |
| 512 if (current_page->type() == HeapPage::kExecutable) { |
| 513 current_page->WriteProtect(true); |
| 514 } |
| 515 current_page = current_page->next(); |
| 516 } |
| 517 current_page = large_pages_; |
| 518 while (current_page != NULL) { |
| 519 if (current_page->type() == HeapPage::kExecutable) { |
| 520 current_page->WriteProtect(true); |
| 521 } |
| 522 current_page = current_page->next(); |
| 523 } |
| 524 |
| 484 // Record data and print if requested. | 525 // Record data and print if requested. |
| 485 intptr_t used_before_in_words = used_in_words_; | 526 intptr_t used_before_in_words = used_in_words_; |
| 486 used_in_words_ = used_in_words; | 527 used_in_words_ = used_in_words; |
| 487 | 528 |
| 488 int64_t end = OS::GetCurrentTimeMicros(); | 529 int64_t end = OS::GetCurrentTimeMicros(); |
| 489 | 530 |
| 490 // Record signals for growth control. | 531 // Record signals for growth control. |
| 491 page_space_controller_.EvaluateGarbageCollection(used_before_in_words, | 532 page_space_controller_.EvaluateGarbageCollection(used_before_in_words, |
| 492 used_in_words, | 533 used_in_words, |
| 493 start, end); | 534 start, end); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 return 0; | 667 return 0; |
| 627 } else { | 668 } else { |
| 628 ASSERT(total_time >= gc_time); | 669 ASSERT(total_time >= gc_time); |
| 629 int result= static_cast<int>((static_cast<double>(gc_time) / | 670 int result= static_cast<int>((static_cast<double>(gc_time) / |
| 630 static_cast<double>(total_time)) * 100); | 671 static_cast<double>(total_time)) * 100); |
| 631 return result; | 672 return result; |
| 632 } | 673 } |
| 633 } | 674 } |
| 634 | 675 |
| 635 } // namespace dart | 676 } // namespace dart |
| OLD | NEW |