Java Reference
In-Depth Information
code in memory and reusing it to speed up execution of the program. When doing
so, however, you lose your ability to generate meaningful stack traces, even though
the debugger may still work. If a problem arises in executing the cached machine
code, the stack trace will only display the unhelpful reference in compiled code .
Therefore, you may want to turn off the JIT while debugging in order to more
clearly follow what's happening in the case of a problem. Options vary by VM ,
but generally you can disable the JIT by launching the VM with the parameter
compiler=none . JDK 1.4 is smart about this type of thing, and it makes sure meth-
ods with breakpoints in them aren't optimized by the JIT ; this is supposed to
eliminate this problem in the debugger.
Setting breakpoints
When you launch your program in the debugger, it runs uninterrupted until it
hits a breakpoint marker. A breakpoint is a logical code reference that causes the
debugger to suspend the program (or take some other action) when it reaches
that point. Once suspended, you can use the debugger's tools to examine the
state of your program. You can then advance the program to the next breakpoint
or the next line of code at your leisure.
Generally, you'll set up breakpoints in your code to suspend the VM just as your
program enters a section of code that you suspect is the source of a bug. Then you
can follow the program step by step and make sure things are going as expected.
Breakpoints are markers known only to IDEA and the VM . They aren't saved in
your Java source or built into your generated class files. Therefore, breakpoints
can be set or cleared as needed, at any timeā€”even while the program is running.
You may need to set them before launching your program, for example, should
you wish to stop its execution early. Conversely, you may wish to toggle break-
points on and off throughout the debugging session as you try to narrow down
the problem.
6.1.3
Debugging your source code
Once your code is compiled and ready to go, you launch the application in the
debugger to begin your bug hunting at the first breakpoint. From there, you can
peek at what's happening inside your application. We'll discuss the details of
using the debugger in the next section of this chapter.
Launching your application in the debugger
When you use IDEA 's debugger to launch your program, you're actually run-
ning your program with the VM 's debug mode enabled. In debug mode, the VM
 
 
 
 
 
 
Search WWH ::




Custom Search