]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gprofng/testsuite/gprofng.display/jsynprog/Launcher.java
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gprofng / testsuite / gprofng.display / jsynprog / Launcher.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.lang.reflect.*;
22
23public class Launcher {
24// Byte array for dynamically loaded class: //
25//public class DynLoadedClass { //
26// public int DynamicFunction(int x) { //
27// float f = 0; //
28// for (int k=0 ; k<20000; k++) { //
29// f = ((float)k) / x; //
30// } //
31// return (int)f; //
32// } //
33// //
34// public static void main(String[] args){ //
35// DynLoadedClass dcls = new DynLoadedClass(); //
36// for (int k=0 ; k<10; k++) { //
37// dcls.DynamicFunction(k); //
38// } //
39// } //
40//} //
41static final byte [] bClassGenerated = {
42 -54, -2, -70, -66, 0, 0, 0, 46, 0, 20, 10, 0, 5, 0, 16, 7, 0, 17, 10, 0, 2, 0, 16, 10, 0, 2,
43 0, 18, 7, 0, 19, 1, 0, 6, 60, 105, 110, 105, 116, 62, 1, 0, 3, 40, 41, 86, 1, 0, 4, 67, 111,
44 100, 101, 1, 0, 15, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 84, 97, 98, 108, 101, 1, 0, 15, 68, 121,
45 110, 97, 109, 105, 99, 70, 117, 110, 99, 116, 105, 111, 110, 1, 0, 4, 40, 73, 41, 73, 1, 0, 4, 109, 97,
46 105, 110, 1, 0, 22, 40, 91, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59,
47 41, 86, 1, 0, 10, 83, 111, 117, 114, 99, 101, 70, 105, 108, 101, 1, 0, 19, 68, 121, 110, 76, 111, 97, 100,
48 101, 100, 67, 108, 97, 115, 115, 46, 106, 97, 118, 97, 12, 0, 6, 0, 7, 1, 0, 14, 68, 121, 110, 76, 111,
49 97, 100, 101, 100, 67, 108, 97, 115, 115, 12, 0, 10, 0, 11, 1, 0, 16, 106, 97, 118, 97, 47, 108, 97, 110,
50 103, 47, 79, 98, 106, 101, 99, 116, 0, 33, 0, 2, 0, 5, 0, 0, 0, 0, 0, 3, 0, 1, 0, 6, 0,
51 7, 0, 1, 0, 8, 0, 0, 0, 29, 0, 1, 0, 1, 0, 0, 0, 5, 42, -73, 0, 1, -79, 0, 0, 0,
52 1, 0, 9, 0, 0, 0, 6, 0, 1, 0, 0, 0, 1, 0, 1, 0, 10, 0, 11, 0, 1, 0, 8, 0, 0,
53 0, 66, 0, 2, 0, 4, 0, 0, 0, 26, 11, 69, 3, 62, 29, 17, 78, 32, -94, 0, 15, 29, -122, 27, -122,
54 110, 69, -124, 3, 1, -89, -1, -16, 36, -117, -84, 0, 0, 0, 1, 0, 9, 0, 0, 0, 22, 0, 5, 0, 0,
55 0, 3, 0, 2, 0, 4, 0, 11, 0, 5, 0, 17, 0, 4, 0, 23, 0, 7, 0, 9, 0, 12, 0, 13, 0,
56 1, 0, 8, 0, 0, 0, 69, 0, 2, 0, 3, 0, 0, 0, 29, -69, 0, 2, 89, -73, 0, 3, 76, 3, 61,
57 28, 16, 10, -94, 0, 15, 43, 28, -74, 0, 4, 87, -124, 2, 1, -89, -1, -15, -79, 0, 0, 0, 1, 0, 9,
58 0, 0, 0, 22, 0, 5, 0, 0, 0, 11, 0, 8, 0, 12, 0, 16, 0, 13, 0, 22, 0, 12, 0, 28, 0,
59 15, 0, 1, 0, 14, 0, 0, 0, 2, 0, 15
60 };
61
62 private static DynClassLoader persistentInstance;
63
64 public static DynClassLoader getPersistentInstance()
65 {
66 if (persistentInstance == null)
67 persistentInstance = new DynClassLoader();
68 return persistentInstance;
69 }
70
71 public static void main(String args []) {
72 if (args.length != 1) {
73 System.err.println("Usage: Launcher DynLoadedClass");
74 return;
75 }
76
77 String className = args[0]; // Dynamic class name
78
79 try {
80 Class genClass = getPersistentInstance().getClassFromByteArray(className, bClassGenerated);
81 Method[] methods_g = genClass.getDeclaredMethods();
82
83 for (int i = 0; i < methods_g.length; i++) {
84 Method m = methods_g[i];
85 String methodName = m.getName();
86 String progArgs[] = new String[1];
87 //System.out.println("Invoking method " + className + "." + methodName);
88 if (methodName.equals("main"))
89 m.invoke( null, (Object[]) progArgs );
90 }
91 } catch (InvocationTargetException iex) {
92 System.err.println("InvocationTargetException");
93 } catch (IllegalAccessException aex) {
94 System.err.println("IllegalAccessException");
95 }
96 }
97
98 // Class loader to generate dynamic class on the fly from the byte array
99 private static class DynClassLoader extends ClassLoader {
100 public DynClassLoader() { }
101 public Class getClassFromByteArray(String name, byte[] b) {
102 return super.defineClass(name, b, 0, b.length);
103 }
104 }
105
106
107}