8299254: Support dealing with standard assert macro
Reviewed-by: erikj, xuelei, dholmes, mikael
This commit is contained in:
parent
a49ccb959b
commit
3e2314d082
@ -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
|
||||
|
36
src/hotspot/share/utilities/vmassert_reinstall.hpp
Normal file
36
src/hotspot/share/utilities/vmassert_reinstall.hpp
Normal file
@ -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
src/hotspot/share/utilities/vmassert_uninstall.hpp
Normal file
45
src/hotspot/share/utilities/vmassert_uninstall.hpp
Normal file
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 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
|
||||
@ -29,9 +29,12 @@
|
||||
#include "asm/macroAssembler.inline.hpp"
|
||||
#include "compiler/disassembler.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "unittest.hpp"
|
||||
|
||||
#include "utilities/vmassert_uninstall.hpp"
|
||||
#include <regex>
|
||||
#include "utilities/vmassert_reinstall.hpp"
|
||||
|
||||
#include "unittest.hpp"
|
||||
|
||||
static const char* replace_addr_expr(const char* str)
|
||||
{
|
||||
|
@ -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 <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;
|
||||
|
@ -24,10 +24,14 @@
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "gc/shenandoah/shenandoahNumberSeq.hpp"
|
||||
#include <iostream>
|
||||
#include "unittest.hpp"
|
||||
#include "utilities/ostream.hpp"
|
||||
|
||||
#include "utilities/vmassert_uninstall.hpp"
|
||||
#include <iostream>
|
||||
#include "utilities/vmassert_reinstall.hpp"
|
||||
|
||||
#include "unittest.hpp"
|
||||
|
||||
class ShenandoahNumberSeqTest: public ::testing::Test {
|
||||
protected:
|
||||
HdrSeq seq;
|
||||
|
@ -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
|
||||
@ -41,11 +41,14 @@
|
||||
#include "runtime/os_perf.hpp"
|
||||
#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 {
|
||||
|
||||
|
@ -48,26 +48,16 @@
|
||||
#undef F1
|
||||
#undef F2
|
||||
|
||||
#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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user