| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 374 } |
| 375 | 375 |
| 376 | 376 |
| 377 uword PageSpace::TryAllocateInternal(intptr_t size, | 377 uword PageSpace::TryAllocateInternal(intptr_t size, |
| 378 HeapPage::PageType type, | 378 HeapPage::PageType type, |
| 379 GrowthPolicy growth_policy, | 379 GrowthPolicy growth_policy, |
| 380 bool is_protected, | 380 bool is_protected, |
| 381 bool is_locked) { | 381 bool is_locked) { |
| 382 ASSERT(size >= kObjectAlignment); | 382 ASSERT(size >= kObjectAlignment); |
| 383 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 383 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| 384 #ifdef DEBUG | |
| 385 SpaceUsage usage_before = GetCurrentUsage(); | |
| 386 #endif | |
| 387 uword result = 0; | 384 uword result = 0; |
| 388 if (size < kAllocatablePageSize) { | 385 if (size < kAllocatablePageSize) { |
| 389 if (is_locked) { | 386 if (is_locked) { |
| 390 result = freelist_[type].TryAllocateLocked(size, is_protected); | 387 result = freelist_[type].TryAllocateLocked(size, is_protected); |
| 391 } else { | 388 } else { |
| 392 result = freelist_[type].TryAllocate(size, is_protected); | 389 result = freelist_[type].TryAllocate(size, is_protected); |
| 393 } | 390 } |
| 394 if (result == 0) { | 391 if (result == 0) { |
| 395 result = TryAllocateInFreshPage(size, type, growth_policy, is_locked); | 392 result = TryAllocateInFreshPage(size, type, growth_policy, is_locked); |
| 396 // usage_ is updated by the call above. | 393 // usage_ is updated by the call above. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 413 CanIncreaseCapacityInWords(page_size_in_words)) { | 410 CanIncreaseCapacityInWords(page_size_in_words)) { |
| 414 HeapPage* page = AllocateLargePage(size, type); | 411 HeapPage* page = AllocateLargePage(size, type); |
| 415 if (page != NULL) { | 412 if (page != NULL) { |
| 416 result = page->object_start(); | 413 result = page->object_start(); |
| 417 // Note: usage_.capacity_in_words is increased by AllocateLargePage. | 414 // Note: usage_.capacity_in_words is increased by AllocateLargePage. |
| 418 AtomicOperations::IncrementBy(&(usage_.used_in_words), | 415 AtomicOperations::IncrementBy(&(usage_.used_in_words), |
| 419 (size >> kWordSizeLog2)); | 416 (size >> kWordSizeLog2)); |
| 420 } | 417 } |
| 421 } | 418 } |
| 422 } | 419 } |
| 423 #ifdef DEBUG | |
| 424 if (result != 0) { | |
| 425 // A successful allocation should increase usage_. | |
| 426 ASSERT(usage_before.used_in_words < usage_.used_in_words); | |
| 427 } | |
| 428 // Note we cannot assert that a failed allocation should not change | |
| 429 // used_in_words as another thread could have changed used_in_words. | |
| 430 #endif | |
| 431 ASSERT((result & kObjectAlignmentMask) == kOldObjectAlignmentOffset); | 420 ASSERT((result & kObjectAlignmentMask) == kOldObjectAlignmentOffset); |
| 432 return result; | 421 return result; |
| 433 } | 422 } |
| 434 | 423 |
| 435 | 424 |
| 436 void PageSpace::AcquireDataLock() { | 425 void PageSpace::AcquireDataLock() { |
| 437 freelist_[HeapPage::kData].mutex()->Lock(); | 426 freelist_[HeapPage::kData].mutex()->Lock(); |
| 438 } | 427 } |
| 439 | 428 |
| 440 | 429 |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 return 0; | 1258 return 0; |
| 1270 } else { | 1259 } else { |
| 1271 ASSERT(total_time >= gc_time); | 1260 ASSERT(total_time >= gc_time); |
| 1272 int result = static_cast<int>( | 1261 int result = static_cast<int>( |
| 1273 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); | 1262 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); |
| 1274 return result; | 1263 return result; |
| 1275 } | 1264 } |
| 1276 } | 1265 } |
| 1277 | 1266 |
| 1278 } // namespace dart | 1267 } // namespace dart |
| OLD | NEW |