Skip to content
Permalink
Browse files
8263185: Mallinfo deprecated in glibc 2.33
Reviewed-by: stuefe, dholmes
  • Loading branch information
mychris authored and tstuefe committed Mar 19, 2021
1 parent d24e4cf commit 454af8719e3f0e09de7665941a9a19f6e93f6d7a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
@@ -167,6 +167,11 @@ const char * os::Linux::_libc_version = NULL;
const char * os::Linux::_libpthread_version = NULL;
size_t os::Linux::_default_large_page_size = 0;

#ifdef __GLIBC__
os::Linux::mallinfo_func_t os::Linux::_mallinfo = NULL;
os::Linux::mallinfo2_func_t os::Linux::_mallinfo2 = NULL;
#endif // __GLIBC__

static jlong initial_time_count=0;

static int clock_tics_per_sec = 100;
@@ -2174,19 +2179,25 @@ void os::Linux::print_process_memory_info(outputStream* st) {
// Print glibc outstanding allocations.
// (note: there is no implementation of mallinfo for muslc)
#ifdef __GLIBC__
struct mallinfo mi = ::mallinfo();

// mallinfo is an old API. Member names mean next to nothing and, beyond that, are int.
// So values may have wrapped around. Still useful enough to see how much glibc thinks
// we allocated.
const size_t total_allocated = (size_t)(unsigned)mi.uordblks;
st->print("C-Heap outstanding allocations: " SIZE_FORMAT "K", total_allocated / K);
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
if ((vmrss * K) > UINT_MAX && (vmrss * K) > (total_allocated + UINT_MAX)) {
st->print(" (may have wrapped)");
size_t total_allocated = 0;
bool might_have_wrapped = false;
if (_mallinfo2 != NULL) {
struct glibc_mallinfo2 mi = _mallinfo2();
total_allocated = mi.uordblks;
} else if (_mallinfo != NULL) {
// mallinfo is an old API. Member names mean next to nothing and, beyond that, are int.
// So values may have wrapped around. Still useful enough to see how much glibc thinks
// we allocated.
struct glibc_mallinfo mi = _mallinfo();
total_allocated = (size_t)(unsigned)mi.uordblks;
// Since mallinfo members are int, glibc values may have wrapped. Warn about this.
might_have_wrapped = (vmrss * K) > UINT_MAX && (vmrss * K) > (total_allocated + UINT_MAX);
}
if (_mallinfo2 != NULL || _mallinfo != NULL) {
st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K%s",
total_allocated / K,
might_have_wrapped ? " (may have wrapped)" : "");
}
st->cr();

#endif // __GLIBC__

}
@@ -4351,6 +4362,11 @@ void os::init(void) {

Linux::initialize_system_info();

#ifdef __GLIBC__
Linux::_mallinfo = CAST_TO_FN_PTR(Linux::mallinfo_func_t, dlsym(RTLD_DEFAULT, "mallinfo"));
Linux::_mallinfo2 = CAST_TO_FN_PTR(Linux::mallinfo2_func_t, dlsym(RTLD_DEFAULT, "mallinfo2"));
#endif // __GLIBC__

os::Linux::CPUPerfTicks pticks;
bool res = os::Linux::get_tick_information(&pticks, -1);

@@ -253,6 +253,40 @@ class Linux {
};
static NumaAllocationPolicy _current_numa_policy;

#ifdef __GLIBC__
struct glibc_mallinfo {
int arena;
int ordblks;
int smblks;
int hblks;
int hblkhd;
int usmblks;
int fsmblks;
int uordblks;
int fordblks;
int keepcost;
};

struct glibc_mallinfo2 {
size_t arena;
size_t ordblks;
size_t smblks;
size_t hblks;
size_t hblkhd;
size_t usmblks;
size_t fsmblks;
size_t uordblks;
size_t fordblks;
size_t keepcost;
};

typedef struct glibc_mallinfo (*mallinfo_func_t)(void);
typedef struct glibc_mallinfo2 (*mallinfo2_func_t)(void);

static mallinfo_func_t _mallinfo;
static mallinfo2_func_t _mallinfo2;
#endif

public:
static int sched_getcpu() { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }
static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen);

0 comments on commit 454af87

Please sign in to comment.