/* * Copyright (c) 1998, 2021, 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.
*/
/** * This method is used for setting VM options on spawned VMs. * It returns the extra command line options required * to turn on jcov code coverage analysis.
*/ protectedstatic String getCodeCoverageOptions() { return TestLibrary.getExtraProperty("jcov.options","");
}
/** * Exec the VM as specified in this object's constructor.
*/ privatevoid start0() throws IOException {
outputStream.reset();
errorStream.reset();
if (vm != null) thrownew IllegalStateException("JavaVM already started");
/* * If specified, add option for policy file
*/ if (policyFileName != null) {
String option = "-Djava.security.policy=" + policyFileName;
addOptions(new String[] { option });
}
StringTokenizer optionsTokenizer = new StringTokenizer(options);
StringTokenizer argsTokenizer = new StringTokenizer(args); int optionsCount = optionsTokenizer.countTokens(); int argsCount = argsTokenizer.countTokens();
String javaCommand[] = new String[optionsCount + argsCount + 2]; int count = 0;
javaCommand[count++] = JavaVM.javaProgram; while (optionsTokenizer.hasMoreTokens()) {
javaCommand[count++] = optionsTokenizer.nextToken();
}
javaCommand[count++] = classname; while (argsTokenizer.hasMoreTokens()) {
javaCommand[count++] = argsTokenizer.nextToken();
}
/* output from the exec'ed process may optionally be captured. */
outPipe = StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
errPipe = StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
}
publicvoid destroy() { if (vm != null) {
vm.destroyForcibly();
}
vm = null;
}
/** * Return exit value for vm process. * @return exit value for vm process * @throws IllegalThreadStateException if the vm process has not yet terminated
*/ publicint exitValue() { return vm.exitValue();
}
/** * Destroy the vm process, and do necessary cleanup.
*/ publicvoid cleanup() {
destroy();
}
/** * Destroys the VM, waits for it to terminate, and returns * its exit status. * * @throws IllegalStateException if the VM has already been destroyed * @throws InterruptedException if the caller is interrupted while waiting
*/ publicint terminate() throws InterruptedException { if (vm == null) { thrownew IllegalStateException("JavaVM already destroyed");
}
vm.destroy(); int status = waitFor();
vm = null; return status;
}
/** * Waits for the subprocess to exit, joins the pipe threads to ensure that * all output is collected, and returns its exit status.
*/ publicint waitFor() throws InterruptedException { if (vm == null) thrownew IllegalStateException("can't wait for JavaVM that isn't running");
int status = vm.waitFor();
outPipe.join();
errPipe.join(); return status;
}
/** * Causes the current thread to wait the vm process to exit, if necessary, * wait until the vm process has terminated, or the specified waiting time * elapses. Release allocated input/output after vm process has terminated. * @param timeout the maximum milliseconds to wait. * @return exit value for vm process. * @throws InterruptedException if the current thread is interrupted * while waiting. * @throws TimeoutException if subprocess does not end after timeout * milliseconds passed
*/ publicint waitFor(long timeout) throws InterruptedException, TimeoutException { if (vm == null) thrownew IllegalStateException("can't wait for JavaVM that isn't running"); long deadline = TestLibrary.computeDeadline(System.currentTimeMillis(), timeout);
while (true) { try { int status = vm.exitValue();
outPipe.join();
errPipe.join(); return status;
} catch (IllegalThreadStateException ignore) { }
if (System.currentTimeMillis() > deadline) thrownew TimeoutException();
Thread.sleep(POLLTIME_MS);
}
}
/** * Starts the subprocess, waits for it to exit, and returns its exit status.
*/ publicint execute() throws IOException, InterruptedException {
start(); return waitFor();
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
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.