]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gprofng/testsuite/gprofng.display/jsynprog/jsynprog.java
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gprofng / testsuite / gprofng.display / jsynprog / jsynprog.java
CommitLineData
fd67aa11 1/* Copyright (C) 2021-2024 Free Software Foundation, Inc.
defb7341
VM
2 Contributed by Oracle.
3
4 This file is part of GNU Binutils.
5
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)
9 any later version.
10
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.
15
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. */
bb368aad
VM
20
21import java.util.*;
22import java.io.*;
23import java.text.*;
24
25class jsynprog
26{
27 private static String dir_home;
28 private static PrintWriter log;
29 private static double pstart, cstart;
30
31 /* JNI calls */
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;
defb7341
VM
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";
bb368aad
VM
50
51 createAcct();
52 LoadJNILibrary(args);
53 testtime = computeSet();
54
55 /* check for invocation parameter */
defb7341
VM
56 for (int i = 0; i < args.length; i++) {
57 if (args[i].equals("-fast")) {
bb368aad 58 scale = 10000;
defb7341 59 } else if (args[i].equals("-slow")) {
bb368aad 60 scale = 1;
defb7341
VM
61 } else if (args[i].equals("-j") && i + 1 < args.length) {
62 commands = args[++i];
bb368aad
VM
63 } else {
64 System.err.println("fatal: unexpected argument: " + args[0] );
65 System.exit(1);
66 }
67 }
68
69 /* large memory allocations, trigger gc */
70 Routine rtn = new Routine();
71 Sub_Routine sbrt = new Sub_Routine();
defb7341
VM
72
73 if (commands.indexOf("memalloc") >= 0) {
74 recTime();
75 rtn.memalloc(10000, scale);
76 printValue("Routine.memalloc", false);
77 }
bb368aad
VM
78
79 /* add integers */
defb7341
VM
80 if (commands.indexOf("add_int") >= 0) {
81 recTime();
82 ni = new Integer (rtn.add_int(scale));
83 printValue("Routine.add_int", true);
84 }
bb368aad
VM
85
86 /* add double */
defb7341
VM
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 }
bb368aad
VM
92
93 /* call method in derived class */
defb7341
VM
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 }
bb368aad
VM
99
100 /* call method that defines an inner class */
defb7341
VM
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 }
bb368aad
VM
106
107 /* recursion */
defb7341
VM
108 if (commands.indexOf("recurse") >= 0) {
109 recTime();
110 rtn.recurse(0,80, scale);
111 printValue("Routine.recurse", true);
112 }
bb368aad
VM
113
114 /* deep recursion */
defb7341
VM
115 if (commands.indexOf("recursedeep") >= 0) {
116 recTime();
117 rtn.recursedeep(0,500, scale);
118 printValue("<Truncated-stack>", true);
119 }
bb368aad
VM
120
121 /* indirect recursion */
defb7341
VM
122 if (commands.indexOf("bounce") >= 0) {
123 recTime();
124 rtn.bounce(0,20, scale);
125 printValue("Routine.bounce", true);
126 }
bb368aad
VM
127
128 /* array operations */
defb7341
VM
129 if (commands.indexOf("array_op") >= 0) {
130 recTime();
131 rtn.array_op(scale);
132 printValue("Routine.array_op", false);
133 }
bb368aad
VM
134
135 /* Vector operations */
defb7341
VM
136 if (commands.indexOf("vector_op") >= 0) {
137 recTime();
138 rtn.vector_op(scale);
139 printValue("Routine.vector_op", false);
140 }
bb368aad
VM
141
142 /* spend time in system calls */
defb7341
VM
143 if (commands.indexOf("sys_op") >= 0) {
144 recTime();
145 rtn.sys_op(scale);
146 printValue("Routine.sys_op", false);
147 }
bb368aad
VM
148
149 /* java->java->c */
defb7341
VM
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 }
bb368aad
VM
156
157 /* java->c->c */
defb7341
VM
158 if (commands.indexOf("JavaCC") >= 0) {
159 recTime();
160 JavaCC(scale);
161 printValue("jsynprog.JavaCC", true);
162 }
bb368aad
VM
163
164 /* java->c->java */
defb7341
VM
165 if (commands.indexOf("JavaCJava") >= 0) {
166 recTime();
167 JavaCJava(scale);
168 printValue("jsynprog.JavaCJava", true);
169 }
bb368aad
VM
170
171
172 /* dynamically loaded classes */
defb7341
VM
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 }
bb368aad
VM
181
182 System.gc();
183 }
184
185 /*
186 ** Create accounting file
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 ** Print output in acct file
203 */
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");
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 ** Record intial times
221 */
222 private static void recTime() {
223 pstart = Timer(); // Global.Timer();
224 cstart = cTimer(); // Global.cTimer();
225 }
226
227 /*
228 ** Load dynamic shared library for JNI
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 // Find which JVM was invoked
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 ** Makes a lot of JNI calls
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 // System.out.println("Entering javafunc, scale = " + scale);
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}