< prev index next >
test/hotspot/gtest/metaspace/test_chunkManager_stress.cpp
Print this page
rev 60811 : imported patch jep387-all.patch
rev 60812 : [mq]: diff1
*** 1,8 ****
/*
! * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
! * Copyright (c) 2018, 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.
--- 1,8 ----
/*
! * 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.
*** 23,44 ****
*
*/
#include "precompiled.hpp"
//#define LOG_PLEASE
- #include "metaspace/metaspace_sparsearray.hpp"
- #include "metaspace/metaspaceTestsCommon.hpp"
- #include "metaspace/metaspaceTestContexts.hpp"
class ChunkManagerRandomChunkAllocTest {
static const size_t max_footprint_words = 8 * M;
! ChunkTestsContext _helper;
// All allocated live chunks
typedef SparseArray<Metachunk*> SparseArrayOfChunks;
SparseArrayOfChunks _chunks;
--- 23,51 ----
*
*/
#include "precompiled.hpp"
+ #include "memory/metaspace/msChunkManager.hpp"
+ #include "memory/metaspace/msSettings.hpp"
+ #include "memory/metaspace/msVirtualSpaceList.hpp"
+
//#define LOG_PLEASE
+ #include "metaspaceGtestCommon.hpp"
+ #include "metaspaceGtestContexts.hpp"
+ #include "metaspaceGtestRangeHelpers.hpp"
+ #include "metaspaceGtestSparseArray.hpp"
+ using metaspace::ChunkManager;
+ using metaspace::Settings;
class ChunkManagerRandomChunkAllocTest {
static const size_t max_footprint_words = 8 * M;
! ChunkGtestContext _context;
// All allocated live chunks
typedef SparseArray<Metachunk*> SparseArrayOfChunks;
SparseArrayOfChunks _chunks;
*** 57,67 ****
return max_chunks;
}
// Return true if, after an allocation error happened, a reserve error seems likely.
bool could_be_reserve_error() {
! return _helper.vslist().is_full();
}
// Return true if, after an allocation error happened, a commit error seems likely.
bool could_be_commit_error(size_t additional_word_size) {
--- 64,74 ----
return max_chunks;
}
// Return true if, after an allocation error happened, a reserve error seems likely.
bool could_be_reserve_error() {
! return _context.vslist().is_full();
}
// Return true if, after an allocation error happened, a commit error seems likely.
bool could_be_commit_error(size_t additional_word_size) {
*** 82,95 ****
// (a) and (b) should be precisely in sync. This is tested by
// VirtualSpaceList::verify().
// (c) can be, by design, imprecise (too low).
//
// Here, I check (b) and trust it to be correct. We also call vslist::verify().
! DEBUG_ONLY(_helper.verify();)
const size_t commit_add = align_up(additional_word_size, Settings::commit_granule_words());
! if (_helper.commit_limit() <= (commit_add + _helper.vslist().committed_words())) {
return true;
}
return false;
--- 89,102 ----
// (a) and (b) should be precisely in sync. This is tested by
// VirtualSpaceList::verify().
// (c) can be, by design, imprecise (too low).
//
// Here, I check (b) and trust it to be correct. We also call vslist::verify().
! DEBUG_ONLY(_context.verify();)
const size_t commit_add = align_up(additional_word_size, Settings::commit_granule_words());
! if (_context.commit_limit() <= (commit_add + _context.vslist().committed_words())) {
return true;
}
return false;
*** 102,112 ****
return 0;
}
return MIN2(SizeRange(sz).random_value(), sz);
}
-
//// Chunk allocation ////
// Given an slot index, allocate a random chunk and set it into that slot. Slot must be empty.
// Returns false if allocation fails.
bool allocate_random_chunk_at(int slot) {
--- 109,118 ----
*** 117,127 ****
const chunklevel_t pref_level = r.lowest();
const chunklevel_t max_level = r.highest();
const size_t min_committed = random_committed_words(max_level, _commit_factor);
Metachunk* c = NULL;
! _helper.alloc_chunk(&c, r.lowest(), r.highest(), min_committed);
if (c == NULL) {
EXPECT_TRUE(could_be_reserve_error() ||
could_be_commit_error(min_committed));
LOG("Alloc chunk at %d failed.", slot);
return false;
--- 123,133 ----
const chunklevel_t pref_level = r.lowest();
const chunklevel_t max_level = r.highest();
const size_t min_committed = random_committed_words(max_level, _commit_factor);
Metachunk* c = NULL;
! _context.alloc_chunk(&c, r.lowest(), r.highest(), min_committed);
if (c == NULL) {
EXPECT_TRUE(could_be_reserve_error() ||
could_be_commit_error(min_committed));
LOG("Alloc chunk at %d failed.", slot);
return false;
*** 161,171 ****
// Given an slot index, return the chunk in that slot to the chunk manager.
void return_chunk_at(int slot) {
Metachunk* c = _chunks.at(slot);
LOG("Returning chunk at %d: " METACHUNK_FORMAT ".", slot, METACHUNK_FORMAT_ARGS(c));
! _helper.return_chunk(c);
_chunks.set_at(slot, NULL);
}
// return a random number of chunks (at most a quarter of the full slot range)
void return_random_chunks() {
--- 167,177 ----
// Given an slot index, return the chunk in that slot to the chunk manager.
void return_chunk_at(int slot) {
Metachunk* c = _chunks.at(slot);
LOG("Returning chunk at %d: " METACHUNK_FORMAT ".", slot, METACHUNK_FORMAT_ARGS(c));
! _context.return_chunk(c);
_chunks.set_at(slot, NULL);
}
// return a random number of chunks (at most a quarter of the full slot range)
void return_random_chunks() {
*** 194,204 ****
fill_all_slots_with_random_chunks();
_chunks.shuffle();
IntRange rand(100);
! for (int j = 0; j < 1000; j ++) {
bool force_alloc = false;
bool force_free = true;
bool do_alloc =
--- 200,210 ----
fill_all_slots_with_random_chunks();
_chunks.shuffle();
IntRange rand(100);
! for (int j = 0; j < 1000; j++) {
bool force_alloc = false;
bool force_free = true;
bool do_alloc =
*** 220,244 ****
return_all_chunks();
}
-
public:
// A test with no limits
ChunkManagerRandomChunkAllocTest(ChunkLevelRange r, float commit_factor)
! : _helper(),
_chunks(max_num_live_chunks(r, commit_factor)),
_chunklevel_range(r),
_commit_factor(commit_factor)
{}
// A test with no reserve limit but commit limit
ChunkManagerRandomChunkAllocTest(size_t commit_limit,
ChunkLevelRange r, float commit_factor)
! : _helper(commit_limit),
_chunks(max_num_live_chunks(r, commit_factor)),
_chunklevel_range(r),
_commit_factor(commit_factor)
{}
--- 226,249 ----
return_all_chunks();
}
public:
// A test with no limits
ChunkManagerRandomChunkAllocTest(ChunkLevelRange r, float commit_factor)
! : _context(),
_chunks(max_num_live_chunks(r, commit_factor)),
_chunklevel_range(r),
_commit_factor(commit_factor)
{}
// A test with no reserve limit but commit limit
ChunkManagerRandomChunkAllocTest(size_t commit_limit,
ChunkLevelRange r, float commit_factor)
! : _context(commit_limit),
_chunks(max_num_live_chunks(r, commit_factor)),
_chunklevel_range(r),
_commit_factor(commit_factor)
{}
*** 249,262 ****
// _chunks(max_num_live_chunks(r, commit_factor)),
// _chunklevel_range(r),
// _commit_factor(commit_factor)
// {}
-
void do_tests() {
const int num_runs = 5;
! for (int n = 0; n < num_runs; n ++) {
one_test();
}
}
};
--- 254,266 ----
// _chunks(max_num_live_chunks(r, commit_factor)),
// _chunklevel_range(r),
// _commit_factor(commit_factor)
// {}
void do_tests() {
const int num_runs = 5;
! for (int n = 0; n < num_runs; n++) {
one_test();
}
}
};
*** 288,293 ****
DEFINE_TEST_2(test_with_limit_4, ChunkLevelRanges::all_chunks(), 0.0f)
DEFINE_TEST_2(test_with_limit_5, ChunkLevelRanges::all_chunks(), 0.5f)
DEFINE_TEST_2(test_with_limit_6, ChunkLevelRanges::all_chunks(), 1.0f)
-
--- 292,296 ----
< prev index next >