diff --git a/src/hotspot/os/posix/os_posix.cpp b/src/hotspot/os/posix/os_posix.cpp index 44b23bfadf3..3f9ffe303ac 100644 --- a/src/hotspot/os/posix/os_posix.cpp +++ b/src/hotspot/os/posix/os_posix.cpp @@ -49,6 +49,10 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" #include "utilities/vmError.hpp" +#if INCLUDE_JFR +#include "jfr/jfrEvents.hpp" +#endif + #ifdef AIX #include "loadlib_aix.hpp" #endif @@ -714,6 +718,7 @@ void os::dll_unload(void *lib) { // calling dlclose the dynamic loader may free the memory containing the string, thus we need to // copy the string to be able to reference it after dlclose. const char* l_path = nullptr; + #ifdef LINUX char* l_pathdup = nullptr; l_path = os::Linux::dll_path(lib); @@ -721,6 +726,12 @@ void os::dll_unload(void *lib) { l_path = l_pathdup = os::strdup(l_path); } #endif // LINUX + +#if INCLUDE_JFR + EventNativeLibraryUnload event; + event.set_name(l_path); +#endif + if (l_path == nullptr) { l_path = ""; } @@ -730,6 +741,11 @@ void os::dll_unload(void *lib) { Events::log_dll_message(nullptr, "Unloaded shared library \"%s\" [" INTPTR_FORMAT "]", l_path, p2i(lib)); log_info(os)("Unloaded shared library \"%s\" [" INTPTR_FORMAT "]", l_path, p2i(lib)); +#if INCLUDE_JFR + event.set_success(true); + event.set_errorMessage(nullptr); + event.commit(); +#endif } else { const char* error_report = ::dlerror(); if (error_report == nullptr) { @@ -740,6 +756,11 @@ void os::dll_unload(void *lib) { 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); +#if INCLUDE_JFR + event.set_success(false); + event.set_errorMessage(error_report); + event.commit(); +#endif } // Update the dll cache AIX_ONLY(LoadedLibraries::reload()); diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 2c072bf8e60..2b457b6af2a 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -1254,13 +1254,34 @@ void os::dll_unload(void *lib) { if (::GetModuleFileName((HMODULE)lib, name, sizeof(name)) == 0) { snprintf(name, MAX_PATH, ""); } + +#if INCLUDE_JFR + EventNativeLibraryUnload event; + event.set_name(name); +#endif + if (::FreeLibrary((HMODULE)lib)) { Events::log_dll_message(nullptr, "Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib)); log_info(os)("Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib)); +#if INCLUDE_JFR + event.set_success(true); + event.set_errorMessage(nullptr); + event.commit(); +#endif } else { const DWORD errcode = ::GetLastError(); + char buf[500]; + size_t tl = os::lasterror(buf, sizeof(buf)); Events::log_dll_message(nullptr, "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); +#if INCLUDE_JFR + event.set_success(false); + if (tl == 0) { + os::snprintf(buf, sizeof(buf), "Attempt to unload dll failed (error code %d)", (int) errcode); + } + event.set_errorMessage(buf); + event.commit(); +#endif } } diff --git a/src/hotspot/share/jfr/metadata/metadata.xml b/src/hotspot/share/jfr/metadata/metadata.xml index 70715294a5e..f8fc4e5bccd 100644 --- a/src/hotspot/share/jfr/metadata/metadata.xml +++ b/src/hotspot/share/jfr/metadata/metadata.xml @@ -946,6 +946,13 @@ + + + + + + diff --git a/src/jdk.jfr/share/conf/jfr/default.jfc b/src/jdk.jfr/share/conf/jfr/default.jfc index ba3eb50e53f..6b0aa1724c4 100644 --- a/src/jdk.jfr/share/conf/jfr/default.jfc +++ b/src/jdk.jfr/share/conf/jfr/default.jfc @@ -700,6 +700,12 @@ 0 ms + + true + true + 0 ms + + true endChunk diff --git a/src/jdk.jfr/share/conf/jfr/profile.jfc b/src/jdk.jfr/share/conf/jfr/profile.jfc index 5563b690569..79ce390052a 100644 --- a/src/jdk.jfr/share/conf/jfr/profile.jfc +++ b/src/jdk.jfr/share/conf/jfr/profile.jfc @@ -700,6 +700,12 @@ 0 ms + + true + true + 0 ms + + true endChunk diff --git a/test/jdk/jdk/jfr/event/metadata/TestLookForUntestedEvents.java b/test/jdk/jdk/jfr/event/metadata/TestLookForUntestedEvents.java index 0e0891615ac..bdb10a47259 100644 --- a/test/jdk/jdk/jfr/event/metadata/TestLookForUntestedEvents.java +++ b/test/jdk/jdk/jfr/event/metadata/TestLookForUntestedEvents.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -54,7 +54,7 @@ public class TestLookForUntestedEvents { private static final Set hardToTestEvents = new HashSet<>( Arrays.asList( - "DataLoss", "IntFlag", "ReservedStackActivation", + "DataLoss", "IntFlag", "ReservedStackActivation", "NativeLibraryUnload", "DoubleFlag", "UnsignedLongFlagChanged", "IntFlagChanged", "UnsignedIntFlag", "UnsignedIntFlagChanged", "DoubleFlagChanged") ); diff --git a/test/lib/jdk/test/lib/jfr/EventNames.java b/test/lib/jdk/test/lib/jfr/EventNames.java index f0978d189d7..9263c234e4b 100644 --- a/test/lib/jdk/test/lib/jfr/EventNames.java +++ b/test/lib/jdk/test/lib/jfr/EventNames.java @@ -184,6 +184,7 @@ public class EventNames { public static final String InitialEnvironmentVariable = PREFIX + "InitialEnvironmentVariable"; public static final String NativeLibrary = PREFIX + "NativeLibrary"; public static final String NativeLibraryLoad = PREFIX + "NativeLibraryLoad"; + public static final String NativeLibraryUnload = PREFIX + "NativeLibraryUnload"; public static final String PhysicalMemory = PREFIX + "PhysicalMemory"; public static final String NetworkUtilization = PREFIX + "NetworkUtilization"; public static final String ProcessStart = PREFIX + "ProcessStart";