894N/A/*
894N/A * Copyright 2009 D.E. Shaw. All Rights Reserved.
894N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
894N/A *
894N/A * This code is free software; you can redistribute it and/or modify it
894N/A * under the terms of the GNU General Public License version 2 only, as
894N/A * published by the Free Software Foundation.
894N/A *
894N/A * This code is distributed in the hope that it will be useful, but WITHOUT
894N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
894N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
894N/A * version 2 for more details (a copy is included in the LICENSE file that
894N/A * accompanied this code).
894N/A *
894N/A * You should have received a copy of the GNU General Public License version
894N/A * 2 along with this work; if not, write to the Free Software Foundation,
894N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
894N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
894N/A *
894N/A */
894N/A
894N/A/**
894N/A * @test
894N/A * @bug 6863420
894N/A * @summary os::javaTimeNanos() go backward on Solaris x86
894N/A *
4447N/A * Notice the internal timeout in timeout thread Test.TOT.
4447N/A * @run main/othervm/timeout=300 Test
894N/A */
894N/A
894N/Apublic class Test {
4447N/A
4447N/A static final int INTERNAL_TIMEOUT=240;
4447N/A static class TOT extends Thread {
4447N/A public void run() {
4447N/A try {
4447N/A Thread.sleep(INTERNAL_TIMEOUT*1000);
4447N/A } catch (InterruptedException ex) {
4447N/A }
4447N/A done = true;
4447N/A }
4447N/A }
4447N/A
894N/A static long value = 0;
894N/A static boolean got_backward_time = false;
4447N/A static volatile boolean done = false;
894N/A
894N/A public static void main(String args[]) {
894N/A final int count = 100000;
894N/A
4447N/A TOT tot = new TOT();
4447N/A tot.setDaemon(true);
4447N/A tot.start();
4447N/A
4447N/A for (int numThreads = 1; !done && numThreads <= 32; numThreads++) {
894N/A final int numRuns = 1;
894N/A for (int t=1; t <= numRuns; t++) {
894N/A final int curRun = t;
894N/A
894N/A System.out.println("Spawning " + numThreads + " threads");
894N/A final Thread threads[] = new Thread[numThreads];
894N/A for (int i = 0; i < threads.length; i++) {
894N/A Runnable thread =
894N/A new Runnable() {
894N/A public void run() {
4447N/A for (long l = 0; !done && l < 100000; l++) {
894N/A final long start = System.nanoTime();
894N/A if (value == 12345678) {
894N/A System.out.println("Wow!");
894N/A }
894N/A final long end = System.nanoTime();
894N/A final long time = end - start;
894N/A value += time;
894N/A if (time < 0) {
894N/A System.out.println(
894N/A "Backwards: " +
894N/A "start=" + start + " " +
894N/A "end=" + end + " " +
894N/A "time= " + time
894N/A );
894N/A got_backward_time = true;
894N/A }
894N/A }
894N/A }
894N/A };
894N/A threads[i] = new Thread(thread, "Thread" + i);
894N/A }
894N/A for (int i = 0; i < threads.length; i++) {
894N/A threads[i].start();
894N/A }
894N/A for (int i = 0; i < threads.length; i++) {
894N/A try {
894N/A threads[i].join();
894N/A }
894N/A catch (InterruptedException e) {
894N/A continue;
894N/A }
894N/A }
894N/A }
894N/A }
894N/A
894N/A if (got_backward_time) {
894N/A System.exit(97);
894N/A }
894N/A }
894N/A}