6 Replies Last post: Mar 31, 2012 1:29 AM by Scott McKinney  
Scott McKinney Newbie 54 posts since
Aug 2, 2010
Currently Being Moderated

Feb 9, 2012 9:29 AM

Debugger: Some way to notify target process using JDI?

Our language plugin, not generating class files on disk, needs to notify the debugged process of class changes.  Our type system dynamically compiles to bytecode in memory.  So what I'd like to do is notify the target process's type system via JDI ClassType.invokeMethod().  The general idea is our type system would detect the jdwp agent and if present create a dedicated thread to receive the call.  However, it appears that JDI does not accommodate this scenario; it seems that invokeMethod() can be called only when the thread is suspended during a breakpoint, which is not always the case when compiling in the debugger and it certainly isn't the case for the dedicated thread.  So my question is, is there some way to use JDI from IntelliJ to notify the target process?  I'd really like to piggyback on the existing JDI socket and not have to create a separate line of communication.

Eugene Zhuravlev JetBrains 4,039 posts since
Oct 12, 2001
Currently Being Moderated
Feb 9, 2012 1:18 PM in response to: Scott McKinney
Re: Debugger: Some way to notify target process using JDI?

Hi Scott,

 

This depends on what is the real goal. The method invocation via JDI is not a good idea for the reasons you mentioned. If the goal is to reload classes then the "redefineClasses" API call will do the job. This call does not require the VM to be suspended at a breakpoint. However, there are other limitations instead.

If you described the real goal of this operation, we'd probably suggest something.

Eugene Zhuravlev JetBrains 4,039 posts since
Oct 12, 2001
Currently Being Moderated
Feb 10, 2012 6:29 PM in response to: Scott McKinney
Re: Debugger: Some way to notify target process using JDI?

You may get access to DebuggerSession object via

DebuggerManagerEx.getSessions() method

Then you may obtain a DebugProcess object and get a reverence to VirtualMachineProxy

 

Notifications from compiler subsystem can be received by subscribing to CompilerTopics.COMPILATION_STATUS topic via MessageBus.

Eugene Zhuravlev JetBrains 4,039 posts since
Oct 12, 2001
Currently Being Moderated
Feb 11, 2012 4:08 PM in response to: Scott McKinney
Re: Debugger: Some way to notify target process using JDI?

>   So, essentially, i'd like to be able to send a collection of source strings to the target process where it compiles to bytecode and then calls redefine classes directly.

 

This is only possible via method invocation, which, in turn, is available only when the debuggee's VM is paused at a breakpoint.

So the only possibility here is to establish a different way of communication between processes.

Have a look at "Netty" or "Mina" NIO-based frameworks. They both are lightweight and convenient to use when you need inter-process communication using some custom protocol. For our purposes Netty works pretty good.

More Like This

  • Retrieving data ...