15

Does anyone know why the JSR/RET bytecode pair is deprecated in Java 6?

The only meaningful explanation I found on the net was that they made code analysis by the runtime harder and slower to perform. Does anyone know another reason?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
George Penn.
  • 383
  • 3
  • 13
  • 3
    Do you mean deprecated by the JVM, or simply not used anymore by Oracle's Java compiler? I could not find a deprecation notice on the JVMS 7 https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.jsr – Ciro Santilli OurBigBook.com Apr 30 '15 at 20:32
  • 6
    @CiroSantilli巴拿馬文件六四事件法轮功: After quite a lot of searching, I found the rule against these instructions in Java 7 classes (class file format 51.0). It's in [§4.9.1](http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.9.1) of the JVMS. See [my Q&A on this](http://stackoverflow.com/q/37013761/1468366) for details. – MvG May 03 '16 at 20:32

1 Answers1

15

JSR and RET make bytecode verification a lot more difficult than it might otherwise be due to the relaxation of some normal bytecode constraints (such as having a consistent stack shape on entry to a JSR). The upside is very minor (potentially slightly smaller methods in some cases) and the continuing difficulties in the verifier dealing with odd JSR/RET patterns (and potential security vulnerabilities, and the associated runtime cost of full verification) make it a non-useful feature to continue having.

Stack maps and the lighter-weight verifier that is enabled as a result of the data are a big performance win during class loading for no sacrifice in safety.

Drunix
  • 3,313
  • 8
  • 28
  • 50
Trent Gray-Donald
  • 2,286
  • 14
  • 17
  • 2
    for the record: security vulnerabilities are not only potential, there has been a verifier bug in an older Java version, where using the SWAP bytecode to swap two return addresses on stack (JSR/JSR/SWAP/RET vulnerability) caused type confusion. – mihi Nov 08 '11 at 23:12
  • What does having a consistent stack shape on entry means ? – KodeWarrior Mar 09 '17 at 09:07
  • The JVM uses a stack to represent operands for operations. eg: the iadd bytecode expects 2 integers on the stack, which it pops and then pushes the result of adding those together. So to be a consistent shape means that at any given bytecode position in the method, the stack is always the same depth and each element on the stack is of the right type (ie: int vs reference, etc..). – Trent Gray-Donald Mar 10 '17 at 04:55