[NO ISSUE][HYR] Eliminate reflection when obtaining pid from RuntimeMXBean

Change-Id: I880f9e3bedafc2b9ebd2122fcc2f316bab696bf4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13146
Reviewed-by: Michael Blow <mblow@apache.org>
Reviewed-by: Hussain Towaileb <hussainht@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java
index 46e77e3..3cba2d3 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java
@@ -20,9 +20,6 @@
 
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
@@ -40,22 +37,8 @@
     }
 
     public static long getPid(RuntimeMXBean runtimeMXBean) {
-        // TODO: replace with direct invoke of getPid() once compatibility is at JDK 10 or higher
         try {
-            Method getPidMethod = runtimeMXBean.getClass().getMethod("getPid");
-            return (Long) getPidMethod.invoke(runtimeMXBean);
-        } catch (NoSuchMethodException e) {
-            LOGGER.debug("ignoring exception trying to find getPid() (expected pre-JDK 10)", e);
-        } catch (IllegalAccessException | InvocationTargetException e) {
-            LOGGER.debug("ignoring exception trying to execute getPid()", e);
-        }
-        try {
-            Field jvmField = runtimeMXBean.getClass().getDeclaredField("jvm");
-            jvmField.setAccessible(true);
-            Object vmManagement = jvmField.get(runtimeMXBean);
-            Method getProcessIdMethod = vmManagement.getClass().getDeclaredMethod("getProcessId");
-            getProcessIdMethod.setAccessible(true);
-            return (Integer) getProcessIdMethod.invoke(vmManagement);
+            return runtimeMXBean.getPid();
         } catch (Exception e) {
             LOGGER.log(Level.INFO, "Unable to determine PID due to exception", e);
             return -1;