This commit is contained in:
Jesper Wilhelmsson 2021-07-08 00:55:53 +00:00
commit 270fbcb3f5
35 changed files with 708 additions and 357 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -229,6 +229,7 @@ public class CreateSymbols {
: null, : null,
Paths.get(ctDescriptionFile)); Paths.get(ctDescriptionFile));
stripNonExistentAnnotations(data);
splitHeaders(data.classes); splitHeaders(data.classes);
Map<String, Map<Character, String>> package2Version2Module = new HashMap<>(); Map<String, Map<Character, String>> package2Version2Module = new HashMap<>();
@ -301,6 +302,50 @@ public class CreateSymbols {
} }
} }
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
"Ljdk/internal/PreviewFeature;";
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
"Ljdk/internal/javac/PreviewFeature;";
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
"Ljdk/internal/PreviewFeature+Annotation;";
private static final String VALUE_BASED_ANNOTATION =
"Ljdk/internal/ValueBased;";
private static final String VALUE_BASED_ANNOTATION_INTERNAL =
"Ljdk/internal/ValueBased+Annotation;";
public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
List.of("Ljdk/Profile+Annotation;",
"Lsun/Proprietary+Annotation;",
PREVIEW_FEATURE_ANNOTATION_OLD,
PREVIEW_FEATURE_ANNOTATION_NEW,
VALUE_BASED_ANNOTATION));
private void stripNonExistentAnnotations(LoadDescriptions data) {
Set<String> allClasses = data.classes.name2Class.keySet();
data.modules.values().forEach(mod -> {
stripNonExistentAnnotations(allClasses, mod.header);
});
data.classes.classes.forEach(clazz -> {
stripNonExistentAnnotations(allClasses, clazz.header);
stripNonExistentAnnotations(allClasses, clazz.fields);
stripNonExistentAnnotations(allClasses, clazz.methods);
});
}
private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
}
private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
stripNonExistentAnnotations(allClasses, d.classAnnotations);
stripNonExistentAnnotations(allClasses, d.runtimeAnnotations);
}
private void stripNonExistentAnnotations(Set<String> allClasses, List<AnnotationDescription> annotations) {
if (annotations != null)
annotations.removeIf(ann -> !HARDCODED_ANNOTATIONS.contains(ann.annotationType) &&
!allClasses.contains(ann.annotationType.substring(1, ann.annotationType.length() - 1)));
}
private ZipEntry createZipEntry(String name, long timestamp) { private ZipEntry createZipEntry(String name, long timestamp) {
ZipEntry ze = new ZipEntry(name); ZipEntry ze = new ZipEntry(name);
@ -1140,17 +1185,16 @@ public class CreateSymbols {
values.put("reflective", essentialAPI != null && !essentialAPI); values.put("reflective", essentialAPI != null && !essentialAPI);
} }
if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
//the non-public ValueBased annotation will not be available in ct.sym,
//replace with purely synthetic javac-internal annotation:
annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
}
return new Annotation(null, return new Annotation(null,
addString(constantPool, annotationType), addString(constantPool, annotationType),
createElementPairs(constantPool, values)); createElementPairs(constantPool, values));
} }
//where:
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
"Ljdk/internal/PreviewFeature;";
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
"Ljdk/internal/javac/PreviewFeature;";
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
"Ljdk/internal/PreviewFeature+Annotation;";
private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) { private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) {
element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()]; element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()];

View file

@ -576,6 +576,7 @@ class Assembler : public AbstractAssembler {
XVNMSUBASP_OPCODE=(60u<< OPCODE_SHIFT | 209u << 3), XVNMSUBASP_OPCODE=(60u<< OPCODE_SHIFT | 209u << 3),
XVNMSUBADP_OPCODE=(60u<< OPCODE_SHIFT | 241u << 3), XVNMSUBADP_OPCODE=(60u<< OPCODE_SHIFT | 241u << 3),
XVRDPI_OPCODE = (60u << OPCODE_SHIFT | 201u << 2), XVRDPI_OPCODE = (60u << OPCODE_SHIFT | 201u << 2),
XVRDPIC_OPCODE = (60u << OPCODE_SHIFT | 235u << 2),
XVRDPIM_OPCODE = (60u << OPCODE_SHIFT | 249u << 2), XVRDPIM_OPCODE = (60u << OPCODE_SHIFT | 249u << 2),
XVRDPIP_OPCODE = (60u << OPCODE_SHIFT | 233u << 2), XVRDPIP_OPCODE = (60u << OPCODE_SHIFT | 233u << 2),
@ -2384,6 +2385,7 @@ class Assembler : public AbstractAssembler {
inline void xvnmsubasp(VectorSRegister d, VectorSRegister a, VectorSRegister b); inline void xvnmsubasp(VectorSRegister d, VectorSRegister a, VectorSRegister b);
inline void xvnmsubadp(VectorSRegister d, VectorSRegister a, VectorSRegister b); inline void xvnmsubadp(VectorSRegister d, VectorSRegister a, VectorSRegister b);
inline void xvrdpi( VectorSRegister d, VectorSRegister b); inline void xvrdpi( VectorSRegister d, VectorSRegister b);
inline void xvrdpic( VectorSRegister d, VectorSRegister b);
inline void xvrdpim( VectorSRegister d, VectorSRegister b); inline void xvrdpim( VectorSRegister d, VectorSRegister b);
inline void xvrdpip( VectorSRegister d, VectorSRegister b); inline void xvrdpip( VectorSRegister d, VectorSRegister b);

View file

@ -848,6 +848,7 @@ inline void Assembler::xvmsubadp( VectorSRegister d, VectorSRegister a, VectorSR
inline void Assembler::xvnmsubasp(VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XVNMSUBASP_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); } inline void Assembler::xvnmsubasp(VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XVNMSUBASP_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); }
inline void Assembler::xvnmsubadp(VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XVNMSUBADP_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); } inline void Assembler::xvnmsubadp(VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XVNMSUBADP_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); }
inline void Assembler::xvrdpi( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPI_OPCODE | vsrt(d) | vsrb(b)); } inline void Assembler::xvrdpi( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPI_OPCODE | vsrt(d) | vsrb(b)); }
inline void Assembler::xvrdpic( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIC_OPCODE | vsrt(d) | vsrb(b)); }
inline void Assembler::xvrdpim( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIM_OPCODE | vsrt(d) | vsrb(b)); } inline void Assembler::xvrdpim( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIM_OPCODE | vsrt(d) | vsrb(b)); }
inline void Assembler::xvrdpip( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIP_OPCODE | vsrt(d) | vsrb(b)); } inline void Assembler::xvrdpip( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIP_OPCODE | vsrt(d) | vsrb(b)); }

View file

@ -2108,6 +2108,8 @@ const bool Matcher::match_rule_supported(int opcode) {
switch (opcode) { switch (opcode) {
case Op_SqrtD: case Op_SqrtD:
return VM_Version::has_fsqrt(); return VM_Version::has_fsqrt();
case Op_RoundDoubleMode:
return VM_Version::has_vsx();
case Op_CountLeadingZerosI: case Op_CountLeadingZerosI:
case Op_CountLeadingZerosL: case Op_CountLeadingZerosL:
return UseCountLeadingZerosInstructionsPPC64; return UseCountLeadingZerosInstructionsPPC64;
@ -13964,7 +13966,7 @@ instruct roundD_reg(regD dst, regD src, immI8 rmode) %{
ins_encode %{ ins_encode %{
switch ($rmode$$constant) { switch ($rmode$$constant) {
case RoundDoubleModeNode::rmode_rint: case RoundDoubleModeNode::rmode_rint:
__ frin($dst$$FloatRegister, $src$$FloatRegister); __ xvrdpic($dst$$FloatRegister->to_vsr(), $src$$FloatRegister->to_vsr());
break; break;
case RoundDoubleModeNode::rmode_floor: case RoundDoubleModeNode::rmode_floor:
__ frim($dst$$FloatRegister, $src$$FloatRegister); __ frim($dst$$FloatRegister, $src$$FloatRegister);
@ -13988,7 +13990,7 @@ instruct vround2D_reg(vecX dst, vecX src, immI8 rmode) %{
ins_encode %{ ins_encode %{
switch ($rmode$$constant) { switch ($rmode$$constant) {
case RoundDoubleModeNode::rmode_rint: case RoundDoubleModeNode::rmode_rint:
__ xvrdpi($dst$$VectorSRegister, $src$$VectorSRegister); __ xvrdpic($dst$$VectorSRegister, $src$$VectorSRegister);
break; break;
case RoundDoubleModeNode::rmode_floor: case RoundDoubleModeNode::rmode_floor:
__ xvrdpim($dst$$VectorSRegister, $src$$VectorSRegister); __ xvrdpim($dst$$VectorSRegister, $src$$VectorSRegister);

View file

@ -35,6 +35,11 @@ import static java.lang.annotation.ElementType.TYPE;
* References to <a href="../lang/doc-files/ValueBased.html">value-based classes</a> * References to <a href="../lang/doc-files/ValueBased.html">value-based classes</a>
* should produce warnings about behavior that is inconsistent with value based semantics. * should produce warnings about behavior that is inconsistent with value based semantics.
* *
* Note this internal annotation is handled specially by the javac compiler.
* To work properly with {@code --release older-release}, it requires special
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
*
* @since 16 * @since 16
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View file

@ -31,6 +31,12 @@ import java.lang.annotation.Target;
/** /**
* The element annotated with this annotation should not be marked as a preview element. * The element annotated with this annotation should not be marked as a preview element.
*
* Note this internal annotation is handled specially by the javac compiler.
* To work properly with {@code --release older-release}, it requires special
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
*
*/ */
@Target({ElementType.METHOD, @Target({ElementType.METHOD,
ElementType.CONSTRUCTOR, ElementType.CONSTRUCTOR,

View file

@ -31,6 +31,12 @@ import java.lang.annotation.*;
* Indicates the API declaration in question is associated with a * Indicates the API declaration in question is associated with a
* <em>preview feature</em>. See JEP 12: "Preview Language and VM * <em>preview feature</em>. See JEP 12: "Preview Language and VM
* Features" (http://openjdk.java.net/jeps/12). * Features" (http://openjdk.java.net/jeps/12).
*
* Note this internal annotation is handled specially by the javac compiler.
* To work properly with {@code --release older-release}, it requires special
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
*
* @since 14 * @since 14
*/ */
// Match the meaningful targets of java.lang.Deprecated, omit local // Match the meaningful targets of java.lang.Deprecated, omit local

View file

@ -311,7 +311,12 @@ public class Flags {
/** /**
* Flag to indicate the given ModuleSymbol is a system module. * Flag to indicate the given ModuleSymbol is a system module.
*/ */
public static final long SYSTEM_MODULE = 1L<<53; public static final long SYSTEM_MODULE = 1L<<53; //ModuleSymbols only
/**
* Flag to indicate the given ClassSymbol is a value based.
*/
public static final long VALUE_BASED = 1L<<53; //ClassSymbols only
/** /**
* Flag to indicate the given symbol has a @Deprecated annotation. * Flag to indicate the given symbol has a @Deprecated annotation.

View file

@ -222,6 +222,7 @@ public class Symtab {
public final Type recordType; public final Type recordType;
public final Type switchBootstrapsType; public final Type switchBootstrapsType;
public final Type valueBasedType; public final Type valueBasedType;
public final Type valueBasedInternalType;
/** The symbol representing the length field of an array. /** The symbol representing the length field of an array.
*/ */
@ -588,6 +589,7 @@ public class Symtab {
recordType = enterClass("java.lang.Record"); recordType = enterClass("java.lang.Record");
switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps"); switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");
valueBasedType = enterClass("jdk.internal.ValueBased"); valueBasedType = enterClass("jdk.internal.ValueBased");
valueBasedInternalType = enterSyntheticAnnotation("jdk.internal.ValueBased+Annotation");
synthesizeEmptyInterfaceIfMissing(autoCloseableType); synthesizeEmptyInterfaceIfMissing(autoCloseableType);
synthesizeEmptyInterfaceIfMissing(cloneableType); synthesizeEmptyInterfaceIfMissing(cloneableType);

View file

@ -53,6 +53,7 @@ import static com.sun.tools.javac.code.Flags.SYNTHETIC;
import static com.sun.tools.javac.code.Kinds.Kind.MDL; import static com.sun.tools.javac.code.Kinds.Kind.MDL;
import static com.sun.tools.javac.code.Kinds.Kind.MTH; import static com.sun.tools.javac.code.Kinds.Kind.MTH;
import static com.sun.tools.javac.code.Kinds.Kind.PCK; import static com.sun.tools.javac.code.Kinds.Kind.PCK;
import static com.sun.tools.javac.code.Kinds.Kind.TYP;
import static com.sun.tools.javac.code.Kinds.Kind.VAR; import static com.sun.tools.javac.code.Kinds.Kind.VAR;
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
import static com.sun.tools.javac.code.TypeTag.ARRAY; import static com.sun.tools.javac.code.TypeTag.ARRAY;
@ -369,7 +370,6 @@ public class Annotate {
} }
} }
// Note: @Deprecated has no effect on local variables and parameters
if (!c.type.isErroneous() if (!c.type.isErroneous()
&& types.isSameType(c.type, syms.previewFeatureType)) { && types.isSameType(c.type, syms.previewFeatureType)) {
toAnnotate.flags_field |= Flags.PREVIEW_API; toAnnotate.flags_field |= Flags.PREVIEW_API;
@ -377,6 +377,12 @@ public class Annotate {
toAnnotate.flags_field |= Flags.PREVIEW_REFLECTIVE; toAnnotate.flags_field |= Flags.PREVIEW_REFLECTIVE;
} }
} }
if (!c.type.isErroneous()
&& toAnnotate.kind == TYP
&& types.isSameType(c.type, syms.valueBasedType)) {
toAnnotate.flags_field |= Flags.VALUE_BASED;
}
} }
List<T> buf = List.nil(); List<T> buf = List.nil();

View file

@ -1871,14 +1871,7 @@ public class Attr extends JCTree.Visitor {
} }
// where // where
private boolean isValueBased(Type t) { private boolean isValueBased(Type t) {
if (t != null && t.tsym != null) { return t != null && t.tsym != null && (t.tsym.flags() & VALUE_BASED) != 0;
for (Attribute.Compound a: t.tsym.getDeclarationAttributes()) {
if (a.type.tsym == syms.valueBasedType.tsym) {
return true;
}
}
}
return false;
} }

View file

@ -386,6 +386,7 @@ public class TransPatterns extends TreeTranslator {
hasNullCase = true; hasNullCase = true;
} }
} }
selector = translate(selector);
statements.append(make.at(tree.pos).VarDef(temp, !hasNullCase ? attr.makeNullCheck(selector) statements.append(make.at(tree.pos).VarDef(temp, !hasNullCase ? attr.makeNullCheck(selector)
: selector)); : selector));
VarSymbol index = new VarSymbol(Flags.SYNTHETIC, VarSymbol index = new VarSymbol(Flags.SYNTHETIC,
@ -469,6 +470,8 @@ public class TransPatterns extends TreeTranslator {
currentValue = prevCurrentValue; currentValue = prevCurrentValue;
bindingContext.pop(); bindingContext.pop();
} }
} else {
c.stats = translate(c.stats);
} }
if (enumSwitch) { if (enumSwitch) {
var labels = c.labels; var labels = c.labels;

View file

@ -1446,6 +1446,9 @@ public class ClassReader {
} else if (proxy.type.tsym.flatName() == syms.previewFeatureInternalType.tsym.flatName()) { } else if (proxy.type.tsym.flatName() == syms.previewFeatureInternalType.tsym.flatName()) {
sym.flags_field |= PREVIEW_API; sym.flags_field |= PREVIEW_API;
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE); setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
} else if (proxy.type.tsym.flatName() == syms.valueBasedInternalType.tsym.flatName()) {
Assert.check(sym.kind == TYP);
sym.flags_field |= VALUE_BASED;
} else { } else {
if (proxy.type.tsym == syms.annotationTargetType.tsym) { if (proxy.type.tsym == syms.annotationTargetType.tsym) {
target = proxy; target = proxy;
@ -1457,6 +1460,8 @@ public class ClassReader {
} else if (proxy.type.tsym == syms.previewFeatureType.tsym) { } else if (proxy.type.tsym == syms.previewFeatureType.tsym) {
sym.flags_field |= PREVIEW_API; sym.flags_field |= PREVIEW_API;
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE); setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
} else if (proxy.type.tsym == syms.valueBasedType.tsym && sym.kind == TYP) {
sym.flags_field |= VALUE_BASED;
} }
proxies.append(proxy); proxies.append(proxy);
} }

View file

@ -772,8 +772,8 @@ public class JavacParser implements Parser {
accept(RPAREN); accept(RPAREN);
pattern = toP(F.at(startPos).ParenthesizedPattern(p)); pattern = toP(F.at(startPos).ParenthesizedPattern(p));
} else { } else {
JCExpression e = parsedType == null ? term(EXPR | TYPE | NOLAMBDA) : parsedType; mods = mods != null ? mods : optFinal(0);
mods = mods != null ? mods : F.at(token.pos).Modifiers(0); JCExpression e = parsedType == null ? term(TYPE | NOLAMBDA) : parsedType;
JCVariableDecl var = toP(F.at(token.pos).VarDef(mods, ident(), e, null)); JCVariableDecl var = toP(F.at(token.pos).VarDef(mods, ident(), e, null));
pattern = toP(F.at(pos).BindingPattern(var)); pattern = toP(F.at(pos).BindingPattern(var));
} }
@ -1694,16 +1694,12 @@ public class JavacParser implements Parser {
* method reference or a binary expression. To disambiguate, look for a * method reference or a binary expression. To disambiguate, look for a
* matching '&gt;' and see if the subsequent terminal is either '.' or '::'. * matching '&gt;' and see if the subsequent terminal is either '.' or '::'.
*/ */
ParensResult analyzeParens() {
return analyzeParens(0);
}
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
ParensResult analyzeParens(int startLookahead) { ParensResult analyzeParens() {
int depth = 0; int depth = 0;
boolean type = false; boolean type = false;
ParensResult defaultResult = ParensResult.PARENS; ParensResult defaultResult = ParensResult.PARENS;
outer: for (int lookahead = startLookahead; ; lookahead++) { outer: for (int lookahead = 0; ; lookahead++) {
TokenKind tk = S.token(lookahead).kind; TokenKind tk = S.token(lookahead).kind;
switch (tk) { switch (tk) {
case COMMA: case COMMA:
@ -1729,7 +1725,7 @@ public class JavacParser implements Parser {
} }
break; break;
case LPAREN: case LPAREN:
if (lookahead != startLookahead) { if (lookahead != 0) {
// '(' in a non-starting position -> parens // '(' in a non-starting position -> parens
return ParensResult.PARENS; return ParensResult.PARENS;
} else if (peekToken(lookahead, RPAREN)) { } else if (peekToken(lookahead, RPAREN)) {
@ -1780,31 +1776,7 @@ public class JavacParser implements Parser {
return ParensResult.EXPLICIT_LAMBDA; return ParensResult.EXPLICIT_LAMBDA;
case MONKEYS_AT: case MONKEYS_AT:
type = true; type = true;
lookahead += 1; //skip '@' lookahead = skipAnnotation(lookahead);
while (peekToken(lookahead, DOT)) {
lookahead += 2;
}
if (peekToken(lookahead, LPAREN)) {
lookahead++;
//skip annotation values
int nesting = 0;
for (; ; lookahead++) {
TokenKind tk2 = S.token(lookahead).kind;
switch (tk2) {
case EOF:
return ParensResult.PARENS;
case LPAREN:
nesting++;
break;
case RPAREN:
nesting--;
if (nesting == 0) {
continue outer;
}
break;
}
}
}
break; break;
case LBRACKET: case LBRACKET:
if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) { if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) {
@ -1861,6 +1833,35 @@ public class JavacParser implements Parser {
} }
} }
private int skipAnnotation(int lookahead) {
lookahead += 1; //skip '@'
while (peekToken(lookahead, DOT)) {
lookahead += 2;
}
if (peekToken(lookahead, LPAREN)) {
lookahead++;
//skip annotation values
int nesting = 0;
for (; ; lookahead++) {
TokenKind tk2 = S.token(lookahead).kind;
switch (tk2) {
case EOF:
return lookahead;
case LPAREN:
nesting++;
break;
case RPAREN:
nesting--;
if (nesting == 0) {
return lookahead;
}
break;
}
}
}
return lookahead;
}
/** Accepts all identifier-like tokens */ /** Accepts all identifier-like tokens */
protected Predicate<TokenKind> LAX_IDENTIFIER = t -> t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM; protected Predicate<TokenKind> LAX_IDENTIFIER = t -> t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM;
@ -3067,34 +3068,69 @@ public class JavacParser implements Parser {
nextToken(); nextToken();
label = toP(F.at(patternPos).DefaultCaseLabel()); label = toP(F.at(patternPos).DefaultCaseLabel());
} else { } else {
if (token.kind == LPAREN) { int lookahead = 0;
int lookahead = 0; while (S.token(lookahead).kind == LPAREN) {
while (S.token(lookahead + 1).kind == LPAREN) { lookahead++;
lookahead++; }
} JCModifiers mods = optFinal(0);
boolean pattern = analyzeParens(lookahead) == ParensResult.EXPLICIT_LAMBDA; boolean pattern = mods.flags != 0 || mods.annotations.nonEmpty() ||
if (pattern) { analyzePattern(lookahead) == PatternResult.PATTERN;
checkSourceLevel(token.pos, Feature.PATTERN_SWITCH); if (pattern) {
return parsePattern(token.pos, null, null, false); checkSourceLevel(token.pos, Feature.PATTERN_SWITCH);
} else { return parsePattern(patternPos, mods, null, false);
return term(EXPR | TYPE | NOLAMBDA);
}
} else { } else {
JCModifiers mods = optFinal(0); return term(EXPR | NOLAMBDA);
JCExpression e = term(EXPR | TYPE | NOLAMBDA);
if (token.kind == IDENTIFIER || mods.flags != 0 || mods.annotations.nonEmpty()) {
checkSourceLevel(token.pos, Feature.PATTERN_SWITCH);
return parsePattern(patternPos, null, e, false);
} else {
return e;
}
} }
} }
return label; return label;
} }
@SuppressWarnings("fallthrough")
PatternResult analyzePattern(int lookahead) {
int depth = 0;
while (true) {
TokenKind token = S.token(lookahead).kind;
switch (token) {
case BYTE: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE: case BOOLEAN: case CHAR: case VOID:
case ASSERT, ENUM, IDENTIFIER, UNDERSCORE:
if (depth == 0 && peekToken(lookahead, LAX_IDENTIFIER)) return PatternResult.PATTERN;
break;
case DOT, QUES, EXTENDS, SUPER, COMMA: break;
case LT: depth++; break;
case GTGTGT: depth--;
case GTGT: depth--;
case GT:
depth--;
if (depth == 0) {
return peekToken(lookahead, LAX_IDENTIFIER) ? PatternResult.PATTERN
: PatternResult.EXPRESSION;
} else if (depth < 0) return PatternResult.EXPRESSION;
break;
case MONKEYS_AT:
lookahead = skipAnnotation(lookahead);
break;
case LBRACKET:
if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) {
return PatternResult.PATTERN;
} else if (peekToken(lookahead, RBRACKET)) {
lookahead++;
break;
} else {
return PatternResult.EXPRESSION;
}
default: return PatternResult.EXPRESSION;
}
lookahead++;
}
}
private enum PatternResult {
EXPRESSION,
PATTERN;
}
/** MoreStatementExpressions = { COMMA StatementExpression } /** MoreStatementExpressions = { COMMA StatementExpression }
*/ */
<T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos, <T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -188,70 +188,21 @@ public class BasicTypeDataBase implements TypeDataBase {
return false; return false;
} }
// The first implementation searched three locations for this vtbl // See if the vtable at the first address of the object matches the vtable of the
// value; scanning through the entire object was considered, but // specified type. Note this code used to be much more complex in order to support
// we thought we knew where we were looking, and looking only in // Solaris. It included looking at the last 2 words of the object and also trying
// these specific locations should reduce the probability of // to match on all supertypes of the specified type. This turned out to be buggy,
// mistaking random bits as a pointer (although, realistically // and was removed since Solaris is no longer supported. See JDK-8269830.
// speaking, the likelihood of finding a match between the bit
// pattern of, for example, a double and the vtbl is vanishingly
// small.)
// 1. The first word of the object (should handle MSVC++ as
// well as the solstudio compilers with compatibility set to
// v5.0 or greater)
// 2. and 3. The last two Address-aligned words of the part of
// the object defined by its topmost polymorphic superclass.
// This should handle the solstudio compilers, v4.2 or
// earlier, as well as any other compilers which place the vptr
// at the end of the user-defined fields of the first base
// class with virtual functions.
//
// Unfortunately this algorithm did not work properly for the
// specific case of the ThreadShadow/Thread inheritance situation,
// because the Solaris compiler seems to cleverly eliminate the
// vtbl for ThreadShadow since the only virtual is empty. (We
// should get rid of the ThreadShadow and fix the include
// databases, but need to postpone this for the present.) The
// current solution performs the three-location check for this
// class and all of its known superclasses rather than just the
// topmost polymorphic one.
Type curType = type;
try { try {
while (curType != null) { if (vtblAddr.equals(addr.getAddressAt(0))) {
// Using the size information we have for this type, check the return true;
// three locations described above. } else {
if (DEBUG) {
// (1) System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " + type.getName());
if (vtblAddr.equals(addr.getAddressAt(0))) {
return true;
} }
return false;
// (2)
long offset = curType.getSize();
// I don't think this should be misaligned under any
// circumstances, but I'm not sure (FIXME: also not sure which
// way to go here, up or down -- assuming down)
offset -= (offset % getAddressSize());
if (offset <= 0) {
return false;
}
if (vtblAddr.equals(addr.getAddressAt(offset))) {
return true;
}
offset -= getAddressSize();
if (offset <= 0) {
return false;
}
if (vtblAddr.equals(addr.getAddressAt(offset))) {
return true;
}
curType = curType.getSuperclass();
} }
} } catch (Exception e) {
catch (Exception e) {
// Any UnmappedAddressExceptions, etc. are a good indication // Any UnmappedAddressExceptions, etc. are a good indication
// that the pointer is not of the specified type // that the pointer is not of the specified type
if (DEBUG) { if (DEBUG) {
@ -261,13 +212,6 @@ public class BasicTypeDataBase implements TypeDataBase {
return false; return false;
} }
if (DEBUG) {
System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
type.getName());
}
return false;
} }
public Type findDynamicTypeForAddress(Address addr, Type baseType) { public Type findDynamicTypeForAddress(Address addr, Type baseType) {

View file

@ -39,6 +39,8 @@ Requires: PACKAGE_DEFAULT_DEPENDENCIES PACKAGE_CUSTOM_DEPENDENCIES
%description %description
APPLICATION_DESCRIPTION APPLICATION_DESCRIPTION
%global __os_install_post %{nil}
%prep %prep
%build %build

View file

@ -28,7 +28,7 @@ java/rmi/Naming java/util/prefs sun/management/jmxremote \
sun/tools/jstatd sun/tools/jcmd \ sun/tools/jstatd sun/tools/jcmd \
sun/tools/jinfo sun/tools/jmap sun/tools/jps sun/tools/jstack sun/tools/jstat \ sun/tools/jinfo sun/tools/jmap sun/tools/jps sun/tools/jstack sun/tools/jstat \
com/sun/tools/attach sun/security/mscapi java/util/stream java/util/Arrays/largeMemory \ com/sun/tools/attach sun/security/mscapi java/util/stream java/util/Arrays/largeMemory \
java/util/BitSet/stream javax/rmi java/util/BitSet/stream javax/rmi java/net/httpclient/websocket
# Group definitions # Group definitions
groups=TEST.groups groups=TEST.groups

View file

@ -899,6 +899,7 @@ public class Basic {
} catch (Throwable t) { unexpected(t); return ""; } } catch (Throwable t) { unexpected(t); return ""; }
} }
@SuppressWarnings("removal")
static void testIORedirection() throws Throwable { static void testIORedirection() throws Throwable {
final File ifile = new File("ifile"); final File ifile = new File("ifile");
final File ofile = new File("ofile"); final File ofile = new File("ofile");
@ -1303,6 +1304,7 @@ public class Basic {
} }
@SuppressWarnings("removal")
private static void realMain(String[] args) throws Throwable { private static void realMain(String[] args) throws Throwable {
if (Windows.is()) if (Windows.is())
System.out.println("This appears to be a Windows system."); System.out.println("This appears to be a Windows system.");
@ -2184,7 +2186,9 @@ public class Basic {
} }
if (r >= 0) { if (r >= 0) {
// The child sent unexpected output; print it to diagnose // The child sent unexpected output; print it to diagnose
System.out.println("Unexpected child output:"); System.out.println("Unexpected child output, to: " +
((action & 0x1) == 0 ? "getInputStream" : "getErrorStream"));
System.out.println("Child args: " + childArgs);
if ((action & 0x2) == 0) { if ((action & 0x2) == 0) {
System.out.write(r); // Single character System.out.write(r); // Single character
@ -2205,7 +2209,7 @@ public class Basic {
thread.start(); thread.start();
latch.await(); latch.await();
Thread.sleep(10); Thread.sleep(30);
if (s instanceof BufferedInputStream) { if (s instanceof BufferedInputStream) {
// Wait until after the s.read occurs in "thread" by // Wait until after the s.read occurs in "thread" by
@ -2662,6 +2666,7 @@ public class Basic {
//---------------------------------------------------------------- //----------------------------------------------------------------
// A Policy class designed to make permissions fiddling very easy. // A Policy class designed to make permissions fiddling very easy.
//---------------------------------------------------------------- //----------------------------------------------------------------
@SuppressWarnings("removal")
private static class Policy extends java.security.Policy { private static class Policy extends java.security.Policy {
static final java.security.Policy DEFAULT_POLICY = java.security.Policy.getPolicy(); static final java.security.Policy DEFAULT_POLICY = java.security.Policy.getPolicy();

View file

@ -72,4 +72,3 @@ tools/sjavac/ClasspathDependencies.java
# #
# jdeps # jdeps
tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java 8258421 generic-all Deprecation vs JDK-private annotation class

View file

@ -1,10 +1,11 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 8254274 * @bug 8254274 8258421
* @summary lint should warn when an instance of a value based class is synchronized upon * @summary lint should warn when an instance of a value based class is synchronized upon
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint ExternalAbuseOfVbc.java * @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint ExternalAbuseOfVbc.java
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:all ExternalAbuseOfVbc.java * @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:all ExternalAbuseOfVbc.java
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java * @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
* @compile/fail/ref=ExternalAbuseOfVbc.out --release 16 -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
* @compile/ref=LintModeOffAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:-synchronization ExternalAbuseOfVbc.java * @compile/ref=LintModeOffAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:-synchronization ExternalAbuseOfVbc.java
*/ */

View file

@ -1,4 +1,4 @@
ExternalAbuseOfVbc.java:18:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class ExternalAbuseOfVbc.java:19:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class
- compiler.err.warnings.and.werror - compiler.err.warnings.and.werror
1 error 1 error
1 warning 1 warning

View file

@ -1,3 +1,26 @@
/*
* Copyright (c) 2021, 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 * @test
* @modules jdk.compiler/com.sun.tools.javac.file * @modules jdk.compiler/com.sun.tools.javac.file
@ -5,8 +28,8 @@
* jdk.compiler/com.sun.tools.javac.parser * jdk.compiler/com.sun.tools.javac.parser
* jdk.compiler/com.sun.tools.javac.tree * jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util * jdk.compiler/com.sun.tools.javac.util
* @compile --enable-preview -source ${jdk.version} DisambiguateParenthesizedPattern.java * @compile --enable-preview -source ${jdk.version} DisambiguatePatterns.java
* @run main/othervm --enable-preview DisambiguateParenthesizedPattern * @run main/othervm --enable-preview DisambiguatePatterns
*/ */
import com.sun.source.tree.CaseLabelTree; import com.sun.source.tree.CaseLabelTree;
@ -24,16 +47,18 @@ import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
import java.nio.charset.Charset; import java.nio.charset.Charset;
public class DisambiguateParenthesizedPattern { public class DisambiguatePatterns {
public static void main(String... args) throws Throwable { public static void main(String... args) throws Throwable {
DisambiguateParenthesizedPattern test = new DisambiguateParenthesizedPattern(); DisambiguatePatterns test = new DisambiguatePatterns();
test.disambiguationTest("String s", test.disambiguationTest("String s",
ExpressionType.PATTERN); ExpressionType.PATTERN);
test.disambiguationTest("String s && s.isEmpty()", test.disambiguationTest("String s && s.isEmpty()",
ExpressionType.PATTERN); ExpressionType.PATTERN);
test.disambiguationTest("(String s)", test.disambiguationTest("(String s)",
ExpressionType.PATTERN); ExpressionType.PATTERN);
test.disambiguationTest("(@Ann String s)",
ExpressionType.PATTERN);
test.disambiguationTest("((String s))", test.disambiguationTest("((String s))",
ExpressionType.PATTERN); ExpressionType.PATTERN);
test.disambiguationTest("(String) s", test.disambiguationTest("(String) s",
@ -56,11 +81,41 @@ public class DisambiguateParenthesizedPattern {
ExpressionType.EXPRESSION); ExpressionType.EXPRESSION);
test.disambiguationTest("(a < c.d > b)", test.disambiguationTest("(a < c.d > b)",
ExpressionType.PATTERN); ExpressionType.PATTERN);
test.disambiguationTest("a<? extends c.d> b",
ExpressionType.PATTERN);
test.disambiguationTest("@Ann a<? extends c.d> b",
ExpressionType.PATTERN);
test.disambiguationTest("a<? extends @Ann c.d> b",
ExpressionType.PATTERN);
test.disambiguationTest("a<? super c.d> b",
ExpressionType.PATTERN);
test.disambiguationTest("a<? super @Ann c.d> b",
ExpressionType.PATTERN);
test.disambiguationTest("a<b<c.d>> b",
ExpressionType.PATTERN);
test.disambiguationTest("a<b<@Ann c.d>> b",
ExpressionType.PATTERN);
test.disambiguationTest("a<b<c<d>>> b",
ExpressionType.PATTERN);
test.disambiguationTest("a[] b",
ExpressionType.PATTERN);
test.disambiguationTest("a[][] b",
ExpressionType.PATTERN);
test.disambiguationTest("int i",
ExpressionType.PATTERN);
test.disambiguationTest("int[] i",
ExpressionType.PATTERN);
test.disambiguationTest("a[a]",
ExpressionType.EXPRESSION);
test.disambiguationTest("a[b][c]",
ExpressionType.EXPRESSION);
test.disambiguationTest("a & b",
ExpressionType.EXPRESSION);
} }
private final ParserFactory factory; private final ParserFactory factory;
public DisambiguateParenthesizedPattern() { public DisambiguatePatterns() {
Context context = new Context(); Context context = new Context();
JavacFileManager jfm = new JavacFileManager(context, true, Charset.defaultCharset()); JavacFileManager jfm = new JavacFileManager(context, true, Charset.defaultCharset());
Options.instance(context).put(Option.PREVIEW, ""); Options.instance(context).put(Option.PREVIEW, "");

View file

@ -0,0 +1,19 @@
/*
* @test /nodynamiccopyright/
* @bug 8268859
* @summary Verify error recovery/disambiguation of case labels that mix expressions and patterns
* @compile/fail/ref=PatternCaseErrorRecovery.out --enable-preview -source ${jdk.version} -XDrawDiagnostics PatternCaseErrorRecovery.java
*/
public class PatternCaseErrorRecovery {
Object expressionLikeType(Object o1, Object o2) {
final int a = 1;
final int b = 2;
return switch (o1) {
case true t -> o2;
case 1 + 1 e -> o2;
case a < b ? a : b e -> o2;
default -> null;
};
}
}

View file

@ -0,0 +1,7 @@
PatternCaseErrorRecovery.java:13:22: compiler.err.expected2: :, ->
PatternCaseErrorRecovery.java:13:23: compiler.err.not.stmt
PatternCaseErrorRecovery.java:14:23: compiler.err.expected2: :, ->
PatternCaseErrorRecovery.java:14:24: compiler.err.not.stmt
PatternCaseErrorRecovery.java:15:31: compiler.err.expected2: :, ->
PatternCaseErrorRecovery.java:15:32: compiler.err.not.stmt
6 errors

View file

@ -0,0 +1,3 @@
PatternErrorRecovery.java:12:18: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)
PatternErrorRecovery.java:11:18: compiler.err.const.expr.req
2 errors

View file

@ -0,0 +1,15 @@
/*
* @test /nodynamiccopyright/
* @bug 8268320
* @summary Verify user-friendly errors are reported for ill-formed pattern.
* @compile/fail/ref=PatternErrorRecovery.out -XDrawDiagnostics -XDshould-stop.at=FLOW --enable-preview -source ${jdk.version} PatternErrorRecovery.java
* @compile/fail/ref=PatternErrorRecovery-no-preview.out -XDrawDiagnostics -XDshould-stop.at=FLOW PatternErrorRecovery.java
*/
public class PatternErrorRecovery {
void errorRecoveryNoPattern1(Object o) {
switch (o) {
case String: break;
case Object obj: break;
}
}
}

View file

@ -0,0 +1,4 @@
PatternErrorRecovery.java:11:18: compiler.err.pattern.expected
- compiler.note.preview.filename: PatternErrorRecovery.java, DEFAULT
- compiler.note.preview.recompile
1 error

View file

@ -76,7 +76,7 @@ public class SourceLevelChecks extends TestRunner {
} }
} }
""", """,
"Test.java:5:26: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)", "Test.java:5:18: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)",
"1 error"); "1 error");
} }

View file

@ -1,42 +0,0 @@
SwitchErrors.java:35:31: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)
SwitchErrors.java:34:18: compiler.err.constant.label.not.compatible: java.lang.String, java.lang.Object
SwitchErrors.java:40:18: compiler.err.constant.label.not.compatible: int, java.lang.Object
SwitchErrors.java:46:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
SwitchErrors.java:47:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.CharSequence)
SwitchErrors.java:52:18: compiler.err.preview.feature.disabled: (compiler.misc.feature.case.null)
SwitchErrors.java:53:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
SwitchErrors.java:54:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.CharSequence)
SwitchErrors.java:60:20: compiler.err.total.pattern.and.default
SwitchErrors.java:66:13: compiler.err.pattern.dominated
SwitchErrors.java:72:18: compiler.err.total.pattern.and.default
SwitchErrors.java:78:18: compiler.err.duplicate.total.pattern
SwitchErrors.java:84:20: compiler.err.duplicate.default.label
SwitchErrors.java:90:20: compiler.err.duplicate.default.label
SwitchErrors.java:101:13: compiler.err.duplicate.case.label
SwitchErrors.java:106:13: compiler.err.duplicate.case.label
SwitchErrors.java:111:28: compiler.err.flows.through.to.pattern
SwitchErrors.java:117:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:124:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:131:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:136:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
SwitchErrors.java:142:18: compiler.err.instanceof.reifiable.not.safe: java.util.List, java.util.List<java.lang.Integer>
SwitchErrors.java:148:18: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:155:18: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
SwitchErrors.java:172:27: compiler.err.flows.through.to.pattern
SwitchErrors.java:178:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:184:13: compiler.err.pattern.dominated
SwitchErrors.java:196:18: compiler.err.const.expr.req
SwitchErrors.java:202:76: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:208:71: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:33:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:39:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:45:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:51:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:99:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:105:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:110:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:115:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:121:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:128:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:188:9: compiler.err.not.exhaustive.statement
41 errors

View file

@ -1,32 +1,8 @@
/* /*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. * @test /nodynamiccopyright/
* 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 8262891 * @bug 8262891
* @summary Verify errors related to pattern switches. * @summary Verify errors related to pattern switches.
* @compile/fail/ref=SwitchErrors.out --enable-preview -source ${jdk.version} -XDrawDiagnostics -XDshould-stop.at=FLOW SwitchErrors.java * @compile/fail/ref=SwitchErrors.out --enable-preview -source ${jdk.version} -XDrawDiagnostics -XDshould-stop.at=FLOW SwitchErrors.java
* @compile/fail/ref=SwitchErrors-no-preview.out -XDrawDiagnostics -XDshould-stop.at=FLOW SwitchErrors.java
*/ */
public class SwitchErrors { public class SwitchErrors {
void incompatibleSelectorObjectString(Object o) { void incompatibleSelectorObjectString(Object o) {

View file

@ -1,47 +1,47 @@
SwitchErrors.java:34:18: compiler.err.constant.label.not.compatible: java.lang.String, java.lang.Object SwitchErrors.java:10:18: compiler.err.constant.label.not.compatible: java.lang.String, java.lang.Object
SwitchErrors.java:40:18: compiler.err.constant.label.not.compatible: int, java.lang.Object SwitchErrors.java:16:18: compiler.err.constant.label.not.compatible: int, java.lang.Object
SwitchErrors.java:46:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer) SwitchErrors.java:22:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
SwitchErrors.java:47:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.CharSequence) SwitchErrors.java:23:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.CharSequence)
SwitchErrors.java:52:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, int) SwitchErrors.java:28:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, int)
SwitchErrors.java:53:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int) SwitchErrors.java:29:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
SwitchErrors.java:54:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.CharSequence) SwitchErrors.java:30:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.CharSequence)
SwitchErrors.java:60:20: compiler.err.total.pattern.and.default SwitchErrors.java:36:20: compiler.err.total.pattern.and.default
SwitchErrors.java:66:13: compiler.err.pattern.dominated SwitchErrors.java:42:13: compiler.err.pattern.dominated
SwitchErrors.java:66:24: compiler.err.total.pattern.and.default SwitchErrors.java:42:24: compiler.err.total.pattern.and.default
SwitchErrors.java:72:18: compiler.err.total.pattern.and.default SwitchErrors.java:48:18: compiler.err.total.pattern.and.default
SwitchErrors.java:78:18: compiler.err.duplicate.total.pattern SwitchErrors.java:54:18: compiler.err.duplicate.total.pattern
SwitchErrors.java:84:20: compiler.err.duplicate.default.label SwitchErrors.java:60:20: compiler.err.duplicate.default.label
SwitchErrors.java:90:20: compiler.err.duplicate.default.label SwitchErrors.java:66:20: compiler.err.duplicate.default.label
SwitchErrors.java:95:27: compiler.err.duplicate.default.label SwitchErrors.java:71:27: compiler.err.duplicate.default.label
SwitchErrors.java:101:13: compiler.err.duplicate.case.label SwitchErrors.java:77:13: compiler.err.duplicate.case.label
SwitchErrors.java:106:13: compiler.err.duplicate.case.label SwitchErrors.java:82:13: compiler.err.duplicate.case.label
SwitchErrors.java:111:28: compiler.err.flows.through.to.pattern SwitchErrors.java:87:28: compiler.err.flows.through.to.pattern
SwitchErrors.java:117:18: compiler.err.flows.through.to.pattern SwitchErrors.java:93:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:124:18: compiler.err.flows.through.to.pattern SwitchErrors.java:100:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:131:18: compiler.err.flows.through.to.pattern SwitchErrors.java:107:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:136:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer) SwitchErrors.java:112:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
SwitchErrors.java:142:18: compiler.err.instanceof.reifiable.not.safe: java.util.List, java.util.List<java.lang.Integer> SwitchErrors.java:118:18: compiler.err.instanceof.reifiable.not.safe: java.util.List, java.util.List<java.lang.Integer>
SwitchErrors.java:148:18: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, SwitchErrors, null) SwitchErrors.java:124:18: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:155:18: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array) SwitchErrors.java:131:18: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
SwitchErrors.java:161:28: compiler.err.flows.through.from.pattern SwitchErrors.java:137:28: compiler.err.flows.through.from.pattern
SwitchErrors.java:167:18: compiler.err.flows.through.from.pattern SwitchErrors.java:143:18: compiler.err.flows.through.from.pattern
SwitchErrors.java:172:27: compiler.err.flows.through.to.pattern SwitchErrors.java:148:27: compiler.err.flows.through.to.pattern
SwitchErrors.java:178:18: compiler.err.flows.through.to.pattern SwitchErrors.java:154:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:184:13: compiler.err.pattern.dominated SwitchErrors.java:160:13: compiler.err.pattern.dominated
SwitchErrors.java:196:18: compiler.err.pattern.expected SwitchErrors.java:172:18: compiler.err.pattern.expected
SwitchErrors.java:202:76: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null) SwitchErrors.java:178:76: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:208:71: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null) SwitchErrors.java:184:71: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:33:9: compiler.err.not.exhaustive.statement SwitchErrors.java:9:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:39:9: compiler.err.not.exhaustive.statement SwitchErrors.java:15:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:45:9: compiler.err.not.exhaustive.statement SwitchErrors.java:21:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:51:9: compiler.err.not.exhaustive.statement SwitchErrors.java:27:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:99:9: compiler.err.not.exhaustive.statement SwitchErrors.java:75:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:105:9: compiler.err.not.exhaustive.statement SwitchErrors.java:81:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:110:9: compiler.err.not.exhaustive.statement SwitchErrors.java:86:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:115:9: compiler.err.not.exhaustive.statement SwitchErrors.java:91:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:121:9: compiler.err.not.exhaustive.statement SwitchErrors.java:97:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:128:9: compiler.err.not.exhaustive.statement SwitchErrors.java:104:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:188:9: compiler.err.not.exhaustive.statement SwitchErrors.java:164:9: compiler.err.not.exhaustive.statement
- compiler.note.preview.filename: SwitchErrors.java, DEFAULT - compiler.note.preview.filename: SwitchErrors.java, DEFAULT
- compiler.note.preview.recompile - compiler.note.preview.recompile
44 errors 44 errors

View file

@ -22,12 +22,13 @@
*/ */
import java.util.Objects; import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
/* /*
* @test * @test
* @bug 8262891 8268333 8268896 * @bug 8262891 8268333 8268896 8269802 8269808
* @summary Check behavior of pattern switches. * @summary Check behavior of pattern switches.
* @compile --enable-preview -source ${jdk.version} Switches.java * @compile --enable-preview -source ${jdk.version} Switches.java
* @run main/othervm --enable-preview Switches * @run main/othervm --enable-preview Switches
@ -66,6 +67,11 @@ public class Switches {
npeTest(this::npeTestExpression); npeTest(this::npeTestExpression);
exhaustiveStatementSane(""); exhaustiveStatementSane("");
exhaustiveStatementSane(null); exhaustiveStatementSane(null);
switchNestingTest(this::switchNestingStatementStatement);
switchNestingTest(this::switchNestingStatementExpression);
switchNestingTest(this::switchNestingExpressionStatement);
switchNestingTest(this::switchNestingExpressionExpression);
switchNestingTest(this::switchNestingIfSwitch);
} }
void run(Function<Object, Integer> mapper) { void run(Function<Object, Integer> mapper) {
@ -119,6 +125,13 @@ public class Switches {
} }
} }
void switchNestingTest(BiFunction<Object, Object, String> testCase) {
assertEquals("string, string", testCase.apply("", ""));
assertEquals("string, other", testCase.apply("", 1));
assertEquals("other, string", testCase.apply(1, ""));
assertEquals("other, other", testCase.apply(1, 1));
}
int typeTestPatternSwitchTest(Object o) { int typeTestPatternSwitchTest(Object o) {
switch (o) { switch (o) {
case String s: return Integer.parseInt(s.toString()); case String s: return Integer.parseInt(s.toString());
@ -366,6 +379,113 @@ public class Switches {
} }
} }
String switchNestingStatementStatement(Object o1, Object o2) {
switch (o1) {
case String s1 -> {
switch (o2) {
case String s2 -> {
return "string, string";
}
default -> {
return "string, other";
}
}
}
default -> {
switch (o2) {
case String s2 -> {
return "other, string";
}
default -> {
return "other, other";
}
}
}
}
}
String switchNestingStatementExpression(Object o1, Object o2) {
switch (o1) {
case String s1 -> {
return switch (o2) {
case String s2 -> "string, string";
default -> "string, other";
};
}
default -> {
return switch (o2) {
case String s2 -> "other, string";
default -> "other, other";
};
}
}
}
String switchNestingExpressionStatement(Object o1, Object o2) {
return switch (o1) {
case String s1 -> {
switch (o2) {
case String s2 -> {
yield "string, string";
}
default -> {
yield "string, other";
}
}
}
default -> {
switch (o2) {
case String s2 -> {
yield "other, string";
}
default -> {
yield "other, other";
}
}
}
};
}
String switchNestingExpressionExpression(Object o1, Object o2) {
return switch (o1) {
case String s1 ->
switch (o2) {
case String s2 -> "string, string";
default -> "string, other";
};
default ->
switch (o2) {
case String s2 -> "other, string";
default -> "other, other";
};
};
}
String switchNestingIfSwitch(Object o1, Object o2) {
BiFunction<Object, Object, String> f = (n1, n2) -> {
if (o1 instanceof CharSequence cs) {
return switch (cs) {
case String s1 ->
switch (o2) {
case String s2 -> "string, string";
default -> "string, other";
};
default ->
switch (o2) {
case String s2 -> "other, string";
default -> "other, other";
};
};
} else {
return switch (o2) {
case String s2 -> "other, string";
default -> "other, other";
};
}
};
return f.apply(o1, o2);
}
//verify that for cases like: //verify that for cases like:
//case ConstantClassClash -> //case ConstantClassClash ->
//ConstantClassClash is interpreted as a field, not as a class //ConstantClassClash is interpreted as a field, not as a class

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2021, 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 8266036 8258421
* @summary Verify no error is reported for extended ForkJoinPool with --release 8.
* @modules jdk.compiler
* @build NonPublicAnnotations
* @compile -processor NonPublicAnnotations --release 8 NonPublicAnnotations.java
*/
import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
@SupportedAnnotationTypes("*")
public class NonPublicAnnotations extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> roots, RoundEnvironment roundEnv) {
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}
class TestForkJoinPool extends ForkJoinPool {}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -215,82 +215,88 @@ public class CreateSymbolsTestImpl {
@Test @Test
void testAnnotations() throws Exception { void testAnnotations() throws Exception {
doPrintElementTest("package t;" + Set<String> extraAnnotations = Set.of("Ljava/lang/annotation/Retention;");
"import java.lang.annotation.*;" + CreateSymbols.HARDCODED_ANNOTATIONS.addAll(extraAnnotations);
"public @Visible @Invisible class T { public void extra() { } }" + try {
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" + doPrintElementTest("package t;" +
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }", "import java.lang.annotation.*;" +
"package t;" + "public @Visible @Invisible class T { public void extra() { } }" +
"import java.lang.annotation.*;" + "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
"public @Visible @Invisible class T { }" + "@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" + "package t;" +
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }", "import java.lang.annotation.*;" +
"t.T", "public @Visible @Invisible class T { }" +
"package t;\n\n" + "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
"@t.Invisible\n" + "@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
"@t.Visible\n" + "t.T",
"public class T {\n\n" + "package t;\n\n" +
" public T();\n\n" + "@t.Invisible\n" +
" public void extra();\n" + "@t.Visible\n" +
"}\n", "public class T {\n\n" +
"t.Visible", " public T();\n\n" +
"package t;\n\n" + " public void extra();\n" +
"@java.lang.annotation.Retention(RUNTIME)\n" + "}\n",
"@interface Visible {\n" + "t.Visible",
"}\n"); "package t;\n\n" +
doPrintElementTest("package t;" + "@java.lang.annotation.Retention(RUNTIME)\n" +
"import java.lang.annotation.*;" + "@interface Visible {\n" +
"import java.util.*;" + "}\n");
"public class T {" + doPrintElementTest("package t;" +
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" + "import java.lang.annotation.*;" +
"}" + "import java.util.*;" +
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" + "public class T {" +
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }", " public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
"package t;" + "}" +
"import java.lang.annotation.*;" + "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
"import java.util.*;" + "@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
"public class T {" + "package t;" +
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" + "import java.lang.annotation.*;" +
" public void extra() { }" + "import java.util.*;" +
"}" + "public class T {" +
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" + " public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }", " public void extra() { }" +
"t.T", "}" +
"package t;\n\n" + "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
"public class T {\n\n" + "@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
" public T();\n\n" + "t.T",
" public void test(int arg0,\n" + "package t;\n\n" +
" @t.Invisible int arg1,\n" + "public class T {\n\n" +
" @t.Visible java.util.List<java.lang.String> arg2,\n" + " public T();\n\n" +
" int arg3);\n" + " public void test(int arg0,\n" +
"}\n", " @t.Invisible int arg1,\n" +
"t.Visible", " @t.Visible java.util.List<java.lang.String> arg2,\n" +
"package t;\n\n" + " int arg3);\n" +
"@java.lang.annotation.Retention(RUNTIME)\n" + "}\n",
"@interface Visible {\n" + "t.Visible",
"}\n"); "package t;\n\n" +
doPrintElementTest("package t;" + "@java.lang.annotation.Retention(RUNTIME)\n" +
"import java.lang.annotation.*;" + "@interface Visible {\n" +
"public class T {" + "}\n");
" public void test(@Ann(v=\"url\", dv=\"\\\"\\\"\") String str) { }" + doPrintElementTest("package t;" +
"}" + "import java.lang.annotation.*;" +
"@Retention(RetentionPolicy.RUNTIME) @interface Ann {" + "public class T {" +
" public String v();" + " public void test(@Ann(v=\"url\", dv=\"\\\"\\\"\") String str) { }" +
" public String dv();" + "}" +
"}", "@Retention(RetentionPolicy.RUNTIME) @interface Ann {" +
"package t;" + " public String v();" +
"public class T { }", " public String dv();" +
"t.T", "}",
"package t;\n\n" + "package t;" +
"public class T {\n\n" + "public class T { }",
" public T();\n\n" + "t.T",
" public void test(@t.Ann(dv=\"\\\"\\\"\", v=\"url\") java.lang.String arg0);\n" + "package t;\n\n" +
"}\n", "public class T {\n\n" +
"t.T", " public T();\n\n" +
"package t;\n\n" + " public void test(@t.Ann(dv=\"\\\"\\\"\", v=\"url\") java.lang.String arg0);\n" +
"public class T {\n\n" + "}\n",
" public T();\n" + "t.T",
"}\n"); "package t;\n\n" +
"public class T {\n\n" +
" public T();\n" +
"}\n");
} finally {
CreateSymbols.HARDCODED_ANNOTATIONS.removeAll(extraAnnotations);
}
} }
@Test @Test
@ -360,11 +366,70 @@ public class CreateSymbolsTestImpl {
Expect.SUCCESS); Expect.SUCCESS);
} }
@Test
void testClearMissingAnnotations() throws Exception {
doPrintElementTest(new String[] {
"""
package t;
import t.impl.HC;
import t.impl.HR;
@HC @HR public class T {
@HC @HR public static final int i = 0;
@HC @HR public void t() {}
}
""",
"""
package t.impl;
import java.lang.annotation.*;
@Retention(RetentionPolicy.CLASS)
public @interface HC {
}
""",
"""
package t.impl;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface HR {
}
"""
},
new String[] {
"""
package t;
public class T {
public static final int i = 0;
}
"""
},
"t.T",
"""
package t;
public class T {
public static final int i = 0;
public T();
public void t();
}
""",
"t.T",
"""
package t;
public class T {
public static final int i = 0;
public T();
}
""");
}
int i = 0; int i = 0;
void doTest(String code7, String code8, String testCode, Expect result7, Expect result8) throws Exception { void doTest(String code7, String code8, String testCode, Expect result7, Expect result8) throws Exception {
ToolBox tb = new ToolBox(); ToolBox tb = new ToolBox();
Path classes = prepareVersionedCTSym(code7, code8); Path classes = prepareVersionedCTSym(new String[] {code7}, new String[] {code8});
Path output = classes.getParent(); Path output = classes.getParent();
Path scratch = output.resolve("scratch"); Path scratch = output.resolve("scratch");
@ -392,6 +457,10 @@ public class CreateSymbolsTestImpl {
} }
void doPrintElementTest(String code7, String code8, String className7, String printed7, String className8, String printed8) throws Exception { void doPrintElementTest(String code7, String code8, String className7, String printed7, String className8, String printed8) throws Exception {
doPrintElementTest(new String[] {code7}, new String[] {code8}, className7, printed7, className8, printed8);
}
void doPrintElementTest(String[] code7, String[] code8, String className7, String printed7, String className8, String printed8) throws Exception {
ToolBox tb = new ToolBox(); ToolBox tb = new ToolBox();
Path classes = prepareVersionedCTSym(code7, code8); Path classes = prepareVersionedCTSym(code7, code8);
Path output = classes.getParent(); Path output = classes.getParent();
@ -419,7 +488,7 @@ public class CreateSymbolsTestImpl {
} }
void doTestEquivalence(String code7, String code8, String testClass) throws Exception { void doTestEquivalence(String code7, String code8, String testClass) throws Exception {
Path classes = prepareVersionedCTSym(code7, code8); Path classes = prepareVersionedCTSym(new String[] {code7}, new String[] {code8});
Path classfile = classes.resolve("78").resolve("java.base").resolve(testClass.replace('.', '/') + ".class"); Path classfile = classes.resolve("78").resolve("java.base").resolve(testClass.replace('.', '/') + ".class");
if (!Files.isReadable(classfile)) { if (!Files.isReadable(classfile)) {
@ -576,7 +645,7 @@ public class CreateSymbolsTestImpl {
boolean oldIncludeAll = includeAll; boolean oldIncludeAll = includeAll;
try { try {
includeAll = false; includeAll = false;
Path classes = prepareVersionedCTSym(code, "package other; public class Other {}"); Path classes = prepareVersionedCTSym(new String[] {code}, new String[] {"package other; public class Other {}"});
Path root = classes.resolve("7").resolve("java.base"); Path root = classes.resolve("7").resolve("java.base");
try (Stream<Path> classFiles = Files.walk(root)) { try (Stream<Path> classFiles = Files.walk(root)) {
Set<String> names = classFiles.map(p -> root.relativize(p)) Set<String> names = classFiles.map(p -> root.relativize(p))
@ -595,7 +664,7 @@ public class CreateSymbolsTestImpl {
} }
} }
Path prepareVersionedCTSym(String code7, String code8) throws Exception { Path prepareVersionedCTSym(String[] code7, String[] code8) throws Exception {
String testClasses = System.getProperty("test.classes"); String testClasses = System.getProperty("test.classes");
Path output = Paths.get(testClasses, "test-data" + i++); Path output = Paths.get(testClasses, "test-data" + i++);
deleteRecursively(output); deleteRecursively(output);
@ -694,6 +763,7 @@ public class CreateSymbolsTestImpl {
return files.filter(p -> Files.isRegularFile(p)) return files.filter(p -> Files.isRegularFile(p))
.filter(p -> p.getFileName().toString().endsWith(".class")) .filter(p -> p.getFileName().toString().endsWith(".class"))
.map(p -> root.relativize(p).toString()) .map(p -> root.relativize(p).toString())
.filter(p -> !p.contains("impl"))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View file

@ -128,16 +128,16 @@ public class ElementStructureTest {
(byte) 0xB7, (byte) 0x52, (byte) 0x0F, (byte) 0x68 (byte) 0xB7, (byte) 0x52, (byte) 0x0F, (byte) 0x68
}; };
static final byte[] hash7 = new byte[] { static final byte[] hash7 = new byte[] {
(byte) 0x3C, (byte) 0x03, (byte) 0xEA, (byte) 0x4A, (byte) 0x45, (byte) 0xCA, (byte) 0x83, (byte) 0xCD,
(byte) 0x62, (byte) 0xD2, (byte) 0x18, (byte) 0xE5, (byte) 0x1A, (byte) 0x68, (byte) 0x57, (byte) 0x9C,
(byte) 0xA5, (byte) 0xC2, (byte) 0xB7, (byte) 0x85, (byte) 0x6F, (byte) 0x2D, (byte) 0xEB, (byte) 0x28,
(byte) 0x90, (byte) 0xFA, (byte) 0x98, (byte) 0xCD (byte) 0xAB, (byte) 0x05, (byte) 0x53, (byte) 0x6E
}; };
static final byte[] hash8 = new byte[] { static final byte[] hash8 = new byte[] {
(byte) 0x24, (byte) 0x38, (byte) 0x52, (byte) 0x1C, (byte) 0x26, (byte) 0x8C, (byte) 0xFD, (byte) 0x61,
(byte) 0x5E, (byte) 0x83, (byte) 0x82, (byte) 0xE6, (byte) 0x53, (byte) 0x00, (byte) 0x57, (byte) 0x10,
(byte) 0x41, (byte) 0xC2, (byte) 0xDD, (byte) 0x2A, (byte) 0x36, (byte) 0x2B, (byte) 0x92, (byte) 0x0B,
(byte) 0xFD, (byte) 0xFF, (byte) 0x5E, (byte) 0x2F (byte) 0xE1, (byte) 0x6A, (byte) 0xB5, (byte) 0xFD
}; };
final static Map<String, byte[]> version2Hash = new HashMap<>(); final static Map<String, byte[]> version2Hash = new HashMap<>();