sun.java.launcher.pid property usage

David Holmes david.holmes at oracle.com
Wed Sep 18 01:15:57 UTC 2019


Hi Matthias,

On 18/09/2019 12:18 am, Baesken, Matthias wrote:
> Hello,  while looking at some  atoi usages in the codebase I started to wonder about the  "sun.java.launcher.pid"  property.
> Currently in java_md_solinux.c  the property is set on Linux only  by default (code is guarded #ifdef __linux__ ).
> Later it is passed  to the int  variable _sun_java_launcher_pid (arguments.cpp) and can be retrieved by sun_java_launcher_pid() .
> However only in src/hotspot/os/bsd/os_bsd.cpp it is really used.
> 
> Is the property still supported (one would need to set it from user side on the command line on non-Linux because it is not set by default on bsd/macOS) ?
> Can the coding be removed (or should it enabled for BSD/Mac like we do on Linux) ?
> 
> The os_bsd comment mentiones the bug 6351349 :
> 
> https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6351349
> JDK-6351349 : On linux with the old thread lib, jps should return the same PID as $!
> 
> but this looks very old.

That was the bug that added this code as it was needed on Linux with 
LinuxThreads. The code was then removed on Linux under

https://bugs.openjdk.java.net/browse/JDK-8078513

The review thread starts here:

http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2015-May/014709.html

I think we were focussed solely on cleaning up the hotspot Linux code 
and didn't really look at the wider implication of the use of 
sun.java.launcher.pid. The code in os_bsd.cpp was simply copied from the 
Linux code without giving it any consideration - as you can tell from 
the comment:

   // With BsdThreads the JavaMain thread pid (primordial thread)
   // is different than the pid of the java launcher thread.
   // So, on Bsd, the launcher thread pid is passed to the VM
   // via the sun.java.launcher.pid property.

where you can tell that Linux was simply replaced by Bsd, so we 
reference the non-existent BsdThreads :(

So yes this all seems to be dead code that should be removed - core-libs 
folk will need to be involved of course as they own the launcher. :) It 
looks like SetJavaLauncherPlatformProps() can be removed completely.

Thanks,
David

> Best regards, Matthias
> 
> 
> 
> 
> coding parts mentioned :
> 
> src/hotspot/os/bsd/os_bsd.cpp
> -----------------------------------
> 
> void os::init(void) {
>    char dummy;   // used to get a guess on initial stack address
> 
>    // With BsdThreads the JavaMain thread pid (primordial thread)
>    // is different than the pid of the java launcher thread.
>    // So, on Bsd, the launcher thread pid is passed to the VM
>    // via the sun.java.launcher.pid property.
>    // Use this property instead of getpid() if it was correctly passed.
>    // See bug 6351349.
>    pid_t java_launcher_pid = (pid_t) Arguments::sun_java_launcher_pid();
> 
>    _initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid();
> 
> 
> arguments.cpp / hpp
> ---------------------
> 
>      if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
>        _sun_java_launcher_pid = atoi(tail);
>        continue;
>      }
> 
>    static int sun_java_launcher_pid()        { return _sun_java_launcher_pid; }
> 
> 
> java_md_solinux.c
> ---------------------
> 
> void SetJavaLauncherPlatformProps() {
>     /* Linux only */
> #ifdef __linux__
>      const char *substr = "-Dsun.java.launcher.pid=";
>      char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1);
>      sprintf(pid_prop_str, "%s%d", substr, getpid());
>      AddOption(pid_prop_str, NULL);
> #endif /* __linux__ */
> }
> 


More information about the hotspot-dev mailing list