Skip to content

Commit

Permalink
Support dealing with standard assert macro assert bug fix and disable…
Browse files Browse the repository at this point in the history
… gtest deprecated-copy
  • Loading branch information
elifaslan1 authored Oct 28, 2023
1 parent c10989e commit b0e7e0d
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 24 deletions.
4 changes: 2 additions & 2 deletions make/hotspot/lib/CompileGtest.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ $(eval $(call SetupJdkLibrary, BUILD_GTEST_LIBGTEST, \
$(GTEST_FRAMEWORK_SRC)/googlemock/src, \
INCLUDE_FILES := gtest-all.cc gmock-all.cc, \
DISABLED_WARNINGS_gcc := undef unused-result format-nonliteral maybe-uninitialized, \
DISABLED_WARNINGS_clang := undef unused-result format-nonliteral, \
DISABLED_WARNINGS_clang := deprecated-copy undef unused-result format-nonliteral, \
CFLAGS := $(JVM_CFLAGS) \
-I$(GTEST_FRAMEWORK_SRC)/googletest \
-I$(GTEST_FRAMEWORK_SRC)/googletest/include \
Expand Down Expand Up @@ -103,7 +103,7 @@ $(eval $(call SetupJdkLibrary, BUILD_GTEST_LIBJVM, \
DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc) \
undef stringop-overflow, \
DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang) \
undef switch format-nonliteral tautological-undefined-compare \
deprecated-copy undef switch format-nonliteral tautological-undefined-compare \
self-assign-overloaded, \
DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft), \
LDFLAGS := $(JVM_LDFLAGS), \
Expand Down
4 changes: 3 additions & 1 deletion make/hotspot/lib/JvmFlags.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ JVM_CFLAGS_TARGET_DEFINES += \
#

ifeq ($(DEBUG_LEVEL), release)
# release builds disable uses of assert macro from <assert.h>.
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
Expand Down
36 changes: 36 additions & 0 deletions src/hotspot/share/utilities/vmassert_reinstall.hpp
Original file line number Diff line number Diff line change
@@ -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

45 changes: 45 additions & 0 deletions src/hotspot/share/utilities/vmassert_uninstall.hpp
Original file line number Diff line number Diff line change
@@ -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 <header including standard assert macro>
// #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

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <string.h>
#include <sstream>
#include "utilities/vmassert_reinstall.hpp"

#include "unittest.hpp"

static unsigned line_byte(const char* line, size_t i) {
return unsigned(line[i]) & 0xFF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@

#include "precompiled.hpp"
#include "gc/shenandoah/shenandoahNumberSeq.hpp"
#include "utilities/ostream.hpp"

#include "utilities/vmassert_uninstall.hpp"
#include <iostream>
#include "utilities/vmassert_reinstall.hpp"

#include "unittest.hpp"
#include "utilities/ostream.hpp"

class ShenandoahNumberSeqTest: public ::testing::Test {
protected:
Expand Down
8 changes: 5 additions & 3 deletions test/hotspot/gtest/jfr/test_networkUtilization.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
Expand Down Expand Up @@ -42,11 +42,13 @@
#include "utilities/globalDefinitions.hpp"
#include "utilities/growableArray.hpp"

#include "unittest.hpp"

#include "utilities/vmassert_uninstall.hpp"
#include <vector>
#include <list>
#include <map>
#include "utilities/vmassert_reinstall.hpp"

#include "unittest.hpp"

namespace {

Expand Down
19 changes: 4 additions & 15 deletions test/hotspot/gtest/unittest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,18 @@
#undef F1
#undef F2

// A work around for GCC math header bug leaving isfinite() undefined,
// see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608
#include "utilities/globalDefinitions.hpp"

#include "utilities/vmassert_uninstall.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "utilities/vmassert_reinstall.hpp"

#ifdef UNDEFINED_Log
#define Log(...) LogImpl<LOG_TAGS(__VA_ARGS__)> // copied from logging/log.hpp
#undef UNDEFINED_Log
#endif

// 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
// Wrapper around os::exit so we don't need to include os.hpp here.
extern void gtest_exit_from_child_vm(int num);

#define CONCAT(a, b) a ## b

Expand Down

0 comments on commit b0e7e0d

Please sign in to comment.