Skip to content

Commit

Permalink
8329850: [AIX] Allow loading of different members of same shared libr…
Browse files Browse the repository at this point in the history
…ary archive

Reviewed-by: mdoerr, mbaesken, stuefe
  • Loading branch information
Joachim Kern authored and TheRealMDoerr committed Apr 26, 2024
1 parent ffd850f commit cfd19f0
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/hotspot/os/aix/porting_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,11 @@ struct TableLocker {
~TableLocker() { pthread_mutex_unlock(&g_handletable_mutex); }
};
struct handletableentry{
void* handle;
ino64_t inode;
dev64_t devid;
uint refcount;
void* handle;
ino64_t inode;
dev64_t devid;
char* member;
uint refcount;
};
constexpr unsigned init_num_handles = 128;
static unsigned max_handletable = 0;
Expand Down Expand Up @@ -1049,14 +1050,25 @@ void* Aix_dlopen(const char* filename, int Flags, const char** error_report) {
return nullptr;
}
else {
// extract member string if exist duplicate it and store pointer of it
// if member does not exist store nullptr
char* member = nullptr;
const char* substr;
if (filename[strlen(filename) - 1] == ')' && (substr = strrchr(filename, '('))) {
member = os::strdup(substr);
}

unsigned i = 0;
TableLocker lock;
// check if library belonging to filename is already loaded.
// If yes use stored handle from previous ::dlopen() and increase refcount
for (i = 0; i < g_handletable_used; i++) {
if ((p_handletable + i)->handle &&
(p_handletable + i)->inode == libstat.st_ino &&
(p_handletable + i)->devid == libstat.st_dev) {
(p_handletable + i)->devid == libstat.st_dev &&
(((p_handletable + i)->member == nullptr && member == nullptr) ||
((p_handletable + i)->member != nullptr && member != nullptr &&
strcmp((p_handletable + i)->member, member) == 0))) {
(p_handletable + i)->refcount++;
result = (p_handletable + i)->handle;
break;
Expand Down Expand Up @@ -1084,6 +1096,7 @@ void* Aix_dlopen(const char* filename, int Flags, const char** error_report) {
(p_handletable + i)->handle = result;
(p_handletable + i)->inode = libstat.st_ino;
(p_handletable + i)->devid = libstat.st_dev;
(p_handletable + i)->member = member;
(p_handletable + i)->refcount = 1;
}
else {
Expand Down Expand Up @@ -1131,7 +1144,7 @@ bool os::pd_dll_unload(void* libhandle, char* ebuf, int ebuflen) {
// while in the second case we simply have to nag.
res = (0 == ::dlclose(libhandle));
if (!res) {
// error analysis when dlopen fails
// error analysis when dlclose fails
const char* error_report = ::dlerror();
if (error_report == nullptr) {
error_report = "dlerror returned no error description";
Expand All @@ -1145,7 +1158,11 @@ bool os::pd_dll_unload(void* libhandle, char* ebuf, int ebuflen) {
if (i < g_handletable_used) {
if (res) {
// First case: libhandle was found (with refcount == 0) and ::dlclose successful,
// so delete entry from array
// so delete entry from array (do not forget to free member-string space if member exists)
if ((p_handletable + i)->member) {
os::free((p_handletable + i)->member);
(p_handletable + i)->member = nullptr;
}
g_handletable_used--;
// If the entry was the last one of the array, the previous g_handletable_used--
// is sufficient to remove the entry from the array, otherwise we move the last
Expand Down

5 comments on commit cfd19f0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoKern65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk22u

@openjdk
Copy link

@openjdk openjdk bot commented on cfd19f0 Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoKern65 the backport was successfully created on the branch backport-JoKern65-cfd19f01 in my personal fork of openjdk/jdk22u. To create a pull request with this backport targeting openjdk/jdk22u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit cfd19f01 from the openjdk/jdk repository.

The commit being backported was authored by Joachim Kern on 26 Apr 2024 and was reviewed by Martin Doerr, Matthias Baesken and Thomas Stuefe.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22u:

$ git fetch https://github.com/openjdk-bots/jdk22u.git backport-JoKern65-cfd19f01:backport-JoKern65-cfd19f01
$ git checkout backport-JoKern65-cfd19f01
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22u.git backport-JoKern65-cfd19f01

⚠️ @JoKern65 You are not yet a collaborator in my fork openjdk-bots/jdk22u. An invite will be sent out and you need to accept it before you can proceed.

@JoKern65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on cfd19f0 Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoKern65 the backport was successfully created on the branch backport-JoKern65-cfd19f01 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit cfd19f01 from the openjdk/jdk repository.

The commit being backported was authored by Joachim Kern on 26 Apr 2024 and was reviewed by Martin Doerr, Matthias Baesken and Thomas Stuefe.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-JoKern65-cfd19f01:backport-JoKern65-cfd19f01
$ git checkout backport-JoKern65-cfd19f01
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-JoKern65-cfd19f01

Please sign in to comment.