Log the server pid to java logging.

PiperOrigin-RevId: 151489034
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
index 368b66b..270d89f 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
@@ -559,7 +559,11 @@
       // Run Blaze in batch mode.
       System.exit(batchMain(modules, args));
     }
-    LOG.info("Starting Blaze server with args " + Arrays.toString(args));
+    LOG.info(
+        "Starting Blaze server with pid "
+            + maybeGetPidString()
+            + " and args "
+            + Arrays.toString(args));
     try {
       // Run Blaze in server mode.
       System.exit(serverMain(modules, OutErr.SYSTEM_OUT_ERR, args));
@@ -736,8 +740,11 @@
   private static int batchMain(Iterable<BlazeModule> modules, String[] args) {
     captureSigint();
     CommandLineOptions commandLineOptions = splitStartupOptions(modules, args);
-    LOG.info("Running Blaze in batch mode with startup args "
-        + commandLineOptions.getStartupArgs());
+    LOG.info(
+        "Running Blaze in batch mode with "
+            + maybeGetPidString()
+            + "startup args "
+            + commandLineOptions.getStartupArgs());
 
     BlazeRuntime runtime;
     try {
@@ -933,7 +940,7 @@
     PathFragment installBase = startupOptions.installBase;
     PathFragment outputBase = startupOptions.outputBase;
 
-    maybeForceJNI(installBase);  // Must be before first use of JNI.
+    maybeForceJNIByGettingPid(installBase); // Must be before first use of JNI.
 
     // From the point of view of the Java program --install_base and --output_base
     // are mandatory options, despite the comment in their declarations.
@@ -1017,13 +1024,15 @@
     return runtime;
   }
 
-  /**
-   * Loads JNI libraries, if necessary under the current platform.
-   */
-  public static void maybeForceJNI(PathFragment installBase) {
-    if (jniLibsAvailable()) {
-      forceJNI(installBase);
-    }
+  private static String maybeGetPidString() {
+    Integer pid = maybeForceJNIByGettingPid(null);
+    return pid == null ? "" : "pid " + pid + " and ";
+  }
+
+  /** Loads JNI libraries, if necessary under the current platform. */
+  @Nullable
+  private static Integer maybeForceJNIByGettingPid(@Nullable PathFragment installBase) {
+    return jniLibsAvailable() ? getPidUsingJNI(installBase) : null;
   }
 
   private static boolean jniLibsAvailable() {
@@ -1032,13 +1041,19 @@
 
   // Force JNI linking at a moment when we have 'installBase' handy, and print
   // an informative error if it fails.
-  private static void forceJNI(PathFragment installBase) {
+  private static int getPidUsingJNI(@Nullable PathFragment installBase) {
     try {
-      ProcessUtils.getpid(); // force JNI initialization
+      return ProcessUtils.getpid(); // force JNI initialization
     } catch (UnsatisfiedLinkError t) {
-      System.err.println("JNI initialization failed: " + t.getMessage() + ".  "
-          + "Possibly your installation has been corrupted; "
-          + "if this problem persists, try 'rm -fr " + installBase + "'.");
+      System.err.println(
+          "JNI initialization failed: "
+              + t.getMessage()
+              + ".  "
+              + "Possibly your installation has been corrupted"
+              + (installBase == null
+                  ? ""
+                  : "; if this problem persists, try 'rm -fr " + installBase + "'")
+              + ".");
       throw t;
     }
   }