kvn@1586: /* kvn@1586: * Copyright 2009 D.E. Shaw. All Rights Reserved. kvn@1586: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. kvn@1586: * kvn@1586: * This code is free software; you can redistribute it and/or modify it kvn@1586: * under the terms of the GNU General Public License version 2 only, as kvn@1586: * published by the Free Software Foundation. kvn@1586: * kvn@1586: * This code is distributed in the hope that it will be useful, but WITHOUT kvn@1586: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or kvn@1586: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License kvn@1586: * version 2 for more details (a copy is included in the LICENSE file that kvn@1586: * accompanied this code). kvn@1586: * kvn@1586: * You should have received a copy of the GNU General Public License version kvn@1586: * 2 along with this work; if not, write to the Free Software Foundation, kvn@1586: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. kvn@1586: * kvn@1586: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, kvn@1586: * CA 95054 USA or visit www.sun.com if you need additional information or kvn@1586: * have any questions. kvn@1586: */ kvn@1586: kvn@1586: /** kvn@1586: * @test kvn@1586: * @bug 6912517 kvn@1586: * @summary JIT bug compiles out (and stops running) code that needs to be run. Causes NPE. kvn@1586: * kvn@1586: * @run main/othervm -Xbatch -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops Test kvn@1586: */ kvn@1586: kvn@1586: /** kvn@1586: * Highlights a bug with the JIT compiler. kvn@1586: * @author Matt Bruce m b r u c e __\at/__ g m a i l DOT c o m kvn@1586: */ kvn@1586: public class Test implements Runnable kvn@1586: { kvn@1586: private final Thread myThread; kvn@1586: private Thread myInitialThread; kvn@1586: private boolean myShouldCheckThreads; kvn@1586: kvn@1586: /** kvn@1586: * Sets up the running thread, and starts it. kvn@1586: */ kvn@1586: public Test(int id) kvn@1586: { kvn@1586: myThread = new Thread(this); kvn@1586: myThread.setName("Runner: " + id); kvn@1586: myThread.start(); kvn@1586: myShouldCheckThreads = false; kvn@1586: } kvn@1586: kvn@1586: /** kvn@1586: * @param shouldCheckThreads the shouldCheckThreads to set kvn@1586: */ kvn@1586: public void setShouldCheckThreads(boolean shouldCheckThreads) kvn@1586: { kvn@1586: myShouldCheckThreads = shouldCheckThreads; kvn@1586: } kvn@1586: kvn@1586: /** kvn@1586: * Starts up the two threads with enough delay between them for JIT to kvn@1586: * kick in. kvn@1586: * @param args kvn@1586: * @throws InterruptedException kvn@1586: */ kvn@1586: public static void main(String[] args) throws InterruptedException kvn@1586: { kvn@1586: // let this run for a bit, so the "run" below is JITTed. kvn@1586: for (int id = 0; id < 20; id++) { kvn@1586: System.out.println("Starting thread: " + id); kvn@1586: Test bug = new Test(id); kvn@1586: bug.setShouldCheckThreads(true); kvn@1586: Thread.sleep(2500); kvn@1586: } kvn@1586: } kvn@1586: kvn@1586: /** kvn@1586: * @see java.lang.Runnable#run() kvn@1586: */ kvn@1586: public void run() kvn@1586: { kvn@1586: long runNumber = 0; kvn@1586: while (true) { kvn@1586: // run hot for a little while, give JIT time to kick in to this loop. kvn@1586: // then run less hot. kvn@1586: if (runNumber > 15000) { kvn@1586: try { kvn@1586: Thread.sleep(5); kvn@1586: } kvn@1586: catch (InterruptedException e) { kvn@1586: e.printStackTrace(); kvn@1586: } kvn@1586: } kvn@1586: runNumber++; kvn@1586: ensureProperCallingThread(); kvn@1586: } kvn@1586: } kvn@1586: kvn@1586: private void ensureProperCallingThread() kvn@1586: { kvn@1586: // this should never be null. but with the JIT bug, it will be. kvn@1586: // JIT BUG IS HERE ==>>>>> kvn@1586: if (myShouldCheckThreads) { kvn@1586: if (myInitialThread == null) { kvn@1586: myInitialThread = Thread.currentThread(); kvn@1586: } kvn@1586: else if (myInitialThread != Thread.currentThread()) { kvn@1586: System.out.println("Not working: " + myInitialThread.getName()); kvn@1586: } kvn@1586: } kvn@1586: } kvn@1586: }