annotate src/os/aix/vm/libperfstat_aix.cpp @ 21947:9f70fc90169d

Truffle: remove expensive assertion
author Andreas Woess <andreas.woess@oracle.com>
date Wed, 17 Jun 2015 04:09:30 +0200
parents 666e6ce3976c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14415
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
1 /*
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
2 * Copyright 2012, 2013 SAP AG. All rights reserved.
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
4 *
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
7 * published by the Free Software Foundation.
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
8 *
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
13 * accompanied this code).
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
14 *
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
18 *
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
21 * questions.
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
22 *
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
23 */
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
24
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
25 #include "runtime/arguments.hpp"
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
26 #include "libperfstat_aix.hpp"
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
27
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
28 // For dlopen and friends
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
29 #include <fcntl.h>
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
30
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
31 // handle to the libperfstat
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
32 static void* g_libhandle = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
33
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
34 // whether initialization worked
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
35 static bool g_initialized = false;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
36
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
37
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
38 typedef int (*fun_perfstat_cpu_total_t) (perfstat_id_t *name, perfstat_cpu_total_t* userbuff,
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
39 int sizeof_userbuff, int desired_number);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
40
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
41 typedef int (*fun_perfstat_memory_total_t) (perfstat_id_t *name, perfstat_memory_total_t* userbuff,
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
42 int sizeof_userbuff, int desired_number);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
43
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
44 typedef void (*fun_perfstat_reset_t) ();
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
45
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
46 static fun_perfstat_cpu_total_t g_fun_perfstat_cpu_total = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
47 static fun_perfstat_memory_total_t g_fun_perfstat_memory_total = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
48 static fun_perfstat_reset_t g_fun_perfstat_reset = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
49
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
50 bool libperfstat::init() {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
51
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
52 if (g_initialized) {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
53 return true;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
54 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
55
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
56 g_initialized = false;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
57
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
58 // dynamically load the libperfstat porting library.
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
59 g_libhandle = dlopen("/usr/lib/libperfstat.a(shr_64.o)", RTLD_MEMBER | RTLD_NOW);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
60 if (!g_libhandle) {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
61 if (Verbose) {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
62 fprintf(stderr, "Cannot load libperfstat.a (dlerror: %s)", dlerror());
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
63 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
64 return false;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
65 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
66
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
67 // resolve function pointers
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
68
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
69 #define RESOLVE_FUN_NO_ERROR(name) \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
70 g_fun_##name = (fun_##name##_t) dlsym(g_libhandle, #name);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
71
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
72 #define RESOLVE_FUN(name) \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
73 RESOLVE_FUN_NO_ERROR(name) \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
74 if (!g_fun_##name) { \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
75 if (Verbose) { \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
76 fprintf(stderr, "Cannot resolve " #name "() from libperfstat.a\n" \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
77 " (dlerror: %s)", dlerror()); \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
78 } \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
79 return false; \
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
80 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
81
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
82 RESOLVE_FUN(perfstat_cpu_total);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
83 RESOLVE_FUN(perfstat_memory_total);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
84 RESOLVE_FUN(perfstat_reset);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
85
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
86 g_initialized = true;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
87
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
88 return true;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
89 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
90
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
91 void libperfstat::cleanup() {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
92
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
93 g_initialized = false;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
94
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
95 if (g_libhandle) {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
96 dlclose(g_libhandle);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
97 g_libhandle = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
98 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
99
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
100 g_fun_perfstat_cpu_total = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
101 g_fun_perfstat_memory_total = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
102 g_fun_perfstat_reset = NULL;
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
103 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
104
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
105 int libperfstat::perfstat_memory_total(perfstat_id_t *name,
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
106 perfstat_memory_total_t* userbuff,
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
107 int sizeof_userbuff, int desired_number) {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
108 assert(g_initialized, "libperfstat not initialized");
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
109 assert(g_fun_perfstat_memory_total, "");
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
110 return g_fun_perfstat_memory_total(name, userbuff, sizeof_userbuff, desired_number);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
111 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
112
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
113 int libperfstat::perfstat_cpu_total(perfstat_id_t *name, perfstat_cpu_total_t* userbuff,
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
114 int sizeof_userbuff, int desired_number) {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
115 assert(g_initialized, "libperfstat not initialized");
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
116 assert(g_fun_perfstat_cpu_total, "");
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
117 return g_fun_perfstat_cpu_total(name, userbuff, sizeof_userbuff, desired_number);
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
118 }
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
119
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
120 void libperfstat::perfstat_reset() {
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
121 assert(g_initialized, "libperfstat not initialized");
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
122 assert(g_fun_perfstat_reset, "");
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
123 g_fun_perfstat_reset();
666e6ce3976c 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
124 }