hotspot/test/compiler/loopopts/UseCountedLoopSafepoints.java
author aeriksso
Fri, 04 Dec 2015 14:06:38 +0100
changeset 35084 5b34a4ae0f58
child 35596 07098f03eb07
permissions -rw-r--r--
6869327: Add new C2 flag to keep safepoints in counted loops. Reviewed-by: kvn, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35084
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     1
/*
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     4
 *
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     8
 *
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    13
 * accompanied this code).
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    14
 *
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    18
 *
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    21
 * questions.
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    22
 *
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    23
 */
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    24
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    25
/**
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    26
 * @test
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    27
 * @bug 6869327
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    28
 * @summary Test that C2 flag UseCountedLoopSafepoints ensures a safepoint is kept in a CountedLoop
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    29
 * @library /testlibrary
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    30
 * @modules java.base
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    31
 * @run main UseCountedLoopSafepoints
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    32
 */
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    33
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    34
import java.util.concurrent.atomic.AtomicLong;
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    35
import jdk.test.lib.ProcessTools;
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    36
import jdk.test.lib.OutputAnalyzer;
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    37
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    38
public class UseCountedLoopSafepoints {
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    39
    private static final AtomicLong _num = new AtomicLong(0);
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    40
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    41
    // Uses the fact that an EnableBiasedLocking vmop will be started
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    42
    // after 500ms, while we are still in the loop. If there is a
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    43
    // safepoint in the counted loop, then we will reach safepoint
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    44
    // very quickly. Otherwise SafepointTimeout will be hit.
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    45
    public static void main (String args[]) throws Exception {
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    46
        if (args.length == 1) {
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    47
            final int loops = Integer.parseInt(args[0]);
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    48
            for (int i = 0; i < loops; i++) {
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    49
                _num.addAndGet(1);
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    50
            }
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    51
        } else {
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    52
            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    53
                    "-XX:+IgnoreUnrecognizedVMOptions",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    54
                    "-XX:-TieredCompilation",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    55
                    "-XX:+UseBiasedLocking",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    56
                    "-XX:BiasedLockingStartupDelay=500",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    57
                    "-XX:+SafepointTimeout",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    58
                    "-XX:SafepointTimeoutDelay=2000",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    59
                    "-XX:+UseCountedLoopSafepoints",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    60
                    "UseCountedLoopSafepoints",
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    61
                    "2000000000"
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    62
                    );
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    63
            OutputAnalyzer output = new OutputAnalyzer(pb.start());
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    64
            output.shouldNotContain("Timeout detected");
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    65
            output.shouldHaveExitValue(0);
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    66
        }
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    67
    }
5b34a4ae0f58 6869327: Add new C2 flag to keep safepoints in counted loops.
aeriksso
parents:
diff changeset
    68
}