This is an automated email from the ASF dual-hosted git repository.
mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 8550e06 [NO ISSUE][HYR] Eliminate reflection when obtaining pid from
RuntimeMXBean
8550e06 is described below
commit 8550e06c533800ae8b4b98a3159e9c0dad3a3eac
Author: Michael Blow <[email protected]>
AuthorDate: Thu Sep 9 23:21:10 2021 -0400
[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 <[email protected]>
Reviewed-by: Hussain Towaileb <[email protected]>
Integration-Tests: Jenkins <[email protected]>
Tested-by: Jenkins <[email protected]>
---
.../main/java/org/apache/hyracks/util/PidHelper.java | 19 +------------------
1 file changed, 1 insertion(+), 18 deletions(-)
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 @@ package org.apache.hyracks.util;
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 class PidHelper {
}
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;