Skip to content

Commit b3dfc39

Browse files
author
Markus Grönlund
committed
8315930: Revert "8315220: Event NativeLibraryLoad breaks invariant by taking a stacktrace when thread is in state _thread_in_native"
Reviewed-by: egahlin
1 parent ebc718f commit b3dfc39

File tree

10 files changed

+152
-281
lines changed

10 files changed

+152
-281
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
#include "utilities/growableArray.hpp"
8282
#include "utilities/vmError.hpp"
8383
#if INCLUDE_JFR
84-
#include "jfr/support/jfrNativeLibraryLoadEvent.hpp"
84+
#include "jfr/jfrEvents.hpp"
8585
#endif
8686

8787
// put OS-includes here (sorted alphabetically)
@@ -1116,6 +1116,11 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
11161116
return nullptr;
11171117
}
11181118

1119+
#if INCLUDE_JFR
1120+
EventNativeLibraryLoad event;
1121+
event.set_name(filename);
1122+
#endif
1123+
11191124
// RTLD_LAZY has currently the same behavior as RTLD_NOW
11201125
// The dl is loaded immediately with all its dependants.
11211126
int dflags = RTLD_LAZY;
@@ -1126,14 +1131,19 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
11261131
dflags |= RTLD_MEMBER;
11271132
}
11281133

1129-
void* result;
1130-
JFR_ONLY(NativeLibraryLoadEvent load_event(filename, &result);)
1131-
result = ::dlopen(filename, dflags);
1134+
void * result= ::dlopen(filename, dflags);
11321135
if (result != nullptr) {
11331136
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
11341137
// Reload dll cache. Don't do this in signal handling.
11351138
LoadedLibraries::reload();
11361139
log_info(os)("shared library load of %s was successful", filename);
1140+
1141+
#if INCLUDE_JFR
1142+
event.set_success(true);
1143+
event.set_errorMessage(nullptr);
1144+
event.commit();
1145+
#endif
1146+
11371147
return result;
11381148
} else {
11391149
// error analysis when dlopen fails
@@ -1147,7 +1157,12 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
11471157
}
11481158
Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report);
11491159
log_info(os)("shared library load of %s failed, %s", filename, error_report);
1150-
JFR_ONLY(load_event.set_error_msg(error_report);)
1160+
1161+
#if INCLUDE_JFR
1162+
event.set_success(false);
1163+
event.set_errorMessage(error_report);
1164+
event.commit();
1165+
#endif
11511166
}
11521167
return nullptr;
11531168
}

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
#include "utilities/vmError.hpp"
7272
#if INCLUDE_JFR
7373
#include "jfr/jfrEvents.hpp"
74-
#include "jfr/support/jfrNativeLibraryLoadEvent.hpp"
7574
#endif
7675

7776
// put OS-includes here
@@ -980,13 +979,21 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
980979
#else
981980
log_info(os)("attempting shared library load of %s", filename);
982981

983-
void* result;
984-
JFR_ONLY(NativeLibraryLoadEvent load_event(filename, &result);)
985-
result = ::dlopen(filename, RTLD_LAZY);
982+
#if INCLUDE_JFR
983+
EventNativeLibraryLoad event;
984+
event.set_name(filename);
985+
#endif
986+
987+
void * result= ::dlopen(filename, RTLD_LAZY);
986988
if (result != nullptr) {
987989
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
988990
// Successful loading
989991
log_info(os)("shared library load of %s was successful", filename);
992+
#if INCLUDE_JFR
993+
event.set_success(true);
994+
event.set_errorMessage(nullptr);
995+
event.commit();
996+
#endif
990997
return result;
991998
}
992999

@@ -1001,7 +1008,11 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
10011008
}
10021009
Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report);
10031010
log_info(os)("shared library load of %s failed, %s", filename, error_report);
1004-
JFR_ONLY(load_event.set_error_msg(error_report);)
1011+
#if INCLUDE_JFR
1012+
event.set_success(false);
1013+
event.set_errorMessage(error_report);
1014+
event.commit();
1015+
#endif
10051016

10061017
return nullptr;
10071018
#endif // STATIC_BUILD
@@ -1013,13 +1024,21 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
10131024
#else
10141025
log_info(os)("attempting shared library load of %s", filename);
10151026

1016-
void* result;
1017-
JFR_ONLY(NativeLibraryLoadEvent load_event(filename, &result);)
1018-
result = ::dlopen(filename, RTLD_LAZY);
1027+
#if INCLUDE_JFR
1028+
EventNativeLibraryLoad event;
1029+
event.set_name(filename);
1030+
#endif
1031+
1032+
void * result= ::dlopen(filename, RTLD_LAZY);
10191033
if (result != nullptr) {
10201034
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
10211035
// Successful loading
10221036
log_info(os)("shared library load of %s was successful", filename);
1037+
#if INCLUDE_JFR
1038+
event.set_success(true);
1039+
event.set_errorMessage(nullptr);
1040+
event.commit();
1041+
#endif
10231042
return result;
10241043
}
10251044

@@ -1036,7 +1055,11 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
10361055
}
10371056
Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report);
10381057
log_info(os)("shared library load of %s failed, %s", filename, error_report);
1039-
JFR_ONLY(load_event.set_error_msg(error_report);)
1058+
#if INCLUDE_JFR
1059+
event.set_success(false);
1060+
event.set_errorMessage(error_report);
1061+
event.commit();
1062+
#endif
10401063
int diag_msg_max_length=ebuflen-strlen(ebuf);
10411064
char* diag_msg_buf=ebuf+strlen(ebuf);
10421065

src/hotspot/os/linux/os_linux.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
#include "utilities/vmError.hpp"
8383
#if INCLUDE_JFR
8484
#include "jfr/jfrEvents.hpp"
85-
#include "jfr/support/jfrNativeLibraryLoadEvent.hpp"
8685
#endif
8786

8887
// put OS-includes here
@@ -1795,10 +1794,15 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
17951794
return nullptr;
17961795
}
17971796

1798-
void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) {
1799-
void* result;
1800-
JFR_ONLY(NativeLibraryLoadEvent load_event(filename, &result);)
1801-
result = ::dlopen(filename, RTLD_LAZY);
1797+
void * os::Linux::dlopen_helper(const char *filename, char *ebuf,
1798+
int ebuflen) {
1799+
void * result = ::dlopen(filename, RTLD_LAZY);
1800+
1801+
#if INCLUDE_JFR
1802+
EventNativeLibraryLoad event;
1803+
event.set_name(filename);
1804+
#endif
1805+
18021806
if (result == nullptr) {
18031807
const char* error_report = ::dlerror();
18041808
if (error_report == nullptr) {
@@ -1810,10 +1814,19 @@ void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) {
18101814
}
18111815
Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report);
18121816
log_info(os)("shared library load of %s failed, %s", filename, error_report);
1813-
JFR_ONLY(load_event.set_error_msg(error_report);)
1817+
#if INCLUDE_JFR
1818+
event.set_success(false);
1819+
event.set_errorMessage(error_report);
1820+
event.commit();
1821+
#endif
18141822
} else {
18151823
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
18161824
log_info(os)("shared library load of %s was successful", filename);
1825+
#if INCLUDE_JFR
1826+
event.set_success(true);
1827+
event.set_errorMessage(nullptr);
1828+
event.commit();
1829+
#endif
18171830
}
18181831
return result;
18191832
}

src/hotspot/os/posix/os_posix.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include "utilities/macros.hpp"
5252
#include "utilities/vmError.hpp"
5353
#if INCLUDE_JFR
54-
#include "jfr/support/jfrNativeLibraryLoadEvent.hpp"
54+
#include "jfr/jfrEvents.hpp"
5555
#endif
5656

5757
#ifdef AIX
@@ -728,7 +728,10 @@ void os::dll_unload(void *lib) {
728728
}
729729
#endif // LINUX
730730

731-
JFR_ONLY(NativeLibraryUnloadEvent unload_event(l_path);)
731+
#if INCLUDE_JFR
732+
EventNativeLibraryUnload event;
733+
event.set_name(l_path);
734+
#endif
732735

733736
if (l_path == nullptr) {
734737
l_path = "<not available>";
@@ -739,7 +742,11 @@ void os::dll_unload(void *lib) {
739742
Events::log_dll_message(nullptr, "Unloaded shared library \"%s\" [" INTPTR_FORMAT "]",
740743
l_path, p2i(lib));
741744
log_info(os)("Unloaded shared library \"%s\" [" INTPTR_FORMAT "]", l_path, p2i(lib));
742-
JFR_ONLY(unload_event.set_result(true);)
745+
#if INCLUDE_JFR
746+
event.set_success(true);
747+
event.set_errorMessage(nullptr);
748+
event.commit();
749+
#endif
743750
} else {
744751
const char* error_report = ::dlerror();
745752
if (error_report == nullptr) {
@@ -750,7 +757,11 @@ void os::dll_unload(void *lib) {
750757
l_path, p2i(lib), error_report);
751758
log_info(os)("Attempt to unload shared library \"%s\" [" INTPTR_FORMAT "] failed, %s",
752759
l_path, p2i(lib), error_report);
753-
JFR_ONLY(unload_event.set_error_msg(error_report);)
760+
#if INCLUDE_JFR
761+
event.set_success(false);
762+
event.set_errorMessage(error_report);
763+
event.commit();
764+
#endif
754765
}
755766
// Update the dll cache
756767
AIX_ONLY(LoadedLibraries::reload());

src/hotspot/os/windows/os_windows.cpp

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
#include "windbghelp.hpp"
8181
#if INCLUDE_JFR
8282
#include "jfr/jfrEvents.hpp"
83-
#include "jfr/support/jfrNativeLibraryLoadEvent.hpp"
8483
#endif
8584

8685
#ifdef _DEBUG
@@ -1247,22 +1246,33 @@ void os::dll_unload(void *lib) {
12471246
snprintf(name, MAX_PATH, "<not available>");
12481247
}
12491248

1250-
JFR_ONLY(NativeLibraryUnloadEvent unload_event(name);)
1249+
#if INCLUDE_JFR
1250+
EventNativeLibraryUnload event;
1251+
event.set_name(name);
1252+
#endif
12511253

12521254
if (::FreeLibrary((HMODULE)lib)) {
12531255
Events::log_dll_message(nullptr, "Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib));
12541256
log_info(os)("Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib));
1255-
JFR_ONLY(unload_event.set_result(true);)
1257+
#if INCLUDE_JFR
1258+
event.set_success(true);
1259+
event.set_errorMessage(nullptr);
1260+
event.commit();
1261+
#endif
12561262
} else {
12571263
const DWORD errcode = ::GetLastError();
12581264
char buf[500];
12591265
size_t tl = os::lasterror(buf, sizeof(buf));
12601266
Events::log_dll_message(nullptr, "Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode);
12611267
log_info(os)("Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode);
1268+
#if INCLUDE_JFR
1269+
event.set_success(false);
12621270
if (tl == 0) {
12631271
os::snprintf(buf, sizeof(buf), "Attempt to unload dll failed (error code %d)", (int) errcode);
12641272
}
1265-
JFR_ONLY(unload_event.set_error_msg(buf);)
1273+
event.set_errorMessage(buf);
1274+
event.commit();
1275+
#endif
12661276
}
12671277
}
12681278

@@ -1531,14 +1541,21 @@ static int _print_module(const char* fname, address base_address,
15311541
// same architecture as Hotspot is running on
15321542
void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
15331543
log_info(os)("attempting shared library load of %s", name);
1534-
void* result;
1535-
JFR_ONLY(NativeLibraryLoadEvent load_event(name, &result);)
1536-
result = LoadLibrary(name);
1544+
#if INCLUDE_JFR
1545+
EventNativeLibraryLoad event;
1546+
event.set_name(name);
1547+
#endif
1548+
void * result = LoadLibrary(name);
15371549
if (result != nullptr) {
15381550
Events::log_dll_message(nullptr, "Loaded shared library %s", name);
15391551
// Recalculate pdb search path if a DLL was loaded successfully.
15401552
SymbolEngine::recalc_search_path();
15411553
log_info(os)("shared library load of %s was successful", name);
1554+
#if INCLUDE_JFR
1555+
event.set_success(true);
1556+
event.set_errorMessage(nullptr);
1557+
event.commit();
1558+
#endif
15421559
return result;
15431560
}
15441561
DWORD errcode = GetLastError();
@@ -1552,7 +1569,11 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
15521569
if (errcode == ERROR_MOD_NOT_FOUND) {
15531570
strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
15541571
ebuf[ebuflen - 1] = '\0';
1555-
JFR_ONLY(load_event.set_error_msg(ebuf);)
1572+
#if INCLUDE_JFR
1573+
event.set_success(false);
1574+
event.set_errorMessage(ebuf);
1575+
event.commit();
1576+
#endif
15561577
return nullptr;
15571578
}
15581579

@@ -1563,7 +1584,11 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
15631584
// else call os::lasterror to obtain system error message
15641585
int fd = ::open(name, O_RDONLY | O_BINARY, 0);
15651586
if (fd < 0) {
1566-
JFR_ONLY(load_event.set_error_msg("open on dll file did not work");)
1587+
#if INCLUDE_JFR
1588+
event.set_success(false);
1589+
event.set_errorMessage("open on dll file did not work");
1590+
event.commit();
1591+
#endif
15671592
return nullptr;
15681593
}
15691594

@@ -1590,7 +1615,11 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
15901615
::close(fd);
15911616
if (failed_to_get_lib_arch) {
15921617
// file i/o error - report os::lasterror(...) msg
1593-
JFR_ONLY(load_event.set_error_msg("failed to get lib architecture");)
1618+
#if INCLUDE_JFR
1619+
event.set_success(false);
1620+
event.set_errorMessage("failed to get lib architecture");
1621+
event.commit();
1622+
#endif
15941623
return nullptr;
15951624
}
15961625

@@ -1635,7 +1664,11 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
16351664
// If the architecture is right
16361665
// but some other error took place - report os::lasterror(...) msg
16371666
if (lib_arch == running_arch) {
1638-
JFR_ONLY(load_event.set_error_msg("lib architecture matches, but other error occured");)
1667+
#if INCLUDE_JFR
1668+
event.set_success(false);
1669+
event.set_errorMessage("lib architecture matches, but other error occured");
1670+
event.commit();
1671+
#endif
16391672
return nullptr;
16401673
}
16411674

@@ -1649,7 +1682,12 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
16491682
"Can't load this .dll (machine code=0x%x) on a %s-bit platform",
16501683
lib_arch, running_arch_str);
16511684
}
1652-
JFR_ONLY(load_event.set_error_msg(ebuf);)
1685+
#if INCLUDE_JFR
1686+
event.set_success(false);
1687+
event.set_errorMessage(ebuf);
1688+
event.commit();
1689+
#endif
1690+
16531691
return nullptr;
16541692
}
16551693

src/hotspot/share/jfr/metadata/metadata.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,14 +939,14 @@
939939
<Field type="ulong" contentType="address" name="topAddress" label="Top Address" description="Ending address of the module, if available" />
940940
</Event>
941941

942-
<Event name="NativeLibraryLoad" category="Java Virtual Machine, Runtime" label="Native Library Load" thread="true" stackTrace="true" startTime="true"
942+
<Event name="NativeLibraryLoad" category="Java Virtual Machine, Runtime" label="Native Library Load" thread="false" stackTrace="true" startTime="true"
943943
description="Information about a dynamic library or other native image load operation">
944944
<Field type="string" name="name" label="Name" />
945945
<Field type="boolean" name="success" label="Success" description="Success or failure of the load operation" />
946946
<Field type="string" name="errorMessage" label="Error Message" description="In case of a load error, error description" />
947947
</Event>
948948

949-
<Event name="NativeLibraryUnload" category="Java Virtual Machine, Runtime" label="Native Library Unload" thread="true" stackTrace="true" startTime="true"
949+
<Event name="NativeLibraryUnload" category="Java Virtual Machine, Runtime" label="Native Library Unload" thread="false" stackTrace="true" startTime="true"
950950
description="Information about a dynamic library or other native image unload operation">
951951
<Field type="string" name="name" label="Name" />
952952
<Field type="boolean" name="success" label="Success" description="Success or failure of the unload operation" />

0 commit comments

Comments
 (0)