This discussion is archived
2 Replies Latest reply: Dec 16, 2008 8:37 PM by 843810 RSS

breakpoint on optimized-out statement?

843810 Newbie
Currently Being Moderated
Should a breakpoint placed on a statement be skipped if the compiler optimizes that statement out? I'm using Eclipse 3.4 and it seems to have done that.

I have a method that looks like
public static something(..) {
   if (true) {
      return somevalue;
   }
   ...
}
I put the if (true) to avoid the unreachable-code error I'd get otherwise.

If I place a breakpoint on that statement (on the if line), it never fires. If I place it on the return statement, it does. If I put a method call before the if, and put a breakpoint there, it fires. Looking at the byte code, it is clear that the if (true) has been optimized out.

So is this behavior to spec? Or is the Eclipse debugger at fault for not retargeting the breakpoint at the return statement? Or is the compiler at fault somehow?

Larry Edelstein
Senior Member of Technical Staff
salesforce.com
  • 1. Re: breakpoint on optimized-out statement?
    843810 Newbie
    Currently Being Moderated
    Larry_E wrote:

    I put the if (true) to avoid the unreachable-code error I'd get otherwise.
    It is not clear to me why you need to insert if(true) to avoid compile error. This could be a compiler bug.
    Please provide more code to understand the compiler problem.

    >
    If I place a breakpoint on that statement (on the if line), it never fires. If I place it on the return statement, it does. If I put a method call before the if, and put a breakpoint there, it fires. Looking at the byte code, it is clear that the if (true) has been optimized out.

    So is this behavior to spec? Or is the Eclipse debugger at fault for not retargeting the breakpoint at the return statement? Or is the compiler at fault somehow?
    Does the eclipse gives any error saying no code found at the line corresponding to "if(true)" statement or just ignored it.
    Eclipse should print error msg. I do not think eclipse has been designed to set a break point at the next nearest statement.
    jdb also does not do that. Optimizing the code this way is not a compiler fault. Only thing I will be looking at the need
    of if(true) statement to avoid compile error. That could be a compiler issue.
  • 2. Re: breakpoint on optimized-out statement?
    843810 Newbie
    Currently Being Moderated
    You can use javap -v <java class> to view the line number table information. Unfortunately there is no option to disable the code optimization.