hotspot/test/compiler/onSpinWait/TestOnSpinWait.java
changeset 38017 55047d16f141
child 38152 80e5da81fb2c
equal deleted inserted replaced
37295:e00dfcc21fa1 38017:55047d16f141
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * Copyright 2016 Azul Systems, Inc.  All Rights Reserved.
       
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     5  *
       
     6  * This code is free software; you can redistribute it and/or modify it
       
     7  * under the terms of the GNU General Public License version 2 only, as
       
     8  * published by the Free Software Foundation.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21  * or visit www.oracle.com if you need additional information or have any
       
    22  * questions.
       
    23  */
       
    24 
       
    25 /**
       
    26  * @test TestOnSpinWait
       
    27  * @summary (x86 only) checks that java.lang.Thread.onSpinWait is intrinsified
       
    28  * @bug 8147844
       
    29  * @library /testlibrary
       
    30  * @requires os.arch=="x86" | os.arch=="amd64" | os.arch=="x86_64"
       
    31  * @run main TestOnSpinWait
       
    32  */
       
    33 
       
    34 import java.lang.invoke.*;
       
    35 import jdk.test.lib.*;
       
    36 import static jdk.test.lib.Asserts.*;
       
    37 
       
    38 public class TestOnSpinWait {
       
    39 
       
    40     public static void main(String[] args) throws Exception {
       
    41 
       
    42         // Test C1 compiler
       
    43         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
       
    44           "-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
       
    45           "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1", "-Xbatch",
       
    46           "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions",
       
    47           "-XX:+PrintInlining", "TestOnSpinWait$Launcher");
       
    48 
       
    49         OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
       
    50 
       
    51         analyzer.shouldHaveExitValue(0);
       
    52 
       
    53         // The test is applicable only to C1 (present in Server VM).
       
    54         analyzer.shouldContain("java.lang.Thread::onSpinWait (1 bytes)   intrinsic");
       
    55 
       
    56         // Test C2 compiler
       
    57         pb = ProcessTools.createJavaProcessBuilder(
       
    58           "-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
       
    59           "-XX:-TieredCompilation", "-Xbatch",
       
    60           "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions",
       
    61           "-XX:+PrintInlining", "TestOnSpinWait$Launcher");
       
    62 
       
    63         analyzer = new OutputAnalyzer(pb.start());
       
    64 
       
    65         analyzer.shouldHaveExitValue(0);
       
    66 
       
    67         // The test is applicable only to C2 (present in Server VM).
       
    68         if (analyzer.getStderr().contains("Server VM")) {
       
    69             analyzer.shouldContain("java.lang.Thread::onSpinWait (1 bytes)   (intrinsic)");
       
    70         }
       
    71     }
       
    72 
       
    73     static class Launcher {
       
    74 
       
    75         public static void main(final String[] args) throws Exception {
       
    76             int end = 20_000;
       
    77 
       
    78             for (int i=0; i < end; i++) {
       
    79                 test();
       
    80             }
       
    81         }
       
    82         static void test() {
       
    83             java.lang.Thread.onSpinWait();
       
    84         }
       
    85     }
       
    86 }