| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 PageSpace::PageSpace(Heap* heap, intptr_t max_capacity_in_words) | 120 PageSpace::PageSpace(Heap* heap, intptr_t max_capacity_in_words) |
| 121 : freelist_(), | 121 : freelist_(), |
| 122 heap_(heap), | 122 heap_(heap), |
| 123 pages_(NULL), | 123 pages_(NULL), |
| 124 pages_tail_(NULL), | 124 pages_tail_(NULL), |
| 125 large_pages_(NULL), | 125 large_pages_(NULL), |
| 126 max_capacity_in_words_(max_capacity_in_words), | 126 max_capacity_in_words_(max_capacity_in_words), |
| 127 capacity_in_words_(0), | 127 capacity_in_words_(0), |
| 128 used_in_words_(0), | 128 used_in_words_(0), |
| 129 external_in_words_(0), |
| 129 sweeping_(false), | 130 sweeping_(false), |
| 130 page_space_controller_(FLAG_heap_growth_space_ratio, | 131 page_space_controller_(FLAG_heap_growth_space_ratio, |
| 131 FLAG_heap_growth_rate, | 132 FLAG_heap_growth_rate, |
| 132 FLAG_heap_growth_time_ratio), | 133 FLAG_heap_growth_time_ratio), |
| 133 gc_time_micros_(0), | 134 gc_time_micros_(0), |
| 134 collections_(0) { | 135 collections_(0) { |
| 135 } | 136 } |
| 136 | 137 |
| 137 | 138 |
| 138 PageSpace::~PageSpace() { | 139 PageSpace::~PageSpace() { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 used_in_words_ += (size >> kWordSizeLog2); | 266 used_in_words_ += (size >> kWordSizeLog2); |
| 266 if (FLAG_compiler_stats && (type == HeapPage::kExecutable)) { | 267 if (FLAG_compiler_stats && (type == HeapPage::kExecutable)) { |
| 267 CompilerStats::code_allocated += size; | 268 CompilerStats::code_allocated += size; |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 ASSERT((result & kObjectAlignmentMask) == kOldObjectAlignmentOffset); | 271 ASSERT((result & kObjectAlignmentMask) == kOldObjectAlignmentOffset); |
| 271 return result; | 272 return result; |
| 272 } | 273 } |
| 273 | 274 |
| 274 | 275 |
| 276 void PageSpace::AllocateExternal(intptr_t size) { |
| 277 intptr_t size_in_words = size >> kWordSizeLog2; |
| 278 external_in_words_ += size_in_words; |
| 279 } |
| 280 |
| 281 |
| 282 void PageSpace::FreeExternal(intptr_t size) { |
| 283 intptr_t size_in_words = size >> kWordSizeLog2; |
| 284 external_in_words_ -= size_in_words; |
| 285 } |
| 286 |
| 287 |
| 275 bool PageSpace::Contains(uword addr) const { | 288 bool PageSpace::Contains(uword addr) const { |
| 276 HeapPage* page = pages_; | 289 HeapPage* page = pages_; |
| 277 while (page != NULL) { | 290 while (page != NULL) { |
| 278 if (page->Contains(addr)) { | 291 if (page->Contains(addr)) { |
| 279 return true; | 292 return true; |
| 280 } | 293 } |
| 281 page = page->next(); | 294 page = page->next(); |
| 282 } | 295 } |
| 283 | 296 |
| 284 page = large_pages_; | 297 page = large_pages_; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 479 } |
| 467 current_page = large_pages_; | 480 current_page = large_pages_; |
| 468 while (current_page != NULL) { | 481 while (current_page != NULL) { |
| 469 if (current_page->type() == HeapPage::kExecutable) { | 482 if (current_page->type() == HeapPage::kExecutable) { |
| 470 current_page->WriteProtect(false); | 483 current_page->WriteProtect(false); |
| 471 } | 484 } |
| 472 current_page = current_page->next(); | 485 current_page = current_page->next(); |
| 473 } | 486 } |
| 474 } | 487 } |
| 475 | 488 |
| 489 // Save old value before GCMarker visits the weak persistent handles. |
| 490 intptr_t external_before_in_words = external_in_words_; |
| 491 |
| 476 // Mark all reachable old-gen objects. | 492 // Mark all reachable old-gen objects. |
| 477 bool collect_code = FLAG_collect_code && ShouldCollectCode(); | 493 bool collect_code = FLAG_collect_code && ShouldCollectCode(); |
| 478 GCMarker marker(heap_); | 494 GCMarker marker(heap_); |
| 479 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); | 495 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); |
| 480 | 496 |
| 481 int64_t mid1 = OS::GetCurrentTimeMicros(); | 497 int64_t mid1 = OS::GetCurrentTimeMicros(); |
| 482 | 498 |
| 483 // Reset the bump allocation page to unused. | 499 // Reset the bump allocation page to unused. |
| 484 // Reset the freelists and setup sweeping. | 500 // Reset the freelists and setup sweeping. |
| 485 freelist_[HeapPage::kData].Reset(); | 501 freelist_[HeapPage::kData].Reset(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 current_page = current_page->next(); | 555 current_page = current_page->next(); |
| 540 } | 556 } |
| 541 } | 557 } |
| 542 | 558 |
| 543 // Record data and print if requested. | 559 // Record data and print if requested. |
| 544 intptr_t used_before_in_words = used_in_words_; | 560 intptr_t used_before_in_words = used_in_words_; |
| 545 used_in_words_ = used_in_words; | 561 used_in_words_ = used_in_words; |
| 546 | 562 |
| 547 int64_t end = OS::GetCurrentTimeMicros(); | 563 int64_t end = OS::GetCurrentTimeMicros(); |
| 548 | 564 |
| 549 // Record signals for growth control. | 565 // Record signals for growth control. Include size of external allocations. |
| 550 page_space_controller_.EvaluateGarbageCollection(used_before_in_words, | 566 page_space_controller_.EvaluateGarbageCollection( |
| 551 used_in_words, | 567 used_before_in_words + external_before_in_words, |
| 552 start, end); | 568 used_in_words + external_in_words_, |
| 569 start, end); |
| 553 | 570 |
| 554 heap_->RecordTime(kMarkObjects, mid1 - start); | 571 heap_->RecordTime(kMarkObjects, mid1 - start); |
| 555 heap_->RecordTime(kResetFreeLists, mid2 - mid1); | 572 heap_->RecordTime(kResetFreeLists, mid2 - mid1); |
| 556 heap_->RecordTime(kSweepPages, mid3 - mid2); | 573 heap_->RecordTime(kSweepPages, mid3 - mid2); |
| 557 heap_->RecordTime(kSweepLargePages, end - mid3); | 574 heap_->RecordTime(kSweepLargePages, end - mid3); |
| 558 | 575 |
| 559 if (FLAG_print_free_list_after_gc) { | 576 if (FLAG_print_free_list_after_gc) { |
| 560 OS::Print("Data Freelist (after GC):\n"); | 577 OS::Print("Data Freelist (after GC):\n"); |
| 561 freelist_[HeapPage::kData].Print(); | 578 freelist_[HeapPage::kData].Print(); |
| 562 OS::Print("Executable Freelist (after GC):\n"); | 579 OS::Print("Executable Freelist (after GC):\n"); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 return 0; | 702 return 0; |
| 686 } else { | 703 } else { |
| 687 ASSERT(total_time >= gc_time); | 704 ASSERT(total_time >= gc_time); |
| 688 int result= static_cast<int>((static_cast<double>(gc_time) / | 705 int result= static_cast<int>((static_cast<double>(gc_time) / |
| 689 static_cast<double>(total_time)) * 100); | 706 static_cast<double>(total_time)) * 100); |
| 690 return result; | 707 return result; |
| 691 } | 708 } |
| 692 } | 709 } |
| 693 | 710 |
| 694 } // namespace dart | 711 } // namespace dart |
| OLD | NEW |