简体   繁体   English

哪些Java编译器使用jsr指令,做什么用?

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

The Java bytecode language has the JSR instruction. Java字节码语言具有JSR指令。

None of the code I've compiled with the Java 7 compiler uses this instruction. 我使用Java 7编译器编译的代码均未使用此指令。

However, sometimes Java binaries I've downloaded do use it, although rarely. 但是,有时我下载的Java二进制文件确实会使用它,尽管很少。

I'd be interested to know what compilers do use the instruction, and what Java code constructs would cause them to use it. 我很想知道哪些编译器确实使用该指令,以及哪些Java代码构造将导致他们使用该指令。

Edit this is not a duplicate as it refers to the JSR bytecode instruction and not a Java Specification Request 编辑这不是重复的,因为它引用了JSR字节码指令,而不是Java规范请求

The JSR instruction is actually not even allowed in Java 7 classfiles. 实际上,Java 7类文件中甚至不允许使用JSR指令。 It is only allowed in version 49.0 or earlier classfiles, corresponding to Java 5 or earlier. 仅在与Java 5或更早版本相对应的49.0或更早版本的类文件中才允许使用。 In practice, it fell out of use long before that. 实际上,它在那之前很久就不使用了。

The JSR/RET mechanism was originally used to implement finally blocks. JSR / RET机制最初用于实现finally块。 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. 我不知道确切的版本,因为我找不到任何旧的编译器,但是根据我在网上找到的讨论,似乎这种转变发生在Java 1.2-1.3时代,不同的编译器在不同的时间切换。 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. 实际上,我在野外看到的JSR唯一用途是用于混淆。 For example, Zelix Klassmaster used to use it for its string decryption code. 例如,Zelix Klassmaster曾经将其用于其字符串解密代码。 I've also used it in several of my own Java crackmes. 我还在自己的几个Java破解程序中使用了它。

According to the JVM specification : 根据JVM规范

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 在Oracle针对Java SE 6之前的Java编程语言的编译器的实现中,在finally子句的实现中, jsr指令与ret指令一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM