1 /* 2 * Copyright (c) 2018, Red Hat, Inc. 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 it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 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 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import jdk.test.lib.*; 25 import jdk.test.lib.process.*; 26 27 /* 28 * @test TestAbortOnVMOperationTimeout 29 * @bug 8181143 30 * @summary Check abort on VM timeout is working 31 * @library /test/lib 32 * @modules java.base/jdk.internal.misc 33 * java.management 34 * @run driver TestAbortOnVMOperationTimeout 35 */ 36 37 public class TestAbortOnVMOperationTimeout { 38 39 public static void main(String[] args) throws Exception { 40 if (args.length > 0) { 41 Object[] arr = new Object[10_000_000]; 42 for (int i = 0; i < arr.length; i++) { 43 arr[i] = new Object(); 44 } 45 return; 46 } 47 48 // These should definitely pass: more than a minute is enough for Serial to act. 49 // The values are deliberately non-round to trip off periodic task granularity. 50 for (int delay : new int[]{63423, 12388131}) { 51 testWith(delay, true); 52 } 53 54 // These should fail: Serial is not very fast. Traversing 10M objects in 5 ms 55 // means less than 0.5 ns per object, which is not doable. 56 for (int delay : new int[]{0, 1, 5}) { 57 testWith(delay, false); 58 } 59 } 60 61 public static void testWith(int delay, boolean shouldPass) throws Exception { 62 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 63 "-XX:+UnlockDiagnosticVMOptions", 64 "-XX:+AbortVMOnVMOperationTimeout", 65 "-XX:AbortVMOnVMOperationTimeoutDelay=" + delay, 66 "-Xmx256m", 67 "-XX:+UseSerialGC", 68 "-XX:-CreateCoredumpOnCrash", 69 "TestAbortOnVMOperationTimeout", 70 "foo" 71 ); 72 73 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 74 if (shouldPass) { 75 output.shouldHaveExitValue(0); 76 } else { 77 output.shouldMatch("VM operation took too long"); 78 output.shouldNotHaveExitValue(0); 79 } 80 } 81 } 82