Skip to content

Commit

Permalink
8288003: log events for os::dll_unload
Browse files Browse the repository at this point in the history
Backport-of: c2ccf4ca85b5375e08dce836acd6e86c851c3bd6
  • Loading branch information
MBaesken committed Jul 18, 2022
1 parent 881ff36 commit d755049
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,18 @@ void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
return result;
}

const char* os::Linux::dll_path(void* lib) {
struct link_map *lmap;
const char* l_path = NULL;
assert(lib != NULL, "dll_path parameter must not be NULL");

int res_dli = ::dlinfo(lib, RTLD_DI_LINKMAP, &lmap);
if (res_dli == 0) {
l_path = lmap->l_name;
}
return l_path;
}

static bool _print_ascii_file(const char* filename, outputStream* st, const char* hdr = NULL) {
int fd = ::open(filename, O_RDONLY);
if (fd == -1) {
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/os/linux/os_linux.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -120,6 +120,7 @@ class Linux {
static bool _stack_is_executable;
static void *dlopen_helper(const char *name, char *ebuf, int ebuflen);
static void *dll_load_in_vmthread(const char *name, char *ebuf, int ebuflen);
static const char *dll_path(void* lib);

static void init_thread_fpu_state();
static int get_fpu_control_word();
Expand Down
21 changes: 20 additions & 1 deletion src/hotspot/os/posix/os_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,26 @@ void* os::dll_lookup(void* handle, const char* name) {
}

void os::dll_unload(void *lib) {
::dlclose(lib);
const char* l_path = LINUX_ONLY(os::Linux::dll_path(lib))
NOT_LINUX("<not available>");
if (l_path == NULL) l_path = "<not available>";
int res = ::dlclose(lib);

if (res == 0) {
Events::log_dll_message(NULL, "Unloaded shared library \"%s\" [" INTPTR_FORMAT "]",
l_path, p2i(lib));
log_info(os)("Unloaded shared library \"%s\" [" INTPTR_FORMAT "]", l_path, p2i(lib));
} else {
const char* error_report = ::dlerror();
if (error_report == NULL) {
error_report = "dlerror returned no error description";
}

Events::log_dll_message(NULL, "Attempt to unload shared library \"%s\" [" INTPTR_FORMAT "] failed, %s",
l_path, p2i(lib), error_report);
log_info(os)("Attempt to unload shared library \"%s\" [" INTPTR_FORMAT "] failed, %s",
l_path, p2i(lib), error_report);
}
}

jlong os::lseek(int fd, jlong offset, int whence) {
Expand Down
13 changes: 12 additions & 1 deletion src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,18 @@ void os::die() {
const char* os::dll_file_extension() { return ".dll"; }

void os::dll_unload(void *lib) {
::FreeLibrary((HMODULE)lib);
char name[MAX_PATH];
if (::GetModuleFileName((HMODULE)lib, name, sizeof(name)) == 0) {
snprintf(name, MAX_PATH, "<not available>");
}
if (::FreeLibrary((HMODULE)lib)) {
Events::log_dll_message(NULL, "Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib));
log_info(os)("Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib));
} else {
const DWORD errcode = ::GetLastError();
Events::log_dll_message(NULL, "Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode);
log_info(os)("Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode);
}
}

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

1 comment on commit d755049

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.