Commit 74565bf3 authored by Pierre Langlois's avatar Pierre Langlois Committed by Commit Bot

[test] Make full space simulation work with --no-inline-new.

When inlined allocations are disabled, the space->limit() does not point to the
end of the current page. Instead, it points to the current allocation pointer so
is the same as space->top().

See how the limit is computed, if heap()->inline_allocation_disabled(), then the
limit will be the same as the requested allocation area:

```
Address SpaceWithLinearArea::ComputeLimit(Address start, Address end,
                                          size_t min_size) {
  DCHECK_GE(end - start, min_size);

  if (heap()->inline_allocation_disabled()) {
    // Fit the requested area exactly.
    return start + min_size;
  } else if (SupportsInlineAllocation() && AllocationObserversActive()) {
    // ...
  } else {
    // The entire node can be used as the linear allocation area.
    return end;
  }
}
```

If we want to simulate filling up a whole page in the new space, we can instead
look at the ToSpace's page_high() which will be the end of the current page in
which we're allocating.

Bug: v8:9906
Change-Id: I81113d151bc083cd22d17ea1a4fbae7fef9dff6d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1886914Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Pierre Langlois <pierre.langlois@arm.com>
Cr-Commit-Position: refs/heads/master@{#64612}
parent 30ec6a89
......@@ -684,9 +684,15 @@ int FixedArrayLenFromSize(int size) {
}
void FillUpOneNewSpacePage(Isolate* isolate, Heap* heap) {
PauseAllocationObserversScope pause_observers(heap);
NewSpace* space = heap->new_space();
int space_remaining = static_cast<int>(*space->allocation_limit_address() -
*space->allocation_top_address());
// We cannot rely on `space->limit()` to point to the end of the current page
// in the case where inline allocations are disabled, it actually points to
// 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());
while (space_remaining > 0) {
int length = FixedArrayLenFromSize(space_remaining);
if (length > 0) {
......@@ -709,7 +715,6 @@ RUNTIME_FUNCTION(Runtime_SimulateNewspaceFull) {
HandleScope scope(isolate);
Heap* heap = isolate->heap();
NewSpace* space = heap->new_space();
PauseAllocationObserversScope pause_observers(heap);
AlwaysAllocateScope always_allocate(heap);
do {
FillUpOneNewSpacePage(isolate, heap);
......
......@@ -121,32 +121,24 @@ std::vector<Handle<FixedArray>> CreatePadding(Heap* heap, int padding_size,
return handles;
}
void AllocateAllButNBytes(v8::internal::NewSpace* space, int extra_bytes,
bool FillCurrentPage(v8::internal::NewSpace* space,
std::vector<Handle<FixedArray>>* out_handles) {
PauseAllocationObserversScope pause_observers(space->heap());
int space_remaining = static_cast<int>(*space->allocation_limit_address() -
*space->allocation_top_address());
CHECK(space_remaining >= extra_bytes);
int new_linear_size = space_remaining - extra_bytes;
if (new_linear_size == 0) return;
std::vector<Handle<FixedArray>> handles = heap::CreatePadding(
space->heap(), new_linear_size, i::AllocationType::kYoung);
if (out_handles != nullptr) {
out_handles->insert(out_handles->end(), handles.begin(), handles.end());
}
}
void FillCurrentPage(v8::internal::NewSpace* space,
std::vector<Handle<FixedArray>>* out_handles) {
heap::AllocateAllButNBytes(space, 0, out_handles);
return heap::FillCurrentPageButNBytes(space, 0, out_handles);
}
bool FillUpOnePage(v8::internal::NewSpace* space,
bool FillCurrentPageButNBytes(v8::internal::NewSpace* space, int extra_bytes,
std::vector<Handle<FixedArray>>* out_handles) {
PauseAllocationObserversScope pause_observers(space->heap());
int space_remaining = static_cast<int>(*space->allocation_limit_address() -
*space->allocation_top_address());
if (space_remaining == 0) return false;
// We cannot rely on `space->limit()` to point to the end of the current page
// in the case where inline allocations are disabled, it actually points to
// 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());
CHECK(space_remaining >= extra_bytes);
int new_linear_size = space_remaining - extra_bytes;
if (new_linear_size == 0) return false;
std::vector<Handle<FixedArray>> handles = heap::CreatePadding(
space->heap(), space_remaining, i::AllocationType::kYoung);
if (out_handles != nullptr) {
......@@ -157,8 +149,7 @@ bool FillUpOnePage(v8::internal::NewSpace* space,
void SimulateFullSpace(v8::internal::NewSpace* space,
std::vector<Handle<FixedArray>>* out_handles) {
heap::FillCurrentPage(space, out_handles);
while (heap::FillUpOnePage(space, out_handles) || space->AddFreshPage()) {
while (heap::FillCurrentPage(space, out_handles) || space->AddFreshPage()) {
}
}
......
......@@ -42,17 +42,14 @@ std::vector<Handle<FixedArray>> CreatePadding(
Heap* heap, int padding_size, AllocationType allocation,
int object_size = kMaxRegularHeapObjectSize);
void AllocateAllButNBytes(
v8::internal::NewSpace* space, int extra_bytes,
bool FillCurrentPage(v8::internal::NewSpace* space,
std::vector<Handle<FixedArray>>* out_handles = nullptr);
void FillCurrentPage(v8::internal::NewSpace* space,
bool FillCurrentPageButNBytes(
v8::internal::NewSpace* space, int extra_bytes,
std::vector<Handle<FixedArray>>* out_handles = nullptr);
// Helper function that simulates a full new-space in the heap.
bool FillUpOnePage(v8::internal::NewSpace* space,
std::vector<Handle<FixedArray>>* out_handles = nullptr);
void SimulateFullSpace(v8::internal::NewSpace* space,
std::vector<Handle<FixedArray>>* out_handles = nullptr);
......
......@@ -3558,7 +3558,7 @@ TEST(Regress169928) {
array_data->set(0, Smi::FromInt(1));
array_data->set(1, Smi::FromInt(2));
heap::AllocateAllButNBytes(
heap::FillCurrentPageButNBytes(
CcTest::heap()->new_space(),
JSArray::kSize + AllocationMemento::kSize + kTaggedSize);
......
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