From e2ebf7b822501916f66e4106f15082ce6c12acc8 Mon Sep 17 00:00:00 2001
From: Matthias Baesken <mbaesken@openjdk.org>
Date: Fri, 20 Sep 2019 10:28:48 +0200
Subject: [PATCH] 8231171: remove remaining sun.java.launcher.pid references

Reviewed-by: alanb, dholmes
---
 src/hotspot/os/bsd/os_bsd.cpp                 | 31 +------------
 src/hotspot/share/runtime/arguments.cpp       | 15 ++-----
 src/hotspot/share/runtime/arguments.hpp       |  5 ---
 .../macosx/native/libjli/java_md_macosx.m     |  4 --
 src/java.base/share/native/libjli/java.c      |  3 --
 src/java.base/share/native/libjli/java.h      |  1 -
 .../unix/native/libjli/java_md_solinux.c      | 10 -----
 src/java.base/windows/native/libjli/java_md.c |  3 --
 test/jdk/tools/launcher/TestSpecialArgs.java  | 44 +------------------
 9 files changed, 6 insertions(+), 110 deletions(-)

diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp
index 16d1cb9a547..c136d160c5c 100644
--- a/src/hotspot/os/bsd/os_bsd.cpp
+++ b/src/hotspot/os/bsd/os_bsd.cpp
@@ -136,8 +136,6 @@ static int clock_tics_per_sec = 100;
 static sigset_t check_signal_done;
 static bool check_signals = true;
 
-static pid_t _initial_pid = 0;
-
 // Signal number used to suspend/resume a thread
 
 // do not use any signal number less than SIGSEGV, see 4355769
@@ -1124,24 +1122,7 @@ intx os::current_thread_id() {
 }
 
 int os::current_process_id() {
-
-  // Under the old bsd thread library, bsd gives each thread
-  // its own process id. Because of this each thread will return
-  // a different pid if this method were to return the result
-  // of getpid(2). Bsd provides no api that returns the pid
-  // of the launcher thread for the vm. This implementation
-  // returns a unique pid, the pid of the launcher thread
-  // that starts the vm 'process'.
-
-  // Under the NPTL, getpid() returns the same pid as the
-  // launcher thread rather than a unique pid per thread.
-  // Use gettid() if you want the old pre NPTL behaviour.
-
-  // if you are looking for the result of a call to getpid() that
-  // returns a unique pid for the calling thread, then look at the
-  // OSThread::thread_id() method in osThread_bsd.hpp file
-
-  return (int)(_initial_pid ? _initial_pid : getpid());
+  return (int)(getpid());
 }
 
 // DLL functions
@@ -3087,16 +3068,6 @@ extern void report_error(char* file_name, int line_no, char* title,
 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();
-
   clock_tics_per_sec = CLK_TCK;
 
   init_random(1234567);
diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp
index 6c303c8dbc6..53501c8d880 100644
--- a/src/hotspot/share/runtime/arguments.cpp
+++ b/src/hotspot/share/runtime/arguments.cpp
@@ -82,7 +82,6 @@ bool   Arguments::_java_compiler                = false;
 bool   Arguments::_xdebug_mode                  = false;
 const char*  Arguments::_java_vendor_url_bug    = DEFAULT_VENDOR_URL_BUG;
 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
-int    Arguments::_sun_java_launcher_pid        = -1;
 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
 
 // These parameters are reset in method parse_vm_init_args()
@@ -361,8 +360,7 @@ bool Arguments::is_internal_module_property(const char* property) {
 
 // Process java launcher properties.
 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
-  // See if sun.java.launcher, sun.java.launcher.is_altjvm or
-  // sun.java.launcher.pid is defined.
+  // See if sun.java.launcher or sun.java.launcher.is_altjvm is defined.
   // Must do this before setting up other system properties,
   // as some of them may depend on launcher type.
   for (int index = 0; index < args->nOptions; index++) {
@@ -379,10 +377,6 @@ void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
       }
       continue;
     }
-    if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
-      _sun_java_launcher_pid = atoi(tail);
-      continue;
-    }
   }
 }
 
@@ -1411,10 +1405,9 @@ bool Arguments::add_property(const char* prop, PropertyWriteable writeable, Prop
   if (strcmp(key, "java.compiler") == 0) {
     process_java_compiler_argument(value);
     // Record value in Arguments, but let it get passed to Java.
-  } else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0 ||
-             strcmp(key, "sun.java.launcher.pid") == 0) {
-    // sun.java.launcher.is_altjvm and sun.java.launcher.pid property are
-    // private and are processed in process_sun_java_launcher_properties();
+  } else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0) {
+    // sun.java.launcher.is_altjvm property is
+    // private and is processed in process_sun_java_launcher_properties();
     // the sun.java.launcher property is passed on to the java application
   } else if (strcmp(key, "sun.boot.library.path") == 0) {
     // append is true, writable is true, internal is false
diff --git a/src/hotspot/share/runtime/arguments.hpp b/src/hotspot/share/runtime/arguments.hpp
index ad3b49b0330..f3a82767347 100644
--- a/src/hotspot/share/runtime/arguments.hpp
+++ b/src/hotspot/share/runtime/arguments.hpp
@@ -322,9 +322,6 @@ class Arguments : AllStatic {
   // java launcher
   static const char* _sun_java_launcher;
 
-  // sun.java.launcher.pid, private property
-  static int    _sun_java_launcher_pid;
-
   // was this VM created via the -XXaltjvm=<path> option
   static bool   _sun_java_launcher_is_altjvm;
 
@@ -548,8 +545,6 @@ class Arguments : AllStatic {
   static bool created_by_java_launcher();
   // -Dsun.java.launcher.is_altjvm
   static bool sun_java_launcher_is_altjvm();
-  // -Dsun.java.launcher.pid
-  static int sun_java_launcher_pid()        { return _sun_java_launcher_pid; }
 
   // -Xrun
   static AgentLibrary* libraries()          { return _libraryList.first(); }
diff --git a/src/java.base/macosx/native/libjli/java_md_macosx.m b/src/java.base/macosx/native/libjli/java_md_macosx.m
index 65b46e25c95..929d4dd93ed 100644
--- a/src/java.base/macosx/native/libjli/java_md_macosx.m
+++ b/src/java.base/macosx/native/libjli/java_md_macosx.m
@@ -757,10 +757,6 @@ CallJavaMainInNewThread(jlong stack_size, void* args) {
     return rslt;
 }
 
-void SetJavaLauncherPlatformProps() {
-   /* Linux only */
-}
-
 static JavaVM* jvmInstance = NULL;
 static jboolean sameThread = JNI_FALSE; /* start VM in current thread */
 
diff --git a/src/java.base/share/native/libjli/java.c b/src/java.base/share/native/libjli/java.c
index 83b35bff8cd..1075dae2605 100644
--- a/src/java.base/share/native/libjli/java.c
+++ b/src/java.base/share/native/libjli/java.c
@@ -338,9 +338,6 @@ JLI_Launch(int argc, char ** argv,              /* main argc, argv */
     /* Set the -Dsun.java.launcher pseudo property */
     SetJavaLauncherProp();
 
-    /* set the -Dsun.java.launcher.* platform properties */
-    SetJavaLauncherPlatformProps();
-
     return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
 }
 /*
diff --git a/src/java.base/share/native/libjli/java.h b/src/java.base/share/native/libjli/java.h
index 45acece2787..a732038709a 100644
--- a/src/java.base/share/native/libjli/java.h
+++ b/src/java.base/share/native/libjli/java.h
@@ -161,7 +161,6 @@ void PrintMachineDependentOptions();
 int CallJavaMainInNewThread(jlong stack_size, void* args);
 
 /* sun.java.launcher.* platform properties. */
-void SetJavaLauncherPlatformProps(void);
 void SetJavaCommandLineProp(char* what, int argc, char** argv);
 void SetJavaLauncherProp(void);
 
diff --git a/src/java.base/unix/native/libjli/java_md_solinux.c b/src/java.base/unix/native/libjli/java_md_solinux.c
index 4d0b9fbbc28..c586e7a0fdf 100644
--- a/src/java.base/unix/native/libjli/java_md_solinux.c
+++ b/src/java.base/unix/native/libjli/java_md_solinux.c
@@ -790,16 +790,6 @@ CallJavaMainInNewThread(jlong stack_size, void* args) {
 /* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */
 #define MAX_PID_STR_SZ   20
 
-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__ */
-}
-
 int
 JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
         int argc, char **argv,
diff --git a/src/java.base/windows/native/libjli/java_md.c b/src/java.base/windows/native/libjli/java_md.c
index 76d0e1bbe95..2920467c5dd 100644
--- a/src/java.base/windows/native/libjli/java_md.c
+++ b/src/java.base/windows/native/libjli/java_md.c
@@ -803,9 +803,6 @@ CallJavaMainInNewThread(jlong stack_size, void* args) {
     return rslt;
 }
 
-/* Unix only, empty on windows. */
-void SetJavaLauncherPlatformProps() {}
-
 /*
  * The implementation for finding classes from the bootstrap
  * class loader, refer to java.h
diff --git a/test/jdk/tools/launcher/TestSpecialArgs.java b/test/jdk/tools/launcher/TestSpecialArgs.java
index 1e6ac4faaab..0e6128827e9 100644
--- a/test/jdk/tools/launcher/TestSpecialArgs.java
+++ b/test/jdk/tools/launcher/TestSpecialArgs.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -132,11 +132,9 @@ public class TestSpecialArgs extends TestHelper {
          *       Code to create env variable not executed.
          * 4) give and invalid value and check to make sure JVM commented
          */
-        String launcherPidString = "launcher.pid=";
         String envVarPidString = "TRACER_MARKER: NativeMemoryTracking: env var is NMT_LEVEL_";
         String NMT_Option_Value = "off";
         String myClassName = "helloworld";
-        boolean haveLauncherPid = false;
 
         // === Run the tests ===
         // ---Test 1a
@@ -163,46 +161,6 @@ public class TestSpecialArgs extends TestHelper {
             throw new RuntimeException("Error: env Var Pid in tracking info is empty string");
         }
 
-        /*
-         * On Linux, Launcher Tracking will print the PID.  Use this info
-         * to validate what we got as the PID in the Launcher itself.
-         * Linux is the only one that prints this, and trying to get it
-         * here for win is awful.  So let the linux test make sure we get
-         * the valid pid, and for non-linux, just make sure pid string is
-         * non-zero.
-         */
-        if (isLinux) {
-            // get what the test says is the launcher pid
-            String launcherPid = null;
-            for (String line : tr.testOutput) {
-                int index = line.indexOf(launcherPidString);
-                if (index >= 0) {
-                    int sindex = index + launcherPidString.length();
-                    int tindex = sindex + line.substring(sindex).indexOf("'");
-                    System.out.println("DEBUG INFO: sindex = " + sindex);
-                    System.out.println("DEBUG INFO: searching substring: " + line.substring(sindex));
-                    System.out.println("DEBUG INFO: tindex = " + tindex);
-                    // DEBUG INFO
-                    System.out.println(tr);
-                    launcherPid = line.substring(sindex, tindex);
-                    break;
-                }
-            }
-            if (launcherPid == null) {
-                System.out.println(tr);
-                throw new RuntimeException("Error: failed to find launcher Pid in launcher tracking info");
-            }
-
-            // did we create the env var with the correct pid?
-            if (!launcherPid.equals(envVarPid)) {
-                System.out.println(tr);
-                System.out.println("Error: wrong pid in creating env var");
-                System.out.println("Error Info: launcherPid = " + launcherPid);
-                System.out.println("Error Info: envVarPid   = " + envVarPid);
-                throw new RuntimeException("Error: wrong pid in creating env var");
-            }
-        }
-
         // --- Test 1b
         if (!tr.contains("NativeMemoryTracking: got value " + NMT_Option_Value)) {
             System.out.println(tr);