hotspot/test/compiler/6863420/Test.java
author malenkov
Thu, 22 May 2014 21:05:30 +0400
changeset 25100 d527cc827d7d
parent 16688 c5d0a0a90f37
permissions -rw-r--r--
8043627: NPE in SynthContext in plugin mode Reviewed-by: alexsch, serb, pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     1
/*
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     2
 * Copyright 2009 D.E. Shaw.  All Rights Reserved.
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     4
 *
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     8
 *
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    13
 * accompanied this code).
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    14
 *
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3594
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3594
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: 3594
diff changeset
    21
 * questions.
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    22
 *
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    23
 */
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    24
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    25
/**
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    26
 * @test
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    27
 * @bug 6863420
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    28
 * @summary os::javaTimeNanos() go backward on Solaris x86
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    29
 *
16688
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    30
 * Notice the internal timeout in timeout thread Test.TOT.
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    31
 * @run main/othervm/timeout=300 Test
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    32
 */
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    33
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    34
public class Test {
16688
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    35
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    36
    static final int INTERNAL_TIMEOUT=240;
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    37
    static class TOT extends Thread {
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    38
       public void run() {
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    39
           try {
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    40
               Thread.sleep(INTERNAL_TIMEOUT*1000);
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    41
           } catch (InterruptedException ex) {
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    42
           }
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    43
           done = true;
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    44
       }
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    45
    }
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    46
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    47
    static long value = 0;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    48
    static boolean got_backward_time = false;
16688
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    49
    static volatile boolean done = false;
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    50
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    51
    public static void main(String args[]) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    52
        final int count = 100000;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    53
16688
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    54
        TOT tot = new TOT();
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    55
        tot.setDaemon(true);
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    56
        tot.start();
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    57
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    58
        for (int numThreads = 1; !done && numThreads <= 32; numThreads++) {
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    59
            final int numRuns = 1;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    60
            for (int t=1; t <= numRuns; t++) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    61
                final int curRun = t;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    62
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    63
                System.out.println("Spawning " + numThreads + " threads");
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    64
                final Thread threads[] = new Thread[numThreads];
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    65
                for (int i = 0; i < threads.length; i++) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    66
                    Runnable thread =
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    67
                        new Runnable() {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    68
                            public void run() {
16688
c5d0a0a90f37 8010913: compiler/6863420 often exceeds timeout
bharadwaj
parents: 5547
diff changeset
    69
                                for (long l = 0; !done && l < 100000; l++) {
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    70
                                    final long start = System.nanoTime();
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    71
                                    if (value == 12345678) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    72
                                        System.out.println("Wow!");
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    73
                                    }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    74
                                    final long end = System.nanoTime();
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    75
                                    final long time = end - start;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    76
                                    value += time;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    77
                                    if (time < 0) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    78
                                        System.out.println(
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    79
                                            "Backwards: " +
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    80
                                            "start=" + start + " " +
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    81
                                            "end=" + end + " " +
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    82
                                            "time= " + time
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    83
                                        );
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    84
                                        got_backward_time = true;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    85
                                    }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    86
                                }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    87
                            }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    88
                        };
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    89
                    threads[i] = new Thread(thread, "Thread" + i);
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    90
                }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    91
                for (int i = 0; i < threads.length; i++) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    92
                    threads[i].start();
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    93
                }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    94
                for (int i = 0; i < threads.length; i++) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    95
                    try {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    96
                        threads[i].join();
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    97
                    }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    98
                    catch (InterruptedException e) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
    99
                        continue;
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   100
                    }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   101
                }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   102
            }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   103
        }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   104
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   105
        if (got_backward_time) {
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   106
            System.exit(97);
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   107
        }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   108
    }
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
diff changeset
   109
}