-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8358799: Refactor os::jvm_path() #25675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8358799: Refactor os::jvm_path() #25675
Conversation
👋 Welcome back ccheung! A progress list of the required criteria for merging this PR into |
@calvinccheung This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 24 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@calvinccheung The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
Not a reviewer or anything, but I'm all for this change. It will help my BSD porting efforts as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea but I think we can go further.
Thanks
src/hotspot/os/posix/os_posix.cpp
Outdated
#ifdef AIX | ||
Dl_info dlinfo; | ||
int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo); | ||
assert(ret != 0, "cannot locate libjvm"); | ||
char* rp = os::realpath((char *)dlinfo.dli_fname, buf, buflen); | ||
assert(rp != nullptr, "error in realpath(): maybe the 'path' argument is too long?"); | ||
#else | ||
char dli_fname[MAXPATHLEN]; | ||
dli_fname[0] = '\0'; | ||
bool ret = dll_address_to_library_name( | ||
CAST_FROM_FN_PTR(address, os::jvm_path), | ||
dli_fname, sizeof(dli_fname), nullptr); | ||
assert(ret, "cannot locate libjvm"); | ||
char *rp = nullptr; | ||
if (ret && dli_fname[0] != '\0') { | ||
rp = os::realpath(dli_fname, buf, buflen); | ||
} | ||
if (rp == nullptr) { | ||
return; | ||
} | ||
#endif // AIX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given both chunks use os::realpath
and otherwise only differ in error handling around realpath
, I think you can reduce this further. E.g. something like
char* fname;
#ifdef AIX
Dl_info dlinfo;
int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
assert(ret != 0, "cannot locate libjvm");
fname = dlinfo.dli_fname;
#else
char dli_fname[MAXPATHLEN];
dli_fname[0] = '\0';
bool ret = dll_address_to_library_name(
CAST_FROM_FN_PTR(address, os::jvm_path),
dli_fname, sizeof(dli_fname), nullptr);
assert(ret, "cannot locate libjvm");
fname = dli_fname;
#endif
char* rp = nullprtr;
...
I would also be asking the AIX folk if there is a reason they use dladdr
directly instead of os::dll_address_to_library_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AIX is very different in this regard. There is a hand-crafted partial implementation of dladdr
in src/hotspot/os/aix/porting_aix.cpp
. I'm not sure this is the reason, just pointing out that this is a typical weakness of AIX where it differs from other unix systems wrt to dladdr
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR based on David's comment and have left the dladdr alone for now.
src/hotspot/os/posix/os_posix.cpp
Outdated
Dl_info dlinfo; | ||
int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo); | ||
assert(ret != 0, "cannot locate libjvm"); | ||
char* rp = os::realpath((char *)dlinfo.dli_fname, buf, buflen); | ||
assert(rp != nullptr, "error in realpath(): maybe the 'path' argument is too long?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing: We should return if ret == 0
and rp == nullptr
, not continue as if it didn't fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the check for ret
.
if (buflen < MAXPATHLEN) { | ||
assert(false, "must use a large-enough buffer"); | ||
buf[0] = '\0'; | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need release the memory of buf
before return, such like
free(buf);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because the caller of the function still references buf
after the function returns, e.g. in os::init_system_properties_values()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More specifically, buf
is owned by the caller and we have no idea what it is so we have no business "releasing" it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still like some input from AIX folk on whether we can do better here, but in lieu of that this seems good enough to me.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also OK with this.
Thanks @dholmes-ora @jdksjolen for the review. /integrate |
Going to push as commit 500a3a2.
Your commit was automatically rebased without conflicts. |
@calvinccheung Pushed as commit 500a3a2. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The linux, bsd, and aix versions of os::jvm_path() are very similar and can be combined into one in os_posix.cpp.
Passed tiers 1 - 3 tests.
However, tests were not run on the aix platform since it is not one of the Oracle supported platforms.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25675/head:pull/25675
$ git checkout pull/25675
Update a local copy of the PR:
$ git checkout pull/25675
$ git pull https://git.openjdk.org/jdk.git pull/25675/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25675
View PR using the GUI difftool:
$ git pr show -t 25675
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25675.diff
Using Webrev
Link to Webrev Comment