changeset 2604:58e7e71b302e

8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class Reviewed-by: mcimadamore, jjg, jlahoda
author vromero
date Tue, 09 Sep 2014 10:43:06 -0700
parents 4ac623ddd8d0
children 9a3e5ce68cef
files src/share/classes/com/sun/tools/javac/comp/Flow.java src/share/classes/com/sun/tools/javac/jvm/Gen.java src/share/classes/com/sun/tools/javac/util/Bits.java
diffstat 3 files changed, 39 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 16 14:15:36 2014 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 09 10:43:06 2014 -0700
@@ -208,7 +208,7 @@
 
     public void analyzeTree(Env<AttrContext> env, TreeMaker make) {
         new AliveAnalyzer().analyzeTree(env, make);
-        new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env);
+        new AssignAnalyzer().analyzeTree(env);
         new FlowAnalyzer().analyzeTree(env, make);
         new CaptureAnalyzer().analyzeTree(env, make);
     }
@@ -241,7 +241,7 @@
         //related errors, which will allow for more errors to be detected
         Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
         try {
-            new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit) {
+            new AssignAnalyzer() {
                 @Override
                 protected boolean trackable(VarSymbol sym) {
                     return !env.info.scope.includes(sym) &&
@@ -1373,12 +1373,12 @@
      * effectively-final local variables/parameters.
      */
 
-    public abstract static class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer.AbstractAssignPendingExit>
+    public abstract class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer<P>.AbstractAssignPendingExit>
         extends BaseAnalyzer<P> {
 
         /** The set of definitely assigned variables.
          */
-        protected final Bits inits;
+        protected Bits inits;
 
         /** The set of definitely unassigned variables.
          */
@@ -1432,13 +1432,7 @@
         /** The starting position of the analysed tree */
         int startPos;
 
-        final Symtab syms;
-
-        protected Names names;
-
-        final boolean enforceThisDotInit;
-
-        public static class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit {
+        public class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit {
 
             final Bits inits;
             final Bits uninits;
@@ -1460,17 +1454,14 @@
             }
         }
 
-        public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names, boolean enforceThisDotInit) {
-            this.inits = inits;
+        public AbstractAssignAnalyzer() {
+            this.inits = new Bits();
             uninits = new Bits();
             uninitsTry = new Bits();
             initsWhenTrue = new Bits(true);
             initsWhenFalse = new Bits(true);
             uninitsWhenTrue = new Bits(true);
             uninitsWhenFalse = new Bits(true);
-            this.syms = syms;
-            this.names = names;
-            this.enforceThisDotInit = enforceThisDotInit;
         }
 
         private boolean isInitialConstructor = false;
@@ -2439,26 +2430,15 @@
         }
     }
 
-    public static class AssignAnalyzer
-        extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> {
+    public class AssignAnalyzer extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> {
 
-        Log log;
-        Lint lint;
-
-        public static class AssignPendingExit
-            extends AbstractAssignAnalyzer.AbstractAssignPendingExit {
+        public class AssignPendingExit extends AbstractAssignAnalyzer<AssignPendingExit>.AbstractAssignPendingExit {
 
             public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) {
                 super(tree, inits, uninits);
             }
         }
 
-        public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names, boolean enforceThisDotInit) {
-            super(new Bits(), syms, names, enforceThisDotInit);
-            this.log = log;
-            this.lint = lint;
-        }
-
         @Override
         protected AssignPendingExit createNewPendingExit(JCTree tree,
             Bits inits, Bits uninits) {
--- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Tue Sep 16 14:15:36 2014 -0700
+++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Tue Sep 09 10:43:06 2014 -0700
@@ -74,6 +74,7 @@
     private Name accessDollar;
     private final Types types;
     private final Lower lower;
+    private final Flow flow;
 
     /** Switch: GJ mode?
      */
@@ -125,6 +126,7 @@
         stringBufferAppend = new HashMap<Type,Symbol>();
         accessDollar = names.
             fromString("access" + target.syntheticNameChar());
+        flow = Flow.instance(context);
         lower = Lower.instance(context);
 
         Options options = Options.instance(context);
@@ -2516,9 +2518,7 @@
              */
             if (varDebugInfo && (cdef.sym.flags() & SYNTHETIC) == 0) {
                 try {
-                    LVTAssignAnalyzer lvtAssignAnalyzer = LVTAssignAnalyzer.make(
-                            lvtRanges, syms, names);
-                    lvtAssignAnalyzer.analyzeTree(localEnv);
+                    new LVTAssignAnalyzer().analyzeTree(localEnv);
                 } catch (Throwable e) {
                     throw e;
                 }
@@ -2609,11 +2609,10 @@
         }
     }
 
-    static class LVTAssignAnalyzer
+    class LVTAssignAnalyzer
         extends Flow.AbstractAssignAnalyzer<LVTAssignAnalyzer.LVTAssignPendingExit> {
 
         final LVTBits lvtInits;
-        final LVTRanges lvtRanges;
 
         /*  This class is anchored to a context dependent tree. The tree can
          *  vary inside the same instruction for example in the switch instruction
@@ -2621,35 +2620,12 @@
          *  to a given case. The aim is to always anchor the bits to the tree
          *  capable of closing a DA range.
          */
-        static class LVTBits extends Bits {
-
-            enum BitsOpKind {
-                INIT,
-                CLEAR,
-                INCL_BIT,
-                EXCL_BIT,
-                ASSIGN,
-                AND_SET,
-                OR_SET,
-                DIFF_SET,
-                XOR_SET,
-                INCL_RANGE,
-                EXCL_RANGE,
-            }
+        class LVTBits extends Bits {
 
             JCTree currentTree;
-            LVTAssignAnalyzer analyzer;
             private int[] oldBits = null;
             BitsState stateBeforeOp;
 
-            LVTBits() {
-                super(false);
-            }
-
-            LVTBits(int[] bits, BitsState initState) {
-                super(bits, initState);
-            }
-
             @Override
             public void clear() {
                 generalOp(null, -1, BitsOpKind.CLEAR);
@@ -2757,12 +2733,11 @@
                 if (currentTree != null &&
                         stateBeforeOp != BitsState.UNKNOWN &&
                         trackTree(currentTree)) {
-                    List<VarSymbol> locals =
-                            analyzer.lvtRanges
-                            .getVars(analyzer.currentMethod, currentTree);
+                    List<VarSymbol> locals = lvtRanges
+                            .getVars(currentMethod, currentTree);
                     locals = locals != null ?
                             locals : List.<VarSymbol>nil();
-                    for (JCVariableDecl vardecl : analyzer.vardecls) {
+                    for (JCVariableDecl vardecl : vardecls) {
                         //once the first is null, the rest will be so.
                         if (vardecl == null) {
                             break;
@@ -2772,7 +2747,7 @@
                         }
                     }
                     if (!locals.isEmpty()) {
-                        analyzer.lvtRanges.setEntry(analyzer.currentMethod,
+                        lvtRanges.setEntry(currentMethod,
                                 currentTree, locals);
                     }
                 }
@@ -2790,7 +2765,7 @@
             boolean trackVar(VarSymbol var) {
                 return (var.owner.kind == MTH &&
                         (var.flags() & PARAMETER) == 0 &&
-                        analyzer.trackable(var));
+                        trackable(var));
             }
 
             boolean trackTree(JCTree tree) {
@@ -2806,7 +2781,8 @@
 
         }
 
-        public class LVTAssignPendingExit extends Flow.AssignAnalyzer.AssignPendingExit {
+        public class LVTAssignPendingExit extends
+                                    Flow.AbstractAssignAnalyzer<LVTAssignPendingExit>.AbstractAssignPendingExit {
 
             LVTAssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) {
                 super(tree, inits, uninits);
@@ -2819,16 +2795,10 @@
             }
         }
 
-        private LVTAssignAnalyzer(LVTRanges lvtRanges, Symtab syms, Names names) {
-            super(new LVTBits(), syms, names, false);
-            lvtInits = (LVTBits)inits;
-            this.lvtRanges = lvtRanges;
-        }
-
-        public static LVTAssignAnalyzer make(LVTRanges lvtRanges, Symtab syms, Names names) {
-            LVTAssignAnalyzer result = new LVTAssignAnalyzer(lvtRanges, syms, names);
-            result.lvtInits.analyzer = result;
-            return result;
+        private LVTAssignAnalyzer() {
+            flow.super();
+            lvtInits = new LVTBits();
+            inits = lvtInits;
         }
 
         @Override
--- a/src/share/classes/com/sun/tools/javac/util/Bits.java	Tue Sep 16 14:15:36 2014 -0700
+++ b/src/share/classes/com/sun/tools/javac/util/Bits.java	Tue Sep 09 10:43:06 2014 -0700
@@ -84,6 +84,20 @@
 
     }
 
+    public enum BitsOpKind {
+        INIT,
+        CLEAR,
+        INCL_BIT,
+        EXCL_BIT,
+        ASSIGN,
+        AND_SET,
+        OR_SET,
+        DIFF_SET,
+        XOR_SET,
+        INCL_RANGE,
+        EXCL_RANGE,
+    }
+
     private final static int wordlen = 32;
     private final static int wordshift = 5;
     private final static int wordmask = wordlen - 1;