# HG changeset patch # User lana # Date 1477603332 0 # Node ID 44d30e3656f5470b00519062da0e8f2d61eb130a # Parent ff7ec37147106bc5ca3177821297f2e89ee740f3# Parent 13a056e8f16e775937613f9ec14ecb768574c255 Merge diff -r ff7ec3714710 -r 44d30e3656f5 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java --- 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 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; } diff -r ff7ec3714710 -r 44d30e3656f5 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java --- 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 caughtPrev = caught; ListBuffer 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 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 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 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(); diff -r ff7ec3714710 -r 44d30e3656f5 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java --- 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 */ diff -r ff7ec3714710 -r 44d30e3656f5 langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java --- 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 processCommandArgs(String[] args) { OptionParser parser = new OptionParser(); OptionSpec cp = parser.accepts("class-path").withRequiredArg(); + OptionSpec mpath = parser.accepts("module-path").withRequiredArg(); + OptionSpec amods = parser.accepts("add-modules").withRequiredArg(); OptionSpec st = parser.accepts("startup").withRequiredArg(); parser.acceptsAll(asList("n", "no-startup")); OptionSpec 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 exports = options.valuesOf(addExports).stream() diff -r ff7ec3714710 -r 44d30e3656f5 langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties --- 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 \n\ where possible options include:\n\ \ --class-path Specify where to find user class files\n\ +\ --module-path Specify where to find application modules\n\ +\ --add-modules (,)*\n\ +\ Specify modules to resolve, or all modules on the\n\ +\ module path if is ALL-MODULE-PATHs\n\ \ --startup One run replacement for the start-up definitions\n\ \ --no-startup Do not run the start-up definitions\n\ \ --feedback 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\ diff -r ff7ec3714710 -r 44d30e3656f5 langtools/test/Makefile --- 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) diff -r ff7ec3714710 -r 44d30e3656f5 langtools/test/jdk/jshell/ToolBasicTest.java --- 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(); diff -r ff7ec3714710 -r 44d30e3656f5 langtools/test/tools/javac/AnonymousClass/AnonymousCtorExceptionTest.java --- /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 diff -r ff7ec3714710 -r 44d30e3656f5 langtools/test/tools/javac/generics/inference/8168134/T8168134.java --- /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 {} + abstract B f(W e); + abstract C g(C b, long i); + + void h(W i) { + g("", f(i)); + } +} diff -r ff7ec3714710 -r 44d30e3656f5 langtools/test/tools/javac/meth/BadPolySig.java --- /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(); +}