Is there asm nop equivalent in java?

前端 未结 5 1845
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 17:48

When I program C/C++ with Visual Studio I often use __asm nop; command to insert a noop code in order to have something to break on. For instance:

5条回答
  •  一整个雨季
    2020-12-18 18:13

    You can just put in any arbitrary assignment statement that doesn't do anything, e.g.

    if (someCondition()) {
      int t=0;
    }
    

    The debugger will be happy to break on this. Since t is local to the block, it can't possibly have any side effects (and will get JIT-compiled out of existence in production code).

    Alternatively, you can write a static function which has a breakpoint permanently set inside it, so you can just do:

    if (someCondition()) {
      breakPoint();
    }
    

提交回复
热议问题