src/share/classes/com/sun/tools/javac/jvm/Gen.java

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

mercurial