Repository: pinpoint-apm/pinpoint
Issue: Pinpoint Agent load failure
Labels: stale

WebSphere Platform 7.0.0.0 [ND 7.0.0.0 r0835.03] running with process name spark-w1Node01Cell\spark-w1Node01\server1 and process id 10489
Host Operating System is Linux, version 3.10.0-327.28.3.el7.x86_64
Java version = 1.6.0, Java Compiler = j9jit24, Java VM name = IBM J9 VM
was.install.root = /data/WAS
user.install.root = /data/WAS/profiles/AppSrv01
Java Home = /data/WAS/java/jre
ws.ext.dirs = /data/WAS/java/lib:/data/WAS/profiles/AppSrv01/classes:/data/WAS/classes:/data/WAS/lib:/data/WAS/installedChannels:/data/WAS/lib/ext:/data/WAS/web/help:/data/WAS/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime
Classpath = /data/WAS/profiles/AppSrv01/properties:/data/WAS/properties:/data/WAS/lib/startup.jar:/data/WAS/lib/bootstrap.jar:/data/WAS/lib/jsf-nls.jar:/data/WAS/lib/lmproxy.jar:/data/WAS/lib/urlprotocols.jar:/data/WAS/deploytool/itp/batchboot.jar:/data/WAS/deploytool/itp/batch2.jar:/data/WAS/java/lib/tools.jar:/data/pinpoint-agent/pinpoint-bootstrap-1.5.0.jar:/data/pinpoint-agent/pinpoint-bootstrap-1.5.0.jar
Java Library path = /data/WAS/java/jre/lib/amd64/compressedrefs:/data/WAS/java/jre/lib/amd64:/data/WAS/bin::/usr/lib
************* End Display Current Environment *************
2018-09-17 19:56:47 [WARN ](com.navercorp.pinpoint.bootstrap.PinpointStarter) pinpoint start failed.
com.navercorp.pinpoint.bootstrap.BootStrapException: execute fail. Error:null
	at com.navercorp.pinpoint.bootstrap.ContextClassLoaderExecuteTemplate.execute(ContextClassLoaderExecuteTemplate.java:52)
	at com.navercorp.pinpoint.bootstrap.AgentClassLoader.boot(AgentClassLoader.java:73)
	at com.navercorp.pinpoint.bootstrap.PinpointStarter.start(PinpointStarter.java:125)
	at com.navercorp.pinpoint.bootstrap.PinpointBootStrap.premain(PinpointBootStrap.java:62)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:599)
	at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:335)
	at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:350)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:45)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:515)
	at com.navercorp.pinpoint.bootstrap.AgentClassLoader$2.call(AgentClassLoader.java:78)
	at com.navercorp.pinpoint.bootstrap.ContextClassLoaderExecuteTemplate.execute(ContextClassLoaderExecuteTemplate.java:42)
	... 9 more
Caused by: com.google.inject.CreationException: Unable to create injector, see the following errors:

1) Error injecting constructor, java.lang.NoSuchMethodError: com/ibm/lang/management/OperatingSystemMXBean.getProcessCpuTimeByNS()J
  at com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor.<init>(DefaultAgentStatMonitor.java:63)
  while locating com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor
  at com.navercorp.pinpoint.profiler.context.module.ApplicationContextModule.configure(ApplicationContextModule.java:258)
  while locating com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor

1 error
	at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470)
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
	at com.google.inject.Guice.createInjector(Guice.java:99)
	at com.google.inject.Guice.createInjector(Guice.java:84)
	at com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext.<init>(DefaultApplicationContext.java:102)
	at com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext.<init>(DefaultApplicationContext.java:86)
	at com.navercorp.pinpoint.profiler.DefaultAgent.newApplicationContext(DefaultAgent.java:125)
	at com.navercorp.pinpoint.profiler.DefaultAgent.<init>(DefaultAgent.java:118)
	at com.navercorp.pinpoint.profiler.DefaultAgent.<init>(DefaultAgent.java:69)
	... 15 more
Caused by: java.lang.NoSuchMethodError: com/ibm/lang/management/OperatingSystemMXBean.getProcessCpuTimeByNS()J
	at com.navercorp.pinpoint.profiler.monitor.metric.cpu.ibm.Java6CpuLoadMetric.getSnapshot(Java6CpuLoadMetric.java:47)
	at com.navercorp.pinpoint.profiler.monitor.collector.cpu.DefaultCpuLoadMetricCollector.collect(DefaultCpuLoadMetricCollector.java:40)
	at com.navercorp.pinpoint.profiler.monitor.collector.cpu.DefaultCpuLoadMetricCollector.collect(DefaultCpuLoadMetricCollector.java:26)
	at com.navercorp.pinpoint.profiler.monitor.collector.AgentStatCollector.collect(AgentStatCollector.java:99)
	at com.navercorp.pinpoint.profiler.monitor.collector.AgentStatCollector.collect(AgentStatCollector.java:34)
	at com.navercorp.pinpoint.profiler.monitor.CollectJob.run(CollectJob.java:67)
	at com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor.preLoadClass(DefaultAgentStatMonitor.java:104)
	at com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor.<init>(DefaultAgentStatMonitor.java:91)
	at com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor.<init>(DefaultAgentStatMonitor.java:63)
	at com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor$$FastClassByGuice$$1e15b61b.newInstance(<generated>)
	at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
	at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
	at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
	at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
	at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
	... 23 more

*****************************************************************************
* Pinpoint Agent load failure
*****************************************************************************
How to solve this problem？


Issue comments:
I found that there isn't " java.lang.management" in the IBM JDK 1.6
So pp-agent can't suppot  the  IBM JDK 1.6, is it right?
@emeroad

![image](https://user-images.githubusercontent.com/20055737/45656389-b891b980-bb17-11e8-8dea-83252f1d77ca.png)


![image](https://user-images.githubusercontent.com/20055737/45656365-926c1980-bb17-11e8-9786-46846331ec02.png)

@shenhongwei33 @chuanyi-fang 
Looks like your version of ibm java 6 does not have the method above.
We'll fix the startup error in the next version.

In the mean time, could you try it again with the jdk 6 downloaded from the ibm website?
Thanks.
#3579 
This issue/proposal has been automatically marked as stale because it hasn't had any recent activity. It will automatically be closed if no further activity occurs for 20days. If you think this should still be open, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up. Thank you for your interest and contribution to the Pinpoint Community.

resolved via #4694 

Pull request review comments:

Patch that resolved the issue:
diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/BootLoaderFactory.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/BootLoaderFactory.java
index f16ce008cb6e..da036fdac33a 100644
--- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/BootLoaderFactory.java
+++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/BootLoaderFactory.java
@@ -16,6 +16,9 @@
 
 package com.navercorp.pinpoint.bootstrap.classloader;
 
+import com.navercorp.pinpoint.common.util.JvmType;
+import com.navercorp.pinpoint.common.util.JvmUtils;
+
 /**
  * @author Woonduk Kang(emeroad)
  */
@@ -40,17 +43,8 @@ public static BootLoader newBootLoader() {
     }
 
     private static boolean isJ9VM() {
-        // ibm-j9 java.vm.name=IBM J9 VM;
-        // openj9 java.vm.name=Eclipse OpenJ9 VM
-//        if (System.getProperty("java.vm.name", "").contains("J9 VM")) {
-//            return true;
-//        }
-        try {
-            ClassLoader.class.getDeclaredField("bootstrapClassLoader");
-            return true;
-        } catch (NoSuchFieldException e) {
-            return false;
-        }
+        JvmType jvmType = JvmUtils.getType();
+        return jvmType == JvmType.IBM;
     }
 
 }
diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/J9BootLoader.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/J9BootLoader.java
index b615eaeae1e7..b0e11b3aa218 100644
--- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/J9BootLoader.java
+++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/J9BootLoader.java
@@ -44,12 +44,19 @@ public class J9BootLoader implements BootLoader {
     }
 
     private static ClassLoader findBootstrapClassLoader() {
+        Field bootstrapClassLoader;
+        try {
+            bootstrapClassLoader = ClassLoader.class.getDeclaredField("bootstrapClassLoader");
+        } catch (NoSuchFieldException e) {
+            try {
+                bootstrapClassLoader = ClassLoader.class.getDeclaredField("systemClassLoader");
+            } catch (NoSuchFieldException e2) {
+                throw new IllegalStateException("bootstrapClassLoader not found Caused by:" + e.getMessage() + ", and " + e2.getMessage(), e2);
+            }
+        }
         try {
-            Field bootstrapClassLoader = ClassLoader.class.getDeclaredField("bootstrapClassLoader");
             bootstrapClassLoader.setAccessible(true);
             return (ClassLoader) bootstrapClassLoader.get(ClassLoader.class);
-        } catch (NoSuchFieldException e) {
-            throw new IllegalStateException("bootstrapClassLoader not found Caused by:" + e.getMessage(), e);
         } catch (IllegalAccessException e) {
             throw new IllegalStateException("bootstrapClassLoader access fail Caused by:" + e.getMessage(), e);
         }
diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/JvmType.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/JvmType.java
index a63af83b5fe7..2537eb561172 100644
--- a/commons/src/main/java/com/navercorp/pinpoint/common/util/JvmType.java
+++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/JvmType.java
@@ -23,7 +23,9 @@
  */
 public enum JvmType {
     UNKNOWN(null),
-    IBM("IBM"),
+    // ibm-j9 java.vm.name=IBM J9 VM;
+    // openj9 java.vm.name=Eclipse OpenJ9 VM
+    IBM("J9"),
     OPENJDK("OpenJDK"),
     ORACLE("HotSpot");
 
diff --git a/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/JvmCpuUsageCalculator.java b/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/JvmCpuUsageCalculator.java
index cee669e9b80e..a4c2bdf899c0 100644
--- a/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/JvmCpuUsageCalculator.java
+++ b/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/JvmCpuUsageCalculator.java
@@ -46,12 +46,14 @@ public double getJvmCpuUsage(final long cpuTimeNS, final long upTimeMS) {
         final long diffUpTimeMS = upTimeMS - lastUpTimeMS;
         final long totalUpTimeNS = (diffUpTimeMS * 1000000) * CPU_COUNT;
 
-        final double cpuLoad = totalUpTimeNS > 0 ?
-                Math.min(100F, totalCpuTimeNS / (float) totalUpTimeNS) : UNSUPPORTED;
+        double cpuUsage = UNSUPPORTED;
+        if (totalUpTimeNS > 0) {
+            cpuUsage = Math.min(100F, totalCpuTimeNS / (float) totalUpTimeNS);
+        }
 
         this.lastCpuTimeNS = cpuTimeNS;
         this.lastUpTimeMS = upTimeMS;
 
-        return cpuLoad;
+        return cpuUsage;
     }
 }
diff --git a/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/Java6CpuLoadMetric.java b/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/Java6CpuLoadMetric.java
index 6faf29537b21..d54426415f4c 100644
--- a/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/Java6CpuLoadMetric.java
+++ b/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/Java6CpuLoadMetric.java
@@ -16,11 +16,15 @@
 
 package com.navercorp.pinpoint.profiler.monitor.metric.cpu.ibm;
 
+import com.ibm.lang.management.OperatingSystemMXBean;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetric;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetricSnapshot;
+import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuUsageProvider;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.JvmCpuUsageCalculator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 
 /**
@@ -28,32 +32,58 @@
  */
 public class Java6CpuLoadMetric implements CpuLoadMetric {
 
-    private final JvmCpuUsageCalculator jvmCpuUsageCalculator = new JvmCpuUsageCalculator();
-    private final com.ibm.lang.management.OperatingSystemMXBean operatingSystemMXBean;
-    private final RuntimeMXBean runtimeMXBean;
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    public Java6CpuLoadMetric(OperatingSystemMXBean operatingSystemMXBean, RuntimeMXBean runtimeMXBean) {
+    private CpuUsageProvider jvmCpuUsageProvider;
+
+    public Java6CpuLoadMetric() {
+        final OperatingSystemMXBean operatingSystemMXBean = (com.ibm.lang.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
         if (operatingSystemMXBean == null) {
-            throw new NullPointerException("operatingSystemMXBean must not be null");
+            throw new IllegalStateException("OperatingSystemMXBean not available");
+        }
+        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
+        if (runtimeMXBean == null) {
+            throw new IllegalStateException("RuntimeMXBean not available");
         }
-        this.operatingSystemMXBean = (com.ibm.lang.management.OperatingSystemMXBean) operatingSystemMXBean;
-        this.runtimeMXBean = runtimeMXBean;
+
+        CpuUsageProvider jvmCpuUsageProvider = new JvmCpuUsageProvider(operatingSystemMXBean, runtimeMXBean);
+        try {
+            jvmCpuUsageProvider.getCpuUsage();
+        } catch (NoSuchMethodError e) {
+            logger.warn("Expected method not found for retrieving jvm cpu usage. Cause : {}", e.getMessage());
+            jvmCpuUsageProvider = CpuUsageProvider.UNSUPPORTED;
+        }
+        this.jvmCpuUsageProvider = jvmCpuUsageProvider;
     }
 
     @Override
     public CpuLoadMetricSnapshot getSnapshot() {
-        double jvmCpuUsage = UNCOLLECTED_USAGE;
-        if (runtimeMXBean != null) {
-            long cpuTimeNS = operatingSystemMXBean.getProcessCpuTimeByNS();
-            long upTimeMS = runtimeMXBean.getUptime();
-            jvmCpuUsage = jvmCpuUsageCalculator.getJvmCpuUsage(cpuTimeNS, upTimeMS);
-        }
-        double systemCpuUsage = operatingSystemMXBean.getSystemCpuLoad();
-        return new CpuLoadMetricSnapshot(jvmCpuUsage, systemCpuUsage);
+        double jvmCpuUsage = jvmCpuUsageProvider.getCpuUsage();
+        return new CpuLoadMetricSnapshot(jvmCpuUsage, UNCOLLECTED_USAGE);
     }
 
     @Override
     public String toString() {
         return "CpuLoadMetric for IBM Java 1.6";
     }
+
+    private static class JvmCpuUsageProvider implements CpuUsageProvider {
+
+        private final JvmCpuUsageCalculator jvmCpuUsageCalculator = new JvmCpuUsageCalculator();
+
+        private final OperatingSystemMXBean operatingSystemMXBean;
+        private final RuntimeMXBean runtimeMXBean;
+
+        private JvmCpuUsageProvider(OperatingSystemMXBean operatingSystemMXBean, RuntimeMXBean runtimeMXBean) {
+            this.operatingSystemMXBean = operatingSystemMXBean;
+            this.runtimeMXBean = runtimeMXBean;
+        }
+
+        @Override
+        public double getCpuUsage() {
+            long cpuTimeNS = operatingSystemMXBean.getProcessCpuTimeByNS();
+            long upTimeMS = runtimeMXBean.getUptime();
+            return jvmCpuUsageCalculator.getJvmCpuUsage(cpuTimeNS, upTimeMS);
+        }
+    }
 }
diff --git a/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/Java6CpuLoadMetric.java b/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/Java6CpuLoadMetric.java
index e3fe36eef104..d4f9ee627ac1 100644
--- a/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/Java6CpuLoadMetric.java
+++ b/profiler-optional/profiler-optional-jdk6/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/Java6CpuLoadMetric.java
@@ -18,9 +18,13 @@
 
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetric;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetricSnapshot;
+import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuUsageProvider;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.JvmCpuUsageCalculator;
+import com.sun.management.OperatingSystemMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 
 /**
@@ -28,32 +32,58 @@
  */
 public class Java6CpuLoadMetric implements CpuLoadMetric {
 
-    private final JvmCpuUsageCalculator jvmCpuUsageCalculator = new JvmCpuUsageCalculator();
-    private final com.sun.management.OperatingSystemMXBean operatingSystemMXBean;
-    private final RuntimeMXBean runtimeMXBean;
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    public Java6CpuLoadMetric(OperatingSystemMXBean operatingSystemMXBean, RuntimeMXBean runtimeMXBean) {
+    private final CpuUsageProvider jvmCpuUsageProvider;
+
+    public Java6CpuLoadMetric() {
+        final OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
         if (operatingSystemMXBean == null) {
-            throw new NullPointerException("operatingSystemMXBean must not be null");
+            throw new IllegalStateException("OperatingSystemMXBean not available");
+        }
+        final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
+        if (runtimeMXBean == null) {
+            throw new IllegalStateException("RuntimeMXBean not available");
         }
-        this.operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) operatingSystemMXBean;
-        this.runtimeMXBean = runtimeMXBean;
+
+        CpuUsageProvider jvmCpuUsageProvider = new JvmCpuUsageProvider(operatingSystemMXBean, runtimeMXBean);
+        try {
+            jvmCpuUsageProvider.getCpuUsage();
+        } catch (NoSuchMethodError e) {
+            logger.warn("Expected method not found for retrieving jvm cpu usage. Cause : {}", e.getMessage());
+            jvmCpuUsageProvider = CpuUsageProvider.UNSUPPORTED;
+        }
+        this.jvmCpuUsageProvider = jvmCpuUsageProvider;
     }
 
     @Override
     public CpuLoadMetricSnapshot getSnapshot() {
-        double jvmCpuUsage = UNCOLLECTED_USAGE;
-        if (runtimeMXBean != null) {
-            long cpuTimeNS = operatingSystemMXBean.getProcessCpuTime();
-            long upTimeMS = runtimeMXBean.getUptime();
-            jvmCpuUsage = jvmCpuUsageCalculator.getJvmCpuUsage(cpuTimeNS, upTimeMS);
-        }
-        double systemCpuUsage = UNCOLLECTED_USAGE;
-        return new CpuLoadMetricSnapshot(jvmCpuUsage, systemCpuUsage);
+        double jvmCpuUsage = jvmCpuUsageProvider.getCpuUsage();
+        return new CpuLoadMetricSnapshot(jvmCpuUsage, UNCOLLECTED_USAGE);
     }
 
     @Override
     public String toString() {
         return "CpuLoadMetric for Oracle Java 1.6";
     }
+
+    private static class JvmCpuUsageProvider implements CpuUsageProvider {
+
+        private final JvmCpuUsageCalculator jvmCpuUsageCalculator = new JvmCpuUsageCalculator();
+
+        private final OperatingSystemMXBean operatingSystemMXBean;
+        private final RuntimeMXBean runtimeMXBean;
+
+        private JvmCpuUsageProvider(OperatingSystemMXBean operatingSystemMXBean, RuntimeMXBean runtimeMXBean) {
+            this.operatingSystemMXBean = operatingSystemMXBean;
+            this.runtimeMXBean = runtimeMXBean;
+        }
+
+        @Override
+        public double getCpuUsage() {
+            long cpuTimeNS = operatingSystemMXBean.getProcessCpuTime();
+            long upTimeMS = runtimeMXBean.getUptime();
+            return jvmCpuUsageCalculator.getJvmCpuUsage(cpuTimeNS, upTimeMS);
+        }
+    }
 }
diff --git a/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/DefaultCpuLoadMetric.java b/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/DefaultCpuLoadMetric.java
index 7d6abb3b2c8b..1baeb68910f1 100644
--- a/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/DefaultCpuLoadMetric.java
+++ b/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/ibm/DefaultCpuLoadMetric.java
@@ -16,29 +16,54 @@
 
 package com.navercorp.pinpoint.profiler.monitor.metric.cpu.ibm;
 
+import com.ibm.lang.management.OperatingSystemMXBean;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetric;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetricSnapshot;
+import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuUsageProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.ManagementFactory;
 
 /**
  * @author HyunGil Jeong
  */
 public class DefaultCpuLoadMetric implements CpuLoadMetric {
 
-    private final com.ibm.lang.management.OperatingSystemMXBean operatingSystemMXBean;
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    public DefaultCpuLoadMetric(OperatingSystemMXBean operatingSystemMXBean) {
+    private final CpuUsageProvider jvmCpuUsageProvider;
+    private final CpuUsageProvider systemCpuUsageProvider;
+
+    public DefaultCpuLoadMetric() {
+        final OperatingSystemMXBean operatingSystemMXBean = (com.ibm.lang.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
         if (operatingSystemMXBean == null) {
-            throw new NullPointerException("operatingSystemMXBean must not be null");
+            throw new IllegalStateException("OperatingSystemMXBean not available");
+        }
+
+        CpuUsageProvider jvmCpuUsageProvider = new JvmCpuUsageProvider(operatingSystemMXBean);
+        try {
+            jvmCpuUsageProvider.getCpuUsage();
+        } catch (NoSuchMethodError e) {
+            logger.warn("Expected method not found for retrieving jvm cpu usage. Cause : {}", e.getMessage());
+            jvmCpuUsageProvider = CpuUsageProvider.UNSUPPORTED;
+        }
+        this.jvmCpuUsageProvider = jvmCpuUsageProvider;
+
+        CpuUsageProvider systemCpuUsageProvider = new SystemCpuUsageProvider(operatingSystemMXBean);
+        try {
+            systemCpuUsageProvider.getCpuUsage();
+        } catch (NoSuchMethodError e) {
+            logger.warn("Expected method not found for retrieving system cpu usage. Cause : {}", e.getMessage());
+            systemCpuUsageProvider = CpuUsageProvider.UNSUPPORTED;
         }
-        this.operatingSystemMXBean = (com.ibm.lang.management.OperatingSystemMXBean) operatingSystemMXBean;
+        this.systemCpuUsageProvider = systemCpuUsageProvider;
     }
 
     @Override
     public CpuLoadMetricSnapshot getSnapshot() {
-        double jvmCpuUsage = operatingSystemMXBean.getProcessCpuLoad();
-        double systemCpuUsage = operatingSystemMXBean.getSystemCpuLoad();
+        double jvmCpuUsage = jvmCpuUsageProvider.getCpuUsage();
+        double systemCpuUsage = systemCpuUsageProvider.getCpuUsage();
         return new CpuLoadMetricSnapshot(jvmCpuUsage, systemCpuUsage);
     }
 
@@ -46,4 +71,32 @@ public CpuLoadMetricSnapshot getSnapshot() {
     public String toString() {
         return "CpuLoadMetric for IBM Java 1.7+";
     }
+
+    private static class JvmCpuUsageProvider implements CpuUsageProvider {
+
+        private final OperatingSystemMXBean operatingSystemMXBean;
+
+        private JvmCpuUsageProvider(OperatingSystemMXBean operatingSystemMXBean) {
+            this.operatingSystemMXBean = operatingSystemMXBean;
+        }
+
+        @Override
+        public double getCpuUsage() {
+            return operatingSystemMXBean.getProcessCpuLoad();
+        }
+    }
+
+    private static class SystemCpuUsageProvider implements CpuUsageProvider {
+
+        private final OperatingSystemMXBean operatingSystemMXBean;
+
+        private SystemCpuUsageProvider(OperatingSystemMXBean operatingSystemMXBean) {
+            this.operatingSystemMXBean = operatingSystemMXBean;
+        }
+
+        @Override
+        public double getCpuUsage() {
+            return operatingSystemMXBean.getSystemCpuLoad();
+        }
+    }
 }
diff --git a/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/DefaultCpuLoadMetric.java b/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/DefaultCpuLoadMetric.java
index 9954ba770128..5f3d011674a4 100644
--- a/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/DefaultCpuLoadMetric.java
+++ b/profiler-optional/profiler-optional-jdk7/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/oracle/DefaultCpuLoadMetric.java
@@ -18,27 +18,52 @@
 
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetric;
 import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetricSnapshot;
+import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuUsageProvider;
+import com.sun.management.OperatingSystemMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.ManagementFactory;
 
 /**
  * @author HyunGil Jeong
  */
 public class DefaultCpuLoadMetric implements CpuLoadMetric {
 
-    private final com.sun.management.OperatingSystemMXBean operatingSystemMXBean;
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    public DefaultCpuLoadMetric(OperatingSystemMXBean operatingSystemMXBean) {
+    private final CpuUsageProvider jvmCpuUsageProvider;
+    private final CpuUsageProvider systemCpuUsageProvider;
+
+    public DefaultCpuLoadMetric() {
+        final OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
         if (operatingSystemMXBean == null) {
-            throw new NullPointerException("operatingSystemMXBean must not be null");
+            throw new IllegalStateException("OperatingSystemMXBean not available");
+        }
+
+        CpuUsageProvider jvmCpuUsageProvider = new JvmCpuUsageProvider(operatingSystemMXBean);
+        try {
+            jvmCpuUsageProvider.getCpuUsage();
+        } catch (NoSuchMethodError e) {
+            logger.warn("Expected method not found for retrieving jvm cpu usage. Cause : {}", e.getMessage());
+            jvmCpuUsageProvider = CpuUsageProvider.UNSUPPORTED;
+        }
+        this.jvmCpuUsageProvider = jvmCpuUsageProvider;
+
+        CpuUsageProvider systemCpuUsageProvider = new SystemCpuUsageProvider(operatingSystemMXBean);
+        try {
+            systemCpuUsageProvider.getCpuUsage();
+        } catch (NoSuchMethodError e) {
+            logger.warn("Expected method not found for retrieving system cpu usage. Cause : {}", e.getMessage());
+            systemCpuUsageProvider = CpuUsageProvider.UNSUPPORTED;
         }
-        this.operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) operatingSystemMXBean;
+        this.systemCpuUsageProvider = systemCpuUsageProvider;
     }
 
     @Override
     public CpuLoadMetricSnapshot getSnapshot() {
-        double jvmCpuUsage = operatingSystemMXBean.getProcessCpuLoad();
-        double systemCpuUsage = operatingSystemMXBean.getSystemCpuLoad();
+        double jvmCpuUsage = jvmCpuUsageProvider.getCpuUsage();
+        double systemCpuUsage = systemCpuUsageProvider.getCpuUsage();
         return new CpuLoadMetricSnapshot(jvmCpuUsage, systemCpuUsage);
     }
 
@@ -46,4 +71,32 @@ public CpuLoadMetricSnapshot getSnapshot() {
     public String toString() {
         return "CpuLoadMetric for Oracle Java 1.7+";
     }
+
+    private static class JvmCpuUsageProvider implements CpuUsageProvider {
+
+        private final OperatingSystemMXBean operatingSystemMXBean;
+
+        private JvmCpuUsageProvider(OperatingSystemMXBean operatingSystemMXBean) {
+            this.operatingSystemMXBean = operatingSystemMXBean;
+        }
+
+        @Override
+        public double getCpuUsage() {
+            return operatingSystemMXBean.getProcessCpuLoad();
+        }
+    }
+
+    private static class SystemCpuUsageProvider implements CpuUsageProvider {
+
+        private final OperatingSystemMXBean operatingSystemMXBean;
+
+        private SystemCpuUsageProvider(OperatingSystemMXBean operatingSystemMXBean) {
+            this.operatingSystemMXBean = operatingSystemMXBean;
+        }
+
+        @Override
+        public double getCpuUsage() {
+            return operatingSystemMXBean.getSystemCpuLoad();
+        }
+    }
 }
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/stat/cpu/CpuLoadMetricProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/stat/cpu/CpuLoadMetricProvider.java
index 322e31d4b252..f4d6faa4db26 100644
--- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/stat/cpu/CpuLoadMetricProvider.java
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/stat/cpu/CpuLoadMetricProvider.java
@@ -26,9 +26,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
-import java.lang.management.RuntimeMXBean;
 import java.lang.reflect.Constructor;
 
 /**
@@ -85,27 +82,15 @@ private CpuLoadMetric createCpuLoadMetric(String classToLoad) {
         if (classToLoad == null) {
             return CpuLoadMetric.UNSUPPORTED_CPU_LOAD_METRIC;
         }
-        OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
-        if (operatingSystemMXBean == null) {
-            return CpuLoadMetric.UNSUPPORTED_CPU_LOAD_METRIC;
-        }
         try {
             @SuppressWarnings("unchecked")
             Class<CpuLoadMetric> cpuLoadMetricClass = (Class<CpuLoadMetric>) Class.forName(classToLoad);
             try {
-                // Create CpuLoadMetric for Java 7+
-                Constructor<CpuLoadMetric> cpuLoadMetricConstructor = cpuLoadMetricClass.getConstructor(OperatingSystemMXBean.class);
-                return cpuLoadMetricConstructor.newInstance(operatingSystemMXBean);
-            } catch (NoSuchMethodException e1) {
-                try {
-                    // Create CpuLoadMetric for Java 6
-                    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
-                    Constructor<CpuLoadMetric> cpuLoadMetricConstructor = cpuLoadMetricClass.getConstructor(OperatingSystemMXBean.class, RuntimeMXBean.class);
-                    return cpuLoadMetricConstructor.newInstance(operatingSystemMXBean, runtimeMXBean);
-                } catch (NoSuchMethodException e2) {
-                    logger.warn("Unknown CpuLoadMetric : {}", classToLoad);
-                    return CpuLoadMetric.UNSUPPORTED_CPU_LOAD_METRIC;
-                }
+                Constructor<CpuLoadMetric> cpuLoadMetricConstructor = cpuLoadMetricClass.getConstructor();
+                return cpuLoadMetricConstructor.newInstance();
+            } catch (NoSuchMethodException e) {
+                logger.warn("Unknown CpuLoadMetric : {}", classToLoad);
+                return CpuLoadMetric.UNSUPPORTED_CPU_LOAD_METRIC;
             }
         } catch (Exception e) {
             logger.warn("Error creating CpuLoadMetric [" + classToLoad + "]", e);
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/CpuUsageProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/CpuUsageProvider.java
new file mode 100644
index 000000000000..66f0717134d1
--- /dev/null
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/cpu/CpuUsageProvider.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2018 NAVER Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.navercorp.pinpoint.profiler.monitor.metric.cpu;
+
+/**
+ * @author HyunGil Jeong
+ */
+public interface CpuUsageProvider {
+
+    double getCpuUsage();
+
+    CpuUsageProvider UNSUPPORTED = new CpuUsageProvider() {
+        @Override
+        public double getCpuUsage() {
+            return CpuLoadMetric.UNCOLLECTED_USAGE;
+        }
+    };
+}


Test patch: