Skip to content

Commit

Permalink
[JSON] Fix GC issue in BuildJsonObject
Browse files Browse the repository at this point in the history
We must ensure that the sweeper is not running or has already swept
mutable_double_buffer. Otherwise the GC can add it to the free list.

Bug: v8:11837
Change-Id: Ifd9cf15f1c94f664fd6489c70bb38b59730cdd78
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2928181
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74859}
  • Loading branch information
victorgomes authored and V8 LUCI CQ committed May 31, 2021
1 parent 687ba03 commit 81181a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,10 @@ void Heap::CompleteSweepingYoung(GarbageCollector collector) {
array_buffer_sweeper()->EnsureFinished();
}

void Heap::EnsureSweepingCompleted() {
mark_compact_collector()->EnsureSweepingCompleted();
}

void Heap::UpdateCurrentEpoch(GarbageCollector collector) {
if (IsYoungGenerationCollector(collector)) {
epoch_young_ = next_epoch();
Expand Down
2 changes: 2 additions & 0 deletions src/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ class Heap {
void CompleteSweepingFull();
void CompleteSweepingYoung(GarbageCollector collector);

void EnsureSweepingCompleted();

IncrementalMarking* incremental_marking() const {
return incremental_marking_.get();
}
Expand Down
5 changes: 5 additions & 0 deletions src/json/json-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ Handle<Object> JsonParser<Char>::BuildJsonObject(
DCHECK_EQ(mutable_double_address, end);
}
#endif
// Before setting the length of mutable_double_buffer back to zero, we
// must ensure that the sweeper is not running or has already swept the
// object's page. Otherwise the GC can add the contents of
// mutable_double_buffer to the free list.
isolate()->heap()->EnsureSweepingCompleted();
mutable_double_buffer->set_length(0);
}
}
Expand Down

0 comments on commit 81181a8

Please sign in to comment.