Skip to content

Commit

Permalink
Backport 89dd23f2fab0d98879e68f817923656e113087e3
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiro committed Sep 19, 2024
1 parent a6eaa75 commit c7a6fe0
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 7 deletions.
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, 2024, 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
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, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, 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
5 changes: 4 additions & 1 deletion test/hotspot/gtest/unittest.hpp
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, 2024, 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 @@ -28,7 +28,10 @@
#include <stdio.h>

#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.
Expand Down

0 comments on commit c7a6fe0

Please sign in to comment.