Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

bytecode

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 binaries I've downloaded do use it, although rarely.

I'd be interested to know what compilers do use the instruction, and what Java code constructs would cause them to use it.

Edit this is not a duplicate as it refers to the JSR bytecode instruction and not a Java Specification Request

like image 916
paj28 Avatar asked Jan 15 '14 23:01

paj28


People also ask

Is Java Virtual Machine a compiler?

The Java Virtual Machine machine is designed to support the Java programming language. Oracle's JDK software contains a compiler from source code written in the Java programming language to the instruction set of the Java Virtual Machine, and a run-time system that implements the Java Virtual Machine itself.

What is Java machine code?

Java bytecode is the instruction set for the Java Virtual Machine. It acts similar to an assembler which is an alias representation of a C++ code. As soon as a java program is compiled, java bytecode is generated. In more apt terms, java bytecode is the machine code in the form of a . class file.


1 Answers

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.

like image 144
Antimony Avatar answered Oct 08 '22 15:10

Antimony