changeset 49037:ed5e12610039 lworld

[lworld] Withdraw @Flattenable annotation and introduce __Flattenable modifier
author sadayapalam
date Tue, 27 Feb 2018 12:00:18 +0530
parents 4ec94fa5992c
children 605a5a1da9fe
files src/java.base/share/classes/java/lang/Flattenable.java src/java.compiler/share/classes/javax/lang/model/element/Modifier.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java src/jdk.jshell/share/classes/jdk/jshell/CompletenessAnalyzer.java test/langtools/tools/javac/diags/examples/BadFlattenableAnno.java test/langtools/tools/javac/diags/examples/IllegalNullAssignmentToFlattenableValue.java test/langtools/tools/javac/valhalla/lworld-values/FlattenableFlagFromClass.java test/langtools/tools/javac/valhalla/lworld-values/FlattenableFlagTest.java test/langtools/tools/javac/valhalla/lworld-values/FlattenableNegativeTest.java test/langtools/tools/javac/valhalla/lworld-values/FlattenableNegativeTest.out
diffstat 16 files changed, 28 insertions(+), 106 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Flattenable.java	Mon Feb 26 14:08:16 2018 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.lang;
-
-import java.lang.annotation.*;
-
-/**
- * Indicates that the so annotated field must never store the null
- * reference. Intended to signal fields that are value instances that could be
- * represented in a flattended manner by the JVM.
- * 
- * @since 1.11
- */
-@Target(ElementType.FIELD)
-@Retention(RetentionPolicy.SOURCE) // lowered into flag bit, so not required further.
-public @interface Flattenable {
-}
\ No newline at end of file
--- a/src/java.compiler/share/classes/javax/lang/model/element/Modifier.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/java.compiler/share/classes/javax/lang/model/element/Modifier.java	Tue Feb 27 12:00:18 2018 +0530
@@ -64,10 +64,10 @@
      */
     VALUE,
     /**
-     * The modifier {@code __ValueFactory}
+     * The modifier {@code __Flattenable}
      * @since 1.11
      */
-    STATICVALUEFACTORY,
+    FLATTENABLE,
 
     /** The modifier {@code static} */          STATIC,
     /** The modifier {@code final} */           FINAL,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Tue Feb 27 12:00:18 2018 +0530
@@ -331,18 +331,18 @@
         MemberClassFlags      = LocalClassFlags | INTERFACE | AccessFlags,
         ClassFlags            = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
         InterfaceVarFlags     = FINAL | STATIC | PUBLIC,
-        VarFlags              = AccessFlags | FINAL | STATIC |
-                                VOLATILE | TRANSIENT | ENUM,
         ConstructorFlags      = AccessFlags,
         InterfaceMethodFlags  = ABSTRACT | PUBLIC,
         MethodFlags           = AccessFlags | ABSTRACT | STATIC | NATIVE |
                                 SYNCHRONIZED | FINAL | STRICTFP;
     public static final long
-        ExtendedStandardFlags       = (long)StandardFlags | DEFAULT | VALUE,
-        ModifierFlags               = ((long)StandardFlags & ~INTERFACE) | DEFAULT,
+        ExtendedStandardFlags       = (long)StandardFlags | DEFAULT | VALUE | FLATTENABLE,
+        ModifierFlags               = ((long)StandardFlags & ~INTERFACE) | DEFAULT | FLATTENABLE,
         InterfaceMethodMask         = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
         AnnotationTypeElementMask   = ABSTRACT | PUBLIC,
         LocalVarFlags               = FINAL | PARAMETER,
+        VarFlags              = AccessFlags | FINAL | STATIC |
+                                VOLATILE | TRANSIENT | FLATTENABLE | ENUM,
         ReceiverParamFlags          = PARAMETER;
 
 
@@ -357,6 +357,7 @@
             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
+            if (0 != (flags & FLATTENABLE)) modifiers.add(Modifier.FLATTENABLE);
             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
             if (0 != (flags & SYNCHRONIZED))
                                           modifiers.add(Modifier.SYNCHRONIZED);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Tue Feb 27 12:00:18 2018 +0530
@@ -205,7 +205,6 @@
     public final Type systemType;
     public final Type autoCloseableType;
     public final Type trustMeType;
-    public final Type flattenableType;
     public final Type lambdaMetafactory;
     public final Type stringConcatFactory;
     public final Type repeatableType;
@@ -541,7 +540,6 @@
                                             List.of(exceptionType), methodClass),
                              autoCloseableType.tsym);
         trustMeType = enterClass("java.lang.SafeVarargs");
-        flattenableType = enterClass("java.lang.Flattenable");
         nativeHeaderType = enterClass("java.lang.annotation.Native");
         lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
         stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Feb 27 12:00:18 2018 +0530
@@ -2903,15 +2903,6 @@
                 log.error(a.pos(), Errors.BadFunctionalIntfAnno1(Fragments.NotAFunctionalIntf(s)));
             }
         }
-        if (a.annotationType.type.tsym == syms.flattenableType.tsym) {
-            if (s.getKind() == ElementKind.FIELD) {  // != field barfed against above (AnnotationTypeNotApplicable)
-                if (!types.isValue(s.type)) {
-                   log.error(a.pos(), Errors.BadFlattenableAnno);
-                } else {
-                    s.flags_field |= Flags.FLATTENABLE;
-                }
-            }
-        }
     }
 
     public void validateTypeAnnotation(JCAnnotation a, boolean isTypeParameter) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Feb 27 12:00:18 2018 +0530
@@ -316,6 +316,7 @@
                 case PROTECTED:
                 case STATIC:
                 case TRANSIENT:
+                case FLATTENABLE:
                 case NATIVE:
                 case VOLATILE:
                 case SYNCHRONIZED:
@@ -2790,6 +2791,7 @@
             case PUBLIC      : flag = Flags.PUBLIC; break;
             case STATIC      : flag = Flags.STATIC; break;
             case TRANSIENT   : flag = Flags.TRANSIENT; break;
+            case FLATTENABLE : checkSourceLevel(Feature.VALUE_TYPES); flag = Flags.FLATTENABLE; break;
             case FINAL       : flag = Flags.FINAL; break;
             case ABSTRACT    : flag = Flags.ABSTRACT; break;
             case NATIVE      : flag = Flags.NATIVE; break;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java	Tue Feb 27 12:00:18 2018 +0530
@@ -162,6 +162,7 @@
         THROW("throw"),
         THROWS("throws"),
         TRANSIENT("transient"),
+        FLATTENABLE("__Flattenable"),
         TRY("try"),
         VALUE("__ByValue"),
         VDEFAULT("__MakeDefault"),
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Feb 27 12:00:18 2018 +0530
@@ -219,9 +219,6 @@
 compiler.err.bad.functional.intf.anno=\
     Unexpected @FunctionalInterface annotation
 
-compiler.err.bad.flattenable.anno=\
-    @Flattenable annotation can be applied only to a field whose type is a value type
-
 # 0: message segment
 compiler.err.bad.functional.intf.anno.1=\
     Unexpected @FunctionalInterface annotation\n\
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java	Tue Feb 27 12:00:18 2018 +0530
@@ -206,7 +206,7 @@
             case ACC_VOLATILE:
                 return "volatile";
             case 0x100:
-                return (t == Kind.Class || t == Kind.InnerClass) ? "value" : t == Kind.Field ? "@Flattenable" : "native";
+                return (t == Kind.Class || t == Kind.InnerClass) ? "value" : t == Kind.Field ? "__Flattenable" : "native";
             case ACC_ABSTRACT:
                 return "abstract";
             case ACC_STRICT:
--- a/src/jdk.jshell/share/classes/jdk/jshell/CompletenessAnalyzer.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/src/jdk.jshell/share/classes/jdk/jshell/CompletenessAnalyzer.java	Tue Feb 27 12:00:18 2018 +0530
@@ -223,6 +223,7 @@
         PROTECTED(TokenKind.PROTECTED, XDECL1),  //  protected
         PUBLIC(TokenKind.PUBLIC, XDECL1),  //  public
         TRANSIENT(TokenKind.TRANSIENT, XDECL1),  //  transient
+        FLATTENABLE(TokenKind.FLATTENABLE, XDECL1),  //  __Flattenable
         VOLATILE(TokenKind.VOLATILE, XDECL1),  //  volatile
 
         // Declarations and type parameters (thus expressions)
--- a/test/langtools/tools/javac/diags/examples/BadFlattenableAnno.java	Mon Feb 26 14:08:16 2018 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.bad.flattenable.anno
-
-class T {
-    __ByValue final class V {
-        @Flattenable final int x = 10;
-    }
-}
\ No newline at end of file
--- a/test/langtools/tools/javac/diags/examples/IllegalNullAssignmentToFlattenableValue.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/test/langtools/tools/javac/diags/examples/IllegalNullAssignmentToFlattenableValue.java	Tue Feb 27 12:00:18 2018 +0530
@@ -25,8 +25,8 @@
 
 
 class IllegalNullAssignmentToFlattenableValue {
-    @Flattenable V v = null;
+    __Flattenable V v = null;
     __ByValue final class V {
         final int x = 10;
     }
-}
\ No newline at end of file
+}
--- a/test/langtools/tools/javac/valhalla/lworld-values/FlattenableFlagFromClass.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/FlattenableFlagFromClass.java	Tue Feb 27 12:00:18 2018 +0530
@@ -27,6 +27,6 @@
         final int x = 10;
     }
 
-    public @Flattenable V v;
+    public __Flattenable V v;
     public V[] va;
-}
\ No newline at end of file
+}
--- a/test/langtools/tools/javac/valhalla/lworld-values/FlattenableFlagTest.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/FlattenableFlagTest.java	Tue Feb 27 12:00:18 2018 +0530
@@ -41,9 +41,9 @@
         final int xx = 10;
     }
 
-    @Flattenable Value v1;
+    __Flattenable Value v1;
     Value v2;
-    @Flattenable Value v3;
+    __Flattenable Value v3;
   
     public static void main(String[] args) {
         new OutputChecker().run();
@@ -56,10 +56,11 @@
                                                     Paths.get(System.getProperty("test.classes"),
                                                         "FlattenableFlagTest.class").toString() };
                 runCheck(params, new String [] {
-                 "@Flattenable FlattenableFlagTest$Value v1;",
+                 "__Flattenable FlattenableFlagTest$Value v1;",
                  "flags: (0x0100) ACC_FLATTENABLE",
                  "FlattenableFlagTest$Value v2;",
-                 "@Flattenable FlattenableFlagTest$Value v3;",
+                 "flags: (0x0000)",
+                 "__Flattenable FlattenableFlagTest$Value v3;",
                  });
 
              }
@@ -85,4 +86,4 @@
                  }
             }
     }
-}
\ No newline at end of file
+}
--- a/test/langtools/tools/javac/valhalla/lworld-values/FlattenableNegativeTest.java	Mon Feb 26 14:08:16 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/FlattenableNegativeTest.java	Tue Feb 27 12:00:18 2018 +0530
@@ -10,8 +10,8 @@
         final int x = 10;
         
         __ByValue final class X {
-            @Flattenable final V v = null;  // Error: initialization illegal
-            @Flattenable final V v2 = v;    // OK, null not constant propagated.
+            __Flattenable final V v = null;  // Error: initialization illegal
+            __Flattenable final V v2 = v;    // OK, null not constant propagated.
 
             V foo(X x) {
                 x.v = null;  // Error: withfield attempt is illegal.
@@ -24,7 +24,7 @@
         }
 
         class Y {
-            @Flattenable V v;
+            __Flattenable V v;
             V [] va = { null }; // Illegal array initialization
             V [] va2 = new V[] { null }; // Illegal array initialization
             void foo(X x) {
@@ -35,4 +35,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}
--- a/test/langtools/tools/javac/valhalla/lworld-values/FlattenableNegativeTest.out	Mon Feb 26 14:08:16 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/FlattenableNegativeTest.out	Tue Feb 27 12:00:18 2018 +0530
@@ -1,4 +1,4 @@
-FlattenableNegativeTest.java:13:38: compiler.err.illegal.null.assignment.to.flattenable.value
+FlattenableNegativeTest.java:13:39: compiler.err.illegal.null.assignment.to.flattenable.value
 FlattenableNegativeTest.java:17:21: compiler.err.illegal.null.assignment.to.flattenable.value
 FlattenableNegativeTest.java:22:17: compiler.err.illegal.null.assignment.to.flattenable.value
 FlattenableNegativeTest.java:28:23: compiler.err.illegal.null.assignment.to.flattenable.value
@@ -7,4 +7,4 @@
 FlattenableNegativeTest.java:32:19: compiler.err.illegal.null.assignment.to.flattenable.value
 FlattenableNegativeTest.java:33:23: compiler.err.illegal.null.assignment.to.flattenable.value
 FlattenableNegativeTest.java:34:22: compiler.err.illegal.null.assignment.to.flattenable.value
-9 errors
\ No newline at end of file
+9 errors