1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
27 private static String dir_home
;
28 private static PrintWriter log
;
29 private static double pstart
, cstart
;
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();
40 public static double testtime
= 3.0 * 1e9
;
42 public static void main (String
[] args
)
44 jsynprog jsyn_obj
= new jsynprog();
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";
53 testtime
= computeSet();
55 /* check for invocation parameter */
56 for (int i
= 0; i
< args
.length
; i
++) {
57 if (args
[i
].equals("-fast")) {
59 } else if (args
[i
].equals("-slow")) {
61 } else if (args
[i
].equals("-j") && i
+ 1 < args
.length
) {
64 System
.err
.println("fatal: unexpected argument: " + args
[0] );
69 /* large memory allocations, trigger gc */
70 Routine rtn
= new Routine();
71 Sub_Routine sbrt
= new Sub_Routine();
73 if (commands
.indexOf("memalloc") >= 0) {
75 rtn
.memalloc(10000, scale
);
76 printValue("Routine.memalloc", false);
80 if (commands
.indexOf("add_int") >= 0) {
82 ni
= new Integer (rtn
.add_int(scale
));
83 printValue("Routine.add_int", true);
87 if (commands
.indexOf("add_double") >= 0) {
89 Double nd
= new Double(rtn
.add_double(scale
));
90 printValue("Routine.add_double", true);
93 /* call method in derived class */
94 if (commands
.indexOf("add_int") >= 0) {
96 ni
= new Integer (sbrt
.add_int(scale
));
97 printValue("Sub_Routine.add_int", true);
100 /* call method that defines an inner class */
101 if (commands
.indexOf("has_inner_class") >= 0) {
103 Integer
[] na
= rtn
.has_inner_class(scale
);
104 printValue("Routine.has_inner_class", true);
108 if (commands
.indexOf("recurse") >= 0) {
110 rtn
.recurse(0,80, scale
);
111 printValue("Routine.recurse", true);
115 if (commands
.indexOf("recursedeep") >= 0) {
117 rtn
.recursedeep(0,500, scale
);
118 printValue("<Truncated-stack>", true);
121 /* indirect recursion */
122 if (commands
.indexOf("bounce") >= 0) {
124 rtn
.bounce(0,20, scale
);
125 printValue("Routine.bounce", true);
128 /* array operations */
129 if (commands
.indexOf("array_op") >= 0) {
132 printValue("Routine.array_op", false);
135 /* Vector operations */
136 if (commands
.indexOf("vector_op") >= 0) {
138 rtn
.vector_op(scale
);
139 printValue("Routine.vector_op", false);
142 /* spend time in system calls */
143 if (commands
.indexOf("sys_op") >= 0) {
146 printValue("Routine.sys_op", false);
150 if (commands
.indexOf("jni_JavaJavaC") >= 0) {
153 jni_JavaJavaC(np
, scale
);
154 printValue("jsynprog.jni_JavaJavaC", true);
158 if (commands
.indexOf("JavaCC") >= 0) {
161 printValue("jsynprog.JavaCC", true);
165 if (commands
.indexOf("JavaCJava") >= 0) {
168 printValue("jsynprog.JavaCJava", true);
172 /* dynamically loaded classes */
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"};
179 printValue("Launcher.main", true);
186 ** Create accounting file
188 private static void createAcct() {
189 System
.out
.println ("Directing output to acct file...");
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 ");
198 log
.println("X\tLWPTime\tCPUTime\tFunction");
202 ** Print output in acct file
204 private static void printValue (String fname
, boolean noignore
) {
205 double p_end
= Timer(); // Global.Timer();
206 double c_end
= cTimer(); // Global.cTimer();
207 double prog_elapsed
= p_end
- pstart
;
208 double cpu_elapsed
= c_end
- cstart
;
209 DecimalFormat format_decimal
= new DecimalFormat("0.000");
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");
220 ** Record intial times
222 private static void recTime() {
223 pstart
= Timer(); // Global.Timer();
224 cstart
= cTimer(); // Global.cTimer();
228 ** Load dynamic shared library for JNI
230 private static void LoadJNILibrary(String
[] args
) {
233 dir_home
= (new File(".")).getCanonicalPath();
234 } catch (IOException e
) {
237 System
.out
.println("libpath:"+dir_home
);
239 // Find which JVM was invoked
240 String jvm_format
= System
.getProperty("java.vm.name");
241 System
.out
.println("jvm "+ jvm_format
);
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
);
253 ** Makes a lot of JNI calls
255 private static void jni_JavaJavaC(int np
, int scale
) {
258 System
.out
.println("Entering jni_JavaJavaC, scale = " + scale
);
259 double tEnd
= Timer() + testtime
;
261 for (int j
=0 ; j
<jmax
; j
++) {
262 ret
= JavaJavaC(np
, scale
);
264 } while (Timer() < tEnd
);
267 public static int javafunc (int scale
) {
268 int jmax
= 200*scale
;
271 // System.out.println("Entering javafunc, scale = " + scale);
272 double tEnd
= Timer() + testtime
;
274 for (int j
=0 ; j
<jmax
; j
++) {
275 for (int i
=0 ; i
<imax
; i
++) {
276 np
= (i
%2==0)?np
:(np
+ 1);
279 } while (Timer() < tEnd
);