2

I have a question. Is it possible to use the hotswap without using breakpoints ?

When notch made prelude of chambered (http://www.youtube.com/user/Nizzotch?feature=playlist-comment#p/u) he used the hotswap without having to : - add breakpoints - save - remove breakpoint - resume In this video it's too fast to see that, but i can't find old ones.

Do you have an idea ? eclipse-options, macro, plugins ... ?

Thank you

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
yohannc
  • 140
  • 2
  • 9

1 Answers1

1

Depends on your JVM, but hotswap in Eclipse worked for me with no tricks on the Sun's HotSpot JVM back in the times of Java 1.5. Here's a related Sun's bug. Which JVM are you using?

public class Test {
    private static int ctr = 0;
    public static void main(String[] args) {
        while (true) {
            method();
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                System.err.println("Interrupted");
            }
        }
    }

    private static void method() {
        System.out.println(ctr);
    }
}

I changed System.out.println(ctr); to System.out.println(ctr++);, and my output altered to an increasing sequence.

Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93
  • Java version : 1.6.0_30. I can use the hotswap when i use breakpoints. But if the code is running when i save, then my modifications are not taken. – yohannc Feb 27 '12 at 14:47
  • OK, are you running in the Debug mode? See [this SO question](http://stackoverflow.com/questions/2673554/hot-code-replace-not-working-eclipse-doesnt-change-any-code-on-jboss) for a possible solution. – Alexander Pavlov Feb 27 '12 at 15:55
  • Yes i run in the debug mode and unlike your linked question, the changes are applied. Test yourself you will see. Create a project, a main method, and another method. In the second method, put an output message surrounded by a infinite loop. Then debug it. If you make a change in the message, and save nothing hapened, and your file is no longer linked. So make a new try, launch debug. Add a breakpoint on the output message, change it and save. Now resume and it's ok. But it's too much step compared when notch debug his application. – yohannc Feb 27 '12 at 16:40
  • Oh, I seem to get the point. Chances are that the JVM cannot hotswap code of existing stackframes without a breakpoint (in which case the affected frames are removed off the stack, and the entry call is executed once again.) I have added an example - it worked for me ONLY in the Debug mode. – Alexander Pavlov Feb 27 '12 at 17:04