File: metaspaceGtestCommon.cpp

package info (click to toggle)
openjdk-25 25.0.1%2B8-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 825,408 kB
  • sloc: java: 5,585,680; cpp: 1,333,948; xml: 1,321,242; ansic: 488,034; asm: 404,003; objc: 21,088; sh: 15,106; javascript: 13,265; python: 8,319; makefile: 2,518; perl: 357; awk: 351; pascal: 103; exp: 83; sed: 72; jsp: 24
file content (97 lines) | stat: -rw-r--r-- 3,559 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
 * Copyright (c) 2020 SAP SE. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#include "metaspaceGtestCommon.hpp"
#include "metaspaceGtestRangeHelpers.hpp"
#include "runtime/os.hpp"

void zap_range(MetaWord* p, size_t word_size) {
  for (MetaWord* pzap = p; pzap < p + word_size; pzap += os::vm_page_size() / BytesPerWord) {
    *pzap = (MetaWord)NOT_LP64(0xFEFEFEFE) LP64_ONLY(0xFEFEFEFEEFEFEFEFULL);
  }
}

// Writes a unique pattern to p
void mark_address(MetaWord* p, uintx pattern) {
  MetaWord x = (MetaWord)((uintx) p ^ pattern);
  *p = x;
}

// checks pattern at address
void check_marked_address(const MetaWord* p, uintx pattern) {
  MetaWord x = (MetaWord)((uintx) p ^ pattern);
  EXPECT_EQ(*p, x);
}

// "fill_range_with_pattern" fills a range of heap words with pointers to itself.
//
// The idea is to fill a memory range with a pattern which is both marked clearly to the caller
// and cannot be moved without becoming invalid.
//
// The filled range can be checked with check_range_for_pattern. One also can only check
// a sub range of the original range.
void fill_range_with_pattern(MetaWord* p, size_t word_size, uintx pattern) {
  assert(word_size > 0 && p != nullptr, "sanity");
  for (MetaWord* p2 = p; p2 < p + word_size; p2++) {
    mark_address(p2, pattern);
  }
}

void check_range_for_pattern(const MetaWord* p, size_t word_size, uintx pattern) {
  assert(p != nullptr, "sanity");
  const MetaWord* p2 = p;
  while (p2 < p + word_size) {
    check_marked_address(p2, pattern);
    p2++;
  }
}

// Similar to fill_range_with_pattern, but only marks start and end. This is optimized for cases
// where fill_range_with_pattern just is too slow.
// Use check_marked_range to check the range. In contrast to check_range_for_pattern, only the original
// range can be checked.
void mark_range(MetaWord* p, size_t word_size, uintx pattern) {
  assert(word_size > 0 && p != nullptr, "sanity");
  mark_address(p, pattern);
  mark_address(p + word_size - 1, pattern);
}

void check_marked_range(const MetaWord* p, size_t word_size, uintx pattern) {
  assert(word_size > 0 && p != nullptr, "sanity");
  check_marked_address(p, pattern);
  check_marked_address(p + word_size - 1, pattern);
}

void mark_range(MetaWord* p, size_t word_size) {
  assert(word_size > 0 && p != nullptr, "sanity");
  uintx pattern = (uintx)p2i(p);
  mark_range(p, word_size, pattern);
}

void check_marked_range(const MetaWord* p, size_t word_size) {
  uintx pattern = (uintx)p2i(p);
  check_marked_range(p, word_size, pattern);
}