Path: blob/master/test/hotspot/jtreg/compiler/runtime/Test6863420.java
41149 views
/*1* Copyright 2009 D.E. Shaw. All Rights Reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/**25* @test26* @bug 686342027* @summary os::javaTimeNanos() go backward on Solaris x8628*29* @run main/othervm/timeout=300 compiler.runtime.Test686342030*/31/*32* Notice the internal timeout in timeout thread Test6863420.TOT.33*/3435package compiler.runtime;3637public class Test6863420 {3839static final int INTERNAL_TIMEOUT=240;40static class TOT extends Thread {41public void run() {42try {43Thread.sleep(INTERNAL_TIMEOUT*1000);44} catch (InterruptedException ex) {45}46done = true;47}48}4950static long value = 0;51static boolean got_backward_time = false;52static volatile boolean done = false;5354public static void main(String args[]) {55final int count = 100000;5657TOT tot = new TOT();58tot.setDaemon(true);59tot.start();6061for (int numThreads = 1; !done && numThreads <= 32; numThreads++) {62final int numRuns = 1;63for (int t=1; t <= numRuns; t++) {64final int curRun = t;6566System.out.println("Spawning " + numThreads + " threads");67final Thread threads[] = new Thread[numThreads];68for (int i = 0; i < threads.length; i++) {69Runnable thread =70new Runnable() {71public void run() {72for (long l = 0; !done && l < 100000; l++) {73final long start = System.nanoTime();74if (value == 12345678) {75System.out.println("Wow!");76}77final long end = System.nanoTime();78final long time = end - start;79value += time;80if (time < 0) {81System.out.println(82"Backwards: " +83"start=" + start + " " +84"end=" + end + " " +85"time= " + time86);87got_backward_time = true;88}89}90}91};92threads[i] = new Thread(thread, "Thread" + i);93}94for (int i = 0; i < threads.length; i++) {95threads[i].start();96}97for (int i = 0; i < threads.length; i++) {98try {99threads[i].join();100}101catch (InterruptedException e) {102continue;103}104}105}106}107108if (got_backward_time) {109System.exit(97);110}111}112}113114115