Merge
authorlana
Thu, 27 Oct 2016 21:22:12 +0000
changeset 41857 44d30e3656f5
parent 41851 ff7ec3714710 (current diff)
parent 41856 13a056e8f16e (diff)
child 41858 5843b57ce3a6
Merge
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Thu Oct 27 16:29:02 2016 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Thu Oct 27 21:22:12 2016 +0000
@@ -1004,7 +1004,7 @@
        List<Type> argtypes = msym.type.getParameterTypes();
        return (msym.flags_field & NATIVE) != 0 &&
               (msym.owner == syms.methodHandleType.tsym || msym.owner == syms.varHandleType.tsym) &&
-               argtypes.tail.tail == null &&
+               argtypes.length() == 1 &&
                argtypes.head.hasTag(TypeTag.ARRAY) &&
                ((ArrayType)argtypes.head).elemtype.tsym == syms.objectType.tsym;
    }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Thu Oct 27 16:29:02 2016 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Thu Oct 27 21:22:12 2016 +0000
@@ -853,9 +853,9 @@
             List<Type> caughtPrev = caught;
             ListBuffer<FlowPendingExit> pendingExitsPrev = pendingExits;
             Lint lintPrev = lint;
-
+            boolean anonymousClass = tree.name == names.empty;
             pendingExits = new ListBuffer<>();
-            if (tree.name != names.empty) {
+            if (!anonymousClass) {
                 caught = List.nil();
             }
             classDef = tree;
@@ -874,7 +874,7 @@
 
                 // add intersection of all thrown clauses of initial constructors
                 // to set of caught exceptions, unless class is anonymous.
-                if (tree.name != names.empty) {
+                if (!anonymousClass) {
                     boolean firstConstructor = true;
                     for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
                         if (TreeInfo.isInitialConstructor(l.head)) {
@@ -905,10 +905,11 @@
                 // Changing the throws clause on the fly is okay here because
                 // the anonymous constructor can't be invoked anywhere else,
                 // and its type hasn't been cached.
-                if (tree.name == names.empty) {
+                if (anonymousClass) {
                     for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
-                        if (TreeInfo.isInitialConstructor(l.head)) {
+                        if (TreeInfo.isConstructor(l.head)) {
                             JCMethodDecl mdef = (JCMethodDecl)l.head;
+                            scan(mdef);
                             mdef.thrown = make.Types(thrown);
                             mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown);
                         }
@@ -918,6 +919,8 @@
 
                 // process all the methods
                 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
+                    if (anonymousClass && TreeInfo.isConstructor(l.head))
+                        continue; // there can never be an uncaught exception.
                     if (l.head.hasTag(METHODDEF)) {
                         scan(l.head);
                         errorUncaught();
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Oct 27 16:29:02 2016 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Oct 27 21:22:12 2016 +0000
@@ -404,15 +404,11 @@
         } else if (to.hasTag(NONE)) {
             to = from.isPrimitive() ? from : syms.objectType;
         } else if (qtype.hasTag(UNDETVAR)) {
-            if (resultInfo.pt.isReference()) {
-                if (needsEagerInstantiation((UndetVar)qtype, to, inferenceContext)) {
-                    to = generateReferenceToTargetConstraint(tree, (UndetVar)qtype, to, resultInfo, inferenceContext);
-                }
-            } else {
-                if (to.isPrimitive()) {
-                    to = generateReturnConstraintsPrimitive(tree, (UndetVar)qtype, to,
-                        resultInfo, inferenceContext);
-                }
+            if (needsEagerInstantiation((UndetVar)qtype, to, inferenceContext) &&
+                    (allowGraphInference || !to.isPrimitive())) {
+                to = generateReferenceToTargetConstraint(tree, (UndetVar)qtype, to, resultInfo, inferenceContext);
+            } else if (to.isPrimitive()) {
+                to = types.boxedClass(to).type;
             }
         } else if (rsInfoInfContext.free(resultInfo.pt)) {
             //propagation - cache captured vars
@@ -432,26 +428,21 @@
         return from;
     }
 
-    private Type generateReturnConstraintsPrimitive(JCTree tree, UndetVar from,
-            Type to, Attr.ResultInfo resultInfo, InferenceContext inferenceContext) {
-        if (!allowGraphInference) {
-            //if legacy, just return boxed type
-            return types.boxedClass(to).type;
+    private boolean needsEagerInstantiation(UndetVar from, Type to, InferenceContext inferenceContext) {
+        if (to.isPrimitive()) {
+            /* T is a primitive type, and one of the primitive wrapper classes is an instantiation,
+             * upper bound, or lower bound for alpha in B2.
+             */
+            for (Type t : from.getBounds(InferenceBound.values())) {
+                Type boundAsPrimitive = types.unboxedType(t);
+                if (boundAsPrimitive == null || boundAsPrimitive.hasTag(NONE)) {
+                    continue;
+                }
+                return true;
+            }
+            return false;
         }
-        //if graph inference we need to skip conflicting boxed bounds...
-        for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.UPPER,
-                InferenceBound.LOWER)) {
-            Type boundAsPrimitive = types.unboxedType(t);
-            if (boundAsPrimitive == null || boundAsPrimitive.hasTag(NONE)) {
-                continue;
-            }
-            return generateReferenceToTargetConstraint(tree, from, to,
-                    resultInfo, inferenceContext);
-        }
-        return types.boxedClass(to).type;
-    }
 
-    private boolean needsEagerInstantiation(UndetVar from, Type to, InferenceContext inferenceContext) {
         Type captureOfTo = types.capture(to);
         /* T is a reference type, but is not a wildcard-parameterized type, and either
          */
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Thu Oct 27 16:29:02 2016 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Thu Oct 27 21:22:12 2016 +0000
@@ -565,6 +565,8 @@
     private List<String> processCommandArgs(String[] args) {
         OptionParser parser = new OptionParser();
         OptionSpec<String> cp = parser.accepts("class-path").withRequiredArg();
+        OptionSpec<String> mpath = parser.accepts("module-path").withRequiredArg();
+        OptionSpec<String> amods = parser.accepts("add-modules").withRequiredArg();
         OptionSpec<String> st = parser.accepts("startup").withRequiredArg();
         parser.acceptsAll(asList("n", "no-startup"));
         OptionSpec<String> fb = parser.accepts("feedback").withRequiredArg();
@@ -658,6 +660,18 @@
         if (options.has(c)) {
             compilerOptions.addAll(options.valuesOf(c));
         }
+        if (options.has(mpath)) {
+            compilerOptions.add("--module-path");
+            compilerOptions.addAll(options.valuesOf(mpath));
+            remoteVMOptions.add("--module-path");
+            remoteVMOptions.addAll(options.valuesOf(mpath));
+        }
+        if (options.has(amods)) {
+            compilerOptions.add("--add-modules");
+            compilerOptions.addAll(options.valuesOf(amods));
+            remoteVMOptions.add("--add-modules");
+            remoteVMOptions.addAll(options.valuesOf(amods));
+        }
 
         if (options.has(addExports)) {
             List<String> exports = options.valuesOf(addExports).stream()
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Thu Oct 27 16:29:02 2016 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Thu Oct 27 21:22:12 2016 +0000
@@ -158,6 +158,10 @@
 Usage:   jshell <options> <load files>\n\
 where possible options include:\n\
 \    --class-path <path>   Specify where to find user class files\n\
+\    --module-path <path>  Specify where to find application modules\n\
+\    --add-modules <module>(,<module>)*\n\
+\                          Specify modules to resolve, or all modules on the\n\
+\                           module path if <module> is ALL-MODULE-PATHs\n\
 \    --startup <file>      One run replacement for the start-up definitions\n\
 \    --no-startup          Do not run the start-up definitions\n\
 \    --feedback <mode>     Specify the initial feedback mode. The mode may be\n\
@@ -316,8 +320,8 @@
 help.reload.summary = reset and replay relevant history -- current or previous (-restore)
 help.reload.args = [-restore] [-quiet]
 help.reload =\
-Reset the jshell tool code and execution state then replay each\n\
-jshell valid command and valid snippet in the order they were entered.\n\
+Reset the jshell tool code and execution state then replay each valid snippet\n\
+and any /drop or /classpath commands in the order they were entered.\n\
 \n\
 /reload\n\t\
      Reset and replay the valid history since jshell was entered, or\n\t\
--- a/langtools/test/Makefile	Thu Oct 27 16:29:02 2016 +0000
+++ b/langtools/test/Makefile	Thu Oct 27 21:22:12 2016 +0000
@@ -253,7 +253,7 @@
 
 # Is the test JVM 32-bit?
 DATA_MODEL := \
-	$(shell $(JT_JAVA)/bin/java -XshowSettings:properties -version 2>&1 | \
+	$(shell $(TESTJAVA)/bin/java -XshowSettings:properties -version 2>&1 | \
 		grep 'sun\.arch\.data\.model' | \
 		awk '{print $$3}')
 ifeq ($(DATA_MODEL), 32)
--- a/langtools/test/jdk/jshell/ToolBasicTest.java	Thu Oct 27 16:29:02 2016 +0000
+++ b/langtools/test/jdk/jshell/ToolBasicTest.java	Thu Oct 27 21:22:12 2016 +0000
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714
+ * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649
  * @summary Tests for Basic tests for REPL tool
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -289,6 +289,21 @@
         );
     }
 
+    public void testModulePath() {
+        Compiler compiler = new Compiler();
+        Path modsDir = Paths.get("mods");
+        Path outDir = Paths.get("mods", "org.astro");
+        compiler.compile(outDir, "package org.astro; public class World { public static String name() { return \"world\"; } }");
+        compiler.compile(outDir, "module org.astro { exports org.astro; }");
+        Path modsPath = compiler.getPath(modsDir);
+        test(new String[] { "--module-path", modsPath.toString(), "--add-modules", "org.astro" },
+                (a) -> assertCommand(a, "import org.astro.World;", ""),
+                (a) -> evaluateExpression(a, "String",
+                        "String.format(\"Greetings %s!\", World.name());",
+                        "\"Greetings world!\"")
+        );
+    }
+
     public void testStartupFileOption() {
         try {
             Compiler compiler = new Compiler();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/AnonymousClass/AnonymousCtorExceptionTest.java	Thu Oct 27 21:22:12 2016 +0000
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+/*
+ * @test
+ * @bug 8166367
+ * @summary Missing ExceptionTable attribute in anonymous class constructors
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavapTask
+ * @run compile -g AnonymousCtorExceptionTest.java
+ * @run main AnonymousCtorExceptionTest
+ */
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import toolbox.JavapTask;
+import toolbox.Task;
+import toolbox.ToolBox;
+
+public class AnonymousCtorExceptionTest {
+
+    AnonymousCtorExceptionTest() throws IOException {
+    }
+
+    public static void main(String args[]) throws Exception {
+
+        new AnonymousCtorExceptionTest() {
+        };
+
+        ToolBox tb = new ToolBox();
+        Path classPath = Paths.get(ToolBox.testClasses, "AnonymousCtorExceptionTest$1.class");
+        String javapOut = new JavapTask(tb)
+                .options("-v", "-p")
+                .classes(classPath.toString())
+                .run()
+                .getOutput(Task.OutputKind.DIRECT);
+        if (!javapOut.contains("AnonymousCtorExceptionTest$1() throws java.io.IOException;"))
+            throw new AssertionError("Unexpected output " + javapOut);
+        if (!javapOut.contains("Exceptions:"))
+            throw new AssertionError("Unexpected output " + javapOut);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/8168134/T8168134.java	Thu Oct 27 21:22:12 2016 +0000
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+/*
+ * @test
+ * @bug 8168134
+ * @summary Inference: javac incorrectly propagating inner constraint with primitive target
+ * @compile T8168134.java
+ */
+
+abstract class T8168134 {
+    interface W<A> {}
+    abstract <B> B f(W<B> e);
+    abstract <C> C g(C b, long i);
+
+    void h(W<Long> i) {
+        g("", f(i));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/meth/BadPolySig.java	Thu Oct 27 21:22:12 2016 +0000
@@ -0,0 +1,12 @@
+/*
+ * @test
+ * @bug 8168774
+ * @summary Polymorhic signature method check crashes javac
+ * @compile -Xmodule:java.base BadPolySig.java
+ */
+
+package java.lang.invoke;
+
+class MethodHandle {
+    native Object m();
+}