From 301dce868d747a534bc476460d9d1323cbf0bbac Mon Sep 17 00:00:00 2001 From: Elif Aslan <116521601+elifaslan1@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:16:26 -0700 Subject: [PATCH] 3e2314d08218dc8a4f4fc61bd4e1d5e58a0129c7 backport (#350) --- make/hotspot/lib/JvmFlags.gmk | 4 +- .../share/utilities/vmassert_reinstall.hpp | 36 +++++++++++++++ .../share/utilities/vmassert_uninstall.hpp | 45 +++++++++++++++++++ .../test_memset_with_concurrent_readers.cpp | 7 ++- .../gtest/jfr/test_networkUtilization.cpp | 10 ++++- test/hotspot/gtest/unittest.hpp | 15 ++----- 6 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 src/hotspot/share/utilities/vmassert_reinstall.hpp create mode 100644 src/hotspot/share/utilities/vmassert_uninstall.hpp diff --git a/make/hotspot/lib/JvmFlags.gmk b/make/hotspot/lib/JvmFlags.gmk index 3246c83155b..1a91eb0079d 100644 --- a/make/hotspot/lib/JvmFlags.gmk +++ b/make/hotspot/lib/JvmFlags.gmk @@ -67,10 +67,12 @@ JVM_CFLAGS_TARGET_DEFINES += \ # ifeq ($(DEBUG_LEVEL), release) + # release builds disable uses of assert macro from . + JVM_CFLAGS_DEBUGLEVEL := -DNDEBUG # For hotspot, release builds differ internally between "optimized" and "product" # in that "optimize" does not define PRODUCT. ifneq ($(HOTSPOT_DEBUG_LEVEL), optimized) - JVM_CFLAGS_DEBUGLEVEL := -DPRODUCT + JVM_CFLAGS_DEBUGLEVEL += -DPRODUCT endif else ifeq ($(DEBUG_LEVEL), fastdebug) JVM_CFLAGS_DEBUGLEVEL := -DASSERT diff --git a/src/hotspot/share/utilities/vmassert_reinstall.hpp b/src/hotspot/share/utilities/vmassert_reinstall.hpp new file mode 100644 index 00000000000..32d31ac0c4f --- /dev/null +++ b/src/hotspot/share/utilities/vmassert_reinstall.hpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022, 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. + * + */ + +// Intentionally no #include guard. May be included multiple times for effect. + +// See vmassert_uninstall.hpp for usage. + +// Remove possible stdlib assert macro (or any others, for that matter). +#undef assert + +// Reinstall HotSpot's assert macro, if previously defined. +#ifdef vmassert +#define assert(p, ...) vmassert(p, __VA_ARGS__) +#endif + diff --git a/src/hotspot/share/utilities/vmassert_uninstall.hpp b/src/hotspot/share/utilities/vmassert_uninstall.hpp new file mode 100644 index 00000000000..dd6d51633dd --- /dev/null +++ b/src/hotspot/share/utilities/vmassert_uninstall.hpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022, 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. + * + */ + +// Intentionally no #include guard. May be included multiple times for effect. + +// The files vmassert_uninstall.hpp and vmassert_reinstall.hpp provide a +// workaround for the name collision between HotSpot's assert macro and the +// Standard Library's assert macro. When including a 3rd-party header that +// uses (and so includes) the standard assert macro, wrap that inclusion with +// includes of these two files, e.g. +// +// #include "utilities/vmassert_uninstall.hpp" +// #include
+// #include "utilities/vmassert_reinstall.hpp" +// +// This removes the HotSpot macro definition while pre-processing the +// 3rd-party header, then reinstates the HotSpot macro (if previously defined) +// for following code. + +// Remove HotSpot's assert macro, if present. +#ifdef vmassert +#undef assert +#endif // vmassert + diff --git a/test/hotspot/gtest/gc/shared/test_memset_with_concurrent_readers.cpp b/test/hotspot/gtest/gc/shared/test_memset_with_concurrent_readers.cpp index 24f25b87af9..7a3845e336a 100644 --- a/test/hotspot/gtest/gc/shared/test_memset_with_concurrent_readers.cpp +++ b/test/hotspot/gtest/gc/shared/test_memset_with_concurrent_readers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2022, 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 @@ -24,10 +24,13 @@ #include "precompiled.hpp" #include "gc/shared/memset_with_concurrent_readers.hpp" #include "utilities/globalDefinitions.hpp" -#include "unittest.hpp" +#include "utilities/vmassert_uninstall.hpp" #include #include +#include "utilities/vmassert_reinstall.hpp" + +#include "unittest.hpp" static unsigned line_byte(const char* line, size_t i) { return unsigned(line[i]) & 0xFF; diff --git a/test/hotspot/gtest/jfr/test_networkUtilization.cpp b/test/hotspot/gtest/jfr/test_networkUtilization.cpp index 19d6a6e2c27..b88afd071fc 100644 --- a/test/hotspot/gtest/jfr/test_networkUtilization.cpp +++ b/test/hotspot/gtest/jfr/test_networkUtilization.cpp @@ -1,5 +1,9 @@ /* +<<<<<<< HEAD * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. +======= + * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. +>>>>>>> 3e2314d0821 (8299254: Support dealing with standard assert macro) * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,11 +46,13 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/growableArray.hpp" -#include "unittest.hpp" - +#include "utilities/vmassert_uninstall.hpp" #include #include #include +#include "utilities/vmassert_reinstall.hpp" + +#include "unittest.hpp" namespace { diff --git a/test/hotspot/gtest/unittest.hpp b/test/hotspot/gtest/unittest.hpp index 0494a0e2408..27350f91594 100644 --- a/test/hotspot/gtest/unittest.hpp +++ b/test/hotspot/gtest/unittest.hpp @@ -28,19 +28,10 @@ #include #define GTEST_DONT_DEFINE_TEST 1 +#include "utilities/vmassert_uninstall.hpp" #include "gtest/gtest.h" +#include "utilities/vmassert_reinstall.hpp" -// gtest/gtest.h includes assert.h which will define the assert macro, but hotspot has its -// own standards incompatible assert macro that takes two parameters. -// The workaround is to undef assert and then re-define it. The re-definition -// must unfortunately be copied since debug.hpp might already have been -// included and a second include wouldn't work due to the header guards in debug.hpp. -#ifdef assert - #undef assert - #ifdef vmassert - #define assert(p, ...) vmassert(p, __VA_ARGS__) - #endif -#endif #define CONCAT(a, b) a ## b @@ -114,4 +105,4 @@ TEST_VM_ASSERT_MSG is only available in debug builds #endif -#endif // UNITTEST_HPP +#endif // UNITTEST_HPP \ No newline at end of file