RFR: 8358799: Refactor os::jvm_path()
David Holmes
dholmes at openjdk.org
Mon Jun 9 05:35:51 UTC 2025
On Fri, 6 Jun 2025 16:35:15 GMT, Calvin Cheung <ccheung at openjdk.org> wrote:
> 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.
Good idea but I think we can go further.
Thanks
src/hotspot/os/posix/os_posix.cpp line 1099:
> 1097: return;
> 1098: }
> 1099: #endif // AIX
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`?
-------------
Changes requested by dholmes (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/25675#pullrequestreview-2908958390
PR Review Comment: https://git.openjdk.org/jdk/pull/25675#discussion_r2135057338
More information about the hotspot-runtime-dev
mailing list