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

Side by Side Diff: runtime/vm/pages.cc

Issue 531153003: Add lost usage update to TryAllocateInternal. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 months 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 | « runtime/tests/vm/vm.status ('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) 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 317 }
318 318
319 319
320 uword PageSpace::TryAllocateInternal(intptr_t size, 320 uword PageSpace::TryAllocateInternal(intptr_t size,
321 HeapPage::PageType type, 321 HeapPage::PageType type,
322 GrowthPolicy growth_policy, 322 GrowthPolicy growth_policy,
323 bool is_protected, 323 bool is_protected,
324 bool is_locked) { 324 bool is_locked) {
325 ASSERT(size >= kObjectAlignment); 325 ASSERT(size >= kObjectAlignment);
326 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 326 ASSERT(Utils::IsAligned(size, kObjectAlignment));
327 #ifdef DEBUG
328 SpaceUsage usage_before = usage_;
329 #endif
327 uword result = 0; 330 uword result = 0;
328 if (size < kAllocatablePageSize) { 331 if (size < kAllocatablePageSize) {
329 if (is_locked) { 332 if (is_locked) {
330 result = freelist_[type].TryAllocateLocked(size, is_protected); 333 result = freelist_[type].TryAllocateLocked(size, is_protected);
331 } else { 334 } else {
332 result = freelist_[type].TryAllocate(size, is_protected); 335 result = freelist_[type].TryAllocate(size, is_protected);
333 } 336 }
334 if (result == 0) { 337 if (result == 0) {
335 result = TryAllocateInFreshPage(size, type, growth_policy, is_locked); 338 result = TryAllocateInFreshPage(size, type, growth_policy, is_locked);
339 // usage_ is updated by the call above.
340 } else {
341 usage_.used_in_words += size >> kWordSizeLog2;
336 } 342 }
337 } else { 343 } else {
338 // Large page allocation. 344 // Large page allocation.
339 intptr_t page_size_in_words = LargePageSizeInWordsFor(size); 345 intptr_t page_size_in_words = LargePageSizeInWordsFor(size);
340 if ((page_size_in_words << kWordSizeLog2) < size) { 346 if ((page_size_in_words << kWordSizeLog2) < size) {
341 // On overflow we fail to allocate. 347 // On overflow we fail to allocate.
342 return 0; 348 return 0;
343 } 349 }
344 SpaceUsage after_allocation = usage_; 350 SpaceUsage after_allocation = usage_;
345 after_allocation.used_in_words += size >> kWordSizeLog2; 351 after_allocation.used_in_words += size >> kWordSizeLog2;
346 after_allocation.capacity_in_words += page_size_in_words; 352 after_allocation.capacity_in_words += page_size_in_words;
347 if ((growth_policy == kForceGrowth || 353 if ((growth_policy == kForceGrowth ||
348 !page_space_controller_.NeedsGarbageCollection(after_allocation)) && 354 !page_space_controller_.NeedsGarbageCollection(after_allocation)) &&
349 CanIncreaseCapacityInWords(page_size_in_words)) { 355 CanIncreaseCapacityInWords(page_size_in_words)) {
350 HeapPage* page = AllocateLargePage(size, type); 356 HeapPage* page = AllocateLargePage(size, type);
351 if (page != NULL) { 357 if (page != NULL) {
352 result = page->object_start(); 358 result = page->object_start();
353 usage_ = after_allocation; 359 usage_ = after_allocation;
354 } 360 }
355 } 361 }
356 } 362 }
357 if (result != 0) { 363 if (result != 0) {
364 #ifdef DEBUG
365 // A successful allocation should increase usage_.
366 ASSERT(usage_before.used_in_words < usage_.used_in_words);
367 #endif
358 if (FLAG_compiler_stats && (type == HeapPage::kExecutable)) { 368 if (FLAG_compiler_stats && (type == HeapPage::kExecutable)) {
359 CompilerStats::code_allocated += size; 369 CompilerStats::code_allocated += size;
360 } 370 }
371 } else {
372 #ifdef DEBUG
373 // A failed allocation should not change usage_.
374 ASSERT(usage_before.used_in_words == usage_.used_in_words);
375 ASSERT(usage_before.capacity_in_words == usage_.capacity_in_words);
376 #endif
361 } 377 }
362 ASSERT((result & kObjectAlignmentMask) == kOldObjectAlignmentOffset); 378 ASSERT((result & kObjectAlignmentMask) == kOldObjectAlignmentOffset);
363 return result; 379 return result;
364 } 380 }
365 381
366 382
367 void PageSpace::AcquireDataLock() { 383 void PageSpace::AcquireDataLock() {
368 freelist_[HeapPage::kData].mutex()->Lock(); 384 freelist_[HeapPage::kData].mutex()->Lock();
369 } 385 }
370 386
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 return 0; 933 return 0;
918 } else { 934 } else {
919 ASSERT(total_time >= gc_time); 935 ASSERT(total_time >= gc_time);
920 int result= static_cast<int>((static_cast<double>(gc_time) / 936 int result= static_cast<int>((static_cast<double>(gc_time) /
921 static_cast<double>(total_time)) * 100); 937 static_cast<double>(total_time)) * 100);
922 return result; 938 return result;
923 } 939 }
924 } 940 }
925 941
926 } // namespace dart 942 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698