Commit 4fa45c6d authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Keep array buffer bytes stable during sweeping

Introduce separate counters for young and old array buffer bytes. They
are used to keep the counter stable during sweeping when the array
buffer lists are moved to the concurrent thread for sweeping.

Bug: v8:10064
Change-Id: I0f11a634341873b4d21759c284c55beb26fe30a5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2045511
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66204}
parent c50dcf68
...@@ -118,6 +118,10 @@ void ArrayBufferSweeper::RequestSweepFull() { ...@@ -118,6 +118,10 @@ void ArrayBufferSweeper::RequestSweepFull() {
RequestSweep(SweepingScope::Full); RequestSweep(SweepingScope::Full);
} }
size_t ArrayBufferSweeper::YoungBytes() { return young_bytes_; }
size_t ArrayBufferSweeper::OldBytes() { return old_bytes_; }
void ArrayBufferSweeper::RequestSweep(SweepingScope scope) { void ArrayBufferSweeper::RequestSweep(SweepingScope scope) {
DCHECK(!sweeping_in_progress_); DCHECK(!sweeping_in_progress_);
...@@ -166,6 +170,8 @@ void ArrayBufferSweeper::Merge() { ...@@ -166,6 +170,8 @@ void ArrayBufferSweeper::Merge() {
CHECK_EQ(job_.state, SweepingState::Swept); CHECK_EQ(job_.state, SweepingState::Swept);
young_.Append(&job_.young); young_.Append(&job_.young);
old_.Append(&job_.old); old_.Append(&job_.old);
young_bytes_ = young_.Bytes();
old_bytes_ = old_.Bytes();
job_.state = SweepingState::Uninitialized; job_.state = SweepingState::Uninitialized;
} }
...@@ -173,6 +179,7 @@ void ArrayBufferSweeper::ReleaseAll() { ...@@ -173,6 +179,7 @@ void ArrayBufferSweeper::ReleaseAll() {
EnsureFinished(); EnsureFinished();
ReleaseAll(&old_); ReleaseAll(&old_);
ReleaseAll(&young_); ReleaseAll(&young_);
old_bytes_ = young_bytes_ = 0;
} }
void ArrayBufferSweeper::ReleaseAll(ArrayBufferList* list) { void ArrayBufferSweeper::ReleaseAll(ArrayBufferList* list) {
...@@ -189,13 +196,16 @@ void ArrayBufferSweeper::ReleaseAll(ArrayBufferList* list) { ...@@ -189,13 +196,16 @@ void ArrayBufferSweeper::ReleaseAll(ArrayBufferList* list) {
void ArrayBufferSweeper::Append(JSArrayBuffer object, void ArrayBufferSweeper::Append(JSArrayBuffer object,
ArrayBufferExtension* extension) { ArrayBufferExtension* extension) {
size_t bytes = extension->accounting_length();
if (Heap::InYoungGeneration(object)) { if (Heap::InYoungGeneration(object)) {
young_.Append(extension); young_.Append(extension);
young_bytes_ += bytes;
} else { } else {
old_.Append(extension); old_.Append(extension);
old_bytes_ += bytes;
} }
size_t bytes = extension->accounting_length();
IncrementExternalMemoryCounters(bytes); IncrementExternalMemoryCounters(bytes);
} }
......
...@@ -48,7 +48,10 @@ struct ArrayBufferList { ...@@ -48,7 +48,10 @@ struct ArrayBufferList {
class ArrayBufferSweeper { class ArrayBufferSweeper {
public: public:
explicit ArrayBufferSweeper(Heap* heap) explicit ArrayBufferSweeper(Heap* heap)
: heap_(heap), sweeping_in_progress_(false) {} : heap_(heap),
sweeping_in_progress_(false),
young_bytes_(0),
old_bytes_(0) {}
~ArrayBufferSweeper() { ReleaseAll(); } ~ArrayBufferSweeper() { ReleaseAll(); }
void EnsureFinished(); void EnsureFinished();
...@@ -60,6 +63,9 @@ class ArrayBufferSweeper { ...@@ -60,6 +63,9 @@ class ArrayBufferSweeper {
ArrayBufferList young() { return young_; } ArrayBufferList young() { return young_; }
ArrayBufferList old() { return old_; } ArrayBufferList old() { return old_; }
size_t YoungBytes();
size_t OldBytes();
private: private:
enum class SweepingScope { Young, Full }; enum class SweepingScope { Young, Full };
...@@ -105,6 +111,9 @@ class ArrayBufferSweeper { ...@@ -105,6 +111,9 @@ class ArrayBufferSweeper {
ArrayBufferList young_; ArrayBufferList young_;
ArrayBufferList old_; ArrayBufferList old_;
size_t young_bytes_;
size_t old_bytes_;
}; };
} // namespace internal } // namespace internal
......
...@@ -5999,12 +5999,12 @@ void Heap::RememberUnmappedPage(Address page, bool compacted) { ...@@ -5999,12 +5999,12 @@ void Heap::RememberUnmappedPage(Address page, bool compacted) {
size_t Heap::YoungArrayBufferBytes() { size_t Heap::YoungArrayBufferBytes() {
DCHECK(V8_ARRAY_BUFFER_EXTENSION_BOOL); DCHECK(V8_ARRAY_BUFFER_EXTENSION_BOOL);
return array_buffer_sweeper()->young().Bytes(); return array_buffer_sweeper()->YoungBytes();
} }
size_t Heap::OldArrayBufferBytes() { size_t Heap::OldArrayBufferBytes() {
DCHECK(V8_ARRAY_BUFFER_EXTENSION_BOOL); DCHECK(V8_ARRAY_BUFFER_EXTENSION_BOOL);
return array_buffer_sweeper()->old().Bytes(); return array_buffer_sweeper()->OldBytes();
} }
void Heap::RegisterStrongRoots(FullObjectSlot start, FullObjectSlot end) { void Heap::RegisterStrongRoots(FullObjectSlot start, FullObjectSlot end) {
......
...@@ -509,6 +509,7 @@ TEST(ArrayBuffer_ExternalBackingStoreSizeIncreases) { ...@@ -509,6 +509,7 @@ TEST(ArrayBuffer_ExternalBackingStoreSizeIncreases) {
} }
TEST(ArrayBuffer_ExternalBackingStoreSizeDecreases) { TEST(ArrayBuffer_ExternalBackingStoreSizeDecreases) {
FLAG_concurrent_array_buffer_sweeping = false;
CcTest::InitializeVM(); CcTest::InitializeVM();
LocalContext env; LocalContext env;
v8::Isolate* isolate = env->GetIsolate(); v8::Isolate* isolate = env->GetIsolate();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment