2018-12-13 15:45:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018, Red Hat, Inc. 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.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import jdk.test.lib.*;
|
|
|
|
import jdk.test.lib.process.*;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test TestAbortOnVMOperationTimeout
|
2023-05-11 18:21:30 +00:00
|
|
|
* @bug 8181143 8269523 8307653
|
2018-12-13 15:45:24 +00:00
|
|
|
* @summary Check abort on VM timeout is working
|
2021-08-04 19:46:13 +00:00
|
|
|
* @requires vm.flagless
|
2018-12-13 15:45:24 +00:00
|
|
|
* @library /test/lib
|
|
|
|
* @modules java.base/jdk.internal.misc
|
|
|
|
* java.management
|
2020-04-30 02:51:45 +00:00
|
|
|
* @run driver TestAbortOnVMOperationTimeout
|
2018-12-13 15:45:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class TestAbortOnVMOperationTimeout {
|
|
|
|
|
2021-07-30 04:03:11 +00:00
|
|
|
// A static array is unlikely to be optimised away by the JIT.
|
|
|
|
static Object[] arr;
|
|
|
|
|
2018-12-13 15:45:24 +00:00
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
if (args.length > 0) {
|
2021-07-30 04:03:11 +00:00
|
|
|
arr = new Object[10_000_000];
|
2018-12-13 15:45:24 +00:00
|
|
|
for (int i = 0; i < arr.length; i++) {
|
|
|
|
arr[i] = new Object();
|
|
|
|
}
|
2021-07-30 04:03:11 +00:00
|
|
|
// Try to force at least one full GC cycle.
|
|
|
|
System.gc();
|
2018-12-13 15:45:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:21:30 +00:00
|
|
|
// This should definitely pass: more than 3 minutes is enough for Serial to act.
|
|
|
|
// The value is deliberately non-round to trip off periodic task granularity.
|
|
|
|
testWith(183423, true);
|
2018-12-13 15:45:24 +00:00
|
|
|
|
2021-07-30 04:03:11 +00:00
|
|
|
// These should fail: Serial is not very fast but we have seen the test
|
|
|
|
// execute as quickly as 2ms!
|
|
|
|
for (int delay : new int[]{0, 1}) {
|
2018-12-13 15:45:24 +00:00
|
|
|
testWith(delay, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void testWith(int delay, boolean shouldPass) throws Exception {
|
2023-10-27 08:47:26 +00:00
|
|
|
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
|
2018-12-13 15:45:24 +00:00
|
|
|
"-XX:+UnlockDiagnosticVMOptions",
|
|
|
|
"-XX:+AbortVMOnVMOperationTimeout",
|
|
|
|
"-XX:AbortVMOnVMOperationTimeoutDelay=" + delay,
|
|
|
|
"-Xmx256m",
|
|
|
|
"-XX:+UseSerialGC",
|
|
|
|
"-XX:-CreateCoredumpOnCrash",
|
2023-05-11 18:21:30 +00:00
|
|
|
"-Xlog:gc*=info",
|
2018-12-13 15:45:24 +00:00
|
|
|
"TestAbortOnVMOperationTimeout",
|
|
|
|
"foo"
|
|
|
|
);
|
|
|
|
|
|
|
|
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
|
|
|
if (shouldPass) {
|
|
|
|
output.shouldHaveExitValue(0);
|
|
|
|
} else {
|
2021-07-27 23:20:19 +00:00
|
|
|
output.shouldContain("VM operation took too long");
|
2018-12-13 15:45:24 +00:00
|
|
|
output.shouldNotHaveExitValue(0);
|
|
|
|
}
|
2021-07-30 04:03:11 +00:00
|
|
|
output.reportDiagnosticSummary();
|
2018-12-13 15:45:24 +00:00
|
|
|
}
|
|
|
|
}
|