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

Unified Diff: src/heap/spaces.h

Issue 1932883002: Revert "[heap] Optimize NewSpace::AllocatedSinceLastGC" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 | « src/heap/heap-inl.h ('k') | src/heap/spaces.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/spaces.h
diff --git a/src/heap/spaces.h b/src/heap/spaces.h
index a097fb3cf5503243ebed600f532c9757437825f8..91c9d0376eb16a7e7a5614863862f1074c8f5044 100644
--- a/src/heap/spaces.h
+++ b/src/heap/spaces.h
@@ -548,10 +548,6 @@ class MemoryChunk {
return reinterpret_cast<MemoryChunk*>(OffsetFrom(a) & ~kAlignmentMask);
}
- static intptr_t OffsetInPage(Address a) {
- return reinterpret_cast<intptr_t>(a) & kPageAlignmentMask;
- }
-
static inline MemoryChunk* FromAnyPointerAddress(Heap* heap, Address addr);
static inline void UpdateHighWaterMark(Address mark) {
@@ -2529,7 +2525,6 @@ class NewSpace : public Space {
from_space_(heap, kFromSpace),
reservation_(),
pages_used_(0),
- allocated_since_last_gc_(0),
top_on_previous_step_(0),
allocated_histogram_(nullptr),
promoted_histogram_(nullptr) {}
@@ -2601,7 +2596,42 @@ class NewSpace : public Space {
// Return the available bytes without growing.
intptr_t Available() override { return Capacity() - Size(); }
- V8_INLINE size_t AllocatedSinceLastGC();
+ size_t AllocatedSinceLastGC() {
+ bool seen_age_mark = false;
+ Address age_mark = to_space_.age_mark();
+ Page* current_page = to_space_.first_page();
+ Page* age_mark_page = Page::FromAddress(age_mark);
+ Page* last_page = Page::FromAddress(top() - kPointerSize);
+ if (age_mark_page == last_page) {
+ if (top() - age_mark >= 0) {
+ return top() - age_mark;
+ }
+ // Top was reset at some point, invalidating this metric.
+ return 0;
+ }
+ while (current_page != last_page) {
+ if (current_page == age_mark_page) {
+ seen_age_mark = true;
+ break;
+ }
+ current_page = current_page->next_page();
+ }
+ if (!seen_age_mark) {
+ // Top was reset at some point, invalidating this metric.
+ return 0;
+ }
+ intptr_t allocated = age_mark_page->area_end() - age_mark;
+ DCHECK_EQ(current_page, age_mark_page);
+ current_page = age_mark_page->next_page();
+ while (current_page != last_page) {
+ allocated += Page::kAllocatableMemory;
+ current_page = current_page->next_page();
+ }
+ allocated += top() - current_page->area_start();
+ DCHECK_LE(0, allocated);
+ DCHECK_LE(allocated, Size());
+ return static_cast<size_t>(allocated);
+ }
bool ReplaceWithEmptyPage(Page* page) {
// This method is called after flipping the semispace.
@@ -2641,10 +2671,7 @@ class NewSpace : public Space {
// Get the age mark of the inactive semispace.
Address age_mark() { return from_space_.age_mark(); }
// Set the age mark in the active semispace.
- void set_age_mark(Address mark) {
- to_space_.set_age_mark(mark);
- allocated_since_last_gc_ = 0;
- }
+ void set_age_mark(Address mark) { to_space_.set_age_mark(mark); }
// The allocation top and limit address.
Address* allocation_top_address() { return allocation_info_.top_address(); }
@@ -2765,7 +2792,6 @@ class NewSpace : public Space {
SemiSpace from_space_;
base::VirtualMemory reservation_;
int pages_used_;
- intptr_t allocated_since_last_gc_;
// Allocation pointer and limit for normal allocation and allocation during
// mark-compact collection.
« no previous file with comments | « src/heap/heap-inl.h ('k') | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698