RFR: JDK-8320005 : Native library suffix impact on hotspot code in AIX [v2]
Thomas Stuefe
stuefe at openjdk.org
Fri Nov 24 14:07:08 UTC 2023
On Fri, 24 Nov 2023 11:45:25 GMT, suchismith1993 <duke at openjdk.org> wrote:
> > i would have to repeat the line 1132 and 1139 in os_aix.cpp again , if the condition fails for .so files, because i have to reload it again and check if the .a exists. In the shared code i had repeat less number of lines i believe. Do you suggest moving lines 1132 to 1139 to another function then ?
>
> @tstuefe Any suggestion on this ?
--- a/src/hotspot/os/aix/os_aix.cpp
+++ b/src/hotspot/os/aix/os_aix.cpp
@@ -1108,7 +1108,7 @@ bool os::dll_address_to_library_name(address addr, char* buf,
return true;
}
-void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
+static void* dll_load_inner(const char *filename, char *ebuf, int ebuflen) {
log_info(os)("attempting shared library load of %s", filename);
@@ -1158,6 +1158,35 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
return nullptr;
}
+void* os::dll_load(const char *filename, char *ebuf, int ebuflen) {
+
+ void* result = nullptr;
+
+ // First try using *.so suffix; failing that, retry with *.a suffix.
+ const size_t len = strlen(filename);
+ constexpr size_t safety = 3 + 1;
+ constexpr size_t bufsize = len + safety;
+ char* buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
+ strcpy(buf, filename);
+ char* const dot = strrchr(buf, '.');
+
+ assert(dot != nullptr, "Attempting to load a shared object without extension? %s", filename);
+ assert(strcmp(dot, ".a") == 0 || strcmp(dot, ".so") == 0,
+ "Attempting to load a shared object that is neither *.so nor *.a", filename);
+
+ sprintf(dot, ".so");
+ result = dll_load_inner(buf, ebuf, ebuflen);
+
+ if (result == nullptr) {
+ sprintf(dot, ".a");
+ result = dll_load_inner(buf, ebuf, ebuflen);
+ }
+
+ FREE_C_HEAP_ARRAY(char, buf);
+
+ return result;
+}
+
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16604#issuecomment-1825721906
More information about the hotspot-dev
mailing list