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: * This class is used to execute the BLOAT benchmarks while the Shade
025: * performanace monitoring software is running.
026: */
027: public class Shade {
028: static {
029: System.loadLibrary("shade");
030: }
031:
032: public static native void run(Class main, String[] args,
033: boolean quit);
034:
035: public static void main(final String[] args) throws Exception {
036: boolean quit = false;
037: int runs = 1;
038: int eat = 0;
039:
040: if (args.length <= 1) {
041: Shade.usage();
042: }
043:
044: for (eat = 0; eat < args.length; eat++) {
045: if (args[eat].equals("-quit")) {
046: quit = true;
047: } else if (args[eat].equals("-run")) {
048: if (++eat >= args.length) {
049: Shade.usage();
050: }
051:
052: runs = Integer.parseInt(args[eat]);
053:
054: if (runs <= 0) {
055: Shade.usage();
056: }
057: } else {
058: // The main class
059: eat++;
060: break;
061: }
062: }
063:
064: /* Got all the args. */
065: if (eat > args.length) {
066: Shade.usage();
067: }
068:
069: // Install a secutiry manager in which we can control whether or
070: // not the virtual machine is allowed to exit. We want to be able
071: // to make multiple runs of the main class without the VM exiting.
072: final BenchmarkSecurityManager sec = new BenchmarkSecurityManager();
073: System.setSecurityManager(sec);
074:
075: final String mainClassName = args[eat - 1];
076: final String[] a = new String[args.length - eat];
077:
078: System.err.println("Running " + mainClassName);
079:
080: for (int i = 0; i < runs; i++) {
081: try {
082: final Class mainClass = Class.forName(mainClassName);
083:
084: System.arraycopy(args, eat, a, 0, a.length);
085:
086: Shade.run(mainClass, a, quit);
087:
088: } catch (final SecurityException e) {
089: // An execution of the mainClass finished and the VM attempted
090: // to exit, thus causing a SecutiryException to be thrown by
091: // the BenchmarkSecurityManager.
092: continue;
093:
094: } catch (final Exception e) {
095: e.printStackTrace(System.err);
096: sec.allowExit = true;
097: System.exit(1);
098: }
099: }
100:
101: sec.allowExit = true;
102: }
103:
104: private static void usage() {
105: System.err.print("usage: java EDU.purdue.cs.bloat.Shade ");
106: System.err.println("options class args...");
107: System.err.println("where options are one of:");
108: System.err.println(" -run n time n runs of the program");
109: System.exit(1);
110: }
111: }
|