// Path: src/main/java/com/github/eostermueller/heapspank/util/IOUtil.java
// public class IOUtil {
// 
//     private IOUtil() {}
// 
//     public static String read(InputStream in) throws IOException {
//         StringBuilder builder = new StringBuilder();
//         byte b[] = new byte[256];
//         int n;
//         do {
//             n = in.read(b);
//             if (n > 0) {
//                 builder.append(new String(b, 0, n, "UTF-8"));
//             }
//         } while (n > 0);
//         in.close();
//         return builder.toString();
//     }
// 	/**
// 	 * @stolen from http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id
// 	 * @return
// 	 */
// 	public static long getMyPid() {
// 		  String processName =
// 			      java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
// 			    return Long.parseLong(processName.split("@")[0]);		
// 	}
// 
// }


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import com.github.eostermueller.heapspank.util.IOUtil;
			//Class<?> c = loader.loadClass("com.sun.tools.attach.VirtualMachine");
			c = loader.loadClass(HOT_SPOT_VM_CLASS_NAME);
		} catch (Exception e1) {
			JMapHistoException e2 = new JMapHistoException(e1);
			throw e2;
		}
        return c;
    }
	/**
	 * The following link shows that -live or -all must be passed to heapHist() with java 1.8 and greater. 
	 * http://cr.openjdk.java.net/~chegar/8153181/00/hotspot/src/share/vm/services/attachListener.cpp.rhs.html
	 * @return
	 * @throws IllegalAccessException
	 * @throws IllegalArgumentException
	 * @throws InvocationTargetException
	 * @throws IOException
	 */
	public String heapHisto(boolean live) throws JMapHistoException {
		String parm = null;
		if (live)
			parm = "-live";
		else 
			parm = "-all";
		Object[] arguments = new Object[] {  new String[] { parm }  } ; //trigger gc b4 cnt
		Object rc;
		String histo = null;
		try {
			if (this.heapHistoMethod!=null) {
				rc = this.heapHistoMethod.invoke(this.vm, arguments);
		        final InputStream in = (InputStream)rc;
// Path: src/main/java/com/github/eostermueller/heapspank/util/IOUtil.java
// public class IOUtil {
// 
//     private IOUtil() {}
// 
//     public static String read(InputStream in) throws IOException {
//         StringBuilder builder = new StringBuilder();
//         byte b[] = new byte[256];
//         int n;
//         do {
//             n = in.read(b);
//             if (n > 0) {
//                 builder.append(new String(b, 0, n, "UTF-8"));
//             }
//         } while (n > 0);
//         in.close();
//         return builder.toString();
//     }
// 	/**
// 	 * @stolen from http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id
// 	 * @return
// 	 */
// 	public static long getMyPid() {
// 		  String processName =
// 			      java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
// 			    return Long.parseLong(processName.split("@")[0]);		
// 	}
// 
// }


// Path: src/main/java/com/github/eostermueller/heapspank/leakyspank/tools/VirtualMachineWrapper.java
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import com.github.eostermueller.heapspank.util.IOUtil;

			//Class<?> c = loader.loadClass("com.sun.tools.attach.VirtualMachine");
			c = loader.loadClass(HOT_SPOT_VM_CLASS_NAME);
		} catch (Exception e1) {
			JMapHistoException e2 = new JMapHistoException(e1);
			throw e2;
		}
        return c;
    }
	/**
	 * The following link shows that -live or -all must be passed to heapHist() with java 1.8 and greater. 
	 * http://cr.openjdk.java.net/~chegar/8153181/00/hotspot/src/share/vm/services/attachListener.cpp.rhs.html
	 * @return
	 * @throws IllegalAccessException
	 * @throws IllegalArgumentException
	 * @throws InvocationTargetException
	 * @throws IOException
	 */
	public String heapHisto(boolean live) throws JMapHistoException {
		String parm = null;
		if (live)
			parm = "-live";
		else 
			parm = "-all";
		Object[] arguments = new Object[] {  new String[] { parm }  } ; //trigger gc b4 cnt
		Object rc;
		String histo = null;
		try {
			if (this.heapHistoMethod!=null) {
				rc = this.heapHistoMethod.invoke(this.vm, arguments);
		        final InputStream in = (InputStream)rc;
		        histo = IOUtil.read(in);