1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Jul 31 08:37:34 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Aug 06 15:08:49 2013 +0100 1.3 @@ -1478,74 +1478,82 @@ 1.4 code.statBegin(TreeInfo.endPos(body)); 1.5 genFinalizer(env); 1.6 code.statBegin(TreeInfo.endPos(env.tree)); 1.7 - Chain exitChain = code.branch(goto_); 1.8 + Chain exitChain; 1.9 + if (startpc != endpc) { 1.10 + exitChain = code.branch(goto_); 1.11 + } else { 1.12 + exitChain = code.branch(dontgoto); 1.13 + } 1.14 endFinalizerGap(env); 1.15 - if (startpc != endpc) for (List<JCCatch> l = catchers; l.nonEmpty(); l = l.tail) { 1.16 - // start off with exception on stack 1.17 - code.entryPoint(stateTry, l.head.param.sym.type); 1.18 - genCatch(l.head, env, startpc, endpc, gaps); 1.19 - genFinalizer(env); 1.20 - if (hasFinalizer || l.tail.nonEmpty()) { 1.21 - code.statBegin(TreeInfo.endPos(env.tree)); 1.22 - exitChain = Code.mergeChains(exitChain, 1.23 - code.branch(goto_)); 1.24 + if (startpc != endpc) { 1.25 + for (List<JCCatch> l = catchers; l.nonEmpty(); l = l.tail) { 1.26 + // start off with exception on stack 1.27 + code.entryPoint(stateTry, l.head.param.sym.type); 1.28 + genCatch(l.head, env, startpc, endpc, gaps); 1.29 + genFinalizer(env); 1.30 + if (hasFinalizer || l.tail.nonEmpty()) { 1.31 + code.statBegin(TreeInfo.endPos(env.tree)); 1.32 + exitChain = Code.mergeChains(exitChain, 1.33 + code.branch(goto_)); 1.34 + } 1.35 + endFinalizerGap(env); 1.36 } 1.37 - endFinalizerGap(env); 1.38 - } 1.39 - if (hasFinalizer) { 1.40 - // Create a new register segement to avoid allocating 1.41 - // the same variables in finalizers and other statements. 1.42 - code.newRegSegment(); 1.43 1.44 - // Add a catch-all clause. 1.45 + if (hasFinalizer) { 1.46 + // Create a new register segement to avoid allocating 1.47 + // the same variables in finalizers and other statements. 1.48 + code.newRegSegment(); 1.49 1.50 - // start off with exception on stack 1.51 - int catchallpc = code.entryPoint(stateTry, syms.throwableType); 1.52 + // Add a catch-all clause. 1.53 1.54 - // Register all exception ranges for catch all clause. 1.55 - // The range of the catch all clause is from the beginning 1.56 - // of the try or synchronized block until the present 1.57 - // code pointer excluding all gaps in the current 1.58 - // environment's GenContext. 1.59 - int startseg = startpc; 1.60 - while (env.info.gaps.nonEmpty()) { 1.61 - int endseg = env.info.gaps.next().intValue(); 1.62 - registerCatch(body.pos(), startseg, endseg, 1.63 - catchallpc, 0); 1.64 - startseg = env.info.gaps.next().intValue(); 1.65 - } 1.66 - code.statBegin(TreeInfo.finalizerPos(env.tree)); 1.67 - code.markStatBegin(); 1.68 + // start off with exception on stack 1.69 + int catchallpc = code.entryPoint(stateTry, syms.throwableType); 1.70 1.71 - Item excVar = makeTemp(syms.throwableType); 1.72 - excVar.store(); 1.73 - genFinalizer(env); 1.74 - excVar.load(); 1.75 - registerCatch(body.pos(), startseg, 1.76 - env.info.gaps.next().intValue(), 1.77 - catchallpc, 0); 1.78 - code.emitop0(athrow); 1.79 - code.markDead(); 1.80 - 1.81 - // If there are jsr's to this finalizer, ... 1.82 - if (env.info.cont != null) { 1.83 - // Resolve all jsr's. 1.84 - code.resolve(env.info.cont); 1.85 - 1.86 - // Mark statement line number 1.87 + // Register all exception ranges for catch all clause. 1.88 + // The range of the catch all clause is from the beginning 1.89 + // of the try or synchronized block until the present 1.90 + // code pointer excluding all gaps in the current 1.91 + // environment's GenContext. 1.92 + int startseg = startpc; 1.93 + while (env.info.gaps.nonEmpty()) { 1.94 + int endseg = env.info.gaps.next().intValue(); 1.95 + registerCatch(body.pos(), startseg, endseg, 1.96 + catchallpc, 0); 1.97 + startseg = env.info.gaps.next().intValue(); 1.98 + } 1.99 code.statBegin(TreeInfo.finalizerPos(env.tree)); 1.100 code.markStatBegin(); 1.101 1.102 - // Save return address. 1.103 - LocalItem retVar = makeTemp(syms.throwableType); 1.104 - retVar.store(); 1.105 + Item excVar = makeTemp(syms.throwableType); 1.106 + excVar.store(); 1.107 + genFinalizer(env); 1.108 + excVar.load(); 1.109 + registerCatch(body.pos(), startseg, 1.110 + env.info.gaps.next().intValue(), 1.111 + catchallpc, 0); 1.112 + code.emitop0(athrow); 1.113 + code.markDead(); 1.114 1.115 - // Generate finalizer code. 1.116 - env.info.finalize.genLast(); 1.117 + // If there are jsr's to this finalizer, ... 1.118 + if (env.info.cont != null) { 1.119 + // Resolve all jsr's. 1.120 + code.resolve(env.info.cont); 1.121 1.122 - // Return. 1.123 - code.emitop1w(ret, retVar.reg); 1.124 - code.markDead(); 1.125 + // Mark statement line number 1.126 + code.statBegin(TreeInfo.finalizerPos(env.tree)); 1.127 + code.markStatBegin(); 1.128 + 1.129 + // Save return address. 1.130 + LocalItem retVar = makeTemp(syms.throwableType); 1.131 + retVar.store(); 1.132 + 1.133 + // Generate finalizer code. 1.134 + env.info.finalize.genLast(); 1.135 + 1.136 + // Return. 1.137 + code.emitop1w(ret, retVar.reg); 1.138 + code.markDead(); 1.139 + } 1.140 } 1.141 } 1.142 // Resolve all breaks.