/* * Copyright (c) 1999, 2008, 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.
*/
/** * Manages a VM conection for the JDI test framework.
*/ class VMConnection { private VirtualMachine vm; private Process process = null; privateint outputCompleteCount = 0;
/** * Return a String containing VM Options to pass to the debugee * or an empty string if there are none. * These are read from TESTVMOPTS and/or TESTJAVAOPTS.
*/ staticpublic String getDebuggeeVMOptions() {
String retVal = "";
// When we run under jtreg, test.classes contains the pathname of // the dir in which the .class files will be placed.
String testClasses = System.getProperty("test.classes"); if (testClasses == null) { return retVal;
}
retVal += "-classpath " + testClasses;
privatesynchronizedvoid waitOutputComplete() { // Wait for stderr and stdout if (process != null) { while (outputCompleteCount < 2) { try {wait();} catch (InterruptedException e) {}
}
}
}
publicvoid disposeVM() { try { if (vm != null) {
vm.dispose();
vm = null;
}
} finally { if (process != null) {
process.destroy();
process = null;
}
waitOutputComplete();
}
}
privatevoid dumpStream(InputStream stream) throws IOException {
PrintStream outStream = System.out;
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
String line; while(true){ try{
line = in.readLine(); if( line == null ){ break;
}
outStream.println(line);
} catch(IOException ieo){ /** * IOException with "Bad file number..." can happen * when the debuggee process is destroyed. Ignore such exception. *
*/
String s = ieo.getMessage(); if( s.startsWith("Bad file number") ){ break;
} throw ieo;
} catch(NullPointerException npe){ thrownew IOException("Bug 4728096 in Java io may cause in.readLine() to throw a NULL pointer exception");
}
}
}
/** * Create a Thread that will retrieve and display any output. * Needs to be high priority, else debugger may exit before * it can be displayed.
*/ privatevoid displayRemoteOutput(final InputStream stream) { Thread thr = newThread("output reader") { publicvoid run() { try {
dumpStream(stream);
} catch (IOException ex) {
System.err.println("IOException reading output of child java interpreter:"
+ ex.getMessage());
} finally {
notifyOutputComplete();
}
}
};
thr.setPriority(Thread.MAX_PRIORITY-1);
thr.start();
}
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 und die Messung sind noch experimentell.