6912517: JIT bug compiles out (and stops running) code that needs to be run. Causes NPE.

Thu, 07 Jan 2010 16:26:31 -0800

author
kvn
date
Thu, 07 Jan 2010 16:26:31 -0800
changeset 1586
1271af4ec18c
parent 1585
f62a22282a47
child 1587
cd37471eaecc

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

src/share/vm/opto/lcm.cpp file | annotate | diff | comparison | revisions
test/compiler/6912517/Test.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/opto/lcm.cpp	Thu Jan 07 16:24:17 2010 -0800
     1.2 +++ b/src/share/vm/opto/lcm.cpp	Thu Jan 07 16:26:31 2010 -0800
     1.3 @@ -120,6 +120,7 @@
     1.4      case Op_LoadRange:
     1.5      case Op_LoadD_unaligned:
     1.6      case Op_LoadL_unaligned:
     1.7 +      assert(mach->in(2) == val, "should be address");
     1.8        break;
     1.9      case Op_StoreB:
    1.10      case Op_StoreC:
    1.11 @@ -146,6 +147,21 @@
    1.12      default:                    // Also check for embedded loads
    1.13        if( !mach->needs_anti_dependence_check() )
    1.14          continue;               // Not an memory op; skip it
    1.15 +      {
    1.16 +        // Check that value is used in memory address.
    1.17 +        Node* base;
    1.18 +        Node* index;
    1.19 +        const MachOper* oper = mach->memory_inputs(base, index);
    1.20 +        if (oper == NULL || oper == (MachOper*)-1) {
    1.21 +          continue;             // Not an memory op; skip it
    1.22 +        }
    1.23 +        if (val == base ||
    1.24 +            val == index && val->bottom_type()->isa_narrowoop()) {
    1.25 +          break;                // Found it
    1.26 +        } else {
    1.27 +          continue;             // Skip it
    1.28 +        }
    1.29 +      }
    1.30        break;
    1.31      }
    1.32      // check if the offset is not too high for implicit exception
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/6912517/Test.java	Thu Jan 07 16:26:31 2010 -0800
     2.3 @@ -0,0 +1,113 @@
     2.4 +/*
     2.5 + * Copyright 2009 D.E. Shaw.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * @test
    2.29 + * @bug 6912517
    2.30 + * @summary JIT bug compiles out (and stops running) code that needs to be run.  Causes NPE.
    2.31 + *
    2.32 + * @run main/othervm -Xbatch -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops Test
    2.33 + */
    2.34 +
    2.35 +/**
    2.36 + * Highlights a bug with the JIT compiler.
    2.37 + * @author Matt Bruce m b r u c e __\at/__ g m a i l DOT c o m
    2.38 + */
    2.39 +public class Test implements Runnable
    2.40 +{
    2.41 +    private final Thread myThread;
    2.42 +    private Thread       myInitialThread;
    2.43 +    private boolean      myShouldCheckThreads;
    2.44 +
    2.45 +    /**
    2.46 +     * Sets up the running thread, and starts it.
    2.47 +     */
    2.48 +    public Test(int id)
    2.49 +    {
    2.50 +        myThread = new Thread(this);
    2.51 +        myThread.setName("Runner: " + id);
    2.52 +        myThread.start();
    2.53 +        myShouldCheckThreads = false;
    2.54 +    }
    2.55 +
    2.56 +    /**
    2.57 +     * @param shouldCheckThreads the shouldCheckThreads to set
    2.58 +     */
    2.59 +    public void setShouldCheckThreads(boolean shouldCheckThreads)
    2.60 +    {
    2.61 +        myShouldCheckThreads = shouldCheckThreads;
    2.62 +    }
    2.63 +
    2.64 +    /**
    2.65 +     * Starts up the two threads with enough delay between them for JIT to
    2.66 +     * kick in.
    2.67 +     * @param args
    2.68 +     * @throws InterruptedException
    2.69 +     */
    2.70 +    public static void main(String[] args) throws InterruptedException
    2.71 +    {
    2.72 +        // let this run for a bit, so the "run" below is JITTed.
    2.73 +        for (int id = 0; id < 20; id++) {
    2.74 +            System.out.println("Starting thread: " + id);
    2.75 +            Test bug = new Test(id);
    2.76 +            bug.setShouldCheckThreads(true);
    2.77 +            Thread.sleep(2500);
    2.78 +        }
    2.79 +    }
    2.80 +
    2.81 +    /**
    2.82 +     * @see java.lang.Runnable#run()
    2.83 +     */
    2.84 +    public void run()
    2.85 +    {
    2.86 +        long runNumber = 0;
    2.87 +        while (true) {
    2.88 +            // run hot for a little while, give JIT time to kick in to this loop.
    2.89 +            // then run less hot.
    2.90 +            if (runNumber > 15000) {
    2.91 +                try {
    2.92 +                    Thread.sleep(5);
    2.93 +                }
    2.94 +                catch (InterruptedException e) {
    2.95 +                    e.printStackTrace();
    2.96 +                }
    2.97 +            }
    2.98 +            runNumber++;
    2.99 +            ensureProperCallingThread();
   2.100 +        }
   2.101 +    }
   2.102 +
   2.103 +    private void ensureProperCallingThread()
   2.104 +    {
   2.105 +        // this should never be null.  but with the JIT bug, it will be.
   2.106 +        // JIT BUG IS HERE ==>>>>>
   2.107 +        if (myShouldCheckThreads) {
   2.108 +            if (myInitialThread == null) {
   2.109 +                myInitialThread = Thread.currentThread();
   2.110 +            }
   2.111 +            else if (myInitialThread != Thread.currentThread()) {
   2.112 +                System.out.println("Not working: " + myInitialThread.getName());
   2.113 +            }
   2.114 +        }
   2.115 +    }
   2.116 +}

mercurial