Tue, 09 Sep 2014 10:43:06 -0700
8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
Reviewed-by: mcimadamore, jjg, jlahoda
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Tue Sep 16 14:15:36 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Tue Sep 09 10:43:06 2014 -0700 1.3 @@ -208,7 +208,7 @@ 1.4 1.5 public void analyzeTree(Env<AttrContext> env, TreeMaker make) { 1.6 new AliveAnalyzer().analyzeTree(env, make); 1.7 - new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env); 1.8 + new AssignAnalyzer().analyzeTree(env); 1.9 new FlowAnalyzer().analyzeTree(env, make); 1.10 new CaptureAnalyzer().analyzeTree(env, make); 1.11 } 1.12 @@ -241,7 +241,7 @@ 1.13 //related errors, which will allow for more errors to be detected 1.14 Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); 1.15 try { 1.16 - new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit) { 1.17 + new AssignAnalyzer() { 1.18 @Override 1.19 protected boolean trackable(VarSymbol sym) { 1.20 return !env.info.scope.includes(sym) && 1.21 @@ -1373,12 +1373,12 @@ 1.22 * effectively-final local variables/parameters. 1.23 */ 1.24 1.25 - public abstract static class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer.AbstractAssignPendingExit> 1.26 + public abstract class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer<P>.AbstractAssignPendingExit> 1.27 extends BaseAnalyzer<P> { 1.28 1.29 /** The set of definitely assigned variables. 1.30 */ 1.31 - protected final Bits inits; 1.32 + protected Bits inits; 1.33 1.34 /** The set of definitely unassigned variables. 1.35 */ 1.36 @@ -1432,13 +1432,7 @@ 1.37 /** The starting position of the analysed tree */ 1.38 int startPos; 1.39 1.40 - final Symtab syms; 1.41 - 1.42 - protected Names names; 1.43 - 1.44 - final boolean enforceThisDotInit; 1.45 - 1.46 - public static class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit { 1.47 + public class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit { 1.48 1.49 final Bits inits; 1.50 final Bits uninits; 1.51 @@ -1460,17 +1454,14 @@ 1.52 } 1.53 } 1.54 1.55 - public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names, boolean enforceThisDotInit) { 1.56 - this.inits = inits; 1.57 + public AbstractAssignAnalyzer() { 1.58 + this.inits = new Bits(); 1.59 uninits = new Bits(); 1.60 uninitsTry = new Bits(); 1.61 initsWhenTrue = new Bits(true); 1.62 initsWhenFalse = new Bits(true); 1.63 uninitsWhenTrue = new Bits(true); 1.64 uninitsWhenFalse = new Bits(true); 1.65 - this.syms = syms; 1.66 - this.names = names; 1.67 - this.enforceThisDotInit = enforceThisDotInit; 1.68 } 1.69 1.70 private boolean isInitialConstructor = false; 1.71 @@ -2439,26 +2430,15 @@ 1.72 } 1.73 } 1.74 1.75 - public static class AssignAnalyzer 1.76 - extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> { 1.77 + public class AssignAnalyzer extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> { 1.78 1.79 - Log log; 1.80 - Lint lint; 1.81 - 1.82 - public static class AssignPendingExit 1.83 - extends AbstractAssignAnalyzer.AbstractAssignPendingExit { 1.84 + public class AssignPendingExit extends AbstractAssignAnalyzer<AssignPendingExit>.AbstractAssignPendingExit { 1.85 1.86 public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { 1.87 super(tree, inits, uninits); 1.88 } 1.89 } 1.90 1.91 - public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names, boolean enforceThisDotInit) { 1.92 - super(new Bits(), syms, names, enforceThisDotInit); 1.93 - this.log = log; 1.94 - this.lint = lint; 1.95 - } 1.96 - 1.97 @Override 1.98 protected AssignPendingExit createNewPendingExit(JCTree tree, 1.99 Bits inits, Bits uninits) {
2.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Sep 16 14:15:36 2014 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Sep 09 10:43:06 2014 -0700 2.3 @@ -74,6 +74,7 @@ 2.4 private Name accessDollar; 2.5 private final Types types; 2.6 private final Lower lower; 2.7 + private final Flow flow; 2.8 2.9 /** Switch: GJ mode? 2.10 */ 2.11 @@ -125,6 +126,7 @@ 2.12 stringBufferAppend = new HashMap<Type,Symbol>(); 2.13 accessDollar = names. 2.14 fromString("access" + target.syntheticNameChar()); 2.15 + flow = Flow.instance(context); 2.16 lower = Lower.instance(context); 2.17 2.18 Options options = Options.instance(context); 2.19 @@ -2516,9 +2518,7 @@ 2.20 */ 2.21 if (varDebugInfo && (cdef.sym.flags() & SYNTHETIC) == 0) { 2.22 try { 2.23 - LVTAssignAnalyzer lvtAssignAnalyzer = LVTAssignAnalyzer.make( 2.24 - lvtRanges, syms, names); 2.25 - lvtAssignAnalyzer.analyzeTree(localEnv); 2.26 + new LVTAssignAnalyzer().analyzeTree(localEnv); 2.27 } catch (Throwable e) { 2.28 throw e; 2.29 } 2.30 @@ -2609,11 +2609,10 @@ 2.31 } 2.32 } 2.33 2.34 - static class LVTAssignAnalyzer 2.35 + class LVTAssignAnalyzer 2.36 extends Flow.AbstractAssignAnalyzer<LVTAssignAnalyzer.LVTAssignPendingExit> { 2.37 2.38 final LVTBits lvtInits; 2.39 - final LVTRanges lvtRanges; 2.40 2.41 /* This class is anchored to a context dependent tree. The tree can 2.42 * vary inside the same instruction for example in the switch instruction 2.43 @@ -2621,35 +2620,12 @@ 2.44 * to a given case. The aim is to always anchor the bits to the tree 2.45 * capable of closing a DA range. 2.46 */ 2.47 - static class LVTBits extends Bits { 2.48 - 2.49 - enum BitsOpKind { 2.50 - INIT, 2.51 - CLEAR, 2.52 - INCL_BIT, 2.53 - EXCL_BIT, 2.54 - ASSIGN, 2.55 - AND_SET, 2.56 - OR_SET, 2.57 - DIFF_SET, 2.58 - XOR_SET, 2.59 - INCL_RANGE, 2.60 - EXCL_RANGE, 2.61 - } 2.62 + class LVTBits extends Bits { 2.63 2.64 JCTree currentTree; 2.65 - LVTAssignAnalyzer analyzer; 2.66 private int[] oldBits = null; 2.67 BitsState stateBeforeOp; 2.68 2.69 - LVTBits() { 2.70 - super(false); 2.71 - } 2.72 - 2.73 - LVTBits(int[] bits, BitsState initState) { 2.74 - super(bits, initState); 2.75 - } 2.76 - 2.77 @Override 2.78 public void clear() { 2.79 generalOp(null, -1, BitsOpKind.CLEAR); 2.80 @@ -2757,12 +2733,11 @@ 2.81 if (currentTree != null && 2.82 stateBeforeOp != BitsState.UNKNOWN && 2.83 trackTree(currentTree)) { 2.84 - List<VarSymbol> locals = 2.85 - analyzer.lvtRanges 2.86 - .getVars(analyzer.currentMethod, currentTree); 2.87 + List<VarSymbol> locals = lvtRanges 2.88 + .getVars(currentMethod, currentTree); 2.89 locals = locals != null ? 2.90 locals : List.<VarSymbol>nil(); 2.91 - for (JCVariableDecl vardecl : analyzer.vardecls) { 2.92 + for (JCVariableDecl vardecl : vardecls) { 2.93 //once the first is null, the rest will be so. 2.94 if (vardecl == null) { 2.95 break; 2.96 @@ -2772,7 +2747,7 @@ 2.97 } 2.98 } 2.99 if (!locals.isEmpty()) { 2.100 - analyzer.lvtRanges.setEntry(analyzer.currentMethod, 2.101 + lvtRanges.setEntry(currentMethod, 2.102 currentTree, locals); 2.103 } 2.104 } 2.105 @@ -2790,7 +2765,7 @@ 2.106 boolean trackVar(VarSymbol var) { 2.107 return (var.owner.kind == MTH && 2.108 (var.flags() & PARAMETER) == 0 && 2.109 - analyzer.trackable(var)); 2.110 + trackable(var)); 2.111 } 2.112 2.113 boolean trackTree(JCTree tree) { 2.114 @@ -2806,7 +2781,8 @@ 2.115 2.116 } 2.117 2.118 - public class LVTAssignPendingExit extends Flow.AssignAnalyzer.AssignPendingExit { 2.119 + public class LVTAssignPendingExit extends 2.120 + Flow.AbstractAssignAnalyzer<LVTAssignPendingExit>.AbstractAssignPendingExit { 2.121 2.122 LVTAssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { 2.123 super(tree, inits, uninits); 2.124 @@ -2819,16 +2795,10 @@ 2.125 } 2.126 } 2.127 2.128 - private LVTAssignAnalyzer(LVTRanges lvtRanges, Symtab syms, Names names) { 2.129 - super(new LVTBits(), syms, names, false); 2.130 - lvtInits = (LVTBits)inits; 2.131 - this.lvtRanges = lvtRanges; 2.132 - } 2.133 - 2.134 - public static LVTAssignAnalyzer make(LVTRanges lvtRanges, Symtab syms, Names names) { 2.135 - LVTAssignAnalyzer result = new LVTAssignAnalyzer(lvtRanges, syms, names); 2.136 - result.lvtInits.analyzer = result; 2.137 - return result; 2.138 + private LVTAssignAnalyzer() { 2.139 + flow.super(); 2.140 + lvtInits = new LVTBits(); 2.141 + inits = lvtInits; 2.142 } 2.143 2.144 @Override
3.1 --- a/src/share/classes/com/sun/tools/javac/util/Bits.java Tue Sep 16 14:15:36 2014 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/util/Bits.java Tue Sep 09 10:43:06 2014 -0700 3.3 @@ -84,6 +84,20 @@ 3.4 3.5 } 3.6 3.7 + public enum BitsOpKind { 3.8 + INIT, 3.9 + CLEAR, 3.10 + INCL_BIT, 3.11 + EXCL_BIT, 3.12 + ASSIGN, 3.13 + AND_SET, 3.14 + OR_SET, 3.15 + DIFF_SET, 3.16 + XOR_SET, 3.17 + INCL_RANGE, 3.18 + EXCL_RANGE, 3.19 + } 3.20 + 3.21 private final static int wordlen = 32; 3.22 private final static int wordshift = 5; 3.23 private final static int wordmask = wordlen - 1;