Path: blob/master/test/hotspot/jtreg/runtime/Metaspace/elastic/TestMetaspaceAllocationMT2.java
41155 views
/*1* Copyright (c) 2020, 2021, 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*/2425/*26* This is a stress test for allocating from a single MetaspaceArena from27* multiple threads, optionally with reserve limit (mimicking the non-expandable CompressedClassSpace)28* or commit limit (mimimcking MaxMetaspaceSize).29*30* The test threads will start to allocate from the Arena, and occasionally deallocate.31* The threads run with a safety allocation max; if reached (or, if the underlying arena32* hits either commit or reserve limit, if given) they will switch to deallocation and then33* kind of float at the allocation ceiling, alternating between allocation and deallocation.34*35* We test with various flags, to exercise all 3 reclaim policies (none, balanced (default)36* and aggessive) as well as one run with allocation guards enabled.37*38* We also set MetaspaceVerifyInterval very low to trigger many verifications in debug vm.39*40*/4142/*43* @test id=debug-default44* @library /test/lib45* @modules java.base/jdk.internal.misc46* java.management47* @build sun.hotspot.WhiteBox48* @key randomness49* @requires (vm.debug == true)50*51* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox52*53* @run main/othervm/timeout=40054* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI55* -XX:VerifyMetaspaceInterval=1056* TestMetaspaceAllocationMT257*/5859/*60* @test id=debug-none61* @library /test/lib62* @modules java.base/jdk.internal.misc63* java.management64* @build sun.hotspot.WhiteBox65* @key randomness66* @requires (vm.debug == true)67*68* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox69*70* @run main/othervm/timeout=40071* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI72* -XX:VerifyMetaspaceInterval=1073* -XX:MetaspaceReclaimPolicy=none74* TestMetaspaceAllocationMT275*/7677/*78* @test id=debug-aggressive79* @library /test/lib80* @modules java.base/jdk.internal.misc81* java.management82* @build sun.hotspot.WhiteBox83* @key randomness84* @requires (vm.debug == true)85*86* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox87*88* @run main/othervm/timeout=40089* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI90* -XX:VerifyMetaspaceInterval=1091* -XX:MetaspaceReclaimPolicy=aggressive92* TestMetaspaceAllocationMT293*/9495/*96* @test id=debug-guard97* @library /test/lib98* @modules java.base/jdk.internal.misc99* java.management100* @build sun.hotspot.WhiteBox101* @key randomness102* @requires (vm.debug == true)103*104* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox105*106* @run main/othervm/timeout=400107* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI108* -XX:VerifyMetaspaceInterval=10109* -XX:+MetaspaceGuardAllocations110* TestMetaspaceAllocationMT2111*/112113/*114* @test id=ndebug-default115* @library /test/lib116* @modules java.base/jdk.internal.misc117* java.management118* @build sun.hotspot.WhiteBox119* @key randomness120* @requires (vm.debug == false)121*122* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox123*124* @run main/othervm/timeout=400125* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI126* TestMetaspaceAllocationMT2127*/128129/*130* @test id=ndebug-none131* @library /test/lib132* @modules java.base/jdk.internal.misc133* java.management134* @build sun.hotspot.WhiteBox135* @key randomness136* @requires (vm.debug == false)137*138* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox139*140* @run main/othervm/timeout=400141* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI142* -XX:MetaspaceReclaimPolicy=none143* TestMetaspaceAllocationMT2144*/145146/*147* @test id=ndebug-aggressive148* @library /test/lib149* @modules java.base/jdk.internal.misc150* java.management151* @build sun.hotspot.WhiteBox152* @key randomness153* @requires (vm.debug == false)154*155* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox156*157* @run main/othervm/timeout=400158* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI159* -XX:MetaspaceReclaimPolicy=aggressive160* TestMetaspaceAllocationMT2161*/162163public class TestMetaspaceAllocationMT2 {164165public static void main(String[] args) throws Exception {166167final long testAllocationCeiling = 1024 * 1024 * 6; // 8m words = 64M on 64bit168final int numThreads = 4;169final int seconds = 10;170171for (int i = 0; i < 3; i ++) {172173long commitLimit = (i == 1) ? 1024 * 256 : 0;174175// Note: reserve limit must be a multiple of Metaspace::reserve_alignment_words()176// (512K on 64bit, 1M on 32bit)177long reserveLimit = (i == 2) ? 1024 * 1024 : 0;178179System.out.println("#### Test: ");180System.out.println("#### testAllocationCeiling: " + testAllocationCeiling);181System.out.println("#### numThreads: " + numThreads);182System.out.println("#### seconds: " + seconds);183System.out.println("#### commitLimit: " + commitLimit);184System.out.println("#### reserveLimit: " + reserveLimit);185System.out.println("#### ReclaimPolicy: " + Settings.settings().reclaimPolicy);186System.out.println("#### guards: " + Settings.settings().usesAllocationGuards);187188MetaspaceTestContext context = new MetaspaceTestContext(commitLimit, reserveLimit);189MetaspaceTestManyArenasManyThreads test = new MetaspaceTestManyArenasManyThreads(context, testAllocationCeiling, numThreads, seconds);190191try {192test.runTest();193} catch (RuntimeException e) {194System.out.println(e);195context.printToTTY();196throw e;197}198199context.destroy();200201System.out.println("#### Done. ####");202System.out.println("###############");203204}205206}207208}209210211212