langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java
changeset 19247 71b0c0710a47
parent 19131 519fa466d8ba
child 19923 4895f15b3845
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Jul 31 08:37:34 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Tue Aug 06 15:08:49 2013 +0100
@@ -1478,74 +1478,82 @@
             code.statBegin(TreeInfo.endPos(body));
             genFinalizer(env);
             code.statBegin(TreeInfo.endPos(env.tree));
-            Chain exitChain = code.branch(goto_);
+            Chain exitChain;
+            if (startpc != endpc) {
+                exitChain = code.branch(goto_);
+            } else {
+                exitChain = code.branch(dontgoto);
+            }
             endFinalizerGap(env);
-            if (startpc != endpc) for (List<JCCatch> l = catchers; l.nonEmpty(); l = l.tail) {
-                // start off with exception on stack
-                code.entryPoint(stateTry, l.head.param.sym.type);
-                genCatch(l.head, env, startpc, endpc, gaps);
-                genFinalizer(env);
-                if (hasFinalizer || l.tail.nonEmpty()) {
-                    code.statBegin(TreeInfo.endPos(env.tree));
-                    exitChain = Code.mergeChains(exitChain,
-                                                 code.branch(goto_));
+            if (startpc != endpc) {
+                for (List<JCCatch> l = catchers; l.nonEmpty(); l = l.tail) {
+                    // start off with exception on stack
+                    code.entryPoint(stateTry, l.head.param.sym.type);
+                    genCatch(l.head, env, startpc, endpc, gaps);
+                    genFinalizer(env);
+                    if (hasFinalizer || l.tail.nonEmpty()) {
+                        code.statBegin(TreeInfo.endPos(env.tree));
+                        exitChain = Code.mergeChains(exitChain,
+                                                     code.branch(goto_));
+                    }
+                    endFinalizerGap(env);
                 }
-                endFinalizerGap(env);
-            }
-            if (hasFinalizer) {
-                // Create a new register segement to avoid allocating
-                // the same variables in finalizers and other statements.
-                code.newRegSegment();
-
-                // Add a catch-all clause.
-
-                // start off with exception on stack
-                int catchallpc = code.entryPoint(stateTry, syms.throwableType);
 
-                // Register all exception ranges for catch all clause.
-                // The range of the catch all clause is from the beginning
-                // of the try or synchronized block until the present
-                // code pointer excluding all gaps in the current
-                // environment's GenContext.
-                int startseg = startpc;
-                while (env.info.gaps.nonEmpty()) {
-                    int endseg = env.info.gaps.next().intValue();
-                    registerCatch(body.pos(), startseg, endseg,
-                                  catchallpc, 0);
-                    startseg = env.info.gaps.next().intValue();
-                }
-                code.statBegin(TreeInfo.finalizerPos(env.tree));
-                code.markStatBegin();
+                if (hasFinalizer) {
+                    // Create a new register segement to avoid allocating
+                    // the same variables in finalizers and other statements.
+                    code.newRegSegment();
+
+                    // Add a catch-all clause.
+
+                    // start off with exception on stack
+                    int catchallpc = code.entryPoint(stateTry, syms.throwableType);
 
-                Item excVar = makeTemp(syms.throwableType);
-                excVar.store();
-                genFinalizer(env);
-                excVar.load();
-                registerCatch(body.pos(), startseg,
-                              env.info.gaps.next().intValue(),
-                              catchallpc, 0);
-                code.emitop0(athrow);
-                code.markDead();
-
-                // If there are jsr's to this finalizer, ...
-                if (env.info.cont != null) {
-                    // Resolve all jsr's.
-                    code.resolve(env.info.cont);
-
-                    // Mark statement line number
+                    // Register all exception ranges for catch all clause.
+                    // The range of the catch all clause is from the beginning
+                    // of the try or synchronized block until the present
+                    // code pointer excluding all gaps in the current
+                    // environment's GenContext.
+                    int startseg = startpc;
+                    while (env.info.gaps.nonEmpty()) {
+                        int endseg = env.info.gaps.next().intValue();
+                        registerCatch(body.pos(), startseg, endseg,
+                                      catchallpc, 0);
+                        startseg = env.info.gaps.next().intValue();
+                    }
                     code.statBegin(TreeInfo.finalizerPos(env.tree));
                     code.markStatBegin();
 
-                    // Save return address.
-                    LocalItem retVar = makeTemp(syms.throwableType);
-                    retVar.store();
+                    Item excVar = makeTemp(syms.throwableType);
+                    excVar.store();
+                    genFinalizer(env);
+                    excVar.load();
+                    registerCatch(body.pos(), startseg,
+                                  env.info.gaps.next().intValue(),
+                                  catchallpc, 0);
+                    code.emitop0(athrow);
+                    code.markDead();
+
+                    // If there are jsr's to this finalizer, ...
+                    if (env.info.cont != null) {
+                        // Resolve all jsr's.
+                        code.resolve(env.info.cont);
 
-                    // Generate finalizer code.
-                    env.info.finalize.genLast();
+                        // Mark statement line number
+                        code.statBegin(TreeInfo.finalizerPos(env.tree));
+                        code.markStatBegin();
+
+                        // Save return address.
+                        LocalItem retVar = makeTemp(syms.throwableType);
+                        retVar.store();
 
-                    // Return.
-                    code.emitop1w(ret, retVar.reg);
-                    code.markDead();
+                        // Generate finalizer code.
+                        env.info.finalize.genLast();
+
+                        // Return.
+                        code.emitop1w(ret, retVar.reg);
+                        code.markDead();
+                    }
                 }
             }
             // Resolve all breaks.