1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2020 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 /* 27 * This is a stress test for allocating from a single MetaspaceArena from 28 * multiple threads, optionally with reserve limit (mimicking the non-expandable CompressedClassSpace) 29 * or commit limit (mimimcking MaxMetaspaceSize). 30 * 31 * The test threads will start to allocate from the Arena, and occasionally deallocate. 32 * The threads run with a safety allocation max; if reached (or, if the underlying arena 33 * hits either commit or reserve limit, if given) they will switch to deallocation and then 34 * kind of float at the allocation ceiling, alternating between allocation and deallocation. 35 * 36 * We test with various flags, to exercise all 3 reclaim policies (none, balanced (default) 37 * and aggessive) as well as one run with allocation guards enabled. 38 * 39 * We also set MetaspaceVerifyInterval very low to trigger many verifications in debug vm. 40 * 41 */ 42 43 /* 44 * @test id=debug 45 * @library /test/lib 46 * @modules java.base/jdk.internal.misc 47 * java.management 48 * @build sun.hotspot.WhiteBox 49 * @key randomness 50 * @requires (vm.debug == true) 51 * 52 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 53 * 54 * @run main/othervm/timeout=400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:VerifyMetaspaceInterval=10 TestMetaspaceAllocationMT2 55 * @run main/othervm/timeout=400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:VerifyMetaspaceInterval=10 -XX:MetaspaceReclaimPolicy=none TestMetaspaceAllocationMT2 56 * @run main/othervm/timeout=400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:VerifyMetaspaceInterval=10 -XX:MetaspaceReclaimPolicy=aggressive TestMetaspaceAllocationMT2 57 * @run main/othervm/timeout=400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:VerifyMetaspaceInterval=10 -XX:+MetaspaceGuardAllocations TestMetaspaceAllocationMT2 58 * 59 */ 60 61 /* 62 * @test id=ndebug 63 * @library /test/lib 64 * @modules java.base/jdk.internal.misc 65 * java.management 66 * @build sun.hotspot.WhiteBox 67 * @key randomness 68 * @requires (vm.debug == false) 69 * 70 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 71 * 72 * @run main/othervm/timeout=400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestMetaspaceAllocationMT2 73 * @run main/othervm/timeout=400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:MetaspaceReclaimPolicy=none TestMetaspaceAllocationMT2 74 * @run main/othervm/timeout=400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:MetaspaceReclaimPolicy=aggressive TestMetaspaceAllocationMT2 75 */ 76 77 public class TestMetaspaceAllocationMT2 { 78 79 public static void main(String[] args) throws Exception { 80 81 final long testAllocationCeiling = 1024 * 1024 * 6; // 8m words = 64M on 64bit 82 final int numThreads = 4; 83 final int seconds = 10; 84 85 for (int i = 0; i < 3; i ++) { 86 87 long commitLimit = (i == 1) ? 1024 * 256 : 0; 88 89 // Note: reserve limit must be a multiple of Metaspace::reserve_alignment_words() 90 // (512 K) 91 long reserveLimit = (i == 2) ? 1024 * 512 : 0; 92 93 System.out.println("#### Test: "); 94 System.out.println("#### testAllocationCeiling: " + testAllocationCeiling); 95 System.out.println("#### numThreads: " + numThreads); 96 System.out.println("#### seconds: " + seconds); 97 System.out.println("#### commitLimit: " + commitLimit); 98 System.out.println("#### reserveLimit: " + reserveLimit); 99 System.out.println("#### ReclaimPolicy: " + Settings.settings().reclaimPolicy); 100 System.out.println("#### guards: " + Settings.settings().usesAllocationGuards); 101 102 MetaspaceTestContext context = new MetaspaceTestContext(commitLimit, reserveLimit); 103 MetaspaceTestManyArenasManyThreads test = new MetaspaceTestManyArenasManyThreads(context, testAllocationCeiling, numThreads, seconds); 104 105 try { 106 test.runTest(); 107 } catch (RuntimeException e) { 108 System.out.println(e); 109 context.printToTTY(); 110 throw e; 111 } 112 113 context.destroy(); 114 115 System.out.println("#### Done. ####"); 116 System.out.println("###############"); 117 118 } 119 120 } 121 122 } 123