This commit is contained in:
Lana Steuck 2015-10-21 15:15:36 -07:00
commit 318515fb59
20 changed files with 274 additions and 43 deletions

View File

@ -142,6 +142,10 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
return false;
}
public boolean isIntegral() {
return false;
}
public boolean isPrimitive() {
return false;
}
@ -696,6 +700,20 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
return tag != BOOLEAN;
}
@Override
public boolean isIntegral() {
switch (tag) {
case CHAR:
case BYTE:
case SHORT:
case INT:
case LONG:
return true;
default:
return false;
}
}
@Override
public boolean isPrimitive() {
return true;

View File

@ -409,6 +409,9 @@ public class Check {
* Class name generation
**************************************************************************/
private Map<Pair<Name, Name>, Integer> localClassNameIndexes = new HashMap<>();
/** Return name of local class.
* This is of the form {@code <enclClass> $ n <classname> }
* where
@ -416,17 +419,28 @@ public class Check {
* classname is the simple name of the local class
*/
Name localClassName(ClassSymbol c) {
for (int i=1; ; i++) {
Name flatname = names.
fromString("" + c.owner.enclClass().flatname +
syntheticNameChar + i +
c.name);
if (compiled.get(flatname) == null) return flatname;
Name enclFlatname = c.owner.enclClass().flatname;
String enclFlatnameStr = enclFlatname.toString();
Pair<Name, Name> key = new Pair<>(enclFlatname, c.name);
Integer index = localClassNameIndexes.get(key);
for (int i = (index == null) ? 1 : index; ; i++) {
Name flatname = names.fromString(enclFlatnameStr
+ syntheticNameChar + i + c.name);
if (compiled.get(flatname) == null) {
localClassNameIndexes.put(key, i + 1);
return flatname;
}
}
}
void clearLocalClassNameIndexes(ClassSymbol c) {
localClassNameIndexes.remove(new Pair<>(
c.owner.enclClass().flatname, c.name));
}
public void newRound() {
compiled.clear();
localClassNameIndexes.clear();
}
/* *************************************************************************

View File

@ -472,6 +472,7 @@ public class DeferredAttr extends JCTree.Visitor {
if (csym == null) return;
typeEnvs.remove(csym);
chk.compiled.remove(csym.flatname);
chk.clearLocalClassNameIndexes(csym);
syms.classes.remove(csym.flatname);
super.visitClassDef(tree);
}

View File

@ -404,13 +404,20 @@ public class Operators {
*/
class UnaryNumericOperator extends UnaryOperatorHelper {
Predicate<Type> numericTest;
UnaryNumericOperator(Tag tag) {
this(tag, Type::isNumeric);
}
UnaryNumericOperator(Tag tag, Predicate<Type> numericTest) {
super(tag);
this.numericTest = numericTest;
}
@Override
public boolean test(Type type) {
return unaryPromotion(type).isNumeric();
return numericTest.test(unaryPromotion(type));
}
@Override
@ -462,8 +469,15 @@ public class Operators {
*/
class BinaryNumericOperator extends BinaryOperatorHelper {
Predicate<Type> numericTest;
BinaryNumericOperator(Tag tag) {
this(tag, Type::isNumeric);
}
BinaryNumericOperator(Tag tag, Predicate<Type> numericTest) {
super(tag);
this.numericTest = numericTest;
}
@Override
@ -474,7 +488,8 @@ public class Operators {
@Override
public boolean test(Type arg1, Type arg2) {
return unaryPromotion(arg1).isNumeric() && unaryPromotion(arg2).isNumeric();
return numericTest.test(unaryPromotion(arg1)) &&
numericTest.test(unaryPromotion(arg2));
}
}
@ -518,20 +533,22 @@ public class Operators {
@Override
public boolean test(Type arg1, Type arg2) {
return types.isSameType(arg1, syms.stringType) ||
boolean hasStringOp = types.isSameType(arg1, syms.stringType) ||
types.isSameType(arg2, syms.stringType);
boolean hasVoidOp = arg1.hasTag(TypeTag.VOID) || arg2.hasTag(TypeTag.VOID);
return hasStringOp && !hasVoidOp;
}
/**
* This routine applies following mappings:
* - if input type is primitive, apply numeric promotion
* - if input type is either 'null' or 'String' leave it untouched
* - if input type is either 'void', 'null' or 'String' leave it untouched
* - otherwise return 'Object'
*/
private Type stringPromotion(Type t) {
if (t.isPrimitive()) {
return unaryPromotion(t);
} else if (t.hasTag(TypeTag.BOT) ||
} else if (t.hasTag(TypeTag.VOID) || t.hasTag(TypeTag.BOT) ||
types.isSameType(t, syms.stringType)) {
return t;
} else if (t.hasTag(TypeTag.TYPEVAR)) {
@ -640,7 +657,7 @@ public class Operators {
.addUnaryOperator(FLOAT, FLOAT, fneg)
.addUnaryOperator(LONG, LONG, lneg)
.addUnaryOperator(INT, INT, ineg),
new UnaryNumericOperator(Tag.COMPL)
new UnaryNumericOperator(Tag.COMPL, Type::isIntegral)
.addUnaryOperator(LONG, LONG, lxor)
.addUnaryOperator(INT, INT, ixor),
new UnaryPrefixPostfixOperator(Tag.POSTINC)
@ -713,17 +730,17 @@ public class Operators {
.addBinaryOperator(INT, INT, INT, imod),
new BinaryBooleanOperator(Tag.BITAND)
.addBinaryOperator(BOOLEAN, BOOLEAN, BOOLEAN, iand),
new BinaryNumericOperator(Tag.BITAND)
new BinaryNumericOperator(Tag.BITAND, Type::isIntegral)
.addBinaryOperator(LONG, LONG, LONG, land)
.addBinaryOperator(INT, INT, INT, iand),
new BinaryBooleanOperator(Tag.BITOR)
.addBinaryOperator(BOOLEAN, BOOLEAN, BOOLEAN, ior),
new BinaryNumericOperator(Tag.BITOR)
new BinaryNumericOperator(Tag.BITOR, Type::isIntegral)
.addBinaryOperator(LONG, LONG, LONG, lor)
.addBinaryOperator(INT, INT, INT, ior),
new BinaryBooleanOperator(Tag.BITXOR)
.addBinaryOperator(BOOLEAN, BOOLEAN, BOOLEAN, ixor),
new BinaryNumericOperator(Tag.BITXOR)
new BinaryNumericOperator(Tag.BITXOR, Type::isIntegral)
.addBinaryOperator(LONG, LONG, LONG, lxor)
.addBinaryOperator(INT, INT, INT, ixor),
new BinaryShiftOperator(Tag.SL)

View File

@ -3215,8 +3215,7 @@ public class Resolve {
findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) :
findMethod(env, site, name, argtypes, typeargtypes,
phase.isBoxingRequired(), phase.isVarargsRequired());
return site.getEnclosingType().hasTag(CLASS) && !hasEnclosingInstance(env, site) ?
new BadConstructorReferenceError(sym) : sym;
return enclosingInstanceMissing(env, site) ? new BadConstructorReferenceError(sym) : sym;
}
@Override
@ -3349,9 +3348,12 @@ public class Resolve {
}
}
boolean hasEnclosingInstance(Env<AttrContext> env, Type type) {
Symbol encl = resolveSelfContainingInternal(env, type.tsym, false);
return encl != null && !encl.kind.isResolutionError();
boolean enclosingInstanceMissing(Env<AttrContext> env, Type type) {
if (type.hasTag(CLASS) && type.getEnclosingType().hasTag(CLASS)) {
Symbol encl = resolveSelfContainingInternal(env, type.tsym, false);
return encl == null || encl.kind.isResolutionError();
}
return false;
}
private Symbol resolveSelfContainingInternal(Env<AttrContext> env,

View File

@ -0,0 +1,12 @@
/*
* @test /nodynamiccopyright/
* @bug 8138840 8139243 8139249
* @summary Compiler crashes when compiling bitwise operations with illegal operand types
* @compile/fail/ref=T8138840.out -XDrawDiagnostics T8138840.java
*/
class T8138840 {
void test(int x, double d) {
Object o = x & d;
}
}

View File

@ -0,0 +1,2 @@
T8138840.java:10:22: compiler.err.operator.cant.be.applied.1: &, int, double
1 error

View File

@ -0,0 +1,16 @@
/*
* @test /nodynamiccopyright/
* @bug 8138840 8139243 8139249
* @summary Compiler crashes when compiling bitwise operations with illegal operand types
* 'void' is erroneously accepted as a possible operand for string concatenation
* @compile/fail/ref=T8139243.out -XDrawDiagnostics T8139243.java
*/
class T8139243 {
void test(String s) {
s += m(); // compile time error
}
void m() { }
}

View File

@ -0,0 +1,2 @@
T8139243.java:12:11: compiler.err.operator.cant.be.applied.1: +, java.lang.String, void
1 error

View File

@ -0,0 +1,13 @@
/*
* @test /nodynamiccopyright/
* @bug 8138840 8139243 8139249
* @summary Compiler crashes when compiling bitwise operations with illegal operand types
* Unary operator erroneously applied to non-integral type operand
* @compile/fail/ref=T8139249.out -XDrawDiagnostics T8139249.java
*/
class T8139249 {
void test(float f2) {
float f1 = ~f2;
}
}

View File

@ -0,0 +1,2 @@
T8139249.java:11:20: compiler.err.operator.cant.be.applied: ~, float
1 error

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) 2015, 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 8000316
* @summary Huge performance bottleneck in com.sun.tools.javac.comp.Check.localClassName
* @modules jdk.compiler
* @run main T8000316
*/
import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.List;
import java.util.ArrayList;
import java.util.Locale;
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
public class T8000316 {
final static int N_METHODS = 1024;
final static int N_CLASSES = 8;
static class TestClass extends SimpleJavaFileObject {
String methTemplate = " public static Runnable get#N() {\n" +
" return new Runnable() {\n" +
" @Override\n" +
" public void run() {\n" +
" return;\n" +
" }\n" +
" };\n" +
" }\n";
String classTemplate = "\n\nclass Chain#N {\n\n#M }";
String source;
public TestClass() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
StringBuilder buf = new StringBuilder();
StringBuilder fileBuf = new StringBuilder();
for (int i = 0 ; i < N_CLASSES ; i++) {
for (int j = 0; j < N_METHODS; j++) {
buf.append(methTemplate.replace("#N", String.valueOf(j)));
buf.append("\n");
}
fileBuf.append(classTemplate.replace("#M", buf.toString()).replace("#N", String.valueOf(i)));
buf = new StringBuilder();
source = fileBuf.toString();
}
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return source;
}
}
public static void main(String... args) throws Exception {
ArrayList<JavaFileObject> sources = new ArrayList<>();
sources.add(new TestClass());
new T8000316().run(sources);
}
void run(List<JavaFileObject> sources) throws Exception {
javax.tools.DiagnosticListener<JavaFileObject> dc = (diagnostic) -> {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
throw new AssertionError("unexpected diagnostic: " + diagnostic.getMessage(Locale.getDefault()));
}
};
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
JavacTask ct = (JavacTask)comp.getTask(null, fm, dc,
null, null, sources);
ct.analyze();
}
}
}

View File

@ -0,0 +1,20 @@
/**
* @test /nodynamiccopyright/
* @bug 8139245
* @summary compiler crashes with exception on int:new method reference and generic method inference
* @compile/fail/ref=MethodRefIntColonColonNewTest.out -XDrawDiagnostics MethodRefIntColonColonNewTest.java
*/
public class MethodRefIntColonColonNewTest {
interface SAM<T> {
T m(T s);
}
static <T> SAM<T> infmethod(SAM<T> t) { return t; }
public static void main(String argv[]) {
SAM<Object> s = infmethod(int::new);
s.m();
}
}

View File

@ -0,0 +1,3 @@
MethodRefIntColonColonNewTest.java:17:35: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
MethodRefIntColonColonNewTest.java:18:10: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Object, compiler.misc.no.args, kindname.interface, MethodRefIntColonColonNewTest.SAM<T>, (compiler.misc.arg.length.mismatch)
2 errors

View File

@ -3,11 +3,11 @@
* @bug 6380059
* @summary Emit warnings for proprietary packages in the boot class path
* @author Peter von der Ah\u00e9
* @modules java.base/sun.misc
* @modules java.base/sun.security.x509
* @compile WarnClass.java
* @compile/fail/ref=WarnClass.out -XDrawDiagnostics -Werror WarnClass.java
* @compile/fail/ref=WarnClass.out -XDrawDiagnostics -Werror -nowarn WarnClass.java
* @compile/fail/ref=WarnClass.out -XDrawDiagnostics -Werror -Xlint:none WarnClass.java
*/
public class WarnClass extends sun.misc.Lock {}
public class WarnClass extends sun.security.x509.X509CertInfo {}

View File

@ -1,4 +1,4 @@
WarnClass.java:13:40: compiler.warn.sun.proprietary: sun.misc.Lock
WarnClass.java:13:49: compiler.warn.sun.proprietary: sun.security.x509.X509CertInfo
- compiler.err.warnings.and.werror
1 error
1 warning

View File

@ -2,29 +2,31 @@
* @test /nodynamiccopyright/
* @bug 6594914
* @summary \\@SuppressWarnings("deprecation") does not not work for the type of a variable
* @modules java.base/sun.misc
* @modules java.base/sun.security.x509
* @compile/ref=T6594914b.out -XDenableSunApiLintControl -XDrawDiagnostics -Xlint:sunapi T6594914b.java
*/
class T6747671b {
sun.misc.Lock a1; //warn
sun.security.x509.X509CertInfo a1; //warn
@SuppressWarnings("sunapi")
sun.misc.Lock a2;
sun.security.x509.X509CertInfo a2;
<X extends sun.misc.Lock> sun.misc.Lock m1(sun.misc.Lock a)
throws sun.misc.CEFormatException { return null; } //warn
<X extends sun.security.x509.X509CertInfo>
sun.security.x509.X509CertInfo m1(sun.security.x509.X509CertInfo a)
throws sun.security.x509.CertException { return null; } //warn
@SuppressWarnings("sunapi")
<X extends sun.misc.Lock> sun.misc.Lock m2(sun.misc.Lock a)
throws sun.misc.CEFormatException { return null; }
<X extends sun.security.x509.X509CertInfo>
sun.security.x509.X509CertInfo m2(sun.security.x509.X509CertInfo a)
throws sun.security.x509.CertException { return null; }
void test() {
sun.misc.Lock a1; //warn
sun.security.x509.X509CertInfo a1; //warn
@SuppressWarnings("sunapi")
sun.misc.Lock a2;
sun.security.x509.X509CertInfo a2;
}
}

View File

@ -1,7 +1,9 @@
T6594914b.java:12:13: compiler.warn.sun.proprietary: sun.misc.Lock
T6594914b.java:17:24: compiler.warn.sun.proprietary: sun.misc.Lock
T6594914b.java:17:39: compiler.warn.sun.proprietary: sun.misc.Lock
T6594914b.java:18:28: compiler.warn.sun.proprietary: sun.misc.CEFormatException
T6594914b.java:17:56: compiler.warn.sun.proprietary: sun.misc.Lock
T6594914b.java:25:17: compiler.warn.sun.proprietary: sun.misc.Lock
T6594914b.java:12:22: compiler.warn.sun.proprietary: sun.security.x509.X509CertInfo
T6594914b.java:17:33: compiler.warn.sun.proprietary: sun.security.x509.X509CertInfo
T6594914b.java:18:22: compiler.warn.sun.proprietary: sun.security.x509.X509CertInfo
T6594914b.java:19:37: compiler.warn.sun.proprietary: sun.security.x509.CertException
T6594914b.java:18:56: compiler.warn.sun.proprietary: sun.security.x509.X509CertInfo
T6594914b.java:27:26: compiler.warn.sun.proprietary: sun.security.x509.X509CertInfo
- compiler.note.deprecated.filename: T6594914b.java
- compiler.note.deprecated.recompile
6 warnings

View File

@ -25,7 +25,7 @@
* @test
* @bug 8015912 8029216 8048063 8050804
* @summary Test -apionly and -jdkinternals options
* @modules java.base/sun.misc
* @modules java.base/sun.security.x509
* java.management
* jdk.jdeps/com.sun.tools.classfile
* jdk.jdeps/com.sun.tools.jdeps
@ -72,20 +72,20 @@ public class APIDeps {
new String[] {testDirBasename},
new String[] {"-classpath", testDir.getPath(), "-verbose:class", "-filter:none", "-P"});
test(new File(mDir, "Gee.class"),
new String[] {"g.G", "sun.misc.Lock", "com.sun.tools.classfile.ClassFile",
new String[] {"g.G", "sun.security.x509.X509CertInfo", "com.sun.tools.classfile.ClassFile",
"com.sun.management.ThreadMXBean", "com.sun.source.tree.BinaryTree"},
new String[] {testDirBasename, "JDK internal API", "compact3", ""},
new String[] {"-classpath", testDir.getPath(), "-verbose", "-P"});
// -jdkinternals
test(new File(mDir, "Gee.class"),
new String[] {"sun.misc.Lock", "com.sun.tools.classfile.ClassFile"},
new String[] {"sun.security.x509.X509CertInfo", "com.sun.tools.classfile.ClassFile"},
new String[] {"JDK internal API"},
new String[] {"-jdkinternals"});
// -jdkinternals parses all classes on -classpath and the input arguments
test(new File(mDir, "Gee.class"),
new String[] {"com.sun.tools.jdeps.Main", "com.sun.tools.classfile.ClassFile",
"sun.misc.Lock", "sun.misc.Unsafe"},
"sun.security.x509.X509CertInfo", "sun.misc.Unsafe"},
new String[] {"JDK internal API"},
new String[] {"-classpath", testDir.getPath(), "-jdkinternals"});

View File

@ -25,7 +25,7 @@ package m;
class Gee extends g.G {
public sun.misc.Lock lock;
public sun.security.x509.X509CertInfo cert;
public com.sun.tools.classfile.ClassFile cf; // @jdk.Exported(false)
public com.sun.source.tree.BinaryTree tree; // @jdk.Exported
public com.sun.management.ThreadMXBean mxbean; // @jdk.Exported on package-info