8028545: Add -source 9 and -target 9 to javac
authordarcy
Mon, 16 Dec 2013 10:15:38 -0800
changeset 22151 cb8daa93eeb1
parent 22150 af8945f58fc6
child 22152 aec1999bb1fa
8028545: Add -source 9 and -target 9 to javac 8000961: Change javac source and target default to 9 Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/code/Source.java
langtools/src/share/classes/com/sun/tools/javac/jvm/Profile.java
langtools/src/share/classes/com/sun/tools/javac/jvm/Target.java
langtools/test/tools/javac/6330997/T6330997.java
langtools/test/tools/javac/processing/warnings/TestSourceVersionWarnings.java
langtools/test/tools/javac/profiles/ProfileOptionTest.java
langtools/test/tools/javac/versions/check.sh
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Source.java	Mon Dec 16 17:33:18 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Source.java	Mon Dec 16 10:15:38 2013 -0800
@@ -67,8 +67,11 @@
     /** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */
     JDK1_7("1.7"),
 
-    /** 1.8 covers the to be determined language features that will be added in JDK 8. */
-    JDK1_8("1.8");
+    /** 1.8 lambda expressions and default methods. */
+    JDK1_8("1.8"),
+
+    /** 1.9 covers the to be determined language features that will be added in JDK 9. */
+    JDK1_9("1.9");
 
     private static final Context.Key<Source> sourceKey
         = new Context.Key<Source>();
@@ -87,7 +90,7 @@
 
     public final String name;
 
-    private static final Map<String,Source> tab = new HashMap<String,Source>();
+    private static final Map<String,Source> tab = new HashMap<>();
     static {
         for (Source s : values()) {
             tab.put(s.name, s);
@@ -96,19 +99,21 @@
         tab.put("6", JDK1_6); // Make 6 an alias for 1.6
         tab.put("7", JDK1_7); // Make 7 an alias for 1.7
         tab.put("8", JDK1_8); // Make 8 an alias for 1.8
+        tab.put("9", JDK1_9); // Make 9 an alias for 1.9
     }
 
     private Source(String name) {
         this.name = name;
     }
 
-    public static final Source DEFAULT = JDK1_8;
+    public static final Source DEFAULT = JDK1_9;
 
     public static Source lookup(String name) {
         return tab.get(name);
     }
 
     public Target requiredTarget() {
+        if (this.compareTo(JDK1_9) >= 0) return Target.JDK1_9;
         if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8;
         if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
         if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
@@ -243,6 +248,8 @@
             return RELEASE_7;
         case JDK1_8:
             return RELEASE_8;
+        case JDK1_9:
+            return RELEASE_8; // Adjust once RELEASE_9 exists
         default:
             return null;
         }
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Profile.java	Mon Dec 16 17:33:18 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Profile.java	Mon Dec 16 10:15:38 2013 -0800
@@ -39,9 +39,9 @@
  *  deletion without notice.</b>
  */
 public enum Profile {
-    COMPACT1("compact1", 1, Target.JDK1_8),
-    COMPACT2("compact2", 2, Target.JDK1_8),
-    COMPACT3("compact3", 3, Target.JDK1_8),
+    COMPACT1("compact1", 1, Target.JDK1_8, Target.JDK1_9),
+    COMPACT2("compact2", 2, Target.JDK1_8, Target.JDK1_9),
+    COMPACT3("compact3", 3, Target.JDK1_8, Target.JDK1_9),
 
     DEFAULT {
         @Override
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Target.java	Mon Dec 16 17:33:18 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Target.java	Mon Dec 16 10:15:38 2013 -0800
@@ -48,7 +48,7 @@
     /** J2SE1.4 = Merlin. */
     JDK1_4("1.4", 48, 0),
 
-    /** Tiger. */
+    /** JDK 5, codename Tiger. */
     JDK1_5("1.5", 49, 0),
 
     /** JDK 6. */
@@ -58,7 +58,10 @@
     JDK1_7("1.7", 51, 0),
 
     /** JDK 8. */
-    JDK1_8("1.8", 52, 0);
+    JDK1_8("1.8", 52, 0),
+
+    /** JDK 9, initially an alias for 8. */
+    JDK1_9("1.9", 52, 0);
 
     private static final Context.Key<Target> targetKey =
         new Context.Key<Target>();
@@ -81,7 +84,7 @@
     private static final Target MAX = values()[values().length - 1];
     public static Target MAX() { return MAX; }
 
-    private static final Map<String,Target> tab = new HashMap<String,Target>();
+    private static final Map<String,Target> tab = new HashMap<>();
     static {
         for (Target t : values()) {
             tab.put(t.name, t);
@@ -90,6 +93,7 @@
         tab.put("6", JDK1_6);
         tab.put("7", JDK1_7);
         tab.put("8", JDK1_8);
+        tab.put("9", JDK1_9);
     }
 
     public final String name;
@@ -101,7 +105,7 @@
         this.minorVersion = minorVersion;
     }
 
-    public static final Target DEFAULT = JDK1_8;
+    public static final Target DEFAULT = JDK1_9;
 
     public static Target lookup(String name) {
         return tab.get(name);
--- a/langtools/test/tools/javac/6330997/T6330997.java	Mon Dec 16 17:33:18 2013 +0000
+++ b/langtools/test/tools/javac/6330997/T6330997.java	Mon Dec 16 10:15:38 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, 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
@@ -23,12 +23,12 @@
 
 /**
  * @test
- * @bug     6330997 7025789
+ * @bug     6330997 7025789 8000961
  * @summary javac should accept class files with major version of the next release
  * @author  Wei Tao
  * @clean T1 T2
- * @compile -target 8 T1.java
- * @compile -target 8 T2.java
+ * @compile -source 8 -target 8 T1.java
+ * @compile -source 8 -target 8 T2.java
  * @run main/othervm T6330997
  */
 
@@ -67,19 +67,16 @@
 
     // Increase class file cfile's major version by delta
     static void increaseMajor(String cfile, int delta) {
-        try {
-            RandomAccessFile cls = new RandomAccessFile(
-                    new File(System.getProperty("test.classes", "."), cfile), "rw");
-            FileChannel fc = cls.getChannel();
+        try (RandomAccessFile cls =
+             new RandomAccessFile(new File(System.getProperty("test.classes", "."), cfile), "rw");
+             FileChannel fc = cls.getChannel()) {
             ByteBuffer rbuf = ByteBuffer.allocate(2);
             fc.read(rbuf, 6);
             ByteBuffer wbuf = ByteBuffer.allocate(2);
             wbuf.putShort(0, (short)(rbuf.getShort(0) + delta));
             fc.write(wbuf, 6);
             fc.force(false);
-            cls.close();
-         } catch (Exception e){
-            e.printStackTrace();
+        } catch (Exception e){
             throw new RuntimeException("Failed: unexpected exception");
          }
      }
--- a/langtools/test/tools/javac/processing/warnings/TestSourceVersionWarnings.java	Mon Dec 16 17:33:18 2013 +0000
+++ b/langtools/test/tools/javac/processing/warnings/TestSourceVersionWarnings.java	Mon Dec 16 10:15:38 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2013, 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
@@ -36,7 +36,7 @@
  * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options HelloWorld.java
  * @compile/ref=gold_unsp_warn.out     -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options -Aunsupported HelloWorld.java
  * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_7 -source 1.7 -Xlint:-options HelloWorld.java
- * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_8 -source 1.8                 HelloWorld.java
+ * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_8 -source 1.8 -Xlint:-options HelloWorld.java
  */
 
 import java.util.Set;
--- a/langtools/test/tools/javac/profiles/ProfileOptionTest.java	Mon Dec 16 17:33:18 2013 +0000
+++ b/langtools/test/tools/javac/profiles/ProfileOptionTest.java	Mon Dec 16 10:15:38 2013 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8004182
+ * @bug 8004182 8028545
  * @summary Add support for profiles in javac
  */
 
@@ -110,7 +110,7 @@
             }
 
             for (Profile p: Profile.values()) {
-                List<String> opts = new ArrayList<String>();
+                List<String> opts = new ArrayList<>();
                 opts.addAll(Arrays.asList("-source", t.name, "-target", t.name));
                 opts.add("-Xlint:-options"); // dont warn about no -bootclasspath
                 if (p != Profile.DEFAULT)
@@ -128,6 +128,7 @@
 
                 switch (t) {
                     case JDK1_8:
+                    case JDK1_9:
                         if (!out.isEmpty())
                             error("unexpected output from compiler");
                         break;
--- a/langtools/test/tools/javac/versions/check.sh	Mon Dec 16 17:33:18 2013 +0000
+++ b/langtools/test/tools/javac/versions/check.sh	Mon Dec 16 10:15:38 2013 -0800
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2004, 2013, 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
@@ -22,7 +22,7 @@
 #
 
 # @test
-# @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112
+# @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961
 # @summary Check interpretation of -target and -source options
 # @build CheckClassFileVersion
 # @run shell check.sh 
@@ -44,7 +44,7 @@
 check() {
   V=$1; shift
   echo "+ javac $* [$V]"
-  "$JC" ${TESTTOOLVMOPTS} -d $TC $* $TC/X.java && "$J" $CFV $TC/X.class $V || exit 2
+  "$JC" ${TESTTOOLVMOPTS} -Xlint:-options -d $TC $* $TC/X.java && "$J" $CFV $TC/X.class $V || exit 2
 }
 
 # check for all combinations of target values
@@ -78,6 +78,10 @@
 check_source_target 52.0 7   8
 check_source_target 52.0 8   8
 
+check_target        52.0 1.5 9
+check_source_target 52.0 8   9
+check_source_target 52.0 9   9
+
 # and finally the default with no options
 check 52.0
 
@@ -85,7 +89,7 @@
 
 fail() {
   echo "+ javac $*"
-  if "$JC" ${TESTTOOLVMOPTS} -d $TC $*; then
+  if "$JC" ${TESTTOOLVMOPTS} -Xlint:-options -d $TC $*; then
     echo "-- did not fail as expected"
     exit 3
   else
@@ -95,7 +99,7 @@
 
 pass() {
   echo "+ javac $*"
-  if "$JC" ${TESTTOOLVMOPTS} -d $TC $*; then
+  if "$JC" ${TESTTOOLVMOPTS} -Xlint:options -d $TC $*; then
     echo "-- passed"
   else
     echo "-- failed"
@@ -109,6 +113,7 @@
 checksrc16() { checksrc15 $* ; }
 checksrc17() { checksrc15 $* ; }
 checksrc18() { checksrc15 $* ; }
+checksrc19() { checksrc15 $* ; }
 
 checksrc14 -source 1.4
 checksrc14 -source 1.4 -target 1.5
@@ -126,14 +131,19 @@
 checksrc17 -source 1.7 -target 1.7
 checksrc17 -source 7 -target 7
 
-checksrc18
-checksrc18 -target 1.8
-checksrc18 -target 8
 checksrc18 -source 1.8
 checksrc18 -source 8
 checksrc18 -source 1.8 -target 1.8
 checksrc18 -source 8 -target 8
 
+checksrc19
+checksrc19 -source 1.9
+checksrc19 -source 9
+checksrc19 -source 1.9 -target 1.9
+checksrc19 -source 9 -target 9
+checksrc19 -target 1.9
+checksrc19 -target 9
+
 fail -source 1.5 -target 1.4 $TC/X.java
 fail -source 1.6 -target 1.4 $TC/X.java
 fail -source 6   -target 1.4 $TC/X.java
@@ -142,3 +152,5 @@
 fail -source 7   -target 1.6 $TC/X.java
 fail -source 8   -target 1.6 $TC/X.java
 fail -source 8   -target 1.7 $TC/X.java
+fail -source 9   -target 1.7 $TC/X.java
+fail -source 9   -target 1.8 $TC/X.java