author | stuefe |
Thu, 17 Oct 2019 16:39:45 +0200 | |
branch | stuefe-new-metaspace-branch |
changeset 58683 | 2d5dd194c65c |
parent 58099 | 5aeb07390c74 |
permissions | -rw-r--r-- |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
1 |
/* |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, SAP SE. All rights reserved. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
3 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
5 |
* |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
6 |
* This code is free software; you can redistribute it and/or modify it |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
9 |
* |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
14 |
* accompanied this code). |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
15 |
* |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License version |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
19 |
* |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
22 |
* questions. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
23 |
* |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
24 |
*/ |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
25 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
26 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
27 |
#include "precompiled.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
28 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
29 |
#include "memory/metaspace/commitMask.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
30 |
#include "memory/metaspace/metaspaceCommon.hpp" |
58099 | 31 |
#include "memory/metaspace/settings.hpp" |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
32 |
#include "runtime/stubRoutines.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
33 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
34 |
#include "utilities/align.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
35 |
#include "utilities/debug.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
36 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
37 |
namespace metaspace { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
38 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
39 |
CommitMask::CommitMask(const MetaWord* start, size_t word_size) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
40 |
: CHeapBitMap(mask_size(word_size, Settings::commit_granule_words())) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
41 |
, _base(start) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
42 |
, _word_size(word_size) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
43 |
, _words_per_bit(Settings::commit_granule_words()) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
44 |
{ |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
45 |
assert(_word_size > 0 && _words_per_bit > 0 && |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
46 |
is_aligned(_word_size, _words_per_bit), "Sanity"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
47 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
48 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
49 |
#ifdef ASSERT |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
50 |
|
58683 | 51 |
// This is very expensive |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
52 |
static const bool TEST_UNCOMMITTED_REGION = false; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
53 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
54 |
volatile u1 x; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
55 |
|
58683 | 56 |
static void check_range_is_accessible(const MetaWord* p, size_t word_size) { |
57 |
const MetaWord* const p_end = p + word_size; |
|
58 |
u1 x2 = 0; |
|
59 |
for (const MetaWord* q = p; q < p_end; q += os::vm_page_size() / BytesPerWord) { |
|
60 |
x2 += *(u1*)q; |
|
61 |
} |
|
62 |
x = x2; |
|
63 |
} |
|
64 |
||
65 |
void CommitMask::verify(bool slow) const { |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
66 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
67 |
// Walk the whole commit mask. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
68 |
// For each 1 bit, check if the associated granule is accessible. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
69 |
// For each 0 bit, check if the associated granule is not accessible. Slow mode only. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
70 |
|
58683 | 71 |
assert(_base != NULL && _word_size > 0 && _words_per_bit > 0, "Sanity"); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
72 |
assert_is_aligned(_base, _words_per_bit * BytesPerWord); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
73 |
assert_is_aligned(_word_size, _words_per_bit); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
74 |
|
58683 | 75 |
if (slow) { |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
76 |
for (idx_t i = 0; i < size(); i ++) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
77 |
const MetaWord* const p = _base + (i * _words_per_bit); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
78 |
if (at(i)) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
79 |
// Should be accessible. Just touch it. |
58683 | 80 |
check_range_is_accessible(p, _words_per_bit); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
81 |
} else { |
58683 | 82 |
// Note: results may differ between platforms. On Linux, this should be true since |
83 |
// we uncommit memory by setting protection to PROT_NONE. We may have to look if |
|
84 |
// this works as expected on other platforms. |
|
85 |
if (TEST_UNCOMMITTED_REGION && CanUseSafeFetch32()) { |
|
86 |
assert(os::is_readable_pointer(p) == false, |
|
87 |
"index %u, pointer " PTR_FORMAT ", should not be accessible.", |
|
88 |
(unsigned)i, p2i(p)); |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
89 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
90 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
91 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
92 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
93 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
94 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
95 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
96 |
#endif // ASSERT |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
97 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
98 |
void CommitMask::print_on(outputStream* st) const { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
99 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
100 |
st->print("commit mask, base " PTR_FORMAT ":", p2i(base())); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
101 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
102 |
for (idx_t i = 0; i < size(); i ++) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
103 |
st->print("%c", at(i) ? 'X' : '-'); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
104 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
105 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
106 |
st->cr(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
107 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
108 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
109 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
110 |
} // namespace metaspace |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff
changeset
|
111 |