JDI: How to pause a Java application (JVM) like in the debugger
Asked Answered
U

3

6

I am looking for potentially a JDI API to pause the JVM at any arbitrary point during its execution. Looking at the BreakPointRequest createBreakpointRequest method needs a specific location. Is there any other API that does not need a location or someway to get current Location that could be passed to create a breakpoint.

I am basically looking for a way to attach and pause the application, then use JVMTI agent to receive callback for the BreakPoint event to perform further processing. Thanks

Undervest answered 15/1, 2012 at 4:24 Comment(1)
You want to halt JVM or application? if I understand correctly, one jvm may host multiple applications. If it is Jvm, Virtualmachine class, process method may be worth to research on for your req.Antiphlogistic
S
4

Breakpoints only make sense with a location in source. Arbitrary pausing your application is probably best done by suspending all the threads currently running in the JVM. Take a look at SuspendThreadList() or SuspendThread in jvmti. This mechanism would be the 'pause' you are looking for.

Silberman answered 17/1, 2012 at 17:53 Comment(0)
L
1

If you want to arbitrarily pause a running jvm with JDI, you would use the JDI VirtualMachine interface's suspend method.

However, this doesn't really give you much in terms of being able to then connect to a jvmti agent; as the other answer points out, the jvmti has its own methods for doing the same thing.

If you're looking for a way to define arbitrary callbacks for breakpoints, as opposed to calling out to a specific agent, you might be interested in jdiscript, which is a scripting layer around the JDI that lets you do such things pretty easily in straight Java, rather than having to drop into C++.

Lilytrotter answered 20/3, 2014 at 16:53 Comment(0)
R
0

i think jdb - The Java Debugger will be the best option. please check the url about the jdb

http://docs.oracle.com/javase/1.3/docs/tooldocs/solaris/jdb.html

Reavis answered 17/1, 2012 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.