test/compiler/6912517/Test.java

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

     1 /*
     2  * Copyright 2009 D.E. Shaw.  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  */
    24 /**
    25  * @test
    26  * @bug 6912517
    27  * @summary JIT bug compiles out (and stops running) code that needs to be run.  Causes NPE.
    28  *
    29  * @run main/othervm -Xbatch -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops Test
    30  */
    32 /**
    33  * Highlights a bug with the JIT compiler.
    34  * @author Matt Bruce m b r u c e __\at/__ g m a i l DOT c o m
    35  */
    36 public class Test implements Runnable
    37 {
    38     private final Thread myThread;
    39     private Thread       myInitialThread;
    40     private boolean      myShouldCheckThreads;
    42     /**
    43      * Sets up the running thread, and starts it.
    44      */
    45     public Test(int id)
    46     {
    47         myThread = new Thread(this);
    48         myThread.setName("Runner: " + id);
    49         myThread.start();
    50         myShouldCheckThreads = false;
    51     }
    53     /**
    54      * @param shouldCheckThreads the shouldCheckThreads to set
    55      */
    56     public void setShouldCheckThreads(boolean shouldCheckThreads)
    57     {
    58         myShouldCheckThreads = shouldCheckThreads;
    59     }
    61     /**
    62      * Starts up the two threads with enough delay between them for JIT to
    63      * kick in.
    64      * @param args
    65      * @throws InterruptedException
    66      */
    67     public static void main(String[] args) throws InterruptedException
    68     {
    69         // let this run for a bit, so the "run" below is JITTed.
    70         for (int id = 0; id < 20; id++) {
    71             System.out.println("Starting thread: " + id);
    72             Test bug = new Test(id);
    73             bug.setShouldCheckThreads(true);
    74             Thread.sleep(2500);
    75         }
    76     }
    78     /**
    79      * @see java.lang.Runnable#run()
    80      */
    81     public void run()
    82     {
    83         long runNumber = 0;
    84         while (true) {
    85             // run hot for a little while, give JIT time to kick in to this loop.
    86             // then run less hot.
    87             if (runNumber > 15000) {
    88                 try {
    89                     Thread.sleep(5);
    90                 }
    91                 catch (InterruptedException e) {
    92                     e.printStackTrace();
    93                 }
    94             }
    95             runNumber++;
    96             ensureProperCallingThread();
    97         }
    98     }
   100     private void ensureProperCallingThread()
   101     {
   102         // this should never be null.  but with the JIT bug, it will be.
   103         // JIT BUG IS HERE ==>>>>>
   104         if (myShouldCheckThreads) {
   105             if (myInitialThread == null) {
   106                 myInitialThread = Thread.currentThread();
   107             }
   108             else if (myInitialThread != Thread.currentThread()) {
   109                 System.out.println("Not working: " + myInitialThread.getName());
   110             }
   111         }
   112     }
   113 }

mercurial