8314653: Metaspace: remove allocation guard feature
Reviewed-by: azafari, dholmes
This commit is contained in:
parent
6a472797a4
commit
b0efd77402
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -117,9 +117,6 @@ MetaspaceArena::MetaspaceArena(ChunkManager* chunk_manager, const ArenaGrowthPol
|
|||||||
_fbl(nullptr),
|
_fbl(nullptr),
|
||||||
_total_used_words_counter(total_used_words_counter),
|
_total_used_words_counter(total_used_words_counter),
|
||||||
_name(name)
|
_name(name)
|
||||||
#ifdef ASSERT
|
|
||||||
, _first_fence(nullptr)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
UL(debug, ": born.");
|
UL(debug, ": born.");
|
||||||
|
|
||||||
@ -128,14 +125,7 @@ MetaspaceArena::MetaspaceArena(ChunkManager* chunk_manager, const ArenaGrowthPol
|
|||||||
}
|
}
|
||||||
|
|
||||||
MetaspaceArena::~MetaspaceArena() {
|
MetaspaceArena::~MetaspaceArena() {
|
||||||
#ifdef ASSERT
|
|
||||||
SOMETIMES(verify();)
|
|
||||||
if (Settings::use_allocation_guard()) {
|
|
||||||
verify_allocation_guards();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
MemRangeCounter return_counter;
|
MemRangeCounter return_counter;
|
||||||
|
|
||||||
Metachunk* c = _chunks.first();
|
Metachunk* c = _chunks.first();
|
||||||
Metachunk* c2 = nullptr;
|
Metachunk* c2 = nullptr;
|
||||||
|
|
||||||
@ -239,23 +229,6 @@ MetaWord* MetaspaceArena::allocate(size_t requested_word_size) {
|
|||||||
// Primary allocation
|
// Primary allocation
|
||||||
p = allocate_inner(aligned_word_size);
|
p = allocate_inner(aligned_word_size);
|
||||||
|
|
||||||
#ifdef ASSERT
|
|
||||||
// Fence allocation
|
|
||||||
if (p != nullptr && Settings::use_allocation_guard()) {
|
|
||||||
STATIC_ASSERT(is_aligned(sizeof(Fence), BytesPerWord));
|
|
||||||
MetaWord* guard = allocate_inner(sizeof(Fence) / BytesPerWord);
|
|
||||||
if (guard != nullptr) {
|
|
||||||
// Ignore allocation errors for the fence to keep coding simple. If this
|
|
||||||
// happens (e.g. because right at this time we hit the Metaspace GC threshold)
|
|
||||||
// we miss adding this one fence. Not a big deal. Note that his would
|
|
||||||
// be pretty rare. Chances are much higher the primary allocation above
|
|
||||||
// would have already failed).
|
|
||||||
Fence* f = new(guard) Fence(_first_fence);
|
|
||||||
_first_fence = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // ASSERT
|
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,18 +400,6 @@ void MetaspaceArena::verify() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetaspaceArena::Fence::verify() const {
|
|
||||||
assert(_eye1 == EyeCatcher && _eye2 == EyeCatcher,
|
|
||||||
"Metaspace corruption: fence block at " PTR_FORMAT " broken.", p2i(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MetaspaceArena::verify_allocation_guards() const {
|
|
||||||
assert(Settings::use_allocation_guard(), "Don't call with guards disabled.");
|
|
||||||
for (const Fence* f = _first_fence; f != nullptr; f = f->next()) {
|
|
||||||
f->verify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if the area indicated by pointer and size have actually been allocated
|
// Returns true if the area indicated by pointer and size have actually been allocated
|
||||||
// from this arena.
|
// from this arena.
|
||||||
bool MetaspaceArena::is_valid_area(MetaWord* p, size_t word_size) const {
|
bool MetaspaceArena::is_valid_area(MetaWord* p, size_t word_size) const {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright (c) 2020 SAP SE. All rights reserved.
|
* Copyright (c) 2020 SAP SE. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -100,28 +100,6 @@ class MetaspaceArena : public CHeapObj<mtClass> {
|
|||||||
// A name for purely debugging/logging purposes.
|
// A name for purely debugging/logging purposes.
|
||||||
const char* const _name;
|
const char* const _name;
|
||||||
|
|
||||||
#ifdef ASSERT
|
|
||||||
// Allocation guards: When active, arena allocations are interleaved with
|
|
||||||
// fence allocations. An overwritten fence indicates a buffer overrun in either
|
|
||||||
// the preceding or the following user block. All fences are linked together;
|
|
||||||
// validating the fences just means walking that linked list.
|
|
||||||
// Note that for the Arena, fence blocks are just another form of user blocks.
|
|
||||||
class Fence {
|
|
||||||
static const uintx EyeCatcher =
|
|
||||||
NOT_LP64(0x77698465) LP64_ONLY(0x7769846577698465ULL); // "META" resp "METAMETA"
|
|
||||||
// Two eyecatchers to easily spot a corrupted _next pointer
|
|
||||||
const uintx _eye1;
|
|
||||||
const Fence* const _next;
|
|
||||||
NOT_LP64(uintx _dummy;)
|
|
||||||
const uintx _eye2;
|
|
||||||
public:
|
|
||||||
Fence(const Fence* next) : _eye1(EyeCatcher), _next(next), _eye2(EyeCatcher) {}
|
|
||||||
const Fence* next() const { return _next; }
|
|
||||||
void verify() const;
|
|
||||||
};
|
|
||||||
const Fence* _first_fence;
|
|
||||||
#endif // ASSERT
|
|
||||||
|
|
||||||
ChunkManager* chunk_manager() const { return _chunk_manager; }
|
ChunkManager* chunk_manager() const { return _chunk_manager; }
|
||||||
|
|
||||||
// free block list
|
// free block list
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -36,8 +36,6 @@
|
|||||||
|
|
||||||
namespace metaspace {
|
namespace metaspace {
|
||||||
|
|
||||||
DEBUG_ONLY(bool Settings::_use_allocation_guard = false;)
|
|
||||||
|
|
||||||
void Settings::ergo_initialize() {
|
void Settings::ergo_initialize() {
|
||||||
|
|
||||||
// Granules must be a multiple of page size, and a power-2-value.
|
// Granules must be a multiple of page size, and a power-2-value.
|
||||||
@ -46,9 +44,6 @@ void Settings::ergo_initialize() {
|
|||||||
"Granule size must be a page-size-aligned power-of-2 value");
|
"Granule size must be a page-size-aligned power-of-2 value");
|
||||||
assert(commit_granule_words() <= chunklevel::MAX_CHUNK_WORD_SIZE, "Too large granule size");
|
assert(commit_granule_words() <= chunklevel::MAX_CHUNK_WORD_SIZE, "Too large granule size");
|
||||||
|
|
||||||
// Off for release builds, off by default - but switchable - for debug builds.
|
|
||||||
DEBUG_ONLY(_use_allocation_guard = MetaspaceGuardAllocations;)
|
|
||||||
|
|
||||||
LogStream ls(Log(metaspace)::info());
|
LogStream ls(Log(metaspace)::info());
|
||||||
Settings::print_on(&ls);
|
Settings::print_on(&ls);
|
||||||
}
|
}
|
||||||
@ -58,7 +53,6 @@ void Settings::print_on(outputStream* st) {
|
|||||||
st->print_cr(" - commit_granule_words: " SIZE_FORMAT ".", commit_granule_words());
|
st->print_cr(" - commit_granule_words: " SIZE_FORMAT ".", commit_granule_words());
|
||||||
st->print_cr(" - virtual_space_node_default_size: " SIZE_FORMAT ".", virtual_space_node_default_word_size());
|
st->print_cr(" - virtual_space_node_default_size: " SIZE_FORMAT ".", virtual_space_node_default_word_size());
|
||||||
st->print_cr(" - enlarge_chunks_in_place: %d.", (int)enlarge_chunks_in_place());
|
st->print_cr(" - enlarge_chunks_in_place: %d.", (int)enlarge_chunks_in_place());
|
||||||
st->print_cr(" - use_allocation_guard: %d.", (int)use_allocation_guard());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace metaspace
|
} // namespace metaspace
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -56,9 +56,6 @@ class Settings : public AllStatic {
|
|||||||
// the requested size, we attempt to double the chunk size in place...
|
// the requested size, we attempt to double the chunk size in place...
|
||||||
static const bool _enlarge_chunks_in_place = true;
|
static const bool _enlarge_chunks_in_place = true;
|
||||||
|
|
||||||
// If true, metablock allocations are guarded and periodically checked.
|
|
||||||
DEBUG_ONLY(static bool _use_allocation_guard;)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static size_t commit_granule_bytes() { return _commit_granule_bytes; }
|
static size_t commit_granule_bytes() { return _commit_granule_bytes; }
|
||||||
@ -66,7 +63,6 @@ public:
|
|||||||
static size_t virtual_space_node_default_word_size() { return _virtual_space_node_default_word_size; }
|
static size_t virtual_space_node_default_word_size() { return _virtual_space_node_default_word_size; }
|
||||||
static size_t virtual_space_node_reserve_alignment_words() { return _virtual_space_node_reserve_alignment_words; }
|
static size_t virtual_space_node_reserve_alignment_words() { return _virtual_space_node_reserve_alignment_words; }
|
||||||
static bool enlarge_chunks_in_place() { return _enlarge_chunks_in_place; }
|
static bool enlarge_chunks_in_place() { return _enlarge_chunks_in_place; }
|
||||||
static bool use_allocation_guard() { return DEBUG_ONLY(_use_allocation_guard) NOT_DEBUG(false); }
|
|
||||||
|
|
||||||
static void ergo_initialize();
|
static void ergo_initialize();
|
||||||
|
|
||||||
|
@ -1408,9 +1408,6 @@ const int ObjectAlignmentInBytes = 8;
|
|||||||
product(bool, PrintMetaspaceStatisticsAtExit, false, DIAGNOSTIC, \
|
product(bool, PrintMetaspaceStatisticsAtExit, false, DIAGNOSTIC, \
|
||||||
"Print metaspace statistics upon VM exit.") \
|
"Print metaspace statistics upon VM exit.") \
|
||||||
\
|
\
|
||||||
develop(bool, MetaspaceGuardAllocations, false, \
|
|
||||||
"Metapace allocations are guarded.") \
|
|
||||||
\
|
|
||||||
product(uintx, MinHeapFreeRatio, 40, MANAGEABLE, \
|
product(uintx, MinHeapFreeRatio, 40, MANAGEABLE, \
|
||||||
"The minimum percentage of heap free after GC to avoid expansion."\
|
"The minimum percentage of heap free after GC to avoid expansion."\
|
||||||
" For most GCs this applies to the old generation. In G1 and" \
|
" For most GCs this applies to the old generation. In G1 and" \
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2020, 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 "precompiled.hpp"
|
|
||||||
#include "memory/metaspace/metaspaceArena.hpp"
|
|
||||||
#include "memory/metaspace/metaspaceSettings.hpp"
|
|
||||||
#include "memory/metaspace/testHelpers.hpp"
|
|
||||||
#include "utilities/debug.hpp"
|
|
||||||
#include "utilities/ostream.hpp"
|
|
||||||
|
|
||||||
//#define LOG_PLEASE
|
|
||||||
#include "metaspaceGtestCommon.hpp"
|
|
||||||
#include "metaspaceGtestContexts.hpp"
|
|
||||||
|
|
||||||
#ifdef ASSERT
|
|
||||||
|
|
||||||
using metaspace::MetaspaceArena;
|
|
||||||
using metaspace::MetaspaceTestArena;
|
|
||||||
using metaspace::Settings;
|
|
||||||
|
|
||||||
// Test that overwriting memory triggers an assert if allocation guards are enabled.
|
|
||||||
// Note: We use TEST_VM_ASSERT_MSG. However, an assert is only triggered if allocation
|
|
||||||
// guards are enabled; if guards are disabled for the gtests, this test would fail.
|
|
||||||
// So for that case, we trigger a fake assert.
|
|
||||||
TEST_VM_ASSERT_MSG(metaspace, test_overwriter, ".*Metaspace corruption.*") {
|
|
||||||
|
|
||||||
if (Settings::use_allocation_guard()) {
|
|
||||||
MetaspaceGtestContext context;
|
|
||||||
MetaspaceTestArena* arena = context.create_arena(Metaspace::StandardMetaspaceType);
|
|
||||||
// We allocate two blocks. We then write over the end of the first block, which
|
|
||||||
// should corrupt the fence between the two blocks.
|
|
||||||
// Note: there is of course no guarantee that blocks allocated sequentially are neighbors;
|
|
||||||
// but in this case (clean standard-sized test arena and very small allocations) it can
|
|
||||||
// be safely assumed).
|
|
||||||
MetaWord* p1 = arena->allocate(8);
|
|
||||||
MetaWord* p2 = arena->allocate(2);
|
|
||||||
p1[8] = (MetaWord)0x9345; // Overwriter
|
|
||||||
// Now we delete the arena (as happens during class unloading); this will check all
|
|
||||||
// block canaries and should trigger an assert (see MetaspaceArena::verify_allocation_guards()).
|
|
||||||
delete arena;
|
|
||||||
} else {
|
|
||||||
assert(false, "Metaspace corruption - please ignore this, fake message to satisfy tests");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ASSERT
|
|
@ -291,11 +291,6 @@ TEST_VM(metaspace, MetaspaceArena_test_enlarge_in_place_micro_nc) {
|
|||||||
// Here, we give it an ideal policy which should enable the initial chunk to grow unmolested
|
// Here, we give it an ideal policy which should enable the initial chunk to grow unmolested
|
||||||
// until finish.
|
// until finish.
|
||||||
TEST_VM(metaspace, MetaspaceArena_test_enlarge_in_place_2) {
|
TEST_VM(metaspace, MetaspaceArena_test_enlarge_in_place_2) {
|
||||||
|
|
||||||
if (Settings::use_allocation_guard()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: internally, chunk in-place enlargement is disallowed if growing the chunk
|
// Note: internally, chunk in-place enlargement is disallowed if growing the chunk
|
||||||
// would cause the arena to claim more memory than its growth policy allows. This
|
// would cause the arena to claim more memory than its growth policy allows. This
|
||||||
// is done to prevent the arena to grow too fast.
|
// is done to prevent the arena to grow too fast.
|
||||||
@ -337,11 +332,6 @@ TEST_VM(metaspace, MetaspaceArena_test_enlarge_in_place_2) {
|
|||||||
// test that in place enlargement correctly fails if growing the chunk would bring us
|
// test that in place enlargement correctly fails if growing the chunk would bring us
|
||||||
// beyond the max. size of a chunk.
|
// beyond the max. size of a chunk.
|
||||||
TEST_VM(metaspace, MetaspaceArena_test_failing_to_enlarge_in_place_max_chunk_size) {
|
TEST_VM(metaspace, MetaspaceArena_test_failing_to_enlarge_in_place_max_chunk_size) {
|
||||||
|
|
||||||
if (Settings::use_allocation_guard()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MetaspaceGtestContext context;
|
MetaspaceGtestContext context;
|
||||||
|
|
||||||
for (size_t first_allocation_size = 1; first_allocation_size <= MAX_CHUNK_WORD_SIZE / 2; first_allocation_size *= 2) {
|
for (size_t first_allocation_size = 1; first_allocation_size <= MAX_CHUNK_WORD_SIZE / 2; first_allocation_size *= 2) {
|
||||||
@ -372,11 +362,6 @@ TEST_VM(metaspace, MetaspaceArena_test_failing_to_enlarge_in_place_max_chunk_siz
|
|||||||
// test that in place enlargement correctly fails if growing the chunk would cause more
|
// test that in place enlargement correctly fails if growing the chunk would cause more
|
||||||
// than doubling its size
|
// than doubling its size
|
||||||
TEST_VM(metaspace, MetaspaceArena_test_failing_to_enlarge_in_place_doubling_chunk_size) {
|
TEST_VM(metaspace, MetaspaceArena_test_failing_to_enlarge_in_place_doubling_chunk_size) {
|
||||||
|
|
||||||
if (Settings::use_allocation_guard()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MetaspaceGtestContext context;
|
MetaspaceGtestContext context;
|
||||||
MetaspaceArenaTestHelper helper(context, Metaspace::StandardMetaspaceType, false);
|
MetaspaceArenaTestHelper helper(context, Metaspace::StandardMetaspaceType, false);
|
||||||
|
|
||||||
@ -399,9 +384,6 @@ TEST_VM(metaspace, MetaspaceArena_test_failing_to_enlarge_in_place_doubling_chun
|
|||||||
// Allocate, deallocate, then allocate the same block again. The second allocate should
|
// Allocate, deallocate, then allocate the same block again. The second allocate should
|
||||||
// reuse the deallocated block.
|
// reuse the deallocated block.
|
||||||
TEST_VM(metaspace, MetaspaceArena_deallocate) {
|
TEST_VM(metaspace, MetaspaceArena_deallocate) {
|
||||||
if (Settings::use_allocation_guard()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (size_t s = 2; s <= MAX_CHUNK_WORD_SIZE; s *= 2) {
|
for (size_t s = 2; s <= MAX_CHUNK_WORD_SIZE; s *= 2) {
|
||||||
MetaspaceGtestContext context;
|
MetaspaceGtestContext context;
|
||||||
MetaspaceArenaTestHelper helper(context, Metaspace::StandardMetaspaceType, false);
|
MetaspaceArenaTestHelper helper(context, Metaspace::StandardMetaspaceType, false);
|
||||||
@ -505,10 +487,6 @@ static void test_controlled_growth(Metaspace::MetaspaceType type, bool is_class,
|
|||||||
bool test_in_place_enlargement)
|
bool test_in_place_enlargement)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Settings::use_allocation_guard()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// From a MetaspaceArena in a clean room allocate tiny amounts;
|
// From a MetaspaceArena in a clean room allocate tiny amounts;
|
||||||
// watch it grow. Used/committed/capacity should not grow in
|
// watch it grow. Used/committed/capacity should not grow in
|
||||||
// large jumps. Also, different types of MetaspaceArena should
|
// large jumps. Also, different types of MetaspaceArena should
|
||||||
|
@ -106,15 +106,13 @@ class MetaspaceArenaTestBed : public CHeapObj<mtInternal> {
|
|||||||
// - alignment/padding of allocations
|
// - alignment/padding of allocations
|
||||||
// - inside used counter contains blocks in free list
|
// - inside used counter contains blocks in free list
|
||||||
// - free block list splinter threshold
|
// - free block list splinter threshold
|
||||||
// - if +MetaspaceGuardAllocations, guard costs
|
|
||||||
|
|
||||||
// Since what we deallocated may have been given back to us in a following allocation,
|
// Since what we deallocated may have been given back to us in a following allocation,
|
||||||
// we only know fore sure we allocated what we did not give back.
|
// we only know fore sure we allocated what we did not give back.
|
||||||
const size_t at_least_allocated = _alloc_count.total_size() - _dealloc_count.total_size();
|
const size_t at_least_allocated = _alloc_count.total_size() - _dealloc_count.total_size();
|
||||||
|
|
||||||
// At most we allocated this:
|
// At most we allocated this:
|
||||||
const size_t max_word_overhead_per_alloc =
|
constexpr size_t max_word_overhead_per_alloc = 4;
|
||||||
4 + (metaspace::Settings::use_allocation_guard() ? 4 : 0);
|
|
||||||
const size_t at_most_allocated = _alloc_count.total_size() + max_word_overhead_per_alloc * _alloc_count.count();
|
const size_t at_most_allocated = _alloc_count.total_size() + max_word_overhead_per_alloc * _alloc_count.count();
|
||||||
|
|
||||||
ASSERT_LE(at_least_allocated, in_use_stats._used_words - stats._free_blocks_word_size);
|
ASSERT_LE(at_least_allocated, in_use_stats._used_words - stats._free_blocks_word_size);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: This runs the metaspace-related parts of gtest in configurations which
|
* Note: This runs the metaspace-related parts of gtest in configurations which
|
||||||
* are not tested explicitly in the standard gtests.
|
* are not tested explicitly in the standard gtest. Hence, there is no "default-ndebug"
|
||||||
*
|
* since that would be equivalent to the normal gtest for release builds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test id=default-debug
|
/* @test id=default-debug
|
||||||
@ -40,17 +40,7 @@
|
|||||||
* @run main/native GTestWrapper --gtest_filter=metaspace* -XX:+UnlockDiagnosticVMOptions -XX:VerifyMetaspaceInterval=1
|
* @run main/native GTestWrapper --gtest_filter=metaspace* -XX:+UnlockDiagnosticVMOptions -XX:VerifyMetaspaceInterval=1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test id=balanced-with-guards
|
/* @test id=no-ccs
|
||||||
* @summary Run metaspace-related gtests with allocation guards enabled
|
|
||||||
* @library /test/lib
|
|
||||||
* @modules java.base/jdk.internal.misc
|
|
||||||
* java.xml
|
|
||||||
* @requires vm.debug
|
|
||||||
* @requires vm.flagless
|
|
||||||
* @run main/native GTestWrapper --gtest_filter=metaspace* -XX:VerifyMetaspaceInterval=1 -XX:+MetaspaceGuardAllocations
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* @test id=balanced-no-ccs
|
|
||||||
* @summary Run metaspace-related gtests with compressed class pointers off
|
* @summary Run metaspace-related gtests with compressed class pointers off
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright (c) 2018, SAP and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, SAP and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -36,17 +36,6 @@ import jdk.test.lib.JDKToolFinder;
|
|||||||
* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers PrintMetaspaceDcmd
|
* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers PrintMetaspaceDcmd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* @test id=test-64bit-ccs-guarded
|
|
||||||
* @summary Test the VM.metaspace command
|
|
||||||
* @requires vm.bits == "64"
|
|
||||||
* @requires vm.debug == true
|
|
||||||
* @library /test/lib
|
|
||||||
* @modules java.base/jdk.internal.misc
|
|
||||||
* java.management
|
|
||||||
* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UnlockDiagnosticVMOptions -XX:+MetaspaceGuardAllocations PrintMetaspaceDcmd
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test id=test-64bit-noccs
|
* @test id=test-64bit-noccs
|
||||||
* @summary Test the VM.metaspace command
|
* @summary Test the VM.metaspace command
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -195,17 +195,11 @@ public class MetaspaceTestContext {
|
|||||||
// - whatever we allocated
|
// - whatever we allocated
|
||||||
// - deallocated blocks in fbl
|
// - deallocated blocks in fbl
|
||||||
// - remains of retired chunks in fbl
|
// - remains of retired chunks in fbl
|
||||||
// - overhead per allocation (padding for alignment, possibly allocation guards)
|
// - overhead per allocation (padding for alignment)
|
||||||
|
|
||||||
// Overhead per allocation (see metaspaceArena.cpp, get_raw_allocation_word_size() )
|
// Overhead per allocation (see metaspaceArena.cpp, get_raw_allocation_word_size() )
|
||||||
// Any allocation is 3 words least
|
// Any allocation is 3 words least
|
||||||
expectedMaxUsage += (numAllocated * 3);
|
expectedMaxUsage += (numAllocated * 3);
|
||||||
if (Settings.settings().usesAllocationGuards) {
|
|
||||||
// Guards need space.
|
|
||||||
expectedMaxUsage += (numAllocated * 2);
|
|
||||||
// Also, they disable the fbl, so deallocated still counts as used.
|
|
||||||
expectedMaxUsage += deallocatedWords;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lets add a overhead per arena. Each arena carries a free block list containing
|
// Lets add a overhead per arena. Each arena carries a free block list containing
|
||||||
// deallocated/retired blocks. We do not know how much. In general, the free block list should not
|
// deallocated/retired blocks. We do not know how much. In general, the free block list should not
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright (c) 2020 SAP SE. All rights reserved.
|
* Copyright (c) 2020 SAP SE. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
@ -27,8 +27,6 @@ import jdk.test.whitebox.WhiteBox;
|
|||||||
|
|
||||||
public final class Settings {
|
public final class Settings {
|
||||||
|
|
||||||
public boolean usesAllocationGuards = WhiteBox.getWhiteBox().getBooleanVMFlag("MetaspaceGuardAllocations");
|
|
||||||
|
|
||||||
final static long rootChunkWordSize = 2048 * 1024;
|
final static long rootChunkWordSize = 2048 * 1024;
|
||||||
|
|
||||||
static Settings theSettings;
|
static Settings theSettings;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -27,30 +27,22 @@
|
|||||||
* @test id=debug
|
* @test id=debug
|
||||||
* @bug 8251158
|
* @bug 8251158
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc java.management
|
||||||
* java.management
|
|
||||||
* @build jdk.test.whitebox.WhiteBox
|
* @build jdk.test.whitebox.WhiteBox
|
||||||
* @requires (vm.debug == true)
|
* @requires (vm.debug == true)
|
||||||
*
|
|
||||||
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
||||||
*
|
|
||||||
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:VerifyMetaspaceInterval=10 TestMetaspaceAllocation
|
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:VerifyMetaspaceInterval=10 TestMetaspaceAllocation
|
||||||
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:VerifyMetaspaceInterval=10 -XX:+MetaspaceGuardAllocations TestMetaspaceAllocation
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test id=ndebug
|
* @test id=ndebug
|
||||||
* @bug 8251158
|
* @bug 8251158
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc java.management
|
||||||
* java.management
|
|
||||||
* @build jdk.test.whitebox.WhiteBox
|
* @build jdk.test.whitebox.WhiteBox
|
||||||
* @requires (vm.debug == false)
|
* @requires (vm.debug == false)
|
||||||
*
|
|
||||||
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
||||||
*
|
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestMetaspaceAllocation
|
||||||
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestMetaspaceAllocation
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TestMetaspaceAllocation {
|
public class TestMetaspaceAllocation {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -58,7 +58,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test id=debug-default-strict
|
* @test id=debug-default-long-manual
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc
|
||||||
* java.management
|
* java.management
|
||||||
@ -74,24 +74,6 @@
|
|||||||
* TestMetaspaceAllocationMT1 10
|
* TestMetaspaceAllocationMT1 10
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* @test id=debug-guard
|
|
||||||
* @library /test/lib
|
|
||||||
* @modules java.base/jdk.internal.misc
|
|
||||||
* java.management
|
|
||||||
* @build jdk.test.whitebox.WhiteBox
|
|
||||||
* @key randomness
|
|
||||||
* @requires (vm.debug == true)
|
|
||||||
*
|
|
||||||
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
|
||||||
*
|
|
||||||
* @run main/othervm/timeout=400
|
|
||||||
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
|
|
||||||
* -XX:VerifyMetaspaceInterval=10
|
|
||||||
* -XX:+MetaspaceGuardAllocations
|
|
||||||
* TestMetaspaceAllocationMT1 3
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test id=ndebug-default
|
* @test id=ndebug-default
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
@ -130,7 +112,6 @@ public class TestMetaspaceAllocationMT1 {
|
|||||||
System.out.println("#### seconds: " + seconds);
|
System.out.println("#### seconds: " + seconds);
|
||||||
System.out.println("#### commitLimit: " + commitLimit);
|
System.out.println("#### commitLimit: " + commitLimit);
|
||||||
System.out.println("#### reserveLimit: " + reserveLimit);
|
System.out.println("#### reserveLimit: " + reserveLimit);
|
||||||
System.out.println("#### guards: " + Settings.settings().usesAllocationGuards);
|
|
||||||
|
|
||||||
MetaspaceTestContext context = new MetaspaceTestContext(commitLimit, reserveLimit);
|
MetaspaceTestContext context = new MetaspaceTestContext(commitLimit, reserveLimit);
|
||||||
MetaspaceTestOneArenaManyThreads test = new MetaspaceTestOneArenaManyThreads(context, testAllocationCeiling, numThreads, seconds);
|
MetaspaceTestOneArenaManyThreads test = new MetaspaceTestOneArenaManyThreads(context, testAllocationCeiling, numThreads, seconds);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -58,7 +58,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test id=debug-default-strict
|
* @test id=debug-default-long-manual
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc
|
||||||
* java.management
|
* java.management
|
||||||
@ -74,24 +74,6 @@
|
|||||||
* TestMetaspaceAllocationMT2 10
|
* TestMetaspaceAllocationMT2 10
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* @test id=debug-guard
|
|
||||||
* @library /test/lib
|
|
||||||
* @modules java.base/jdk.internal.misc
|
|
||||||
* java.management
|
|
||||||
* @build jdk.test.whitebox.WhiteBox
|
|
||||||
* @key randomness
|
|
||||||
* @requires (vm.debug == true)
|
|
||||||
*
|
|
||||||
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
|
||||||
*
|
|
||||||
* @run main/othervm/timeout=400
|
|
||||||
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
|
|
||||||
* -XX:VerifyMetaspaceInterval=10
|
|
||||||
* -XX:+MetaspaceGuardAllocations
|
|
||||||
* TestMetaspaceAllocationMT2 3
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test id=ndebug-default
|
* @test id=ndebug-default
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
@ -129,7 +111,6 @@ public class TestMetaspaceAllocationMT2 {
|
|||||||
System.out.println("#### seconds: " + seconds);
|
System.out.println("#### seconds: " + seconds);
|
||||||
System.out.println("#### commitLimit: " + commitLimit);
|
System.out.println("#### commitLimit: " + commitLimit);
|
||||||
System.out.println("#### reserveLimit: " + reserveLimit);
|
System.out.println("#### reserveLimit: " + reserveLimit);
|
||||||
System.out.println("#### guards: " + Settings.settings().usesAllocationGuards);
|
|
||||||
|
|
||||||
MetaspaceTestContext context = new MetaspaceTestContext(commitLimit, reserveLimit);
|
MetaspaceTestContext context = new MetaspaceTestContext(commitLimit, reserveLimit);
|
||||||
MetaspaceTestManyArenasManyThreads test = new MetaspaceTestManyArenasManyThreads(context, testAllocationCeiling, numThreads, seconds);
|
MetaspaceTestManyArenasManyThreads test = new MetaspaceTestManyArenasManyThreads(context, testAllocationCeiling, numThreads, seconds);
|
||||||
|
Loading…
Reference in New Issue
Block a user