What Java compilers use the jsr instruction, and what for?

前端 未结 2 945
情书的邮戳
情书的邮戳 2020-12-03 13:56

The Java bytecode language has the JSR instruction.

None of the code I\'ve compiled with the Java 7 compiler uses this instruction.

However, sometimes Java b

相关标签:
2条回答
  • 2020-12-03 14:51

    According to the JVM specification:

    In Oracle's implementation of a compiler for the Java programming language prior to Java SE 6, the jsr instruction was used with the ret instruction in the implementation of the finally clause

    0 讨论(0)
  • 2020-12-03 14:55

    The JSR instruction is actually not even allowed in Java 7 classfiles. It is only allowed in version 49.0 or earlier classfiles, corresponding to Java 5 or earlier. In practice, it fell out of use long before that.

    The JSR/RET mechanism was originally used to implement finally blocks. However, they decided that the code size savings weren't worth the extra complexity and it got gradually phased out.

    I don't know the exact versions since I can't find any compilers that old, but based on discussions I found online, it seems that the transition happened in the Java 1.2-1.3 era, with different compilers switching at different times. I have never seen a legitimate classfile from one of these old compilers, but you never know when it could happen.

    In practice, the only use of JSR I've seen in the wild is for obfuscation. For example, Zelix Klassmaster used to use it for its string decryption code. I've also used it in several of my own Java crackmes.

    0 讨论(0)
提交回复
热议问题