changeset 47379:f289e2c1ef4d condy-folding

track all constants using the constant map instead of attaching them to the type
author vromero
date Wed, 04 Oct 2017 17:55:46 -0400
parents a968514d842b
children 7e9a554ddaf3
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ConstablesVisitor.java
diffstat 2 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Oct 04 16:35:51 2017 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Oct 04 17:55:46 2017 -0400
@@ -399,6 +399,14 @@
         return (flags() & ENUM) != 0;
     }
 
+    public boolean isFinal() {
+        return (flags() & FINAL) != 0;
+    }
+
+    public boolean isEffectivelyFinal() {
+        return (flags() & EFFECTIVELY_FINAL) != 0;
+    }
+
     /** Is this symbol declared (directly or indirectly) local
      *  to a method or variable initializer?
      *  Also includes fields of inner classes which are in
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ConstablesVisitor.java	Wed Oct 04 16:35:51 2017 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ConstablesVisitor.java	Wed Oct 04 17:55:46 2017 -0400
@@ -125,18 +125,14 @@
         super.visitVarDef(tree);
         if (tree.init != null) {
             VarSymbol v = tree.sym;
-            Object val = tree.init.type.constValue();
-            Object constant = elementToConstantMap.get(tree.init);
-            if ((val != null || constant != null) &&
-                    ((v.flags_field & FINAL) != 0 ||
-                    (v.flags_field & EFFECTIVELY_FINAL) != 0)) {
-                if (val != null) {
-                    v.setData(val);
-                    tree.type = tree.type.constType(val);
-                } else {
-                    elementToConstantMap.remove(tree.init);
-                    elementToConstantMap.put(v, constant);
-                }
+            Object constant = tree.init.type.constValue();
+            constant = constant != null ?
+                    constant :
+                    elementToConstantMap.get(tree.init);
+            if (constant != null &&
+                    (v.isFinal() || v.isEffectivelyFinal())) {
+                elementToConstantMap.remove(tree.init);
+                elementToConstantMap.put(v, constant);
             }
         }
     }
@@ -155,7 +151,8 @@
                 getConstant(tree.rhs) != null) {
             Type ctype = cfolder.fold2(tree.operator.opcode, tree.lhs.type, tree.rhs.type, getConstant(tree.lhs), getConstant(tree.rhs));
             if (ctype != null) {
-                tree.type = cfolder.coerce(ctype, tree.type);
+                ctype = cfolder.coerce(ctype, tree.type);
+                elementToConstantMap.put(tree, ctype.constValue());
             }
         }
     }
@@ -169,7 +166,8 @@
                 constant instanceof Number) {
             Type ctype = cfolder.fold1(tree.operator.opcode, tree.arg.type, getConstant(tree.arg));
             if (ctype != null) {
-                tree.type = cfolder.coerce(ctype, tree.type);
+                ctype = cfolder.coerce(ctype, tree.type);
+                elementToConstantMap.put(tree, ctype.constValue());
             }
         }
     }