Reland "[wasm][gc] Reenable discarding system pages"

This is a reland of 200a594a63.
The failing DCHECK was wrong, which is fixed now.

Original change's description:
> [wasm][gc] Reenable discarding system pages
>
> On windows, the range to be discarded needs to be split by the
> reservations, analogous to committing. This CL reuses the same logic,
> and reenables discarding pages on all platforms.
>
> R=mstarzinger@chromium.org
>
> Bug: v8:8217
> Change-Id: I11716d6381f765bdfe4cf48502b5cdc1f42cf8ab
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1611682
> Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61526}

Bug: v8:8217
No-Try: true
Change-Id: I293c638a5bc4678591a9c02704770ab54af39bdb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1613248
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61530}
This commit is contained in:
Clemens Hammacher 2019-05-15 15:17:57 +02:00 committed by Commit Bot
parent 9105e5e8a5
commit fb36fd22ad

View File

@ -434,19 +434,18 @@ base::SmallVector<base::AddressRegion, 1> SplitRangeByReservationsIfNeeded(
if (!kNeedsToSplitRangeByReservations) return {range};
base::SmallVector<base::AddressRegion, 1> split_ranges;
size_t missing_begin = range.begin();
size_t missing_end = range.end();
for (auto& vmem : base::Reversed(owned_code_space)) {
Address overlap_start = std::max(range.begin(), vmem.address());
Address overlap_end = std::min(range.end(), vmem.end());
if (overlap_start >= overlap_end) continue;
split_ranges.emplace_back(overlap_start, overlap_end - overlap_start);
// Opportunistically reduce the commit range. This might terminate the
// loop early.
if (range.begin() == overlap_start) {
range = {overlap_end, range.end() - overlap_end};
if (range.is_empty()) break;
} else if (range.end() == overlap_end) {
range = {range.begin(), overlap_start - range.begin()};
}
Address overlap_begin = std::max(missing_begin, vmem.address());
Address overlap_end = std::min(missing_end, vmem.end());
if (overlap_begin >= overlap_end) continue;
split_ranges.emplace_back(overlap_begin, overlap_end - overlap_begin);
// Opportunistically reduce the missing range. This might terminate the loop
// early.
if (missing_begin == overlap_begin) missing_begin = overlap_end;
if (missing_end == overlap_end) missing_end = overlap_begin;
if (missing_begin >= missing_end) break;
}
#ifdef ENABLE_SLOW_DCHECKS
// The returned vector should cover the full range.
@ -599,9 +598,12 @@ void WasmCodeAllocator::FreeCode(Vector<WasmCode* const> codes) {
std::min(RoundDown(merged_region.end(), commit_page_size),
RoundUp(region.end(), commit_page_size));
if (discard_start >= discard_end) continue;
// TODO(clemensh): Reenable after fixing https://crbug.com/960707.
// allocator->DiscardSystemPages(reinterpret_cast<void*>(discard_start),
// discard_end - discard_start);
// TODO(clemensh): Update committed_code_space_ counter.
for (base::AddressRegion split_range : SplitRangeByReservationsIfNeeded(
{discard_start, discard_end - discard_start}, owned_code_space_)) {
allocator->DiscardSystemPages(
reinterpret_cast<void*>(split_range.begin()), split_range.size());
}
}
}