Mercurial > hg > release > heapstats-2.1
view agent/test/race-condition/ClassPrepare/DataDumpRequest/testcase/Test.java @ 227:f421a4c6e7ea
Bug 3357: [TEST][RaceCondition]Add some events with ClassPrepare
Reviewed-by: yasuenag
https://github.com/HeapStats/heapstats/pull/92
author | KUBOTA Yuji <kubota.yuji@lab.ntt.co.jp> |
---|---|
date | Tue, 11 Apr 2017 18:05:01 +0900 |
parents | |
children | 84f67233da38 |
line wrap: on
line source
import java.util.stream.*; import java.net.*; import java.nio.file.*; import java.lang.reflect.*; import com.sun.tools.attach.*; import sun.tools.attach.*; public class Test implements Runnable{ public void run(){ try{ String cp = Stream.of(System.getProperty("java.class.path").split(":")) .filter(p -> !p.contains("tools.jar")) .findAny() .get(); ClassLoader loader = new URLClassLoader(new URL[]{Paths.get(cp, "dynload") .toUri() .toURL()}); Class<?> target = loader.loadClass("DynLoad"); Method targetMethod = target.getMethod("call"); Object targetObj = target.newInstance(); targetMethod.invoke(targetObj); } catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args) throws Exception{ (new Thread(new Test())).start(); Path selfProc = Paths.get("/proc/self"); String pid = Files.readSymbolicLink(selfProc).toString(); HotSpotVirtualMachine selfVM = (HotSpotVirtualMachine)VirtualMachine.attach(pid); try{ selfVM.localDataDump(); } finally{ selfVM.detach(); } } }