8314211: Add NativeLibraryUnload event

Reviewed-by: stuefe, mdoerr
This commit is contained in:
Matthias Baesken 2023-08-16 07:39:42 +00:00
parent 49ddb19972
commit ef6db5c299
7 changed files with 64 additions and 2 deletions

View File

@ -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 = "<not available>";
}
@ -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());

View File

@ -1254,13 +1254,34 @@ void os::dll_unload(void *lib) {
if (::GetModuleFileName((HMODULE)lib, name, sizeof(name)) == 0) {
snprintf(name, MAX_PATH, "<not available>");
}
#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
}
}

View File

@ -946,6 +946,13 @@
<Field type="string" name="errorMessage" label="Error Message" description="In case of a load error, error description" />
</Event>
<Event name="NativeLibraryUnload" category="Java Virtual Machine, Runtime" label="Native Library Unload" thread="false" stackTrace="true" startTime="true"
description="Information about a dynamic library or other native image unload operation">
<Field type="string" name="name" label="Name" />
<Field type="boolean" name="success" label="Success" description="Success or failure of the unload operation" />
<Field type="string" name="errorMessage" label="Error Message" description="In case of an unload error, error description" />
</Event>
<Event name="ModuleRequire" category="Java Virtual Machine, Runtime, Modules" label="Module Require" thread="false" period="everyChunk"
description="A directed edge representing a dependency">
<Field type="Module" name="source" label="Source Module" />

View File

@ -700,6 +700,12 @@
<setting name="threshold">0 ms</setting>
</event>
<event name="jdk.NativeLibraryUnload">
<setting name="enabled">true</setting>
<setting name="stackTrace">true</setting>
<setting name="threshold">0 ms</setting>
</event>
<event name="jdk.ModuleRequire">
<setting name="enabled">true</setting>
<setting name="period">endChunk</setting>

View File

@ -700,6 +700,12 @@
<setting name="threshold">0 ms</setting>
</event>
<event name="jdk.NativeLibraryUnload">
<setting name="enabled">true</setting>
<setting name="stackTrace">true</setting>
<setting name="threshold">0 ms</setting>
</event>
<event name="jdk.ModuleRequire">
<setting name="enabled">true</setting>
<setting name="period">endChunk</setting>

View File

@ -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<String> hardToTestEvents = new HashSet<>(
Arrays.asList(
"DataLoss", "IntFlag", "ReservedStackActivation",
"DataLoss", "IntFlag", "ReservedStackActivation", "NativeLibraryUnload",
"DoubleFlag", "UnsignedLongFlagChanged", "IntFlagChanged",
"UnsignedIntFlag", "UnsignedIntFlagChanged", "DoubleFlagChanged")
);

View File

@ -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";