From b9e89a80dc0067a4b04756510df5443418525229 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Fri, 25 Oct 2024 08:30:23 +0000 Subject: [PATCH 1/5] 8341966: Broken annotated module may lead to an exception in javac Reviewed-by: asotona, vromero Backport-of: 7ff4ea8d01c681b90ad59be04007557d84c8db94 --- .../com/sun/tools/javac/jvm/ClassReader.java | 4 +- .../javac/modules/AnnotationsOnModules.java | 94 ++++++++++++++++++- 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java index bd05cf91e91..8b331847112 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, 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 @@ -2174,7 +2174,7 @@ public void visitCompoundAnnotationProxy(CompoundAnnotationProxy proxy) { Type resolvePossibleProxyType(Type t) { if (t instanceof ProxyType proxyType) { - Assert.check(requestingOwner.owner.kind == MDL); + Assert.check(requestingOwner.owner instanceof ModuleSymbol); ModuleSymbol prevCurrentModule = currentModule; currentModule = (ModuleSymbol) requestingOwner.owner; try { diff --git a/test/langtools/tools/javac/modules/AnnotationsOnModules.java b/test/langtools/tools/javac/modules/AnnotationsOnModules.java index bfae27d4d21..18b79b95f0a 100644 --- a/test/langtools/tools/javac/modules/AnnotationsOnModules.java +++ b/test/langtools/tools/javac/modules/AnnotationsOnModules.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8159602 8170549 8171255 8171322 8254023 + * @bug 8159602 8170549 8171255 8171322 8254023 8341966 * @summary Test annotations on module declaration. * @library /tools/lib * @enablePreview @@ -35,8 +35,10 @@ */ import java.io.File; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -55,6 +57,7 @@ import java.lang.classfile.*; import java.lang.classfile.ClassFile; import java.lang.classfile.attribute.*; +import java.lang.reflect.AccessFlag; import toolbox.JavacTask; import toolbox.Task; import toolbox.Task.OutputKind; @@ -726,6 +729,93 @@ public TestCase(String extraDecl, String decl, String use, String expectedAnnota } } + @Test + public void testBrokenModuleInfoClassWithAnnotation(Path base) throws Exception { + Path lib = base.resolve("lib"); + tb.writeJavaFiles(lib, + """ + @Deprecated + module m{} + """); + + Path libClasses = base.resolve("lib-classes"); + Files.createDirectories(libClasses); + + new JavacTask(tb) + .options("--release", "21") + .outdir(libClasses) + .files(findJavaFiles(lib)) + .run() + .writeAll(); + + Path modifiedModuleInfo = libClasses.resolve("module-info.class"); + ClassModel cm1 = ClassFile.of().parse(modifiedModuleInfo); + byte[] newBytes = ClassFile.of().transform(cm1, (builder, element) -> { + if (element instanceof ModuleAttribute attr) { + List requires = new ArrayList<>(); + + for (ModuleRequireInfo mri : attr.requires()) { + if (mri.requires().name().equalsString("java.base")) { + requires.add(ModuleRequireInfo.of(mri.requires(), + List.of(AccessFlag.TRANSITIVE), + mri.requiresVersion() + .orElse(null))); + } else { + requires.add(mri); + } + } + + builder.accept(ModuleAttribute.of(attr.moduleName(), + attr.moduleFlagsMask(), + attr.moduleVersion() + .orElseGet(() -> null), + requires, + attr.exports(), + attr.opens(), + attr.uses(), + attr.provides())); + } else { + builder.accept(element); + } + }); + + try (OutputStream out = Files.newOutputStream(modifiedModuleInfo)) { + out.write(newBytes); + } + + Path src = base.resolve("src"); + Path classes = base.resolve("classes"); + + tb.writeJavaFiles(src, + """ + public class C {} + """); + + Files.createDirectories(classes); + + List actualErrors = + new JavacTask(tb) + .options("--module-path", libClasses.toString(), + "--add-modules", "m", + "-XDshould-stop.at=FLOW", + "-XDdev", + "-XDrawDiagnostics") + .outdir(classes) + .files(findJavaFiles(src)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(OutputKind.DIRECT); + List expectedErrors = List.of( + "- compiler.err.cant.access: m.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.bad.requires.flag: ACC_TRANSITIVE (0x0020))", + "1 error" + ); + + if (!expectedErrors.equals(actualErrors)) { + throw new AssertionError("Unexpected errors, expected: " + expectedErrors + + ", but got: " + actualErrors); + } + } + private static final String OPT_EXPECTED_ANNOTATIONS = "expectedAnnotations"; @SupportedAnnotationTypes("*") From e56655f3184c731b457bcd16462a8196e5eb6996 Mon Sep 17 00:00:00 2001 From: Martin Doerr Date: Fri, 25 Oct 2024 16:11:44 +0000 Subject: [PATCH 2/5] 8342701: [PPC64] TestOSRLotsOfLocals.java crashes Backport-of: 3bba0f3dc8faf83a3aadcd704ae2ae4967e6daa4 --- src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp b/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp index 3ae35949b21..ccbb635ce2e 100644 --- a/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp @@ -133,9 +133,20 @@ void LIR_Assembler::osr_entry() { // copied into place by code emitted in the IR. Register OSR_buf = osrBufferPointer()->as_register(); - { assert(frame::interpreter_frame_monitor_size() == BasicObjectLock::size(), "adjust code below"); - int monitor_offset = BytesPerWord * method()->max_locals() + - (2 * BytesPerWord) * (number_of_locks - 1); + { + assert(frame::interpreter_frame_monitor_size() == BasicObjectLock::size(), "adjust code below"); + + const int locals_space = BytesPerWord * method()->max_locals(); + int monitor_offset = locals_space + (2 * BytesPerWord) * (number_of_locks - 1); + bool use_OSR_bias = false; + + if (!Assembler::is_simm16(monitor_offset + BytesPerWord) && number_of_locks > 0) { + // Offsets too large for ld instructions. Use bias. + __ add_const_optimized(OSR_buf, OSR_buf, locals_space); + monitor_offset -= locals_space; + use_OSR_bias = true; + } + // SharedRuntime::OSR_migration_begin() packs BasicObjectLocks in // the OSR buffer using 2 word entries: first the lock and then // the oop. @@ -161,6 +172,11 @@ void LIR_Assembler::osr_entry() { __ ld(R0, slot_offset + 1*BytesPerWord, OSR_buf); __ std(R0, mo.disp(), mo.base()); } + + if (use_OSR_bias) { + // Restore. + __ sub_const_optimized(OSR_buf, OSR_buf, locals_space); + } } } From f7b4584012ae6fedeabec0300c2cf48229cacf71 Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Fri, 25 Oct 2024 16:24:17 +0000 Subject: [PATCH 3/5] 8337968: Problem list compiler/vectorapi/VectorRebracket128Test.java Backport-of: 66286b25a183de2ffd0689da9c2bd1978b881aa7 --- test/hotspot/jtreg/ProblemList.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index 7ffb7405123..cdf8aeb3775 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -74,6 +74,8 @@ compiler/codecache/CheckLargePages.java 8332654 linux-x64 compiler/vectorapi/reshape/TestVectorReinterpret.java 8320897 aix-ppc64,linux-ppc64le compiler/vectorapi/VectorLogicalOpIdentityTest.java 8302459 linux-x64,windows-x64 +compiler/vectorapi/VectorRebracket128Test.java#ZSinglegen 8330538 generic-all +compiler/vectorapi/VectorRebracket128Test.java#ZGenerational 8330538 generic-all compiler/jvmci/TestUncaughtErrorInCompileMethod.java 8309073 generic-all compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/DataPatchTest.java 8331704 linux-riscv64 From a690507f621bbf7816668a33a749b68dfb50639f Mon Sep 17 00:00:00 2001 From: Shivangi Gupta Date: Fri, 25 Oct 2024 16:28:05 +0000 Subject: [PATCH 4/5] 8324672: Update jdk/java/time/tck/java/time/TCKInstant.java now() to be more robust Backport-of: e94e3bba3932f3d92c0a135d333d1ccd6e72b964 --- .../java/time/tck/java/time/TCKInstant.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/jdk/java/time/tck/java/time/TCKInstant.java b/test/jdk/java/time/tck/java/time/TCKInstant.java index d7a63415279..c666a1340d3 100644 --- a/test/jdk/java/time/tck/java/time/TCKInstant.java +++ b/test/jdk/java/time/tck/java/time/TCKInstant.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -187,10 +187,21 @@ public void constant_MAX() { //----------------------------------------------------------------------- @Test public void now() { - Instant expected = Instant.now(Clock.systemUTC()); - Instant test = Instant.now(); - long diff = Math.abs(test.toEpochMilli() - expected.toEpochMilli()); - assertTrue(diff < 100); // less than 0.1 secs + long beforeMillis, instantMillis, afterMillis, diff; + int retryRemaining = 5; // MAX_RETRY_COUNT + do { + beforeMillis = Instant.now(Clock.systemUTC()).toEpochMilli(); + instantMillis = Instant.now().toEpochMilli(); + afterMillis = Instant.now(Clock.systemUTC()).toEpochMilli(); + diff = instantMillis - beforeMillis; + if (instantMillis < beforeMillis || instantMillis > afterMillis) { + throw new RuntimeException(": Invalid instant: (~" + instantMillis + "ms)" + + " when systemUTC in millis is in [" + + beforeMillis + ", " + + afterMillis + "]"); + } + } while (diff > 100 && --retryRemaining > 0); // retry if diff more than 0.1 sec + assertTrue(retryRemaining > 0); } //----------------------------------------------------------------------- From 309ef3f89a10b6292648bba554d61f97cab2067b Mon Sep 17 00:00:00 2001 From: Roland Westrelin Date: Fri, 25 Oct 2024 16:35:25 +0000 Subject: [PATCH 5/5] 8342496: C2/Shenandoah: SEGV in compiled code when running jcstress Backport-of: 680dc5d896f4f7b01b3cf800d548e32bb2ef8c81 --- .../gc/shenandoah/c2/shenandoahSupport.cpp | 1 + .../compiler/TestLoadBypassesNullCheck.java | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 test/hotspot/jtreg/gc/shenandoah/compiler/TestLoadBypassesNullCheck.java diff --git a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp index dbb45995698..68a8cb77c14 100644 --- a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp +++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp @@ -1060,6 +1060,7 @@ void ShenandoahBarrierC2Support::fix_ctrl(Node* barrier, Node* region, const Mem Node* u = ctrl->fast_out(i); if (u->_idx < last && u != barrier && + !u->depends_only_on_test() && // preserve dependency on test !uses_to_ignore.member(u) && (u->in(0) != ctrl || (!u->is_Region() && !u->is_Phi())) && (ctrl->Opcode() != Op_CatchProj || u->Opcode() != Op_CreateEx)) { diff --git a/test/hotspot/jtreg/gc/shenandoah/compiler/TestLoadBypassesNullCheck.java b/test/hotspot/jtreg/gc/shenandoah/compiler/TestLoadBypassesNullCheck.java new file mode 100644 index 00000000000..2feea3308e4 --- /dev/null +++ b/test/hotspot/jtreg/gc/shenandoah/compiler/TestLoadBypassesNullCheck.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024, Red Hat, Inc. 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 8342496 + * @summary C2/Shenandoah: SEGV in compiled code when running jcstress + * @requires vm.flavor == "server" + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:+StressGCM + * -XX:+StressLCM -XX:+UseShenandoahGC -XX:LoopMaxUnroll=0 -XX:StressSeed=270847015 TestLoadBypassesNullCheck + * @run main/othervm -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:+StressGCM + * -XX:+StressLCM -XX:+UseShenandoahGC -XX:LoopMaxUnroll=0 TestLoadBypassesNullCheck + * + */ + +public class TestLoadBypassesNullCheck { + private static A fieldA = new A(); + private static Object fieldO = new Object(); + private static volatile int volatileField; + + public static void main(String[] args) { + for (int i = 0; i < 20_000; i++) { + test1(); + } + fieldA = null; + try { + test1(); + } catch (NullPointerException npe) { + } + } + + private static boolean test1() { + for (int i = 0; i < 1000; i++) { + volatileField = 42; + A a = fieldA; + Object o = a.fieldO; + if (o == fieldO) { + return true; + } + } + return false; + } + + private static class A { + public Object fieldO; + } +}