2013-05-18 3 views
1

jvm 힙에 액세스하여 객체를 반복하고 싶습니다. 나는 이것이 어떻게 행해질 수 있었는지에 따라 example을 발견했다. 나는 jdk1.7.0_11을 사용한다.jvm에 연결

public static void main(String[] args) { 
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); 
    System.out.println(runtimeBean.getVmName()); 
    System.out.println(runtimeBean.getVmVendor()); 
    System.out.println(runtimeBean.getVmVersion()); 
    String jvmName = runtimeBean.getName(); 
    BugSpotAgent agent = new BugSpotAgent(); 
    agent.attach(Integer.parseInt(jvmName.split("@")[0])); // exception here!!!! 

    VM.initialize(null, false); 
    VM vm = VM.getVM(); 

    System.out.println(vm.getVMInternalInfo()); 

    ObjectHeap heap = vm.getObjectHeap(); 
    heap.iterate(new CustomHeapVisitor()); 
} 

출력이 다음입니다 : 나는 다음 코드를 시도

Java HotSpot(TM) 64-Bit Server VM 
Oracle Corporation 
23.6-b04 

예외 :

Exception in thread "main" sun.jvm.hotspot.debugger.DebuggerException: Windbg Error: AttachProcess failed! 
    at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.attach0(Native Method) 
    at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.attach(WindbgDebuggerLocal.java:152) 
    at sun.jvm.hotspot.bugspot.BugSpotAgent.attachDebugger(BugSpotAgent.java:789) 
    at sun.jvm.hotspot.bugspot.BugSpotAgent.setupDebuggerWin32(BugSpotAgent.java:712) 
    at sun.jvm.hotspot.bugspot.BugSpotAgent.setupDebugger(BugSpotAgent.java:515) 
    at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:492) 
    at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:331) 
    at mishanesterenko.jdi.Main.main(Main.java:27) 

또 어떤 작품을 만들기 위해 수행해야? 마지막으로 힙에있는 jvm 객체 그래프에 액세스하여이 그래프를 검색하려고합니다.

+0

작동 시키십니까? – Tupac

+0

@Tupac, 꽤 오래 전에, 불행히도, 나는 일들이 어떻게 끝났는지 기억하지 못합니다. (아마 그냥 포기했을 것입니다. 당신은 user2994487의 대답을 볼 수 있습니다, 잘하면 당신을 도울 것입니다. –

답변

0
agent.attach(Integer.parseInt(jvmName.split("@")[0])); // exception here!!!! 

위의 내용에 대해서는 현재 프로세스 ID가 아닌 다른 jvm 프로세스 ID를 전달해야한다고 생각합니다.

이 줄을 제거 할 수 있습니다 :

VM.initialize(null, false); 

그래서, 내가 잘 작동 할 수 있습니다.