Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/aix/vm/libperfstat_aix.cpp
32284 views
/*1* Copyright 2012, 2013 SAP AG. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "runtime/arguments.hpp"25#include "libperfstat_aix.hpp"2627// For dlopen and friends28#include <fcntl.h>2930// handle to the libperfstat31static void* g_libhandle = NULL;3233// whether initialization worked34static bool g_initialized = false;353637typedef int (*fun_perfstat_cpu_total_t) (perfstat_id_t *name, perfstat_cpu_total_t* userbuff,38int sizeof_userbuff, int desired_number);3940typedef int (*fun_perfstat_memory_total_t) (perfstat_id_t *name, perfstat_memory_total_t* userbuff,41int sizeof_userbuff, int desired_number);4243typedef void (*fun_perfstat_reset_t) ();4445static fun_perfstat_cpu_total_t g_fun_perfstat_cpu_total = NULL;46static fun_perfstat_memory_total_t g_fun_perfstat_memory_total = NULL;47static fun_perfstat_reset_t g_fun_perfstat_reset = NULL;4849bool libperfstat::init() {5051if (g_initialized) {52return true;53}5455g_initialized = false;5657// dynamically load the libperfstat porting library.58g_libhandle = dlopen("/usr/lib/libperfstat.a(shr_64.o)", RTLD_MEMBER | RTLD_NOW);59if (!g_libhandle) {60if (Verbose) {61fprintf(stderr, "Cannot load libperfstat.a (dlerror: %s)", dlerror());62}63return false;64}6566// resolve function pointers6768#define RESOLVE_FUN_NO_ERROR(name) \69g_fun_##name = (fun_##name##_t) dlsym(g_libhandle, #name);7071#define RESOLVE_FUN(name) \72RESOLVE_FUN_NO_ERROR(name) \73if (!g_fun_##name) { \74if (Verbose) { \75fprintf(stderr, "Cannot resolve " #name "() from libperfstat.a\n" \76" (dlerror: %s)", dlerror()); \77} \78return false; \79}8081RESOLVE_FUN(perfstat_cpu_total);82RESOLVE_FUN(perfstat_memory_total);83RESOLVE_FUN(perfstat_reset);8485g_initialized = true;8687return true;88}8990void libperfstat::cleanup() {9192g_initialized = false;9394if (g_libhandle) {95dlclose(g_libhandle);96g_libhandle = NULL;97}9899g_fun_perfstat_cpu_total = NULL;100g_fun_perfstat_memory_total = NULL;101g_fun_perfstat_reset = NULL;102}103104int libperfstat::perfstat_memory_total(perfstat_id_t *name,105perfstat_memory_total_t* userbuff,106int sizeof_userbuff, int desired_number) {107assert(g_initialized, "libperfstat not initialized");108assert(g_fun_perfstat_memory_total, "");109return g_fun_perfstat_memory_total(name, userbuff, sizeof_userbuff, desired_number);110}111112int libperfstat::perfstat_cpu_total(perfstat_id_t *name, perfstat_cpu_total_t* userbuff,113int sizeof_userbuff, int desired_number) {114assert(g_initialized, "libperfstat not initialized");115assert(g_fun_perfstat_cpu_total, "");116return g_fun_perfstat_cpu_total(name, userbuff, sizeof_userbuff, desired_number);117}118119void libperfstat::perfstat_reset() {120assert(g_initialized, "libperfstat not initialized");121assert(g_fun_perfstat_reset, "");122g_fun_perfstat_reset();123}124125126