This commit is contained in:
Jesper Wilhelmsson 2021-07-01 01:01:34 +00:00
commit 9def3b068e
29 changed files with 370 additions and 116 deletions

View File

@ -2413,6 +2413,11 @@ const bool Matcher::match_rule_supported_vector(int opcode, int vlen, BasicType
return false;
}
break;
case Op_VectorMaskCmp:
if (vlen < 2 || bit_size < 64) {
return false;
}
break;
default:
break;
}

View File

@ -3768,9 +3768,8 @@ void TemplateTable::_new() {
// Get instance_size in InstanceKlass (scaled to a count of bytes).
Register Rsize = offset;
const int mask = 1 << Klass::_lh_instance_slow_path_bit;
__ z_llgf(Rsize, Address(iklass, Klass::layout_helper_offset()));
__ z_tmll(Rsize, mask);
__ z_tmll(Rsize, Klass::_lh_instance_slow_path_bit);
__ z_btrue(slow_case);
// Allocate the instance

View File

@ -1427,7 +1427,7 @@ void C2_MacroAssembler::evscatter(BasicType typ, Register base, XMMRegister idx,
}
}
void C2_MacroAssembler::load_vector_mask(XMMRegister dst, XMMRegister src, int vlen_in_bytes, BasicType elem_bt) {
void C2_MacroAssembler::load_vector_mask(XMMRegister dst, XMMRegister src, int vlen_in_bytes, BasicType elem_bt, bool is_legacy) {
if (vlen_in_bytes <= 16) {
pxor (dst, dst);
psubb(dst, src);
@ -1442,10 +1442,12 @@ void C2_MacroAssembler::load_vector_mask(XMMRegister dst, XMMRegister src, int v
default: assert(false, "%s", type2name(elem_bt));
}
} else {
assert(!is_legacy || !is_subword_type(elem_bt) || vlen_in_bytes < 64, "");
int vlen_enc = vector_length_encoding(vlen_in_bytes);
vpxor (dst, dst, dst, vlen_enc);
vpsubb(dst, dst, src, vlen_enc);
vpsubb(dst, dst, src, is_legacy ? AVX_256bit : vlen_enc);
switch (elem_bt) {
case T_BYTE: /* nothing to do */ break;
case T_SHORT: vpmovsxbw(dst, dst, vlen_enc); break;
@ -1461,7 +1463,11 @@ void C2_MacroAssembler::load_vector_mask(XMMRegister dst, XMMRegister src, int v
void C2_MacroAssembler::load_iota_indices(XMMRegister dst, Register scratch, int vlen_in_bytes) {
ExternalAddress addr(StubRoutines::x86::vector_iota_indices());
if (vlen_in_bytes <= 16) {
if (vlen_in_bytes == 4) {
movdl(dst, addr);
} else if (vlen_in_bytes == 8) {
movq(dst, addr);
} else if (vlen_in_bytes == 16) {
movdqu(dst, addr, scratch);
} else if (vlen_in_bytes == 32) {
vmovdqu(dst, addr, scratch);
@ -1470,6 +1476,7 @@ void C2_MacroAssembler::load_iota_indices(XMMRegister dst, Register scratch, int
evmovdqub(dst, k0, addr, false /*merge*/, Assembler::AVX_512bit, scratch);
}
}
// Reductions for vectors of bytes, shorts, ints, longs, floats, and doubles.
void C2_MacroAssembler::reduce_operation_128(BasicType typ, int opcode, XMMRegister dst, XMMRegister src) {

View File

@ -141,7 +141,7 @@ public:
void evpcmp(BasicType typ, KRegister kdmask, KRegister ksmask, XMMRegister src1, XMMRegister src2, int comparison, int vector_len);
void evpblend(BasicType typ, XMMRegister dst, KRegister kmask, XMMRegister src1, XMMRegister src2, bool merge, int vector_len);
void load_vector_mask(XMMRegister dst, XMMRegister src, int vlen_in_bytes, BasicType elem_bt);
void load_vector_mask(XMMRegister dst, XMMRegister src, int vlen_in_bytes, BasicType elem_bt, bool is_legacy);
void load_iota_indices(XMMRegister dst, Register scratch, int vlen_in_bytes);
// vector compare

View File

@ -1835,6 +1835,11 @@ const bool Matcher::match_rule_supported_vector(int opcode, int vlen, BasicType
return false;
}
break;
case Op_VectorMaskCmp:
if (vlen < 2 || size_in_bits < 32) {
return false;
}
break;
}
return true; // Per default match rules are supported.
}
@ -6906,7 +6911,7 @@ instruct evcmpFD(vec dst, vec src1, vec src2, immI8 cond, rRegP scratch, kReg kt
instruct vcmp(legVec dst, legVec src1, legVec src2, immI8 cond, rRegP scratch) %{
predicate((UseAVX <= 2 || !VM_Version::supports_avx512vl()) &&
!is_unsigned_booltest_pred(n->in(2)->get_int()) &&
vector_length_in_bytes(n->in(1)->in(1)) >= 8 && // src1
vector_length_in_bytes(n->in(1)->in(1)) >= 4 && // src1
vector_length_in_bytes(n->in(1)->in(1)) <= 32 && // src1
is_integral_type(vector_element_basic_type(n->in(1)->in(1)))); // src1
match(Set dst (VectorMaskCmp (Binary src1 src2) cond));
@ -7442,7 +7447,8 @@ instruct cmpvptest_anytrue_evex(rFlagsReg cr, legVec src1, legVec src2, immI_0 z
//------------------------------------- LoadMask --------------------------------------------
instruct loadMask(vec dst, vec src) %{
instruct loadMask(legVec dst, legVec src) %{
predicate(!VM_Version::supports_avx512vlbw());
match(Set dst (VectorLoadMask src));
effect(TEMP dst);
format %{ "vector_loadmask_byte $dst,$src\n\t" %}
@ -7450,7 +7456,21 @@ instruct loadMask(vec dst, vec src) %{
int vlen_in_bytes = vector_length_in_bytes(this);
BasicType elem_bt = vector_element_basic_type(this);
__ load_vector_mask($dst$$XMMRegister, $src$$XMMRegister, vlen_in_bytes, elem_bt);
__ load_vector_mask($dst$$XMMRegister, $src$$XMMRegister, vlen_in_bytes, elem_bt, true);
%}
ins_pipe( pipe_slow );
%}
instruct loadMask_evex(vec dst, vec src) %{
predicate(VM_Version::supports_avx512vlbw());
match(Set dst (VectorLoadMask src));
effect(TEMP dst);
format %{ "vector_loadmask_byte $dst,$src\n\t" %}
ins_encode %{
int vlen_in_bytes = vector_length_in_bytes(this);
BasicType elem_bt = vector_element_basic_type(this);
__ load_vector_mask($dst$$XMMRegister, $src$$XMMRegister, vlen_in_bytes, elem_bt, false);
%}
ins_pipe( pipe_slow );
%}

View File

@ -87,7 +87,7 @@ void ParallelArguments::initialize() {
}
if (FLAG_IS_DEFAULT(ParallelRefProcEnabled) && ParallelGCThreads > 1) {
//FLAG_SET_DEFAULT(ParallelRefProcEnabled, true);
FLAG_SET_DEFAULT(ParallelRefProcEnabled, true);
}
}

View File

@ -71,12 +71,7 @@ class PromotionFailedInfo : public CopyFailedInfo {
void register_copy_failure(size_t size) {
CopyFailedInfo::register_copy_failure(size);
if (_thread_trace_id == 0) {
_thread_trace_id = JFR_THREAD_ID(Thread::current());
} else {
assert(JFR_THREAD_ID(Thread::current()) == _thread_trace_id,
"The PromotionFailedInfo should be thread local.");
}
_thread_trace_id = JFR_THREAD_ID(Thread::current());
}
void reset() {

View File

@ -411,9 +411,6 @@ bool LibraryCallKit::inline_vector_shuffle_iota() {
int num_elem = vlen->get_con();
BasicType elem_bt = T_BYTE;
if (num_elem < 4)
return false;
if (!arch_supports_vector(VectorNode::replicate_opcode(elem_bt), num_elem, elem_bt, VecMaskNotUsed)) {
return false;
}

View File

@ -928,6 +928,7 @@ void ThreadSafepointState::handle_polling_page_exception() {
if( nm->is_at_poll_return(real_return_addr) ) {
// See if return type is an oop.
bool return_oop = nm->method()->is_returning_oop();
HandleMark hm(self);
Handle return_value;
if (return_oop) {
// The oop result has been saved on the stack together with all

View File

@ -43,6 +43,8 @@ import jdk.internal.vm.annotation.IntrinsicCandidate;
* <p> In order to ensure that a reclaimable object remains so, the referent of
* a phantom reference may not be retrieved: The {@code get} method of a
* phantom reference always returns {@code null}.
* The {@link #refersTo(Object) refersTo} method can be used to test
* whether some object is the referent of a phantom reference.
*
* @author Mark Reinhold
* @since 1.2
@ -75,9 +77,7 @@ public class PhantomReference<T> extends Reference<T> {
* is registered with the given queue.
*
* <p> It is possible to create a phantom reference with a {@code null}
* queue, but such a reference is completely useless: Its {@code get}
* method will always return {@code null} and, since it does not have a queue,
* it will never be enqueued.
* queue. Such a reference will never be enqueued.
*
* @param referent the object the new phantom reference will refer to
* @param q the queue with which the reference is to be registered,

View File

@ -455,9 +455,11 @@ import sun.util.locale.provider.TimeZoneNameUtility;
*
* <p>For the backward compatible behavior, the system property
* {@systemProperty java.locale.useOldISOCodes} reverts the behavior
* back to prior to Java SE 17 one. If the system property is set
* to {@code true}, those three current language codes are mapped to their
* backward compatible forms.
* back to that of before Java SE 17. If the system property is set to
* {@code true}, those three current language codes are mapped to their
* backward compatible forms. The property is only read at Java runtime
* startup and subsequent calls to {@code System.setProperty()} will
* have no effect.
*
* <p>The APIs added in 1.7 map between the old and new language codes,
* maintaining the mapped codes internal to Locale (so that

View File

@ -169,6 +169,8 @@ public class Attr extends JCTree.Visitor {
allowStaticInterfaceMethods = Feature.STATIC_INTERFACE_METHODS.allowedInSource(source);
allowReifiableTypesInInstanceof = Feature.REIFIABLE_TYPES_INSTANCEOF.allowedInSource(source);
allowRecords = Feature.RECORDS.allowedInSource(source);
allowPatternSwitch = (preview.isEnabled() || !preview.isPreview(Feature.PATTERN_SWITCH)) &&
Feature.PATTERN_SWITCH.allowedInSource(source);
sourceName = source.name;
useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
@ -209,6 +211,10 @@ public class Attr extends JCTree.Visitor {
*/
private final boolean allowRecords;
/** Are patterns in switch allowed
*/
private final boolean allowPatternSwitch;
/**
* Switch: warn about use of variable before declaration?
* RFE: 6425594
@ -1724,14 +1730,22 @@ public class Attr extends JCTree.Visitor {
rs.basicLogResolveHelper = prevResolveHelper;
}
} else {
Type pattype = attribExpr(expr, switchEnv, seltype);
ResultInfo valTypInfo = new ResultInfo(KindSelector.VAL_TYP,
!seltype.hasTag(ERROR) ? seltype
: Type.noType);
Type pattype = attribTree(expr, switchEnv, valTypInfo);
if (!pattype.hasTag(ERROR)) {
if (!stringSwitch && !types.isAssignable(seltype, syms.intType)) {
log.error(pat.pos(), Errors.ConstantLabelNotCompatible(pattype, seltype));
}
if (pattype.constValue() == null) {
log.error(expr.pos(),
(stringSwitch ? Errors.StringConstReq : Errors.ConstExprReq));
Symbol s = TreeInfo.symbol(expr);
if (s != null && s.kind == TYP && allowPatternSwitch) {
log.error(expr.pos(),
Errors.PatternExpected);
} else {
log.error(expr.pos(),
(stringSwitch ? Errors.StringConstReq : Errors.ConstExprReq));
}
} else if (!stringSwitch && !types.isAssignable(seltype, syms.intType)) {
log.error(pat.pos(), Errors.ConstantLabelNotCompatible(pattype, seltype));
} else if (!labels.add(pattype.constValue())) {
log.error(c.pos(), Errors.DuplicateCaseLabel);
} else {

View File

@ -1375,8 +1375,7 @@ public class Gen extends JCTree.Visitor {
if (switchEnv.info.cont != null) {
Assert.check(patternSwitch);
code.resolve(switchEnv.info.cont);
code.resolve(code.branch(goto_), switchStart);
code.resolve(switchEnv.info.cont, switchStart);
}
// Resolve all breaks.

View File

@ -1189,6 +1189,9 @@ compiler.err.static.imp.only.classes.and.interfaces=\
compiler.err.string.const.req=\
constant string expression required
compiler.err.pattern.expected=\
type pattern expected
# 0: symbol, 1: fragment
compiler.err.cannot.generate.class=\
error while generating class {0}\n\

View File

@ -350,14 +350,12 @@ ul.see-list-long li:not(:last-child):after {
/*
* Styles for tables.
*/
.summary-table {
.summary-table, .details-table {
width:100%;
border-spacing:0;
border-left:1px solid #EEE;
border-right:1px solid #EEE;
border-bottom:1px solid #EEE;
}
.summary-table {
padding:0;
}
.caption {
@ -445,7 +443,7 @@ div.table-tabs > button.table-tab {
grid-template-columns: minmax(15%, max-content) minmax(15%, auto);
}
}
.summary-table > div {
.summary-table > div, .details-table > div {
text-align:left;
padding: 8px 3px 3px 7px;
}

View File

@ -32,3 +32,5 @@ compiler/intrinsics/bmi/verifycode/BzhiTestI2L.java 8268033 generic-x64
vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/TestDescription.java 8205957 generic-all
vmTestbase/vm/mlvm/mixed/stress/regression/b6969574/INDIFY_Test.java 8265295 linux-x64,windows-x64
vmTestbase/nsk/jvmti/scenarios/sampling/SP07/sp07t002/TestDescription.java 8245680 windows-x64

View File

@ -72,7 +72,9 @@ public class MultiCommand extends AbstractTestBase {
Executable exec = Utils.getRandomElement(METHODS).first;
MethodDescriptor md;
if (validOnly) {
// Command.quiet discards the method descriptor - can never fail on the method descriptor
if (validOnly || cmd == Command.QUIET) {
md = AbstractTestBase.getValidMethodDescriptor(exec);
} else {
md = AbstractTestBase.METHOD_GEN.generateRandomDescriptor(exec);

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2021, Huawei Technologies Co. Ltd. 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.
*/
package compiler.vectorapi;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.VectorSpecies;
import jdk.incubator.vector.VectorShuffle;
/*
* @test
* @bug 8265907
* @modules jdk.incubator.vector
* @run main/othervm compiler.vectorapi.TestVectorShuffleIota
*/
public class TestVectorShuffleIota {
static final VectorSpecies<Integer> SPECIESi = IntVector.SPECIES_128;
static final int INVOC_COUNT = 50000;
static int[] ai = {87, 65, 78, 71};
static void testShuffleI() {
IntVector iv = (IntVector) VectorShuffle.iota(SPECIESi, 0, 2, false).toVector();
iv.intoArray(ai, 0);
}
public static void main(String[] args) {
for (int i = 0; i < INVOC_COUNT; i++) {
testShuffleI();
}
for (int i = 0; i < ai.length; i++) {
System.out.print(ai[i] + ", ");
}
System.out.println();
}
}

View File

@ -51,7 +51,7 @@ public class TestParallelRefProc {
}
if (GC.Parallel.isSupported()) {
noneGCSupported = false;
testFlag(new String[] { "-XX:+UseParallelGC" }, false);
testFlag(new String[] { "-XX:+UseParallelGC" }, true);
}
if (GC.G1.isSupported()) {
noneGCSupported = false;

View File

@ -24,38 +24,70 @@
/*
* @test
* @modules java.base/jdk.internal.misc
*
* @summary converted from VM Testbase vm/mlvm/anonloader/stress/oome/metaspace.
* VM Testbase keywords: [feature_mlvm, nonconcurrent]
*
* @library /test/lib
* @library /vmTestbase
* /test/lib
*
* @run driver vm.mlvm.anonloader.stress.oome.metaspace.Test
* @comment build test class and indify classes
* @build vm.mlvm.anonloader.stress.oome.metaspace.Test
* @run driver vm.mlvm.share.IndifiedClassesBuilder
*
* @run main/othervm -XX:MaxRAMPercentage=25 -XX:-UseGCOverheadLimit -XX:MetaspaceSize=10m
* -XX:MaxMetaspaceSize=20m vm.mlvm.anonloader.stress.oome.metaspace.Test
*/
package vm.mlvm.anonloader.stress.oome.metaspace;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.util.List;
import java.io.IOException;
public class Test {
import vm.mlvm.anonloader.share.AnonkTestee01;
import vm.mlvm.share.MlvmOOMTest;
import vm.mlvm.share.MlvmTestExecutor;
import vm.mlvm.share.Env;
import vm.share.FileUtils;
public static void main(String[] args) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xshare:off", "-XX:MaxMetaspaceSize=512k", "-version");
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
analyzer.shouldNotHaveExitValue(0);
if (!analyzer.getStdout().contains("OutOfMemoryError")) {
throw new RuntimeException("TEST FAIL : no OOME");
}
if (!analyzer.getStdout().contains("Metaspace") &&
!analyzer.getStdout().contains("Compressed class space")) {
throw new RuntimeException("TEST FAIL : wrong OOME");
/**
* This test loads classes using defineHiddenClass and stores them,
* expecting Metaspace OOME.
*
*/
public class Test extends MlvmOOMTest {
@Override
protected void checkOOME(OutOfMemoryError oome) {
String message = oome.getMessage();
if (!"Metaspace".equals(message) && !"Compressed class space".equals(message)) {
throw new RuntimeException("TEST FAIL : wrong OOME", oome);
}
}
@Override
protected void eatMemory(List<Object> list) {
byte[] classBytes = null;
try {
classBytes = FileUtils.readClass(AnonkTestee01.class.getName());
} catch (IOException e) {
Env.throwAsUncheckedException(e);
}
try {
while (true) {
Lookup lookup = MethodHandles.lookup();
Lookup ank_lookup = MethodHandles.privateLookupIn(AnonkTestee01.class, lookup);
Class<?> c = ank_lookup.defineHiddenClass(classBytes, true).lookupClass();
list.add(c.newInstance());
}
} catch (InstantiationException | IllegalAccessException e) {
Env.throwAsUncheckedException(e);
}
}
public static void main(String[] args) {
MlvmTestExecutor.launch(args);
}
}

View File

@ -580,7 +580,7 @@ com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957 aix-all
java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java 8247426 generic-all
sun/management/jdp/JdpDefaultsTest.java 8241865 macosx-all
sun/management/jdp/JdpDefaultsTest.java 8241865 linux-aarch64,macosx-all
sun/management/jdp/JdpJmxRemoteDynamicPortTest.java 8241865 macosx-all
sun/management/jdp/JdpSpecificAddressTest.java 8241865 macosx-all

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@ -37,7 +37,6 @@
import java.io.File;
import java.util.Map;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import java.io.IOException;
@ -50,17 +49,15 @@ public class CallerAccessTest {
ProcessBuilder pb = new ProcessBuilder(launcher.toString());
Map<String, String> env = pb.environment();
String libName = Platform.isWindows() ? "bin" : "lib";
Path libPath = Paths.get(Utils.TEST_JDK).resolve(libName);
String libDir = libPath.toAbsolutePath().toString();
String serverDir = libPath.resolve("server").toAbsolutePath().toString();
String libDir = Platform.libDir().toString();
String vmDir = Platform.jvmLibDir().toString();
// set up shared library path
String sharedLibraryPathEnvName = Platform.sharedLibraryPathVariableName();
env.compute(sharedLibraryPathEnvName,
(k, v) -> (v == null) ? libDir : v + File.pathSeparator + libDir);
env.compute(sharedLibraryPathEnvName,
(k, v) -> (v == null) ? serverDir : v + File.pathSeparator + serverDir);
(k, v) -> (v == null) ? vmDir : v + File.pathSeparator + vmDir);
System.out.println("Launching: " + launcher + " shared library path: " +
env.get(sharedLibraryPathEnvName));

View File

@ -120,7 +120,7 @@ public class CheckStylesheetClasses {
"modifiers", "permits", "return-type");
// misc: these are defined in HtmlStyle, and used by the doclet
removeAll(htmlStyleNames, "col-plain", "details-table", "external-link",
removeAll(htmlStyleNames, "col-plain", "external-link",
"hierarchy", "index", "package-uses", "packages", "permits-note",
"serialized-package-container", "source-container");

View File

@ -140,7 +140,7 @@ public class TestStylesheet extends JavadocTester {
overflow: auto;
}""",
"""
.summary-table > div {
.summary-table > div, .details-table > div {
text-align:left;
padding: 8px 3px 3px 7px;
}""",

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
// key: compiler.err.pattern.expected
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --enable-preview -source ${jdk.version}
class PatternSwitch {
private void doSwitch(Object o) {
switch (o) {
case String: break;
default: break;
}
}
}

View File

@ -0,0 +1,42 @@
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

@ -26,6 +26,7 @@
* @bug 8262891
* @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-no-preview.out -XDrawDiagnostics -XDshould-stop.at=FLOW SwitchErrors.java
*/
public class SwitchErrors {
void incompatibleSelectorObjectString(Object o) {
@ -190,6 +191,12 @@ public class SwitchErrors {
}
sealed class SealedNonAbstract permits A {}
final class A extends SealedNonAbstract {}
void errorRecoveryNoPattern1(Object o) {
switch (o) {
case String: break;
case Object obj: break;
}
}
Object guardWithMatchingStatement(Object o1, Object o2) {
switch (o1) {
case String s && s.isEmpty() || o2 instanceof Number n: return n;

View File

@ -1,46 +1,47 @@
SwitchErrors.java:33:18: compiler.err.constant.label.not.compatible: java.lang.String, java.lang.Object
SwitchErrors.java:39:18: compiler.err.constant.label.not.compatible: int, java.lang.Object
SwitchErrors.java:45:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
SwitchErrors.java:46:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.CharSequence)
SwitchErrors.java:51:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, int)
SwitchErrors.java:52:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
SwitchErrors.java:53:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.CharSequence)
SwitchErrors.java:59:20: compiler.err.total.pattern.and.default
SwitchErrors.java:65:13: compiler.err.pattern.dominated
SwitchErrors.java:65:24: compiler.err.total.pattern.and.default
SwitchErrors.java:71:18: compiler.err.total.pattern.and.default
SwitchErrors.java:77:18: compiler.err.duplicate.total.pattern
SwitchErrors.java:83:20: compiler.err.duplicate.default.label
SwitchErrors.java:89:20: compiler.err.duplicate.default.label
SwitchErrors.java:94:27: compiler.err.duplicate.default.label
SwitchErrors.java:100:13: compiler.err.duplicate.case.label
SwitchErrors.java:105:13: compiler.err.duplicate.case.label
SwitchErrors.java:110:28: compiler.err.flows.through.to.pattern
SwitchErrors.java:116:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:123:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:130:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:135:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
SwitchErrors.java:141:18: compiler.err.instanceof.reifiable.not.safe: java.util.List, java.util.List<java.lang.Integer>
SwitchErrors.java:147:18: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:154:18: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
SwitchErrors.java:160:28: compiler.err.flows.through.from.pattern
SwitchErrors.java:166:18: compiler.err.flows.through.from.pattern
SwitchErrors.java:171:27: compiler.err.flows.through.to.pattern
SwitchErrors.java:177:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:183:13: compiler.err.pattern.dominated
SwitchErrors.java:195:76: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:201:71: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
SwitchErrors.java:32:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:38:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:44:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:50:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:98:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:104:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:109:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:114:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:120:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:127:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:187:9: compiler.err.not.exhaustive.statement
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.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: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:66:24: compiler.err.total.pattern.and.default
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:95:27: 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:161:28: compiler.err.flows.through.from.pattern
SwitchErrors.java:167:18: compiler.err.flows.through.from.pattern
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.pattern.expected
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
- compiler.note.preview.filename: SwitchErrors.java, DEFAULT
- compiler.note.preview.recompile
43 errors
44 errors

View File

@ -27,7 +27,7 @@ import java.util.function.Function;
/*
* @test
* @bug 8262891 8268333
* @bug 8262891 8268333 8268896
* @summary Check behavior of pattern switches.
* @compile --enable-preview -source ${jdk.version} Switches.java
* @run main/othervm --enable-preview Switches
@ -60,6 +60,8 @@ public class Switches {
runEnumTest(this::testIntegerWithGuardsExpression1);
runStringWithConstant(this::testStringWithConstant);
runStringWithConstant(this::testStringWithConstantExpression);
runFallThrough(this::testFallThroughStatement);
runFallThrough(this::testFallThroughExpression);
npeTest(this::npeTestStatement);
npeTest(this::npeTestExpression);
exhaustiveStatementSane("");
@ -104,6 +106,10 @@ public class Switches {
assertEquals(-1, mapper.apply(null));
}
void runFallThrough(Function<Integer, Integer> mapper) {
assertEquals(2, mapper.apply(1));
}
void npeTest(Consumer<I> testCase) {
try {
testCase.accept(null);
@ -272,7 +278,7 @@ public class Switches {
String testStringWithGuards1(E e) {
switch (e != null ? e.name() : null) {
case "A": return "a";
case "B": return "b";
case Switches.ConstantClassClash: return "b";
case String x && "C".equals(x): return "C";
case "C": return "broken";
case null, String x: return String.valueOf(x);
@ -282,7 +288,7 @@ public class Switches {
String testStringWithGuardsExpression1(E e) {
return switch (e != null ? e.name() : null) {
case "A" -> "a";
case "B" -> "b";
case ConstantClassClash -> "b";
case String x && "C".equals(x) -> "C";
case "C" -> "broken";
case null, String x -> String.valueOf(x);
@ -309,6 +315,31 @@ public class Switches {
};
}
Integer testFallThroughStatement(Integer i) {
int r = 0;
switch (i) {
case Integer o && o != null:
r = 1;
default:
r = 2;
}
return r;
}
Integer testFallThroughExpression(Integer i) {
int r = switch (i) {
case Integer o && o != null:
r = 1;
default:
r = 2;
yield r;
};
return r;
}
void npeTestStatement(I i) {
switch (i) {
case A a -> {}
@ -335,6 +366,12 @@ public class Switches {
}
}
//verify that for cases like:
//case ConstantClassClash ->
//ConstantClassClash is interpreted as a field, not as a class
private static final String ConstantClassClash = "B";
private static class ConstantClassClash {}
sealed interface I {}
final class A implements I {}
final class B implements I {}