sun.java.launcher.pid property usage
Baesken, Matthias
matthias.baesken at sap.com
Tue Sep 17 14:18:26 UTC 2019
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.
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