This commit is contained in:
Lana Steuck 2016-10-27 21:22:12 +00:00
commit 9d6f124910
10 changed files with 185 additions and 38 deletions

View File

@ -1004,7 +1004,7 @@ public class Types {
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;
}

View File

@ -853,9 +853,9 @@ public class Flow {
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 @@ public class Flow {
// 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 @@ public class Flow {
// 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 @@ public class Flow {
// 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();

View File

@ -404,15 +404,11 @@ public class Infer {
} 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 @@ public class Infer {
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;
}
//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) {
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;
}
Type captureOfTo = types.capture(to);
/* T is a reference type, but is not a wildcard-parameterized type, and either
*/

View File

@ -565,6 +565,8 @@ public class JShellTool implements MessageHandler {
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 @@ public class JShellTool implements MessageHandler {
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()

View File

@ -158,6 +158,10 @@ help.usage = \
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 @@ Save any work before using this command
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\

View File

@ -253,7 +253,7 @@ JCK_RUNTIME_OUTPUT_DIR = $(ABS_TEST_OUTPUT_DIR)/jck-runtime-Xcompile
# 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)

View File

@ -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 class ToolBasicTest extends ReplToolTesting {
);
}
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();

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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();
}