| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import java.util.*; |
| 22 |
import java.io.*; |
| 23 |
import java.text.*; |
| 24 |
|
| 25 |
class jsynprog |
| 26 |
{ |
| 27 |
private static String dir_home; |
| 28 |
private static PrintWriter log; |
| 29 |
private static double pstart, cstart; |
| 30 |
|
| 31 |
|
| 32 |
public static native double Timer(); |
| 33 |
private static native double cTimer(); |
| 34 |
private static native double computeSet(); |
| 35 |
private static native int JavaJavaC(int np, int scale); |
| 36 |
private static native void JavaCC(int scale); |
| 37 |
private static native void JavaCJava(int scale); |
| 38 |
private static native int isJVMPI(); |
| 39 |
|
| 40 |
public static double testtime = 3.0 * 1e9; |
| 41 |
|
| 42 |
public static void main (String [] args) |
| 43 |
{ |
| 44 |
jsynprog jsyn_obj = new jsynprog(); |
| 45 |
Integer ni; |
| 46 |
int scale = 1000; |
| 47 |
String commands = "memalloc.add_int.add_double.has_inner_class" + |
| 48 |
".recurse.recursedeep.bounce.array_op.vector_op.sys_op" + |
| 49 |
".jni_JavaJavaC.JavaCC.JavaCJava.Launcher"; |
| 50 |
|
| 51 |
createAcct(); |
| 52 |
LoadJNILibrary(args); |
| 53 |
testtime = computeSet(); |
| 54 |
|
| 55 |
|
| 56 |
for (int i = 0; i < args.length; i++) { |
| 57 |
if (args[i].equals("-fast")) { |
| 58 |
scale = 10000; |
| 59 |
} else if (args[i].equals("-slow")) { |
| 60 |
scale = 1; |
| 61 |
} else if (args[i].equals("-j") && i + 1 < args.length) { |
| 62 |
commands = args[++i]; |
| 63 |
} else { |
| 64 |
System.err.println("fatal: unexpected argument: " + args[0] ); |
| 65 |
System.exit(1); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
Routine rtn = new Routine(); |
| 71 |
Sub_Routine sbrt = new Sub_Routine(); |
| 72 |
|
| 73 |
if (commands.indexOf("memalloc") >= 0) { |
| 74 |
recTime(); |
| 75 |
rtn.memalloc(10000, scale); |
| 76 |
printValue("Routine.memalloc", false); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
if (commands.indexOf("add_int") >= 0) { |
| 81 |
recTime(); |
| 82 |
ni = new Integer (rtn.add_int(scale)); |
| 83 |
printValue("Routine.add_int", true); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
if (commands.indexOf("add_double") >= 0) { |
| 88 |
recTime(); |
| 89 |
Double nd = new Double(rtn.add_double(scale)); |
| 90 |
printValue("Routine.add_double", true); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
if (commands.indexOf("add_int") >= 0) { |
| 95 |
recTime(); |
| 96 |
ni = new Integer (sbrt.add_int(scale)); |
| 97 |
printValue("Sub_Routine.add_int", true); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
if (commands.indexOf("has_inner_class") >= 0) { |
| 102 |
recTime(); |
| 103 |
Integer[] na = rtn.has_inner_class(scale); |
| 104 |
printValue("Routine.has_inner_class", true); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
if (commands.indexOf("recurse") >= 0) { |
| 109 |
recTime(); |
| 110 |
rtn.recurse(0,80, scale); |
| 111 |
printValue("Routine.recurse", true); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
if (commands.indexOf("recursedeep") >= 0) { |
| 116 |
recTime(); |
| 117 |
rtn.recursedeep(0,500, scale); |
| 118 |
printValue("<Truncated-stack>", true); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
if (commands.indexOf("bounce") >= 0) { |
| 123 |
recTime(); |
| 124 |
rtn.bounce(0,20, scale); |
| 125 |
printValue("Routine.bounce", true); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
if (commands.indexOf("array_op") >= 0) { |
| 130 |
recTime(); |
| 131 |
rtn.array_op(scale); |
| 132 |
printValue("Routine.array_op", false); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
if (commands.indexOf("vector_op") >= 0) { |
| 137 |
recTime(); |
| 138 |
rtn.vector_op(scale); |
| 139 |
printValue("Routine.vector_op", false); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
if (commands.indexOf("sys_op") >= 0) { |
| 144 |
recTime(); |
| 145 |
rtn.sys_op(scale); |
| 146 |
printValue("Routine.sys_op", false); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
if (commands.indexOf("jni_JavaJavaC") >= 0) { |
| 151 |
recTime(); |
| 152 |
int np = 0; |
| 153 |
jni_JavaJavaC(np, scale); |
| 154 |
printValue("jsynprog.jni_JavaJavaC", true); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
if (commands.indexOf("JavaCC") >= 0) { |
| 159 |
recTime(); |
| 160 |
JavaCC(scale); |
| 161 |
printValue("jsynprog.JavaCC", true); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
if (commands.indexOf("JavaCJava") >= 0) { |
| 166 |
recTime(); |
| 167 |
JavaCJava(scale); |
| 168 |
printValue("jsynprog.JavaCJava", true); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
if (commands.indexOf("Launcher") >= 0) { |
| 174 |
String java_ver = System.getProperty("java.version"); |
| 175 |
Launcher lnch = new Launcher(); |
| 176 |
String[] params = new String[]{"DynLoadedClass"}; |
| 177 |
recTime(); |
| 178 |
lnch.main(params); |
| 179 |
printValue("Launcher.main", true); |
| 180 |
} |
| 181 |
|
| 182 |
System.gc(); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
private static void createAcct() { |
| 189 |
System.out.println ("Directing output to acct file..."); |
| 190 |
try { |
| 191 |
log = new PrintWriter (new FileWriter("jsynprog.acct"), true); |
| 192 |
} catch (IOException ioe) { |
| 193 |
ioe.printStackTrace(); |
| 194 |
System.err.println("fatal: Cannot create accounting file "); |
| 195 |
System.exit(1); |
| 196 |
} |
| 197 |
|
| 198 |
log.println("X\tLWPTime\tCPUTime\tFunction"); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
private static void printValue (String fname, boolean noignore) { |
| 205 |
double p_end = Timer(); |
| 206 |
double c_end = cTimer(); |
| 207 |
double prog_elapsed = p_end - pstart; |
| 208 |
double cpu_elapsed = c_end - cstart; |
| 209 |
DecimalFormat format_decimal = new DecimalFormat("0.000"); |
| 210 |
|
| 211 |
System.out.println("Running " + fname + "; T = " + format_decimal.format(prog_elapsed * 0.000000001) |
| 212 |
+" UCPU = " + format_decimal.format(cpu_elapsed * 0.000000001)); |
| 213 |
log.print( (noignore == true? "X" : "Y") |
| 214 |
+ "\t" + format_decimal.format(prog_elapsed * 0.000000001) + "\t" |
| 215 |
+ format_decimal.format(cpu_elapsed * 0.000000001) + "\t"); |
| 216 |
log.println(fname); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
private static void recTime() { |
| 223 |
pstart = Timer(); |
| 224 |
cstart = cTimer(); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
private static void LoadJNILibrary(String[] args) { |
| 231 |
|
| 232 |
try { |
| 233 |
dir_home = (new File(".")).getCanonicalPath(); |
| 234 |
} catch (IOException e) { |
| 235 |
dir_home = ".."; |
| 236 |
} |
| 237 |
System.out.println("libpath:"+dir_home); |
| 238 |
|
| 239 |
|
| 240 |
String jvm_format = System.getProperty("java.vm.name"); |
| 241 |
System.out.println("jvm "+ jvm_format); |
| 242 |
|
| 243 |
try { |
| 244 |
System.out.println("Loading library.... " + dir_home + "/libcloop.so"); |
| 245 |
System.load(dir_home + "/libcloop.so"); |
| 246 |
} catch (UnsatisfiedLinkError e) { |
| 247 |
System.err.println("fatal: Cannot load shared library " + e); |
| 248 |
System.exit(1); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
private static void jni_JavaJavaC(int np, int scale) { |
| 256 |
int ret = 0; |
| 257 |
int jmax = 10000; |
| 258 |
System.out.println("Entering jni_JavaJavaC, scale = " + scale); |
| 259 |
double tEnd = Timer() + testtime; |
| 260 |
do { |
| 261 |
for (int j =0 ; j<jmax; j++) { |
| 262 |
ret = JavaJavaC(np, scale); |
| 263 |
} |
| 264 |
} while (Timer() < tEnd); |
| 265 |
} |
| 266 |
|
| 267 |
public static int javafunc (int scale) { |
| 268 |
int jmax = 200*scale; |
| 269 |
int imax = 40; |
| 270 |
int np = 0; |
| 271 |
|
| 272 |
double tEnd = Timer() + testtime; |
| 273 |
do { np = 0; |
| 274 |
for (int j =0 ; j<jmax; j++) { |
| 275 |
for (int i =0 ; i<imax; i++) { |
| 276 |
np = (i%2==0)?np:(np + 1); |
| 277 |
} |
| 278 |
} |
| 279 |
} while (Timer() < tEnd); |
| 280 |
return np; |
| 281 |
} |
| 282 |
} |