]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gprofng/testsuite/gprofng.display/jsynprog/cloop.cc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gprofng / testsuite / gprofng.display / jsynprog / cloop.cc
1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
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. */
20
21 #include <jni.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdlib.h>
25 #include <sys/time.h>
26 #include "jsynprog.h"
27
28 typedef long long hrtime_t;
29 extern "C" {
30 hrtime_t gethrtime();
31 hrtime_t gethrvtime();
32 }
33 static jdouble testtime = 3.0 * 1e9;
34
35 int cfunc(int);
36
37 JNIEXPORT jdouble JNICALL
38 Java_jsynprog_Timer (JNIEnv *env, jclass obj)
39 {
40 jdouble jd;
41 hrtime_t start;
42
43 start = gethrtime();
44 jd = (double)(start);
45 return jd;
46 }
47
48 JNIEXPORT jdouble JNICALL
49 Java_jsynprog_cTimer (JNIEnv *env, jclass obj)
50 {
51 jdouble jd;
52 hrtime_t vstart;
53
54 vstart = gethrvtime();
55 jd = (double)(vstart);
56 return jd;
57 }
58
59 JNIEXPORT jdouble JNICALL
60 Java_jsynprog_computeSet (JNIEnv *env, jclass obj)
61 {
62 char *s;
63
64 testtime = 3.0;
65 s = getenv("SP_COLLECTOR_TEST_TIMER");
66 if( s ) {
67 testtime = atof(s);
68 if (testtime < 1.0)
69 testtime = 1.0;
70 }
71 testtime *= 1e9;
72 return testtime;
73 }
74
75 JNIEXPORT jint JNICALL
76 Java_jsynprog_JavaJavaC (JNIEnv *env, jclass obj, jint n, int scale )
77 {
78 // fprintf(stderr, "Entering Java_jsynprog_JavaJavaC, scale = %d\n", scale);
79 int imax = 100000;
80 n = 0;
81 for (int i =0; i<imax; i++) {
82 n=n+((i%2==0)?1:2);
83 }
84 return n;
85 }
86
87 JNIEXPORT void JNICALL
88 Java_jsynprog_JavaCC (JNIEnv *env, jclass obj, int scale)
89 {
90 fprintf(stderr, "Entering Java_jsynprog_JavaCC, scale = %d\n", scale);
91 int n =0;
92 if (scale == 1) {
93 scale *= 1000;
94 }
95 int imax = 4*scale;
96 double tEnd = gethrtime() + testtime;
97 do { n = 0;
98 for (int i =0; i<imax; i++) {
99 n = cfunc(n);
100 }
101 } while (gethrtime() < tEnd);
102 }
103
104 int cfunc (int n) {
105 for (int j =0; j<100000;j++) {
106 n=n+1;
107 }
108 return n;
109 }
110
111 JNIEXPORT void JNICALL
112 Java_jsynprog_JavaCJava (JNIEnv *env, jclass obj, int scale)
113 {
114 fprintf(stderr, "Entering Java_jsynprog_JavaCJava, scale = %d\n", scale);
115 int pnum = 0;
116 jmethodID mid = (env)->GetStaticMethodID(obj, "javafunc", "(I)I");
117 if (mid == 0) {
118 fprintf(stderr, "Can't get jmethodID for \"javafunc\", \"(I)I\"\n");
119 return;
120 }
121 fprintf(stderr, "Calling CallStaticIntMethod, scale = %d\n", scale);
122 pnum = (env)->CallStaticIntMethod(obj, mid, scale);
123 }
124
125 JNIEXPORT jint JNICALL
126 Java_jsynprog_isJVMPI (JNIEnv *env, jclass obj)
127 {
128 char *jvmpi = getenv("SP_COLLECTOR_USE_JVMPI");
129
130 return jvmpi ? 1 : 0;
131 }