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

Unified Diff: runtime/vm/pages.cc

Issue 1580813003: Use atomic operations to increment/decrement memory usage counts as multiple threads could be alloc… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-code-review Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/atomic_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/pages.cc
diff --git a/runtime/vm/pages.cc b/runtime/vm/pages.cc
index 5d5df0e2d559398f7494b34059206646c3399233..d7d9106324dff752d44c818dcb856554bfbd3c7a 100644
--- a/runtime/vm/pages.cc
+++ b/runtime/vm/pages.cc
@@ -344,7 +344,8 @@ uword PageSpace::TryAllocateInFreshPage(intptr_t size,
// Start of the newly allocated page is the allocated object.
result = page->object_start();
// Note: usage_.capacity_in_words is increased by AllocatePage.
- usage_.used_in_words += size >> kWordSizeLog2;
+ AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words),
+ (size >> kWordSizeLog2));
// Enqueue the remainder in the free list.
uword free_start = result + size;
intptr_t free_size = page->object_end() - free_start;
@@ -381,7 +382,8 @@ uword PageSpace::TryAllocateInternal(intptr_t size,
result = TryAllocateInFreshPage(size, type, growth_policy, is_locked);
// usage_ is updated by the call above.
} else {
- usage_.used_in_words += size >> kWordSizeLog2;
+ AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words),
Ivan Posva 2016/01/29 18:54:07 I am wondering whether we could make this a per th
siva 2016/01/29 20:52:17 Yes, we could do that, I will do it in a new CL.
+ (size >> kWordSizeLog2));
}
} else {
// Large page allocation.
@@ -400,21 +402,19 @@ uword PageSpace::TryAllocateInternal(intptr_t size,
if (page != NULL) {
result = page->object_start();
// Note: usage_.capacity_in_words is increased by AllocateLargePage.
- usage_.used_in_words += size >> kWordSizeLog2;
+ AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words),
+ (size >> kWordSizeLog2));
}
}
}
- if (result != 0) {
#ifdef DEBUG
+ if (result != 0) {
// A successful allocation should increase usage_.
ASSERT(usage_before.used_in_words < usage_.used_in_words);
-#endif
- } else {
-#ifdef DEBUG
- // A failed allocation should not change used_in_words.
- ASSERT(usage_before.used_in_words == usage_.used_in_words);
-#endif
}
+ // Note we cannot assert that a failed allocation should not change
+ // used_in_words as another thread could have changed used_in_words.
+#endif
ASSERT((result & kObjectAlignmentMask) == kOldObjectAlignmentOffset);
return result;
}
@@ -432,14 +432,16 @@ uword PageSpace::TryAllocateInternal(intptr_t size,
void PageSpace::AllocateExternal(intptr_t size) {
intptr_t size_in_words = size >> kWordSizeLog2;
- usage_.external_in_words += size_in_words;
+ AtomicOperations::FetchAndIncrementBy(&(usage_.external_in_words),
+ size_in_words);
// TODO(koda): Control growth.
}
void PageSpace::FreeExternal(intptr_t size) {
intptr_t size_in_words = size >> kWordSizeLog2;
- usage_.external_in_words -= size_in_words;
+ AtomicOperations::FetchAndDecrementBy(&(usage_.external_in_words),
+ size_in_words);
}
@@ -839,7 +841,8 @@ void PageSpace::MarkSweep(bool invoke_api_callbacks) {
bool collect_code = FLAG_collect_code && ShouldCollectCode();
GCMarker marker(heap_);
marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code);
- usage_.used_in_words = marker.marked_words();
+ AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words),
+ marker.marked_words());
int64_t mid1 = OS::GetCurrentTimeMicros();
@@ -1005,7 +1008,8 @@ uword PageSpace::TryAllocateDataBumpInternal(intptr_t size,
ASSERT(remaining >= size);
uword result = bump_top_;
bump_top_ += size;
- usage_.used_in_words += size >> kWordSizeLog2;
+ AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words),
+ (size >> kWordSizeLog2));
// Note: Remaining block is unwalkable until MakeIterable is called.
#ifdef DEBUG
if (bump_top_ < bump_end_) {
@@ -1035,7 +1039,8 @@ uword PageSpace::TryAllocatePromoLocked(intptr_t size,
FreeList* freelist = &freelist_[HeapPage::kData];
uword result = freelist->TryAllocateSmallLocked(size);
if (result != 0) {
- usage_.used_in_words += size >> kWordSizeLog2;
+ AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words),
+ (size >> kWordSizeLog2));
return result;
}
result = TryAllocateDataBumpLocked(size, growth_policy);
« no previous file with comments | « runtime/vm/atomic_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698