From aca06320cf0d67da7d133027ac3bbf0bcd51e9ae Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Wed, 26 Feb 2025 15:32:11 +0100 Subject: [PATCH 1/2] Added detection on target JDK version --- .../openjdk/jcstress/vm/TargetJvmVersion.java | 44 +++++++++++++++++ .../org/openjdk/jcstress/vm/VMSupport.java | 49 +++++++++++++++++-- 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 jcstress-core/src/main/java/org/openjdk/jcstress/vm/TargetJvmVersion.java diff --git a/jcstress-core/src/main/java/org/openjdk/jcstress/vm/TargetJvmVersion.java b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/TargetJvmVersion.java new file mode 100644 index 00000000..ff176336 --- /dev/null +++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/TargetJvmVersion.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.openjdk.jcstress.vm; + +public class TargetJvmVersion { + + /** + * The "return" message is parsed ond colon and brackets. + * + * @param args + */ + public static void main(String... args) { + try { + Runtime.Version version = Runtime.version(); + System.out.println("Detected: " + version.feature() + " (" + version + ")"); + } catch (Throwable ex) { + System.out.println("Runtime.Version not found, fallback to: 8 (" + System.getProperty("java.version", "unknown)") + ")"); + System.exit(0); + } + } + +} diff --git a/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java index b68c9e2f..7a676d24 100644 --- a/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java +++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java @@ -41,6 +41,16 @@ public class VMSupport { + private static class ResultWithMessage { + private final boolean result; + private final String message; + + public ResultWithMessage(boolean result, String message) { + this.result = result; + this.message = message; + } + } + private static final List GLOBAL_JVM_FLAGS = new ArrayList<>(); private static final List C2_STRESS_JVM_FLAGS = new ArrayList<>(); private static final List C2_ONLY_STRESS_JVM_FLAGS = new ArrayList<>(); @@ -50,6 +60,8 @@ public class VMSupport { private static volatile boolean COMPILER_DIRECTIVES_AVAILABLE; private static volatile boolean PRINT_ASSEMBLY_AVAILABLE; private static volatile boolean STRESS_SEED_AVAILABLE; + private static volatile int JDK_VERSION_MAJOR; + private static volatile String JDK_VERSION_MAJOR_FULL = "undetected"; private static volatile boolean C1_AVAILABLE; private static volatile boolean C2_AVAILABLE; @@ -80,6 +92,10 @@ public static boolean c2Available() { return C2_AVAILABLE; } + public static int getJdkVersionMajor() { + return JDK_VERSION_MAJOR; + } + public static boolean enableNativeAccessAvailable() { return ENABLE_NATIVE_ACCESS_AVAILABLE; } @@ -93,6 +109,14 @@ public static void initFlags(Options opts) { System.out.println(" (all failures are non-fatal, but may affect testing accuracy)"); System.out.println(); + ResultWithMessage futureJdkVersionMajor = + detectWithMessage("Checking JVM feature version", + true, + TargetJvmVersion.class, + null + ); + setDetectedJdkVersion(futureJdkVersionMajor); + detect("Unlocking diagnostic VM options", true, SimpleTestMain.class, @@ -383,21 +407,40 @@ public static void initFlags(Options opts) { System.out.println(); } + private static void setDetectedJdkVersion(ResultWithMessage futureJdkVersionMajor) { + if (futureJdkVersionMajor.result && futureJdkVersionMajor.message!=null){ + try { + JDK_VERSION_MAJOR = Integer.parseInt(futureJdkVersionMajor.message.replaceAll(".*: ", "").replaceAll(" .*", "").trim()); + JDK_VERSION_MAJOR_FULL=futureJdkVersionMajor.message.replaceAll(".*\\(", "").replaceAll("\\).*", "").trim(); + }catch(Exception ex){ + JDK_VERSION_MAJOR = 8; + JDK_VERSION_MAJOR_FULL=futureJdkVersionMajor.message; + } + } else { + JDK_VERSION_MAJOR = 8; + } + } + private static boolean detect(String label, boolean expectPass, Class mainClass, List list, String... opts) { + return detectWithMessage(label, expectPass, mainClass, list, opts).result; + } + + private static ResultWithMessage detectWithMessage(String label, boolean expectPass, Class mainClass, List list, String... opts) { + String msg = "Message not received"; try { String[] arguments = ArrayUtils.concat(opts, mainClass.getName()); - tryWith(arguments); + msg = tryWith(arguments); if (list != null) { list.addAll(Arrays.asList(opts)); } System.out.printf("----- %s %s%n", "[OK]", label); - return true; + return new ResultWithMessage(true, msg); } catch (VMSupportException ex) { System.out.printf("----- %s %s%n", "[N/A]", label); if (expectPass) { System.out.println(ex.getMessage()); } - return false; + return new ResultWithMessage(false, msg); } } From 13537f78a2db8fbce13c081e59c0b0568225668e Mon Sep 17 00:00:00 2001 From: Jiri Date: Wed, 26 Feb 2025 18:39:42 +0100 Subject: [PATCH 2/2] Excluding jdk23+ illegible tests on jdk23+ --- .../java/org/openjdk/jcstress/JCStress.java | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java index 1a488269..9c378516 100644 --- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java +++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java @@ -40,6 +40,7 @@ import java.io.*; import java.util.*; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * JCStress main entry point. @@ -237,15 +238,46 @@ private void forkedUnified(List testConfigs, VMSupport.Config config public SortedSet getTests() { String filter = opts.getTestFilter(); SortedSet s = new TreeSet<>(); - + Pattern byteArrayAndBufferExclusion = null; + if (VMSupport.getJdkVersionMajor() > 22) { + String regexPrefix = "org.openjdk.jcstress.tests".replace(".", "\\."); + String[] members = new String[]{ + "accessAtomic.varHandles.byteArray", + "accessAtomic.varHandles.byteBuffer", + "acqrel.varHandles.byteArray", + "acqrel.vHandles.byteBuffer", + "atomicity.varHandles.byteArray", + "atomicity.varHandles.byteBuffer", + "coherence.varHandles.byteArray", + "coherence.varHandles.byteBuffer"}; + String regexBody = "(" + Arrays.stream(members).map(ss -> ss.replace(".", "\\.")).collect(Collectors.joining("|")) + ")"; + String regexSuffix = "(big|heap|little).*"; + byteArrayAndBufferExclusion = Pattern.compile(regexPrefix + "\\." + regexBody + "\\." + regexSuffix); + } Pattern pattern = Pattern.compile(filter); + int excludedBuffersAndArrays = 0; for (String testName : TestList.tests()) { if (pattern.matcher(testName).find()) { - s.add(testName); + if (byteArrayAndBufferExclusion != null && byteArrayAndBufferExclusion.matcher(testName).find()) { + excludedBuffersAndArrays++; + } else { + s.add(testName); + } } } + if (excludedBuffersAndArrays > 0) { + out.println(); + out.println("Warning! JDK 23 or newer detected and " + excludedBuffersAndArrays + " of selected " + (s.size() + excludedBuffersAndArrays) + " (from total " + TestList.tests().size() + ") tests were excluded by:"); + out.println(byteArrayAndBufferExclusion.toString().replaceAll("\\\\", "")); + out.println("This is known bug: https://bugs.openjdk.org/browse/CODETOOLS-7903671"); + out.println("This is temporarily workaround and issue should be fixed soon."); + if (s.isEmpty()) { + out.println("Warning! Nothing remained!"); + } + out.println(); + } return s; - } + } public int listTests(Options opts) { JCStress.ConfigsWithScheduler configsWithScheduler = getConfigs();