What does the jsr keyword mean?
Asked Answered
V

6

5

I'm looking at some Java code, and I've noticed the following:

if (!foo(bar, baz, qux)) {
    i = 0; jsr 433;
}

javac chokes on it, saying it's not a statement and that a semicolon is expected after the keyword jsr.

I did some Googling, and I found some code containing the same thing, which leads me to believe it's there intentionally (even though they weren't able to get it to compile either). So what does jsr do? How does one get code containing it to compile?

Valet answered 30/11, 2010 at 10:1 Comment(1)
Similar question without accepted answer https://mcmap.net/q/1921766/-are-these-encoded-codes-duplicateYarkand
P
10

I'm close to sure that this code is coming from a Java decompiler.

The JSR 432 smells like a decompiler note, where the decompiler found a "jump" code but doesn't have a clue on how to express it in java language.

Pamella answered 30/11, 2010 at 10:5 Comment(4)
That's got to be it. I'm 90% sure the code I'm looking at is decompiled code. Any way to piece together what was trying to occur here? Or is getting the original source the only option?Valet
@Mark - Hard to tell. You can try to correct it by hand but you need to disassemble the byte code for this method and try to find out where the algorithm continues. 432 is a byte code index. I did it on some occasions, so yes, technically it's possible.Pamella
See here: java.sun.com/docs/books/jvms/second_edition/html/…Subject
@spong, I only saw your link now, after I had added it to the answer.Marola
T
3

You are most likely looking at the results of decompiling some code which the decompiler wasn't able to cope with. JSR is the mnemonic for the jump subroutine bytecode; see this page for a listing. So jsr 432 may mean call a private method at bytecode address 432. However, the decompiler cannot figure that out, so maybe the method is synthetic, or something else is going on.

EDIT

Googled example you found is definitely decompiler output, and it looks like the part with the JSRs is either cause by obfuscation, byte code modification / generation, or by a decompiler stuffup.

Typewritten answered 30/11, 2010 at 10:6 Comment(0)
N
3

jsr 433 is not a valid Java statement. It is a VM instruction which stands for "Jump to Sub Routine" (See the VM Spec for more information). The decompiler inserted it because it didn't understand the bytecode instruction (perhaps it was obfuscated) and so couldn't decompile it into valid Java source.

Neoarsphenamine answered 30/11, 2010 at 10:20 Comment(1)
javac used to emit jsr instructions only for finally blocks. I don't think it even does that any more.Chemmy
I
1

JSR stands for Java Specification Request.

There's probably a typo in that code and it should have been

if (!foo(bar, baz, qux)) {
    i = 0; //jsr 433;
}

It seems to me that somebody did a non working checkin for some reason.

But, looking at that code, it looks awfully artificial, so it's probably decompiled code, as Andreas_D already stated.

Mini update: check the bottom comment:

/* Location:           C:\Users\Matteo\Downloads\FreeDownApplet.signed.jar
 * Qualified Name:     FreeDownApplet
 * JD-Core Version:    0.5.4
 */

From this, I'd say somebody made a signed jar file that was obfuscated, and whoever posted that code decompiled it.

Update 2: Googling "JD core" yields http://java.decompiler.free.fr/ as the first result.

Isidor answered 30/11, 2010 at 10:8 Comment(1)
Yeah, it was an example of what I found Googling, but I'm pretty sure what I'm looking at personally is decompiled code anyway, too. Interesting.Valet
H
0

It is not in the list of Java keywords. So I don't believe it has any meaning. And I doubt it's possible to compile it.

Harumscarum answered 30/11, 2010 at 10:7 Comment(0)
M
0

JSR (which stands for Jump Subroutine) is part of the Java Virtual Machine Specification. It's a instruction set for the JVM.

Brief description

The address of the opcode of the instruction immediately following this jsr instruction is pushed onto the operand stack as a value of type returnAddress.

This can be found on the JVM book 2nd edition.

Marola answered 30/11, 2010 at 10:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.