2
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
3
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
25
#include "precompiled.hpp"
26
#include "runtime/os.hpp"
27
#include "utilities/align.hpp"
28
#include "utilities/ostream.hpp"
30
#include "testutils.hpp"
31
#include "unittest.hpp"
35
// Note: these could be made more suitable for covering large ranges (e.g. just mark one byte per page).
37
void GtestUtils::mark_range_with(void* p, size_t s, uint8_t mark) {
38
if (p != nullptr && s > 0) {
43
bool GtestUtils::is_range_marked(const void* p, size_t s, uint8_t expected) {
44
if (p == nullptr || s == 0) {
48
const char* first_wrong = nullptr;
50
const char* const end = p2 + s;
52
if (*p2 != (char)expected) {
59
if (first_wrong != nullptr) {
60
tty->print_cr("check_range [" PTR_FORMAT ".." PTR_FORMAT "), 0x%X, : wrong pattern around " PTR_FORMAT,
61
p2i(p), p2i(p) + s, expected, p2i(first_wrong));
62
// Note: We deliberately print the surroundings too without bounds check. Might be interesting,
63
// and os::print_hex_dump uses SafeFetch, so this is fine without bounds checks.
64
os::print_hex_dump(tty, (address)(align_down(p2, 0x10) - 0x10),
65
(address)(align_up(end, 0x10) + 0x10), 1);
68
return first_wrong == nullptr;