Skip to content

Commit c2ccf4c

Browse files
committedJun 14, 2022
8288003: log events for os::dll_unload
Reviewed-by: dholmes, stuefe
1 parent 03dca56 commit c2ccf4c

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
 

‎src/hotspot/os/linux/os_linux.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,18 @@ void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
17861786
return result;
17871787
}
17881788

1789+
const char* os::Linux::dll_path(void* lib) {
1790+
struct link_map *lmap;
1791+
const char* l_path = NULL;
1792+
assert(lib != NULL, "dll_path parameter must not be NULL");
1793+
1794+
int res_dli = ::dlinfo(lib, RTLD_DI_LINKMAP, &lmap);
1795+
if (res_dli == 0) {
1796+
l_path = lmap->l_name;
1797+
}
1798+
return l_path;
1799+
}
1800+
17891801
static bool _print_ascii_file(const char* filename, outputStream* st, const char* hdr = NULL) {
17901802
int fd = ::open(filename, O_RDONLY);
17911803
if (fd == -1) {

‎src/hotspot/os/linux/os_linux.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -120,6 +120,7 @@ class Linux {
120120
static bool _stack_is_executable;
121121
static void *dlopen_helper(const char *name, char *ebuf, int ebuflen);
122122
static void *dll_load_in_vmthread(const char *name, char *ebuf, int ebuflen);
123+
static const char *dll_path(void* lib);
123124

124125
static void init_thread_fpu_state();
125126
static int get_fpu_control_word();

‎src/hotspot/os/posix/os_posix.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,26 @@ void* os::dll_lookup(void* handle, const char* name) {
706706
}
707707

708708
void os::dll_unload(void *lib) {
709-
::dlclose(lib);
709+
const char* l_path = LINUX_ONLY(os::Linux::dll_path(lib))
710+
NOT_LINUX("<not available>");
711+
if (l_path == NULL) l_path = "<not available>";
712+
int res = ::dlclose(lib);
713+
714+
if (res == 0) {
715+
Events::log_dll_message(NULL, "Unloaded shared library \"%s\" [" INTPTR_FORMAT "]",
716+
l_path, p2i(lib));
717+
log_info(os)("Unloaded shared library \"%s\" [" INTPTR_FORMAT "]", l_path, p2i(lib));
718+
} else {
719+
const char* error_report = ::dlerror();
720+
if (error_report == NULL) {
721+
error_report = "dlerror returned no error description";
722+
}
723+
724+
Events::log_dll_message(NULL, "Attempt to unload shared library \"%s\" [" INTPTR_FORMAT "] failed, %s",
725+
l_path, p2i(lib), error_report);
726+
log_info(os)("Attempt to unload shared library \"%s\" [" INTPTR_FORMAT "] failed, %s",
727+
l_path, p2i(lib), error_report);
728+
}
710729
}
711730

712731
jlong os::lseek(int fd, jlong offset, int whence) {

‎src/hotspot/os/windows/os_windows.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,18 @@ void os::die() {
12361236
const char* os::dll_file_extension() { return ".dll"; }
12371237

12381238
void os::dll_unload(void *lib) {
1239-
::FreeLibrary((HMODULE)lib);
1239+
char name[MAX_PATH];
1240+
if (::GetModuleFileName((HMODULE)lib, name, sizeof(name)) == 0) {
1241+
snprintf(name, MAX_PATH, "<not available>");
1242+
}
1243+
if (::FreeLibrary((HMODULE)lib)) {
1244+
Events::log_dll_message(NULL, "Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib));
1245+
log_info(os)("Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib));
1246+
} else {
1247+
const DWORD errcode = ::GetLastError();
1248+
Events::log_dll_message(NULL, "Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode);
1249+
log_info(os)("Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode);
1250+
}
12401251
}
12411252

12421253
void* os::dll_lookup(void *lib, const char *name) {

0 commit comments

Comments
 (0)
Please sign in to comment.