Skip to content

Commit

Permalink
8313616: support loading library members on AIX in os::dll_load
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr
  • Loading branch information
MBaesken committed Aug 10, 2023
1 parent f47767f commit 23fe2ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/hotspot/os/aix/libodm_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
#include <dlfcn.h>
#include <string.h>
#include "runtime/arguments.hpp"
#include "runtime/os.hpp"


dynamicOdm::dynamicOdm() {
const char *libodmname = "/usr/lib/libodm.a(shr_64.o)";
_libhandle = dlopen(libodmname, RTLD_MEMBER | RTLD_NOW);
const char* libodmname = "/usr/lib/libodm.a(shr_64.o)";
char ebuf[512];
void* _libhandle = os::dll_load(libodmname, ebuf, sizeof(ebuf));

if (!_libhandle) {
trcVerbose("Couldn't open %s", libodmname);
trcVerbose("Cannot load %s (error %s)", libodmname, ebuf);
return;
}
_odm_initialize = (fun_odm_initialize )dlsym(_libhandle, "odm_initialize" );
Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/os/aix/libperfstat_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "libperfstat_aix.hpp"
#include "misc_aix.hpp"
#include "runtime/os.hpp"

#include <dlfcn.h>

Expand Down Expand Up @@ -71,11 +72,11 @@ static fun_perfstat_reset_t g_fun_perfstat_reset = nullptr;
static fun_wpar_getcid_t g_fun_wpar_getcid = nullptr;

bool libperfstat::init() {

// Dynamically load the libperfstat porting library.
g_libhandle = dlopen("/usr/lib/libperfstat.a(shr_64.o)", RTLD_MEMBER | RTLD_NOW);
const char* libperfstat = "/usr/lib/libperfstat.a(shr_64.o)";
char ebuf[512];
g_libhandle = os::dll_load(libperfstat, ebuf, sizeof(ebuf));
if (!g_libhandle) {
trcVerbose("Cannot load libperfstat.a (dlerror: %s)", dlerror());
trcVerbose("Cannot load %s (error: %s)", libperfstat, ebuf);
return false;
}

Expand Down
15 changes: 11 additions & 4 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,6 @@ bool os::dll_address_to_library_name(address addr, char* buf,
return true;
}

// Loads .dll/.so and in case of error it checks if .dll/.so was built
// for the same architecture as Hotspot is running on.
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {

log_info(os)("attempting shared library load of %s", filename);
Expand All @@ -1122,8 +1120,17 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
event.set_name(filename);
#endif

// RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants.
void * result= ::dlopen(filename, RTLD_LAZY);
// RTLD_LAZY has currently the same behavior as RTLD_NOW
// The dl is loaded immediately with all its dependants.
int dflags = RTLD_LAZY;
// check for filename ending with ')', it indicates we want to load
// a MEMBER module that is a member of an archive.
int flen = strlen(filename);
if (flen > 0 && filename[flen - 1] == ')') {
dflags |= RTLD_MEMBER;
}

void * result= ::dlopen(filename, dflags);
if (result != nullptr) {
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
// Reload dll cache. Don't do this in signal handling.
Expand Down

5 comments on commit 23fe2ec

@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 jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 23fe2ec Oct 16, 2023

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 23fe2ece to openjdk/jdk21u due to conflicts in the following files:

  • src/hotspot/os/aix/os_aix.cpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk21u. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk21u.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b MBaesken-backport-23fe2ece

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 23fe2ece586d3ed750e905e1b71a2cd1da91f335

# Backport the commit
$ git cherry-pick --no-commit 23fe2ece586d3ed750e905e1b71a2cd1da91f335
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 23fe2ece586d3ed750e905e1b71a2cd1da91f335'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk21u with the title Backport 23fe2ece586d3ed750e905e1b71a2cd1da91f335.

@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 jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 23fe2ec Oct 31, 2023

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 23fe2ece to openjdk/jdk21u due to conflicts in the following files:

  • src/hotspot/os/aix/os_aix.cpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk21u. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk21u.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b MBaesken-backport-23fe2ece

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 23fe2ece586d3ed750e905e1b71a2cd1da91f335

# Backport the commit
$ git cherry-pick --no-commit 23fe2ece586d3ed750e905e1b71a2cd1da91f335
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 23fe2ece586d3ed750e905e1b71a2cd1da91f335'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk21u with the title Backport 23fe2ece586d3ed750e905e1b71a2cd1da91f335.

Please sign in to comment.