From d7aa34982053bad37b3b726539f1245d054258f4 Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Thu, 12 Jun 2025 07:08:39 +0000 Subject: [PATCH] 8357826: Avoid running some jtreg tests when asan is configured Reviewed-by: sspitsyn, amitkumar, lmesnik, syan, lucy, cjplummer --- src/hotspot/share/prims/whitebox.cpp | 26 +++++++++++++++++++ src/hotspot/share/prims/whitebox.hpp | 5 +++- test/hotspot/jtreg/TEST.ROOT | 2 ++ .../TestUseCompressedOopsFlagsWithUlimit.java | 2 ++ .../Thread/TestBreakSignalThreadDump.java | 2 ++ .../runtime/XCheckJniJsig/XCheckJSig.java | 2 ++ .../dcmd/vm/SystemDumpMapTest.java | 2 ++ .../serviceability/dcmd/vm/SystemMapTest.java | 4 +++ test/jdk/TEST.ROOT | 2 ++ test/jdk/build/AbsPathsInImage.java | 4 ++- test/jtreg-ext/requires/VMProps.java | 11 ++++++++ test/lib/jdk/test/whitebox/WhiteBox.java | 4 +++ 12 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 374e877faa6..1507696c4d3 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -1075,6 +1075,22 @@ bool WhiteBox::validate_cgroup(bool cgroups_v2_enabled, } #endif +bool WhiteBox::is_asan_enabled() { +#ifdef ADDRESS_SANITIZER + return true; +#else + return false; +#endif +} + +bool WhiteBox::is_ubsan_enabled() { +#ifdef UNDEFINED_BEHAVIOR_SANITIZER + return true; +#else + return false; +#endif +} + bool WhiteBox::compile_method(Method* method, int comp_level, int bci, JavaThread* THREAD) { // Screen for unavailable/bad comp level or null method AbstractCompiler* comp = CompileBroker::compiler(comp_level); @@ -1886,6 +1902,14 @@ WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj)) return (jboolean) obj_oop->mark().has_monitor(); WB_END +WB_ENTRY(jboolean, WB_IsAsanEnabled(JNIEnv* env)) + return (jboolean) WhiteBox::is_asan_enabled(); +WB_END + +WB_ENTRY(jboolean, WB_IsUbsanEnabled(JNIEnv* env)) + return (jboolean) WhiteBox::is_ubsan_enabled(); +WB_END + WB_ENTRY(jlong, WB_getInUseMonitorCount(JNIEnv* env, jobject wb)) return (jlong) WhiteBox::get_in_use_monitor_count(); WB_END @@ -2882,6 +2906,8 @@ static JNINativeMethod methods[] = { (void*)&WB_AddModuleExportsToAll }, {CC"deflateIdleMonitors", CC"()Z", (void*)&WB_DeflateIdleMonitors }, {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated }, + {CC"isAsanEnabled", CC"()Z", (void*)&WB_IsAsanEnabled }, + {CC"isUbsanEnabled", CC"()Z", (void*)&WB_IsUbsanEnabled }, {CC"getInUseMonitorCount", CC"()J", (void*)&WB_getInUseMonitorCount }, {CC"getLockStackCapacity", CC"()I", (void*)&WB_getLockStackCapacity }, {CC"supportsRecursiveLightweightLocking", CC"()Z", (void*)&WB_supportsRecursiveLightweightLocking }, diff --git a/src/hotspot/share/prims/whitebox.hpp b/src/hotspot/share/prims/whitebox.hpp index 4ba684fc09a..c20d35abbbb 100644 --- a/src/hotspot/share/prims/whitebox.hpp +++ b/src/hotspot/share/prims/whitebox.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, 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 @@ -72,6 +72,9 @@ class WhiteBox : public AllStatic { #ifdef LINUX static bool validate_cgroup(bool cgroups_v2_enabled, const char* controllers_file, const char* proc_self_cgroup, const char* proc_self_mountinfo, u1* cg_flags); #endif + // provide info about enabling of Address Sanitizer / Undefined Behavior Sanitizer + static bool is_asan_enabled(); + static bool is_ubsan_enabled(); }; #endif // SHARE_PRIMS_WHITEBOX_HPP diff --git a/test/hotspot/jtreg/TEST.ROOT b/test/hotspot/jtreg/TEST.ROOT index 8f4ef153907..9071dfa2fbf 100644 --- a/test/hotspot/jtreg/TEST.ROOT +++ b/test/hotspot/jtreg/TEST.ROOT @@ -91,6 +91,8 @@ requires.properties= \ vm.compiler1.enabled \ vm.compiler2.enabled \ vm.musl \ + vm.asan \ + vm.ubsan \ vm.flagless \ container.support \ systemd.support \ diff --git a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java index 40d83739ef5..40f607bf8a1 100644 --- a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java +++ b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java @@ -31,6 +31,8 @@ package gc.arguments; * @library /test/lib * @library / * @requires vm.bits == "64" + * @comment ulimit clashes with the memory requirements of ASAN + * @requires !vm.asan * @requires os.family == "linux" * @requires vm.gc != "Z" * @requires vm.opt.UseCompressedOops == null diff --git a/test/hotspot/jtreg/runtime/Thread/TestBreakSignalThreadDump.java b/test/hotspot/jtreg/runtime/Thread/TestBreakSignalThreadDump.java index b985e15bd17..011f6979431 100644 --- a/test/hotspot/jtreg/runtime/Thread/TestBreakSignalThreadDump.java +++ b/test/hotspot/jtreg/runtime/Thread/TestBreakSignalThreadDump.java @@ -38,6 +38,8 @@ * @requires os.family != "windows" & os.family != "aix" * @comment TODO: Decide libjsig support on static JDK with 8351367 * @requires !jdk.static + * @comment loading of the jsig lib does currently not work well with ASAN lib + * @requires !vm.asan * @library /vmTestbase * /test/lib * @run driver TestBreakSignalThreadDump load_libjsig diff --git a/test/hotspot/jtreg/runtime/XCheckJniJsig/XCheckJSig.java b/test/hotspot/jtreg/runtime/XCheckJniJsig/XCheckJSig.java index a8010506d96..6dbe42cebb0 100644 --- a/test/hotspot/jtreg/runtime/XCheckJniJsig/XCheckJSig.java +++ b/test/hotspot/jtreg/runtime/XCheckJniJsig/XCheckJSig.java @@ -29,6 +29,8 @@ * @modules java.base/jdk.internal.misc * java.management * @requires os.family == "linux" | os.family == "mac" + * @comment loading of the jsig lib does currently not work well with ASAN lib + * @requires !vm.asan * @comment TODO: Decide libjsig support on static JDK with 8351367 * @requires !jdk.static * @run driver XCheckJSig diff --git a/test/hotspot/jtreg/serviceability/dcmd/vm/SystemDumpMapTest.java b/test/hotspot/jtreg/serviceability/dcmd/vm/SystemDumpMapTest.java index 1911862b361..8b8ed0b53ab 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/vm/SystemDumpMapTest.java +++ b/test/hotspot/jtreg/serviceability/dcmd/vm/SystemDumpMapTest.java @@ -36,6 +36,8 @@ import java.util.regex.Pattern; * @summary Test of diagnostic command System.map * @library /test/lib * @requires (os.family == "linux" | os.family == "windows" | os.family == "mac") + * @comment ASAN changes the memory map dump slightly, but the test has rather strict requirements + * @requires !vm.asan * @requires os.arch != "riscv64" | !(vm.cpu.features ~= ".*qemu.*") * @modules java.base/jdk.internal.misc * java.compiler diff --git a/test/hotspot/jtreg/serviceability/dcmd/vm/SystemMapTest.java b/test/hotspot/jtreg/serviceability/dcmd/vm/SystemMapTest.java index 283dd4bae72..dcc451d41be 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/vm/SystemMapTest.java +++ b/test/hotspot/jtreg/serviceability/dcmd/vm/SystemMapTest.java @@ -32,6 +32,8 @@ import jdk.test.lib.process.OutputAnalyzer; * @summary Test of diagnostic command System.map * @library /test/lib * @requires (vm.gc != "Z") & (os.family == "linux" | os.family == "windows" | os.family == "mac") + * @comment ASAN changes the memory map dump slightly, but the test has rather strict requirements + * @requires !vm.asan * @modules java.base/jdk.internal.misc * java.compiler * java.management @@ -47,6 +49,8 @@ import jdk.test.lib.process.OutputAnalyzer; * @summary Test of diagnostic command System.map using ZGC * @library /test/lib * @requires vm.gc.Z & (os.family == "linux" | os.family == "windows" | os.family == "mac") + * @comment ASAN changes the memory map dump slightly, but the test has rather strict requirements + * @requires !vm.asan * @modules java.base/jdk.internal.misc * java.compiler * java.management diff --git a/test/jdk/TEST.ROOT b/test/jdk/TEST.ROOT index 97efc340019..0fa78bebc3f 100644 --- a/test/jdk/TEST.ROOT +++ b/test/jdk/TEST.ROOT @@ -102,6 +102,8 @@ requires.properties= \ vm.cds.write.archived.java.heap \ vm.continuations \ vm.musl \ + vm.asan \ + vm.ubsan \ vm.debug \ vm.hasSA \ vm.hasJFR \ diff --git a/test/jdk/build/AbsPathsInImage.java b/test/jdk/build/AbsPathsInImage.java index 7821b60670a..1aa7e59941e 100644 --- a/test/jdk/build/AbsPathsInImage.java +++ b/test/jdk/build/AbsPathsInImage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -40,6 +40,8 @@ import java.util.zip.ZipInputStream; * @bug 8226346 * @summary Check all output files for absolute path fragments * @requires !vm.debug + * @comment ASAN keeps the 'unwanted' paths in the binaries because of its build options + * @requires !vm.asan * @run main/othervm -Xmx900m AbsPathsInImage */ public class AbsPathsInImage { diff --git a/test/jtreg-ext/requires/VMProps.java b/test/jtreg-ext/requires/VMProps.java index 360c96c74ef..3c7a81cd2fa 100644 --- a/test/jtreg-ext/requires/VMProps.java +++ b/test/jtreg-ext/requires/VMProps.java @@ -138,6 +138,8 @@ public class VMProps implements Callable> { map.put("container.support", this::containerSupport); map.put("systemd.support", this::systemdSupport); map.put("vm.musl", this::isMusl); + map.put("vm.asan", this::isAsanEnabled); + map.put("vm.ubsan", this::isUbsanEnabled); map.put("release.implementor", this::implementor); map.put("jdk.containerized", this::jdkContainerized); map.put("vm.flagless", this::isFlagless); @@ -728,6 +730,15 @@ public class VMProps implements Callable> { return Boolean.toString(WB.getLibcName().contains("musl")); } + // Sanitizer support + protected String isAsanEnabled() { + return "" + WB.isAsanEnabled(); + } + + protected String isUbsanEnabled() { + return "" + WB.isUbsanEnabled(); + } + private String implementor() { try (InputStream in = new BufferedInputStream(new FileInputStream( System.getProperty("java.home") + "/release"))) { diff --git a/test/lib/jdk/test/whitebox/WhiteBox.java b/test/lib/jdk/test/whitebox/WhiteBox.java index d1f2c5822af..f3d9ba7b6e9 100644 --- a/test/lib/jdk/test/whitebox/WhiteBox.java +++ b/test/lib/jdk/test/whitebox/WhiteBox.java @@ -322,6 +322,10 @@ public class WhiteBox { public native void NMTFreeArena(long arena); public native void NMTArenaMalloc(long arena, long size); + // Sanitizers + public native boolean isAsanEnabled(); + public native boolean isUbsanEnabled(); + // Compiler // Determines if the libgraal shared library file is present.