001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.benchmark;
022:
023: /**
024: * Runs a Java program multiple times without the Virtual Machine exiting.
025: *
026: * @see BenchmarkSecurityManager
027: */
028: public class Nonstop {
029: static {
030: // Load native code from libbenchmark.so
031: System.loadLibrary("nonstop");
032: }
033:
034: public static native void run(Class main, String[] args);
035:
036: public static void main(final String[] args) throws Exception {
037: int runs = 1;
038: int eat = 0;
039:
040: if (args.length <= 1) {
041: Nonstop.usage();
042: }
043:
044: for (eat = 0; eat < args.length; eat++) {
045: if (args[eat].equals("-run")) {
046: if (++eat >= args.length) {
047: Nonstop.usage();
048: }
049:
050: runs = Integer.parseInt(args[eat]);
051:
052: if (runs <= 0) {
053: Nonstop.usage();
054: }
055:
056: } else {
057: // The main class
058: eat++;
059: break;
060: }
061: }
062:
063: /* Got all the args. */
064: if (eat > args.length) {
065: Nonstop.usage();
066: }
067:
068: final BenchmarkSecurityManager sec = new BenchmarkSecurityManager();
069: System.setSecurityManager(sec);
070:
071: final String mainClassName = args[eat - 1];
072: final String[] a = new String[args.length - eat];
073:
074: System.err.println("Running " + mainClassName);
075:
076: for (int i = 0; i < runs; i++) {
077: try {
078: final Class mainClass = Class.forName(mainClassName);
079:
080: System.arraycopy(args, eat, a, 0, a.length);
081:
082: Benchmark.run(mainClass, a);
083: } catch (final SecurityException e) {
084: continue;
085: } catch (final Exception e) {
086: e.printStackTrace(System.err);
087: sec.allowExit = true;
088: System.exit(1);
089: }
090: }
091:
092: sec.allowExit = true;
093: }
094:
095: private static void usage() {
096: System.err.print("usage: java EDU.purdue.cs.bloat.Benchmark ");
097: System.err.println("options class args...");
098: System.err.println("where options are one of:");
099: System.exit(1);
100: }
101: }
|