public static void dumpHeap(String fileName, boolean live) {
    if (hotspotMBean == null) {
      try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        hotspotMBean = ManagementFactory.newPlatformMXBeanProxy(server,
            HOTSPOT_BEAN_NAME, HOTSPOT_MXBEAN_CLASS);
      } catch (IOException e) {
        LOG.error(e.getMessage());
        throw new RuntimeException(e);
      }
    }
    if(DUMP_HEAP_METHOD != null) {
      try {
        DUMP_HEAP_METHOD.invoke(hotspotMBean, new Object[]{fileName, Boolean.valueOf(live)});
      } catch (RuntimeException re) {
        LOG.error(re.getMessage());
        throw re;
      } catch (Exception exp) {
        LOG.error(exp.getMessage());
        throw new RuntimeException(exp);
      }
    } else {
      LOG.error("Cannot find method dumpHeap() in com.sun.management.HotSpotDiagnosticMXBean.");
    }
  }
Dumps process heap.
@param fileName File name to use.
@param live Whether to only dump live objects.
ql/src/java/org/apache/hadoop/hive/ql/debug/Utils.java