1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. 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 
  25 /**
  26  * @test
  27  * @bug 6869327
  28  * @summary Test that C2 flag UseCountedLoopSafepoints ensures a safepoint is kept in a CountedLoop
  29  * @library /testlibrary
  30  * @modules java.base/jdk.internal.misc
  31  * @ignore 8146096
  32  * @run driver compiler.loopopts.UseCountedLoopSafepoints
  33  */
  34 
  35 package compiler.loopopts;
  36 
  37 import jdk.test.lib.OutputAnalyzer;
  38 import jdk.test.lib.ProcessTools;
  39 
  40 import java.util.concurrent.atomic.AtomicLong;
  41 
  42 public class UseCountedLoopSafepoints {
  43     private static final AtomicLong _num = new AtomicLong(0);
  44 
  45     // Uses the fact that an EnableBiasedLocking vmop will be started
  46     // after 500ms, while we are still in the loop. If there is a
  47     // safepoint in the counted loop, then we will reach safepoint
  48     // very quickly. Otherwise SafepointTimeout will be hit.
  49     public static void main (String args[]) throws Exception {
  50         if (args.length == 1) {
  51             final int loops = Integer.parseInt(args[0]);
  52             for (int i = 0; i < loops; i++) {
  53                 _num.addAndGet(1);
  54             }
  55         } else {
  56             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  57                     "-XX:+IgnoreUnrecognizedVMOptions",
  58                     "-XX:-TieredCompilation",
  59                     "-XX:+UseBiasedLocking",
  60                     "-XX:BiasedLockingStartupDelay=500",
  61                     "-XX:+SafepointTimeout",
  62                     "-XX:SafepointTimeoutDelay=2000",
  63                     "-XX:+UseCountedLoopSafepoints",
  64                     UseCountedLoopSafepoints.class.getName(),
  65                     "2000000000"
  66                     );
  67             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  68             output.shouldNotContain("Timeout detected");
  69             output.shouldHaveExitValue(0);
  70         }
  71     }
  72 }