diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java b/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java index 00b5becdbfa..805df110e9d 100644 --- a/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java +++ b/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -113,8 +113,14 @@ public class TestDwarf { new DwarfConstraint(0, "foo", "libTestDwarf.c", 42), new DwarfConstraint(1, "Java_TestDwarf_crashNativeMultipleMethods", "libTestDwarf.c", 70)); } - runAndCheck(new Flags(TestDwarf.class.getCanonicalName(), "nativeDereferenceNull"), - new DwarfConstraint(0, "dereference_null", "libTestDwarfHelper.h", 46)); + // Null pointer dereferences exhibit different behaviour depending on if GCC or Clang is used. + // When using GCC, the VM will crash gracefully and generate a hs_err which can be parsed. + // On the contrary, with Clang the process exits immediately without hs_err. + // Since runAndCheck needs an hs_err file, we have to skip this subtest. + if (!isUsingClang()) { + runAndCheck(new Flags(TestDwarf.class.getCanonicalName(), "nativeDereferenceNull"), + new DwarfConstraint(0, "dereference_null", "libTestDwarfHelper.h", 46)); + } } // A full pattern could check for lines like: @@ -240,6 +246,7 @@ public class TestDwarf { private static native void crashNativeDivByZero(); private static native void crashNativeDereferenceNull(); private static native void crashNativeMultipleMethods(int x); + private static native boolean isUsingClang(); } class UnsupportedDwarfVersionException extends RuntimeException { } diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarf.c b/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarf.c index 616a6f07d12..6d2051d2126 100644 --- a/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarf.c +++ b/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -28,8 +28,8 @@ int zero = 0; int result = 0; int limit = 20; -// Just big enough by doing some random things such that it is not inlined. -void foo(int x) { +// Explicitly don't inline: foo is large enough that GCC won't inline it, but Clang might. +__attribute__((noinline)) void foo(int x) { printf("foo3:"); printf(" %d\n", x); for (int i = 0; i < limit; i++) { @@ -76,3 +76,12 @@ JNIEXPORT void JNICALL Java_TestDwarf_crashNativeMultipleMethods(JNIEnv* env, jc } } +// Need to tell if Clang was used to build libTestDwarf. +JNIEXPORT jboolean JNICALL Java_TestDwarf_isUsingClang(JNIEnv* env, jobject obj) { +#if defined(__clang__) + return JNI_TRUE; +#else + return JNI_FALSE; +#endif +} + diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h b/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h index 1da05c1c3d3..bca362ccd65 100644 --- a/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h +++ b/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -41,7 +41,7 @@ void unused4() { void unused5() { } -EXPORT void dereference_null() { +__attribute__((noinline)) EXPORT void dereference_null() { int* x = (int*)0; *x = 34; // Crash }