Path: blob/master/test/hotspot/jtreg/runtime/Metaspace/elastic/MetaspaceTestWithThreads.java
41155 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425import java.util.Set;2627public class MetaspaceTestWithThreads {2829// The context to use.30final MetaspaceTestContext context;3132// Total *word* size we allow for the test to allocation. The test may overshoot this a bit, but should not by much.33final long testAllocationCeiling;3435// Number of parallel allocators36final int numThreads;3738// Number of seconds for each test39final int seconds;4041RandomAllocatorThread threads[];4243public MetaspaceTestWithThreads(MetaspaceTestContext context, long testAllocationCeiling, int numThreads, int seconds) {44this.context = context;45this.testAllocationCeiling = testAllocationCeiling;46this.numThreads = numThreads;47this.seconds = seconds;48this.threads = new RandomAllocatorThread[numThreads];49}5051protected void stopAllThreads() throws InterruptedException {52// Stop all threads.53for (Thread t: threads) {54t.interrupt();55t.join();56}57}5859void destroyArenasAndPurgeSpace() {6061for (RandomAllocatorThread t: threads) {62if (t.allocator.arena.isLive()) {63context.destroyArena(t.allocator.arena);64}65}6667context.checkStatistics();6869// After deleting all arenas, we should have no committed space left: all arena chunks have been returned to70// the freelist amd should have been maximally merged to a bunch of root chunks, which should be uncommitted71// in one go.72// Exception: if reclamation policy is none.73if (Settings.settings().doesReclaim()) {74if (context.committedWords() > 0) {75throw new RuntimeException("Expected no committed words after purging empty metaspace context (was: " + context.committedWords() + ")");76}77}7879context.purge();8081context.checkStatistics();8283// After purging - if all arenas had been deleted before - we should have no committed space left even in84// recmalation=none mode:85// purging deletes all nodes with only free chunks, and in this case no node should still house in-use chunks,86// so all nodes would have been unmapped.87// This is independent on reclamation policy. Only one exception: if the area was created with a reserve limit88// (mimicking compressed class space), the underlying virtual space list cannot be purged.89if (context.reserveLimit == 0) {90if (context.committedWords() > 0) {91throw new RuntimeException("Expected no committed words after purging empty metaspace context (was: " + context.committedWords() + ")");92}93}9495}9697@Override98public String toString() {99return "commitLimit=" + context.commitLimit +100", reserveLimit=" + context.reserveLimit +101", testAllocationCeiling=" + testAllocationCeiling +102", num_allocators=" + numThreads +103", seconds=" + seconds;104}105106}107108109