< prev index next >

test/hotspot/jtreg/runtime/Safepoint/TestAbortVMOnSafepointTimeout.java

Print this page




  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 TestAbortVMOnSafepointTimeout
  29  * @summary Check if VM can kill thread which doesn't reach safepoint.
  30  * @bug 8219584
  31  * @requires vm.compiler2.enabled
  32  * @library /test/lib
  33  * @modules java.base/jdk.internal.misc
  34  *          java.management
  35  */
  36 
  37 public class TestAbortVMOnSafepointTimeout {
  38 
  39     public static void main(String[] args) throws Exception {
  40         if (args.length > 0) {
  41             int result = test_loop(3);
  42             System.out.println("This message would occur after some time with result " + result);
  43             return;
  44         }
  45 
  46         testWith(500, 500);
  47     }
  48 
  49     static int test_loop(int x) {
  50         int sum = 0;
  51         if (x != 0) {
  52             // Long running loop without safepoint.
  53             for (int y = 1; y < Integer.MAX_VALUE; ++y) {
  54                 if (y % x == 0) ++sum;
  55             }
  56         }
  57         return sum;
  58     }
  59 
  60     public static void testWith(int sfpt_interval, int timeout_delay) throws Exception {







  61         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  62                 "-XX:+UnlockDiagnosticVMOptions",

  63                 "-XX:+SafepointTimeout",
  64                 "-XX:+SafepointALot",
  65                 "-XX:+AbortVMOnSafepointTimeout",
  66                 "-XX:SafepointTimeoutDelay=" + timeout_delay,
  67                 "-XX:GuaranteedSafepointInterval=" + sfpt_interval,
  68                 "-XX:-TieredCompilation",
  69                 "-XX:-UseCountedLoopSafepoints",
  70                 "-XX:LoopStripMiningIter=0",
  71                 "-XX:LoopUnrollLimit=0",
  72                 "-XX:CompileCommand=compileonly,TestAbortVMOnSafepointTimeout::test_loop",
  73                 "-Xcomp",
  74                 "-XX:-CreateCoredumpOnCrash",
  75                 "-Xms64m",
  76                 "TestAbortVMOnSafepointTimeout",
  77                 "runTestLoop"
  78         );
  79 
  80         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  81         if (Platform.isWindows()) {
  82             output.shouldMatch("Safepoint sync time longer than");


  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 TestAbortVMOnSafepointTimeout
  29  * @summary Check if VM can kill thread which doesn't reach safepoint.
  30  * @bug 8219584 8227528
  31  * @requires vm.compiler2.enabled
  32  * @library /test/lib
  33  * @modules java.base/jdk.internal.misc
  34  *          java.management
  35  */
  36 
  37 public class TestAbortVMOnSafepointTimeout {
  38 
  39     public static void main(String[] args) throws Exception {
  40         if (args.length > 0) {
  41             int result = test_loop(3);
  42             System.out.println("This message would occur after some time with result " + result);
  43             return;
  44         }
  45 
  46         testWith(500, 500);
  47     }
  48 
  49     static int test_loop(int x) {
  50         int sum = 0;
  51         if (x != 0) {
  52             // Long running loop without safepoint.
  53             for (int y = 1; y < Integer.MAX_VALUE; ++y) {
  54                 if (y % x == 0) ++sum;
  55             }
  56         }
  57         return sum;
  58     }
  59 
  60     public static void testWith(int sfpt_interval, int timeout_delay) throws Exception {
  61         // -XX:-UseCountedLoopSafepoints - is used to prevent the loop
  62         // in test_loop() to poll for safepoints.
  63         // -XX:LoopStripMiningIter=0 and -XX:LoopUnrollLimit=0 - are
  64         // used to prevent optimizations over the loop in test_loop()
  65         // since we actually want it to provoke a safepoint timeout.
  66         // -XX:-UseBiasedLocking - is used to prevent biased locking
  67         // handshakes from changing the timing of this test.
  68         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  69                 "-XX:+UnlockDiagnosticVMOptions",
  70                 "-XX:-UseBiasedLocking",
  71                 "-XX:+SafepointTimeout",
  72                 "-XX:+SafepointALot",
  73                 "-XX:+AbortVMOnSafepointTimeout",
  74                 "-XX:SafepointTimeoutDelay=" + timeout_delay,
  75                 "-XX:GuaranteedSafepointInterval=" + sfpt_interval,
  76                 "-XX:-TieredCompilation",
  77                 "-XX:-UseCountedLoopSafepoints",
  78                 "-XX:LoopStripMiningIter=0",
  79                 "-XX:LoopUnrollLimit=0",
  80                 "-XX:CompileCommand=compileonly,TestAbortVMOnSafepointTimeout::test_loop",
  81                 "-Xcomp",
  82                 "-XX:-CreateCoredumpOnCrash",
  83                 "-Xms64m",
  84                 "TestAbortVMOnSafepointTimeout",
  85                 "runTestLoop"
  86         );
  87 
  88         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  89         if (Platform.isWindows()) {
  90             output.shouldMatch("Safepoint sync time longer than");
< prev index next >