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