Skip to content

Commit b53ff5f

Browse files
backesCommit Bot
authored andcommitted
Add test mode to ignore allocation hints
This randomizes new memory allocations and reservations. It's currently used to test far jump tables in wasm better, but might be helpful generally for testing arbitrary virtual memory layouts. R=mstarzinger@chromium.org Bug: v8:9477 Change-Id: Ie60b7c6dd3c4cd0f3b9eb8e2172912e0851c357d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1803340 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/master@{#63802}
1 parent 9f7ae50 commit b53ff5f

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/flags/flag-definitions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,10 @@ DEFINE_BOOL(gc_experiment_less_compaction, false,
967967

968968
DEFINE_BOOL(disable_abortjs, false, "disables AbortJS runtime function")
969969

970+
DEFINE_BOOL(randomize_all_allocations, false,
971+
"randomize virtual memory reservations by ignoring any hints "
972+
"passed when allocating pages")
973+
970974
DEFINE_BOOL(manual_evacuation_candidates_selection, false,
971975
"Test mode only flag. It allows an unit test to select evacuation "
972976
"candidates pages (requires --stress_compaction).")

src/utils/allocation.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "src/base/logging.h"
1111
#include "src/base/page-allocator.h"
1212
#include "src/base/platform/platform.h"
13+
#include "src/flags/flags.h"
1314
#include "src/init/v8.h"
1415
#include "src/sanitizer/lsan-page-allocator.h"
1516
#include "src/utils/memcopy.h"
@@ -166,6 +167,9 @@ void* AllocatePages(v8::PageAllocator* page_allocator, void* hint, size_t size,
166167
DCHECK_NOT_NULL(page_allocator);
167168
DCHECK_EQ(hint, AlignedAddress(hint, alignment));
168169
DCHECK(IsAligned(size, page_allocator->AllocatePageSize()));
170+
if (FLAG_randomize_all_allocations) {
171+
hint = page_allocator->GetRandomMmapAddr();
172+
}
169173
void* result = nullptr;
170174
for (int i = 0; i < kAllocationTries; ++i) {
171175
result = page_allocator->AllocatePages(hint, size, alignment, access);

test/mjsunit/wasm/multiple-code-spaces.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// Flags: --allow-natives-syntax
5+
// Flags: --allow-natives-syntax --randomize-all-allocations
66
// Flags: --wasm-far-jump-table --wasm-max-initial-code-space-reservation=1
77

88
load('test/mjsunit/wasm/wasm-module-builder.js');

0 commit comments

Comments
 (0)