Bug 3184 - Unreachable goto for try combinations (1FUST9E)
Summary: Unreachable goto for try combinations (1FUST9E)
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All Windows NT
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-10 22:50 EDT by Philipe Mulet CLA
Modified: 2007-04-27 04:00 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2001-10-10 22:50:54 EDT
On the following test case, the bytecode at 34 could have been optimized out.

public class X{
	public static void main(String args[]) 
	{
		try{
			try{
				System.out.println("xxx");
			}
			finally{
				System.out.println("xxx");
			}
		}
		finally{
			System.out.println("xxx");
		}
	}
}


 0xB2 0x00 0x12 /*0   : getstatic [12] : Ljava/io/PrintStream;  java/lang/System.out */
 0x12 0x14      /*3   : ldc [14] : xxx */
 0xB6 0x00 0x1A /*5   : invokevirtual [1A] : java/io/PrintStream.println(Ljava/lang/String;)V */
 0xA7 0x00 0x09 /*8   : goto pc 17 : offset 9 */

 0x4E           /*11  : astore_3 */
 0xA8 0x00 0x0B /*12  : jsr pc 23 : offset 11 */
 0x2D           /*15  : aload_3 */
 0xBF           /*16  : athrow */

 0xA8 0x00 0x06 /*17  : jsr pc 23 : offset 6 */
 0xA7 0x00 0x17 /*20  : goto pc 43 : offset 23 */

 0x4D           /*23  : astore_2 */
 0xB2 0x00 0x12 /*24  : getstatic [12] : Ljava/io/PrintStream;  java/lang/System.out */
 0x12 0x14      /*27  : ldc [14] : xxx */
 0xB6 0x00 0x1A /*29  : invokevirtual [1A] : java/io/PrintStream.println(Ljava/lang/String;)V */
 0xA9 0x02      /*32  : ret local variable 2 */

 0xA7 0x00 0x09 /*34  : goto pc 43 : offset 9 */

 0x4D           /*37  : astore_2 */
 0xA8 0x00 0x0B /*38  : jsr pc 49 : offset 11 */
 0x2C           /*41  : aload_2 */
 0xBF           /*42  : athrow */

 0xA8 0x00 0x06 /*43  : jsr pc 49 : offset 6 */
 0xA7 0x00 0x0E /*46  : goto pc 60 : offset 14 */

 0x4C           /*49  : astore_1 */
 0xB2 0x00 0x12 /*50  : getstatic [12] : Ljava/io/PrintStream;  java/lang/System.out */
 0x12 0x14      /*53  : ldc [14] : xxx */
 0xB6 0x00 0x1A /*55  : invokevirtual [1A] : java/io/PrintStream.println(Ljava/lang/String;)V */
 0xA9 0x01      /*58  : ret local variable 1 */

 0xB1           /*60  : return */

 0x0002 /*exception table : count = 2*/
 0x0000 /*catch ANY : from 0 to 11 goto 11 */ 0x000B 0x000B 0x0000
 0x0000 /*catch ANY : from 0 to 37 goto 37 */ 0x0025 0x0025 0x0000
 			
NOTES:

PM (5/11/00 2:23:24 PM)
	This extra bytecode is actually generated as the inside try block natural exit. However, the only reference
	to it (goto at 20) got optimized since it is a transitive goto, and thus in the end bytecode 34 is indeed unreachable.
Comment 1 DJ Houghton CLA 2001-10-23 23:50:55 EDT
PRODUCT VERSION:
11b(5/11/00 2:22:56 PM)

Comment 2 Philipe Mulet CLA 2001-10-24 06:18:18 EDT
Defer
Comment 3 Philipe Mulet CLA 2007-04-02 07:36:47 EDT
reopening
Comment 4 Philipe Mulet CLA 2007-04-02 07:37:20 EDT
Olivier - is this still an issue ? Especially in the light of stackmap tables.
Comment 5 Olivier Thomann CLA 2007-04-02 20:53:08 EDT
Not a problem anymore.
The actual code gen is:
     0  getstatic System.out : PrintStream [16]
     3  ldc <String "xxx"> [22]
     5  invokevirtual PrintStream.println(String) : void [24]
     8  goto 28
    11  astore_2
    12  jsr 17
    15  aload_2
    16  athrow
    17  astore_1
    18  getstatic System.out : PrintStream [16]
    21  ldc <String "xxx"> [22]
    23  invokevirtual PrintStream.println(String) : void [24]
    26  ret 1
    28  jsr 17
    31  goto 53
    34  astore 4
    36  jsr 42
    39  aload 4
    41  athrow
    42  astore_3
    43  getstatic System.out : PrintStream [16]
    46  ldc <String "xxx"> [22]
    48  invokevirtual PrintStream.println(String) : void [24]
    51  ret 3
    53  jsr 42
    56  return
      Exception Table:
        [pc: 0, pc: 11] -> 11 when : any
        [pc: 28, pc: 31] -> 11 when : any
        [pc: 0, pc: 34] -> 34 when : any
        [pc: 53, pc: 56] -> 34 when : any

This might be a consequence of the change you made to remove dead code a while ago.
Closing as WORKSFORME?
Comment 6 Philipe Mulet CLA 2007-04-03 07:40:47 EDT
Likely yes, pls close as worksforme, and add a regression test.
Comment 7 Olivier Thomann CLA 2007-04-03 12:21:43 EDT
Added org.eclipse.jdt.core.tests.compiler.regression.TryStatementTest#test058
Comment 8 Maxime Daniel CLA 2007-04-27 03:57:08 EDT
Verified for 3.3 M7 using build I20070418-1012 (and source code v_751).
Comment 9 Maxime Daniel CLA 2007-04-27 04:00:14 EDT
Wrong build id:
Verified for 3.3 M7 using build I20070418-1012 (and source code v_751).