test/compiler/6863420/Test.java

Mon, 08 Apr 2013 07:40:08 -0700

author
bharadwaj
date
Mon, 08 Apr 2013 07:40:08 -0700
changeset 4907
f67065f02409
parent 1907
c18cbe5936b8
child 6876
710a3c8b516e
permissions
-rw-r--r--

8010913: compiler/6863420 often exceeds timeout
Summary: add longer timeout for jtreg, add internal timeout thread to prevent spurious timeouts
Reviewed-by: twisti, kvn
Contributed-by: drchase <david.r.chase@oracle.com>

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

mercurial