Skip to content

Commit

Permalink
8288003: log events for os::dll_unload
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, stuefe
  • Loading branch information
MBaesken committed Jun 14, 2022
1 parent 03dca56 commit c2ccf4c
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 @@ -1786,6 +1786,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 @@ -706,7 +706,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 @@ -1236,7 +1236,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

5 comments on commit c2ccf4c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on c2ccf4c Jul 15, 2022

Choose a reason for hiding this comment

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

@MBaesken Could not automatically backport c2ccf4ca to openjdk/jdk17u-dev due to conflicts in the following files:

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

To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk17u-dev:

$ git checkout -b MBaesken-backport-c2ccf4ca
$ git fetch --no-tags https://git.openjdk.org/jdk c2ccf4ca85b5375e08dce836acd6e86c851c3bd6
$ git cherry-pick --no-commit c2ccf4ca85b5375e08dce836acd6e86c851c3bd6
$ # Resolve conflicts
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport c2ccf4ca85b5375e08dce836acd6e86c851c3bd6'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport c2ccf4ca85b5375e08dce836acd6e86c851c3bd6.

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on c2ccf4c Jul 15, 2022

Choose a reason for hiding this comment

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

@MBaesken the backport was successfully created on the branch MBaesken-backport-c2ccf4ca in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit c2ccf4ca from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 14 Jun 2022 and was reviewed by David Holmes and Thomas Stuefe.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-c2ccf4ca:MBaesken-backport-c2ccf4ca
$ git checkout MBaesken-backport-c2ccf4ca
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-c2ccf4ca

Please sign in to comment.