RFR: 8358799: Refactor os::jvm_path()

Magnus Ihse Bursie ihse at openjdk.org
Mon Jun 9 17:50:52 UTC 2025


On Mon, 9 Jun 2025 05:33:14 GMT, David Holmes <dholmes 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.
>
> 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`?

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`.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25675#discussion_r2136188895


More information about the hotspot-runtime-dev mailing list