8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
authorvromero
Tue, 09 Sep 2014 10:43:06 -0700
changeset 26537 026471c1a12b
parent 26536 730984f89f90
child 26538 623363d962c9
8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class Reviewed-by: mcimadamore, jjg, jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Bits.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 09 12:16:25 2014 -0400
+++ b/langtools/src/jdk.compiler/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) &&
@@ -1369,12 +1369,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.
          */
@@ -1428,13 +1428,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;
@@ -1456,17 +1450,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;
@@ -2431,26 +2422,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/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Tue Sep 09 12:16:25 2014 -0400
+++ b/langtools/src/jdk.compiler/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;
 
     /** Format of stackmap tables to be generated. */
     private final Code.StackMapFormat stackMap;
@@ -113,6 +114,7 @@
         stringBufferAppend = new HashMap<>();
         accessDollar = names.
             fromString("access" + target.syntheticNameChar());
+        flow = Flow.instance(context);
         lower = Lower.instance(context);
 
         Options options = Options.instance(context);
@@ -2383,9 +2385,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;
                 }
@@ -2476,11 +2476,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
@@ -2488,35 +2487,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);
@@ -2624,12 +2600,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;
@@ -2639,7 +2614,7 @@
                         }
                     }
                     if (!locals.isEmpty()) {
-                        analyzer.lvtRanges.setEntry(analyzer.currentMethod,
+                        lvtRanges.setEntry(currentMethod,
                                 currentTree, locals);
                     }
                 }
@@ -2657,7 +2632,7 @@
             boolean trackVar(VarSymbol var) {
                 return (var.owner.kind == MTH &&
                         (var.flags() & PARAMETER) == 0 &&
-                        analyzer.trackable(var));
+                        trackable(var));
             }
 
             boolean trackTree(JCTree tree) {
@@ -2673,7 +2648,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);
@@ -2686,16 +2662,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/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Bits.java	Tue Sep 09 12:16:25 2014 -0400
+++ b/langtools/src/jdk.compiler/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;