Commit 243b7f63 authored by Pierre Langlois's avatar Pierre Langlois Committed by Commit Bot

[cctest][heap] Fix remaining memory calculation to simulate full pages.

The cctests need to simulate full pages, however the calculation of the
remainging available space is wrong causing an assertion when we change
the V8 page size to 512K:

    $ cctest test-array-buffer-tracker/ArrayBuffer_PagePromotion

    #
    # Fatal error in ../../test/cctest/heap/heap-utils.cc, line 94
    # Check failed: padding_size <= overall_free_memory || overall_free_memory == 0.

The reason is:

  - On startup, we register a scavenger observer on the new space. The
    observer is set to trigger when the new space capacity is at 80% by
    default.

  - On linux, the initial capacity of the new space is 512K, so the
    scavenger observer will be placed at 80% of 512K, which will either
    be in the second page of the space if the page size is 256K, or in
    the first page if the page size is 512K.

  - When placing the observer, if the observer hits the first page, we
    lower the allocation limit (see `ComputeLimit()`). This makes sure
    the observer isn't skipped by allocations inlined in generated code.

However, when we simulate filling the current page, we compute the space
left in the current page by comparing the top with the `page_high()`
rather than `limit()`. This was done so the tests would also work when
inlined allocations are disabled. If we don't look at the `limit()`, we
don't take the observer into account and fill more space than is
available, triggering the assertion.

This can also be reproduced by reducing the % at which the scavenger is
triggered so that it hits the first page instead of the second when the
page size is 256K, for example passing --scavenge-task-trigger=10.

Bug v8:10808, v8:9906

Change-Id: Iad50bb68995de5ee017dcbe069d1fb229c9f5985
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2372545
Commit-Queue: Pierre Langlois <pierre.langlois@arm.com>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69550}
parent 32dd5470
......@@ -719,8 +719,10 @@ void FillUpOneNewSpacePage(Isolate* isolate, Heap* heap) {
// the current allocation pointer.
DCHECK_IMPLIES(space->heap()->inline_allocation_disabled(),
space->limit() == space->top());
int space_remaining =
static_cast<int>(space->to_space().page_high() - space->top());
size_t limit = space->heap()->inline_allocation_disabled()
? space->to_space().page_high()
: space->limit();
int space_remaining = static_cast<int>(limit - space->top());
while (space_remaining > 0) {
int length = FixedArrayLenFromSize(space_remaining);
if (length > 0) {
......
......@@ -137,8 +137,10 @@ bool FillCurrentPageButNBytes(v8::internal::NewSpace* space, int extra_bytes,
// the current allocation pointer.
DCHECK_IMPLIES(space->heap()->inline_allocation_disabled(),
space->limit() == space->top());
int space_remaining =
static_cast<int>(space->to_space().page_high() - space->top());
size_t limit = space->heap()->inline_allocation_disabled()
? space->to_space().page_high()
: space->limit();
int space_remaining = static_cast<int>(limit - space->top());
CHECK(space_remaining >= extra_bytes);
int new_linear_size = space_remaining - extra_bytes;
if (new_linear_size == 0) return false;
......
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