Thu, 07 Jan 2010 16:26:31 -0800
6912517: JIT bug compiles out (and stops running) code that needs to be run. Causes NPE.
Summary: Add missing check that value is used in memory expression in instructions with embedded load.
Reviewed-by: never, jrose
kvn@1586 | 1 | /* |
kvn@1586 | 2 | * Copyright 2009 D.E. Shaw. All Rights Reserved. |
kvn@1586 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
kvn@1586 | 4 | * |
kvn@1586 | 5 | * This code is free software; you can redistribute it and/or modify it |
kvn@1586 | 6 | * under the terms of the GNU General Public License version 2 only, as |
kvn@1586 | 7 | * published by the Free Software Foundation. |
kvn@1586 | 8 | * |
kvn@1586 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
kvn@1586 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
kvn@1586 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
kvn@1586 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
kvn@1586 | 13 | * accompanied this code). |
kvn@1586 | 14 | * |
kvn@1586 | 15 | * You should have received a copy of the GNU General Public License version |
kvn@1586 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
kvn@1586 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
kvn@1586 | 18 | * |
kvn@1586 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
kvn@1586 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
kvn@1586 | 21 | * have any questions. |
kvn@1586 | 22 | */ |
kvn@1586 | 23 | |
kvn@1586 | 24 | /** |
kvn@1586 | 25 | * @test |
kvn@1586 | 26 | * @bug 6912517 |
kvn@1586 | 27 | * @summary JIT bug compiles out (and stops running) code that needs to be run. Causes NPE. |
kvn@1586 | 28 | * |
kvn@1586 | 29 | * @run main/othervm -Xbatch -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops Test |
kvn@1586 | 30 | */ |
kvn@1586 | 31 | |
kvn@1586 | 32 | /** |
kvn@1586 | 33 | * Highlights a bug with the JIT compiler. |
kvn@1586 | 34 | * @author Matt Bruce m b r u c e __\at/__ g m a i l DOT c o m |
kvn@1586 | 35 | */ |
kvn@1586 | 36 | public class Test implements Runnable |
kvn@1586 | 37 | { |
kvn@1586 | 38 | private final Thread myThread; |
kvn@1586 | 39 | private Thread myInitialThread; |
kvn@1586 | 40 | private boolean myShouldCheckThreads; |
kvn@1586 | 41 | |
kvn@1586 | 42 | /** |
kvn@1586 | 43 | * Sets up the running thread, and starts it. |
kvn@1586 | 44 | */ |
kvn@1586 | 45 | public Test(int id) |
kvn@1586 | 46 | { |
kvn@1586 | 47 | myThread = new Thread(this); |
kvn@1586 | 48 | myThread.setName("Runner: " + id); |
kvn@1586 | 49 | myThread.start(); |
kvn@1586 | 50 | myShouldCheckThreads = false; |
kvn@1586 | 51 | } |
kvn@1586 | 52 | |
kvn@1586 | 53 | /** |
kvn@1586 | 54 | * @param shouldCheckThreads the shouldCheckThreads to set |
kvn@1586 | 55 | */ |
kvn@1586 | 56 | public void setShouldCheckThreads(boolean shouldCheckThreads) |
kvn@1586 | 57 | { |
kvn@1586 | 58 | myShouldCheckThreads = shouldCheckThreads; |
kvn@1586 | 59 | } |
kvn@1586 | 60 | |
kvn@1586 | 61 | /** |
kvn@1586 | 62 | * Starts up the two threads with enough delay between them for JIT to |
kvn@1586 | 63 | * kick in. |
kvn@1586 | 64 | * @param args |
kvn@1586 | 65 | * @throws InterruptedException |
kvn@1586 | 66 | */ |
kvn@1586 | 67 | public static void main(String[] args) throws InterruptedException |
kvn@1586 | 68 | { |
kvn@1586 | 69 | // let this run for a bit, so the "run" below is JITTed. |
kvn@1586 | 70 | for (int id = 0; id < 20; id++) { |
kvn@1586 | 71 | System.out.println("Starting thread: " + id); |
kvn@1586 | 72 | Test bug = new Test(id); |
kvn@1586 | 73 | bug.setShouldCheckThreads(true); |
kvn@1586 | 74 | Thread.sleep(2500); |
kvn@1586 | 75 | } |
kvn@1586 | 76 | } |
kvn@1586 | 77 | |
kvn@1586 | 78 | /** |
kvn@1586 | 79 | * @see java.lang.Runnable#run() |
kvn@1586 | 80 | */ |
kvn@1586 | 81 | public void run() |
kvn@1586 | 82 | { |
kvn@1586 | 83 | long runNumber = 0; |
kvn@1586 | 84 | while (true) { |
kvn@1586 | 85 | // run hot for a little while, give JIT time to kick in to this loop. |
kvn@1586 | 86 | // then run less hot. |
kvn@1586 | 87 | if (runNumber > 15000) { |
kvn@1586 | 88 | try { |
kvn@1586 | 89 | Thread.sleep(5); |
kvn@1586 | 90 | } |
kvn@1586 | 91 | catch (InterruptedException e) { |
kvn@1586 | 92 | e.printStackTrace(); |
kvn@1586 | 93 | } |
kvn@1586 | 94 | } |
kvn@1586 | 95 | runNumber++; |
kvn@1586 | 96 | ensureProperCallingThread(); |
kvn@1586 | 97 | } |
kvn@1586 | 98 | } |
kvn@1586 | 99 | |
kvn@1586 | 100 | private void ensureProperCallingThread() |
kvn@1586 | 101 | { |
kvn@1586 | 102 | // this should never be null. but with the JIT bug, it will be. |
kvn@1586 | 103 | // JIT BUG IS HERE ==>>>>> |
kvn@1586 | 104 | if (myShouldCheckThreads) { |
kvn@1586 | 105 | if (myInitialThread == null) { |
kvn@1586 | 106 | myInitialThread = Thread.currentThread(); |
kvn@1586 | 107 | } |
kvn@1586 | 108 | else if (myInitialThread != Thread.currentThread()) { |
kvn@1586 | 109 | System.out.println("Not working: " + myInitialThread.getName()); |
kvn@1586 | 110 | } |
kvn@1586 | 111 | } |
kvn@1586 | 112 | } |
kvn@1586 | 113 | } |