/* * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 6467152 6716076 6829503 8132550 * @summary deadlock occurs in LogManager initialization and JVM termination * @author Serguei Spitsyn / Hitachi / Martin Buchholz * * @build LoggingDeadlock2 * @run main LoggingDeadlock2 * @key randomness
*/
/* * * There is a clear deadlock between LogManager.<clinit> and * Cleaner.run() methods. * T1 thread: * The LogManager.<clinit> creates LogManager.manager object, * sets shutdown hook with the Cleaner class and then waits * to lock the LogManager.manager monitor. * T2 thread: * It is started by the System.exit() as shutdown hook thread. * It locks the LogManager.manager monitor and then calls the * static methods of the LogManager class (in this particular * case it is a trick of the inner classes implementation). * It is waits when the LogManager.<clinit> is completed. * * This is a regression test for this bug.
*/
// signal end of verbose output
System.out.print(MARKER);
System.out.flush();
startingGate.await(); for (int i = 0; i < iters2; i++)
counter.getAndIncrement(); // This may or may not result in a first call to // Runtime.addShutdownHook after shutdown has already // commenced.
LogManager.getLogManager();
if (dojoin) {
exiter.join(); if (thrown[0] != null) thrownew Error(thrown[0]);
check(counter.get() == JITTER);
}
}
}
//---------------------------------------------------------------- // The rest of this test is copied from ProcessBuilder/Basic.java //---------------------------------------------------------------- privatestaticfinal String javaExe =
System.getProperty("java.home") +
File.separator + "bin" + File.separator + "java"; privatestaticfinal String jstackExe =
System.getProperty("java.home") +
File.separator + "bin" + File.separator + "jstack";
publicvoid run() { try {
Reader r = new InputStreamReader(is); int n; while ((n = r.read()) > 0) {
sb.append((char)n);
// prints everything immediately to System.out so that we can // see the traces even in the event of a test timeout
System.out.write((char)n);
System.out.flush();
/** * If the child process deadlocks, then the parent may fail in timeout. * In that case, we won't have any interesting traces, unless we manage * to get a thread dump from the child. * It is unsure whether obtaining a thread dump from a deadlocked child * will work - but maybe we could see something if the timeout is a false * positive (the child has not deadlocked but hasn't managed to fully start * yet, for instance). * The idea here is to periodically try to obtain a thread dump from the * child, every 60sec - which should be always less than the jtreg timeout.
*/ privatestaticclass TimeoutThread extendsThread { finallong ms; final Process process;
TimeoutThread(long ms, Process p) { super("TimeoutThread");
setDaemon(true); this.ms = ms; this.process = p;
}
@Override publicvoid run() { long start = System.nanoTime(); try { while (true) {
sleep(ms);
System.err.println("Timeout reached: " + ms); if (process.isAlive()) { long pid = process.pid();
ProcessBuilder jstack = new ProcessBuilder(jstackExe, String.valueOf(pid));
System.err.println("Dumping subprocess stack: " + pid);
Process p = jstack.inheritIO().start();
p.waitFor(ms, TimeUnit.MILLISECONDS);
} else {
System.err.println("Process is not alive!"); break;
}
}
} catch (InterruptedException ex) {
System.err.println("Interrupted: " + ex);
} catch (IOException io) {
System.err.println("Failed to get stack from subprocess");
io.printStackTrace();
}
}
StreamAccumulator outAccumulator = new StreamAccumulator(p.getInputStream());
StreamAccumulator errAccumulator = new StreamAccumulator(p.getErrorStream());
try {
System.out.println("Waiting for child process to exit");
outAccumulator.start();
errAccumulator.start();
// ask subprocess to dump stack every 60 secs. new TimeoutThread(DUMP_STACK_FREQUENCY_MS, p).start();
exitValue = p.waitFor();
System.out.println("\nChild exited with status: " + exitValue);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.