Path: blob/master/src/hotspot/share/utilities/debug.hpp
40949 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_UTILITIES_DEBUG_HPP25#define SHARE_UTILITIES_DEBUG_HPP2627#include "utilities/breakpoint.hpp"28#include "utilities/compilerWarnings.hpp"29#include "utilities/macros.hpp"3031#include <stddef.h>3233// ShowRegistersOnAssert support (for now Linux only)34#if defined(LINUX) && !defined(ZERO)35#define CAN_SHOW_REGISTERS_ON_ASSERT36extern char* g_assert_poison;37#define TOUCH_ASSERT_POISON (*g_assert_poison) = 'X';38void initialize_assert_poison();39void disarm_assert_poison();40bool handle_assert_poison_fault(const void* ucVoid, const void* faulting_address);41#else42#define TOUCH_ASSERT_POISON43#endif // CAN_SHOW_REGISTERS_ON_ASSERT4445// assertions46#ifndef ASSERT47#define vmassert(p, ...)48#else49// Note: message says "assert" rather than "vmassert" for backward50// compatibility with tools that parse/match the message text.51// Note: The signature is vmassert(p, format, ...), but the solaris52// compiler can't handle an empty ellipsis in a macro without a warning.53#define vmassert(p, ...) \54do { \55if (!(p)) { \56TOUCH_ASSERT_POISON; \57report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", __VA_ARGS__); \58BREAKPOINT; \59} \60} while (0)61#endif6263// For backward compatibility.64#define assert(p, ...) vmassert(p, __VA_ARGS__)6566#define precond(p) assert(p, "precond")67#define postcond(p) assert(p, "postcond")6869#ifndef ASSERT70#define vmassert_status(p, status, msg)71#else72// This version of vmassert is for use with checking return status from73// library calls that return actual error values eg. EINVAL,74// ENOMEM etc, rather than returning -1 and setting errno.75// When the status is not what is expected it is very useful to know76// what status was actually returned, so we pass the status variable as77// an extra arg and use strerror to convert it to a meaningful string78// like "Invalid argument", "out of memory" etc79#define vmassert_status(p, status, msg) \80do { \81if (!(p)) { \82TOUCH_ASSERT_POISON; \83report_vm_status_error(__FILE__, __LINE__, "assert(" #p ") failed", \84status, msg); \85BREAKPOINT; \86} \87} while (0)88#endif8990// For backward compatibility.91#define assert_status(p, status, msg) vmassert_status(p, status, msg)9293// guarantee is like vmassert except it's always executed -- use it for94// cheap tests that catch errors that would otherwise be hard to find.95// guarantee is also used for Verify options.96#define guarantee(p, ...) \97do { \98if (!(p)) { \99TOUCH_ASSERT_POISON; \100report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", __VA_ARGS__); \101BREAKPOINT; \102} \103} while (0)104105#define fatal(...) \106do { \107TOUCH_ASSERT_POISON; \108report_fatal(INTERNAL_ERROR, __FILE__, __LINE__, __VA_ARGS__); \109BREAKPOINT; \110} while (0)111112// out of memory113#define vm_exit_out_of_memory(size, vm_err_type, ...) \114do { \115report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, __VA_ARGS__); \116BREAKPOINT; \117} while (0)118119#define ShouldNotCallThis() \120do { \121TOUCH_ASSERT_POISON; \122report_should_not_call(__FILE__, __LINE__); \123BREAKPOINT; \124} while (0)125126#define ShouldNotReachHere() \127do { \128TOUCH_ASSERT_POISON; \129report_should_not_reach_here(__FILE__, __LINE__); \130BREAKPOINT; \131} while (0)132133#define Unimplemented() \134do { \135TOUCH_ASSERT_POISON; \136report_unimplemented(__FILE__, __LINE__); \137BREAKPOINT; \138} while (0)139140#define Untested(msg) \141do { \142report_untested(__FILE__, __LINE__, msg); \143BREAKPOINT; \144} while (0);145146147// types of VM error - originally in vmError.hpp148enum VMErrorType {149INTERNAL_ERROR = 0xe0000000,150OOM_MALLOC_ERROR = 0xe0000001,151OOM_MMAP_ERROR = 0xe0000002,152OOM_MPROTECT_ERROR = 0xe0000003,153OOM_JAVA_HEAP_FATAL = 0xe0000004154};155156// Set to suppress secondary error reporting.157// Really should have a qualified name or something.158extern bool Debugging;159160// error reporting helper functions161void report_vm_error(const char* file, int line, const char* error_msg);162void report_vm_error(const char* file, int line, const char* error_msg,163const char* detail_fmt, ...) ATTRIBUTE_PRINTF(4, 5);164void report_vm_status_error(const char* file, int line, const char* error_msg,165int status, const char* detail);166void report_fatal(VMErrorType error_type, const char* file, int line, const char* detail_fmt, ...) ATTRIBUTE_PRINTF(4, 5);167void report_vm_out_of_memory(const char* file, int line, size_t size, VMErrorType vm_err_type,168const char* detail_fmt, ...) ATTRIBUTE_PRINTF(5, 6);169void report_should_not_call(const char* file, int line);170void report_should_not_reach_here(const char* file, int line);171void report_unimplemented(const char* file, int line);172void report_untested(const char* file, int line, const char* message);173174void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);175176// Compile-time asserts. Cond must be a compile-time constant expression that177// is convertible to bool. STATIC_ASSERT() can be used anywhere a declaration178// may appear.179//180// Implementation Note: STATIC_ASSERT_FAILURE<true> provides a value member181// rather than type member that could be used directly in the typedef, because182// a type member would require conditional use of "typename", depending on183// whether Cond is dependent or not. The use of a value member leads to the184// use of an array type.185186template<bool x> struct STATIC_ASSERT_FAILURE;187template<> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };188189#define STATIC_ASSERT(Cond) \190typedef char PASTE_TOKENS(STATIC_ASSERT_DUMMY_TYPE_, __LINE__)[ \191STATIC_ASSERT_FAILURE< (Cond) >::value ]192193// out of memory reporting194void report_java_out_of_memory(const char* message);195196#endif // SHARE_UTILITIES_DEBUG_HPP197198199