Bazel IntelliJ plugin: no hotswapping?

381 views
Skip to first unread message

Dan Fabulich

unread,
Jan 31, 2017, 2:51:57 AM1/31/17
to bazel-discuss
I just filed https://github.com/bazelbuild/intellij/issues/50 which notes that the Bazel plugin for IntelliJ doesn't support "hotswap" reloading of classes.

Is this really true? Does nobody at Google use hotswap debugging with Bazel?! It seems shocking to me, as if I must have overlooked something.

Damien Martin-guillerez

unread,
Feb 1, 2017, 5:32:21 AM2/1/17
to Dan Fabulich, bazel-discuss, ku...@google.com
Yes there is no hotswapping for test yet. It is a question of correctness but +Kush Chakraborty is working on having something similar using worker on tests.

On Tue, Jan 31, 2017 at 8:51 AM Dan Fabulich <danfa...@gmail.com> wrote:
I just filed https://github.com/bazelbuild/intellij/issues/50 which notes that the Bazel plugin for IntelliJ doesn't support "hotswap" reloading of classes.

Is this really true? Does nobody at Google use hotswap debugging with Bazel?! It seems shocking to me, as if I must have overlooked something.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/d9d11568-861e-4de2-bb97-3caed4aa250d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Philipp Wollermann

unread,
Feb 1, 2017, 6:41:23 AM2/1/17
to Damien Martin-guillerez, Dan Fabulich, bazel-discuss, ku...@google.com, to...@google.com
The "hotswap" that Dan talks about is a very different thing than Kush's work of keeping a persistent test runner in the background, which is mainly a performance improvement.

Dan talks about the IDE feature where you can reload individual classes while you're actively debugging a running app (e.g. to try a fix without having to restart the app).

I think that would be cool to have, but to be honest, I've never used it myself (maybe because debugging Bazel is such an annoying setup due to our C++ launcher, which prevents us from simply debugging Bazel like any other Java application).

+Tom Lundell for a quick judgement on this feature request.

Tom Lundell

unread,
Feb 1, 2017, 3:20:14 PM2/1/17
to Philipp Wollermann, Damien Martin-guillerez, Dan Fabulich, bazel-discuss, ku...@google.com
I don't exactly see what the IDE has to do with this, in this case? It doesn't compile, deploy, or manage the JVM -- bazel does. Hotswapping would have to be a bazel-side feature before the IDE could take advantage.

On Wed, Feb 1, 2017 at 6:41 AM, Philipp Wollermann <phi...@google.com> wrote:
The "hotswap" that Dan talks about is a very different thing than Kush's work of keeping a persistent test runner in the background, which is mainly a performance improvement.

Dan talks about the IDE feature where you can reload individual classes while you're actively debugging a running app (e.g. to try a fix without having to restart the app).

I think that would be cool to have, but to be honest, I've never used it myself (maybe because debugging Bazel is such an annoying setup due to our C++ launcher, which prevents us from simply debugging Bazel like any other Java application).

+Tom Lundell for a quick judgement on this feature request.

On Wed, Feb 1, 2017 at 11:32 AM 'Damien Martin-guillerez' via bazel-discuss <bazel-discuss@googlegroups.com> wrote:
Yes there is no hotswapping for test yet. It is a question of correctness but +Kush Chakraborty is working on having something similar using worker on tests.

On Tue, Jan 31, 2017 at 8:51 AM Dan Fabulich <danfa...@gmail.com> wrote:
I just filed https://github.com/bazelbuild/intellij/issues/50 which notes that the Bazel plugin for IntelliJ doesn't support "hotswap" reloading of classes.

Is this really true? Does nobody at Google use hotswap debugging with Bazel?! It seems shocking to me, as if I must have overlooked something.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.

Dan Fabulich

unread,
Feb 1, 2017, 5:15:03 PM2/1/17
to Tom Lundell, Philipp Wollermann, Damien Martin-guillerez, bazel-discuss, ku...@google.com
I don't think I agree with that assessment; I think this is, intimately, an IDE feature.

Hotswap debugging doesn't technically require that the IDE launch the process. You can attach an IDE to a remote JVM on another machine over the Java Debug Interface. In addition to setting breakpoints (EventRequestManager#createBreakpointRequest) and stepping through code (#createStepRequest), a JDI client can, if it chooses, transmit modified classes to the remote process (VirtualMachine#redefineClasses), and the JVM will replace whatever class it loaded naturally and with the class definition that the IDE transmitted over the wire.


IDEs are the "normal" clients for JDI; they typically compile the classes and launch the JVM, launching it in debug mode and attaching to the JVM over the Java Debug Wire Protocol (JDWP). When you want to hot swap, you edit the file in the IDE, save, rebuild, and the IDE can then reload the class at that time.

You raise an interesting point that, in the case of the Bazel IntelliJ plugin, the plugin forces the IDE to delegate compiling classes and launching the JVM to Bazel, but the IDE still owns the JDWP connection. IntelliJ handles the breakpoints, stepping through code, enumerating threads, etc.

If you tried to add a bazel-side CLI feature for this, you'd have to have Bazel launch the process and then have Bazel connect to the JVM over JDWP. Then, when a class was rebuilt, Bazel could send the compiled class over the JDWP connection.

But if Bazel owns the JDWP connection, then only Bazel could manage the rest of the debugging facilities. Bazel would have to provide a console UI for debugging java processes, like jdb, and then I wouldn't be able to use the IntelliJ UI that I know and love for stepwise debugging. (I guess in principle Bazel could run a JDWP proxy server? But that sounds Hard™)

So I claim, the thing to do is for the Bazel plugin to finish the compilation and then notify the IDE of any rebuilt classes. IntelliJ could then transmit those classes via JDWP to the launched process. (And a similar feature would have to be implemented/reimplemented in Eclipse.)

-Dan

Tom Lundell

unread,
Feb 1, 2017, 6:08:27 PM2/1/17
to Dan Fabulich, bazel-discuss, Damien Martin-guillerez, ku...@google.com, Philipp Wollermann
Alright, good point. You're right and I'm wrong. Having bazel manage the connection would be silly. It does need IDE support.

Still, bazel is in charge of building and deploying. To support this, bazel would need to output a manifest of classes with checksums of the final deploy jar. Roughly speaking:

* Bazel does a build, outputs checksum manifest
* Bazel does another build, outputs another checksum manifest
* IDE diffs and hotswaps changed classes.

This is pretty much what we were doing for Android's instant run.

On 1 Feb. 2017 17:15, "Dan Fabulich" <danfa...@gmail.com> wrote:
I don't think I agree with that assessment; I think this is, intimately, an IDE feature.

Hotswap debugging doesn't technically require that the IDE launch the process. You can attach an IDE to a remote JVM on another machine over the Java Debug Interface. In addition to setting breakpoints (EventRequestManager#createBreakpointRequest) and stepping through code (#createStepRequest), a JDI client can, if it chooses, transmit modified classes to the remote process (VirtualMachine#redefineClasses), and the JVM will replace whatever class it loaded naturally and with the class definition that the IDE transmitted over the wire.


IDEs are the "normal" clients for JDI; they typically compile the classes and launch the JVM, launching it in debug mode and attaching to the JVM over the Java Debug Wire Protocol (JDWP). When you want to hot swap, you edit the file in the IDE, save, rebuild, and the IDE can then reload the class at that time.

You raise an interesting point that, in the case of the Bazel IntelliJ plugin, the plugin forces the IDE to delegate compiling classes and launching the JVM to Bazel, but the IDE still owns the JDWP connection. IntelliJ handles the breakpoints, stepping through code, enumerating threads, etc.

If you tried to add a bazel-side CLI feature for this, you'd have to have Bazel launch the process and then have Bazel connect to the JVM over JDWP. Then, when a class was rebuilt, Bazel could send the compiled class over the JDWP connection.

But if Bazel owns the JDWP connection, then only Bazel could manage the rest of the debugging facilities. Bazel would have to provide a console UI for debugging java processes, like jdb, and then I wouldn't be able to use the IntelliJ UI that I know and love for stepwise debugging. (I guess in principle Bazel could run a JDWP proxy server? But that sounds Hard™)

So I claim, the thing to do is for the Bazel plugin to finish the compilation and then notify the IDE of any rebuilt classes. IntelliJ could then transmit those classes via JDWP to the launched process. (And a similar feature would have to be implemented/reimplemented in Eclipse.)

-Dan
On Feb 1, 2017, at 12:19 PM, Tom Lundell <to...@google.com> wrote:

I don't exactly see what the IDE has to do with this, in this case? It doesn't compile, deploy, or manage the JVM -- bazel does. Hotswapping would have to be a bazel-side feature before the IDE could take advantage.
On Wed, Feb 1, 2017 at 6:41 AM, Philipp Wollermann <phi...@google.com> wrote:
The "hotswap" that Dan talks about is a very different thing than Kush's work of keeping a persistent test runner in the background, which is mainly a performance improvement.

Dan talks about the IDE feature where you can reload individual classes while you're actively debugging a running app (e.g. to try a fix without having to restart the app).

I think that would be cool to have, but to be honest, I've never used it myself (maybe because debugging Bazel is such an annoying setup due to our C++ launcher, which prevents us from simply debugging Bazel like any other Java application).

+Tom Lundell for a quick judgement on this feature request.

Dan Fabulich

unread,
Feb 1, 2017, 6:10:58 PM2/1/17
to Tom Lundell, bazel-discuss, Damien Martin-guillerez, ku...@google.com, Philipp Wollermann
Intriguing! I haven't used the Bazel/IntelliJ Android plugin. Does it support Instant Run? Point me to some relevant code? Maybe a similar strategy could be applied to hot swap.

-Dan

Tom Lundell

unread,
Feb 1, 2017, 6:15:25 PM2/1/17
to Dan Fabulich, bazel-discuss, Damien Martin-guillerez, ku...@google.com, Philipp Wollermann
Not InstantRun. But you can look at the source code for mobile-install, @src/main/java/com/google/devtools/build/lib/runtime/mobileinstall/MobileInstallCommand.java, which does incremental building in a similar way. Note that this does *not* need the IDE's involvement.
Reply all
Reply to author
Forward
0 new messages