Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1224272

Bad code generated for try..finally{return;}

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0beta
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description

      The java compiler generates bad code for
      try{...}finally{return;} This is only noticed when the
      code is verified, as when an applet is loaded via http,
      because the bad code cannot be reached by program execution.
      Here is an example source file. Note especially method foo().
          public
          class finallyBug extends java.applet.Applet implements Runnable{
      boolean v;
      public void run(){
      v = true;
      }
      static boolean foo( finallyBug b ){
      try{
      Thread t;
      t = new Thread( b );
      t.start();
      t.join();
      } finally {
      return b.v;
      }
      }
          
      public finallyBug(){v = false;}
      public void init(){
      System.out.println("foo() "+(foo( this )?"succeeded":"failed") );
      }
          
      public static void main( String ignore[] ){
      System.out.println("foo() "+(foo( new finallyBug() )?"succeeded":"failed") );
      }
          
          }

      And here is part of the output of javap -c finallyBug. Note
      that the goto at 20 references offset 35, which is past the
      end of the method!

          Method boolean foo(finallyBug)
             0 new #10 <Class java.lang.Thread>
             3 dup
             4 aload_0 0
             5 invokenonvirtual #11 <Method java.lang.Thread.<init>(Ljava/lang/Runnable;)V>
             8 astore_3
             9 aload_3 3
            10 invokevirtual #21 <Method java.lang.Thread.start()V>
            13 aload_3 3
            14 invokevirtual #19 <Method java.lang.Thread.join()V>
            17 jsr 29
            20 goto 35
            23 astore_1
            24 jsr 29
            27 aload_1 1
            28 athrow
            29 astore_2
            30 aload_0 0
            31 getfield #20 <Field finallyBug.v Z>
            34 ireturn
          
          Method finallyBug()

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              fyellinsunw Frank Yellin (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: