/* Copyright (C) 2021-2024 Free Software Foundation, Inc. Contributed by Oracle. This file is part of GNU Binutils. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include "jsynprog.h" typedef long long hrtime_t; extern "C" { hrtime_t gethrtime(); hrtime_t gethrvtime(); } static jdouble testtime = 3.0 * 1e9; int cfunc(int); JNIEXPORT jdouble JNICALL Java_jsynprog_Timer (JNIEnv *env, jclass obj) { jdouble jd; hrtime_t start; start = gethrtime(); jd = (double)(start); return jd; } JNIEXPORT jdouble JNICALL Java_jsynprog_cTimer (JNIEnv *env, jclass obj) { jdouble jd; hrtime_t vstart; vstart = gethrvtime(); jd = (double)(vstart); return jd; } JNIEXPORT jdouble JNICALL Java_jsynprog_computeSet (JNIEnv *env, jclass obj) { char *s; testtime = 3.0; s = getenv("SP_COLLECTOR_TEST_TIMER"); if( s ) { testtime = atof(s); if (testtime < 1.0) testtime = 1.0; } testtime *= 1e9; return testtime; } JNIEXPORT jint JNICALL Java_jsynprog_JavaJavaC (JNIEnv *env, jclass obj, jint n, int scale ) { // fprintf(stderr, "Entering Java_jsynprog_JavaJavaC, scale = %d\n", scale); int imax = 100000; n = 0; for (int i =0; iGetStaticMethodID(obj, "javafunc", "(I)I"); if (mid == 0) { fprintf(stderr, "Can't get jmethodID for \"javafunc\", \"(I)I\"\n"); return; } fprintf(stderr, "Calling CallStaticIntMethod, scale = %d\n", scale); pnum = (env)->CallStaticIntMethod(obj, mid, scale); } JNIEXPORT jint JNICALL Java_jsynprog_isJVMPI (JNIEnv *env, jclass obj) { char *jvmpi = getenv("SP_COLLECTOR_USE_JVMPI"); return jvmpi ? 1 : 0; }