Search code examples
javajava-bytecode-asm

What instructions in ASM are only needed for debugging?


I'd like to streamline my asm code. So far, I'm working with bytecode outline in Eclipse to learn how to write my code. As I only see bytecode with debug information, I don't really know which stuff I can safely leave out and I'd prefer a quick answer by someone knowledgable to testing every possible case myself.

Are these assumptions true?

  1. I can mix different styles, even in the same class or method (injection of code without debug information into a method with debug information)
  2. visitLabel is only needed as a target for jump-instructions and not around every instruction
  3. visitLineNumber can be left out (debug information)
  4. visitLocalVariable can be left out (debug information)

Thanks!


Solution

  • You can compile code without debug information to look at it in the Bytecode Outline View, e.g. use separate project in Eclipse for that.

    Now to answer your questions:

    1. You can mix code with debug and without debug. Just note that when debugging such code, debugger won't show variables omitted from debug info.
    2. The visitLabel call is used to mark any place in the bytecode, e.g. target of jump instruction, boundaries of exception handler range and exception handler entry point, ranges of local variables and line numbers, some of newly instroduced type annotations (i.e. JSR308), etc.
    3. visitLineNumber produces information about line numbers primarily used by debuggers and can be omitted
    4. visitLocalVariable produces information about local vars primarily used by debuggers and can be omitted