Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/debug.hpp
32285 views
/*1* Copyright (c) 1997, 2017, 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_VM_UTILITIES_DEBUG_HPP25#define SHARE_VM_UTILITIES_DEBUG_HPP2627#include "utilities/globalDefinitions.hpp"28#include "prims/jvm.h"2930#include <stdarg.h>3132// Simple class to format the ctor arguments into a fixed-sized buffer.33class FormatBufferBase {34protected:35char* _buf;36inline FormatBufferBase(char* buf) : _buf(buf) {}37public:38operator const char *() const { return _buf; }39};4041// Use resource area for buffer42#define RES_BUFSZ 25643class FormatBufferResource : public FormatBufferBase {44public:45FormatBufferResource(const char * format, ...) ATTRIBUTE_PRINTF(2, 3);46};4748// Use stack for buffer49template <size_t bufsz = 256>50class FormatBuffer : public FormatBufferBase {51public:52inline FormatBuffer(const char * format, ...) ATTRIBUTE_PRINTF(2, 3);53inline void append(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);54inline void print(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);55inline void printv(const char* format, va_list ap) ATTRIBUTE_PRINTF(2, 0);5657char* buffer() { return _buf; }58int size() { return bufsz; }5960private:61FormatBuffer(const FormatBuffer &); // prevent copies62char _buffer[bufsz];6364protected:65inline FormatBuffer();66};6768template <size_t bufsz>69FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) : FormatBufferBase(_buffer) {70va_list argp;71va_start(argp, format);72jio_vsnprintf(_buf, bufsz, format, argp);73va_end(argp);74}7576template <size_t bufsz>77FormatBuffer<bufsz>::FormatBuffer() : FormatBufferBase(_buffer) {78_buf[0] = '\0';79}8081template <size_t bufsz>82void FormatBuffer<bufsz>::print(const char * format, ...) {83va_list argp;84va_start(argp, format);85jio_vsnprintf(_buf, bufsz, format, argp);86va_end(argp);87}8889template <size_t bufsz>90void FormatBuffer<bufsz>::printv(const char * format, va_list argp) {91jio_vsnprintf(_buf, bufsz, format, argp);92}9394template <size_t bufsz>95void FormatBuffer<bufsz>::append(const char* format, ...) {96// Given that the constructor does a vsnprintf we can assume that97// _buf is already initialized.98size_t len = strlen(_buf);99char* buf_end = _buf + len;100101va_list argp;102va_start(argp, format);103jio_vsnprintf(buf_end, bufsz - len, format, argp);104va_end(argp);105}106107// Used to format messages for assert(), guarantee(), fatal(), etc.108typedef FormatBuffer<> err_msg;109typedef FormatBufferResource err_msg_res;110111// assertions112#ifdef ASSERT113#ifndef USE_REPEATED_ASSERTS114#define assert(p, msg) \115do { \116if (!(p)) { \117report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \118BREAKPOINT; \119} \120} while (0)121#else // #ifndef USE_REPEATED_ASSERTS122#define assert(p, msg)123do { \124for (int __i = 0; __i < AssertRepeat; __i++) { \125if (!(p)) { \126report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \127BREAKPOINT; \128} \129} \130} while (0)131#endif // #ifndef USE_REPEATED_ASSERTS132133// This version of assert is for use with checking return status from134// library calls that return actual error values eg. EINVAL,135// ENOMEM etc, rather than returning -1 and setting errno.136// When the status is not what is expected it is very useful to know137// what status was actually returned, so we pass the status variable as138// an extra arg and use strerror to convert it to a meaningful string139// like "Invalid argument", "out of memory" etc140#define assert_status(p, status, msg) \141do { \142if (!(p)) { \143report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", \144err_msg("error %s(%d) %s", strerror(status), \145status, msg)); \146BREAKPOINT; \147} \148} while (0)149150// Do not assert this condition if there's already another error reported.151#define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)152#else // #ifdef ASSERT153#define assert(p,msg)154#define assert_status(p,status,msg)155#define assert_if_no_error(cond,msg)156#endif // #ifdef ASSERT157158// guarantee is like assert except it's always executed -- use it for159// cheap tests that catch errors that would otherwise be hard to find.160// guarantee is also used for Verify options.161#define guarantee(p, msg) \162do { \163if (!(p)) { \164report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg); \165BREAKPOINT; \166} \167} while (0)168169#define fatal(msg) \170do { \171report_fatal(__FILE__, __LINE__, msg); \172BREAKPOINT; \173} while (0)174175// out of memory176#define vm_exit_out_of_memory(size, vm_err_type, msg) \177do { \178report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, msg); \179BREAKPOINT; \180} while (0)181182#define ShouldNotCallThis() \183do { \184report_should_not_call(__FILE__, __LINE__); \185BREAKPOINT; \186} while (0)187188#define ShouldNotReachHere() \189do { \190report_should_not_reach_here(__FILE__, __LINE__); \191BREAKPOINT; \192} while (0)193194#define Unimplemented() \195do { \196report_unimplemented(__FILE__, __LINE__); \197BREAKPOINT; \198} while (0)199200#define Untested(msg) \201do { \202report_untested(__FILE__, __LINE__, msg); \203BREAKPOINT; \204} while (0);205206207// types of VM error - originally in vmError.hpp208enum VMErrorType {209INTERNAL_ERROR = 0xe0000000,210OOM_MALLOC_ERROR = 0xe0000001,211OOM_MMAP_ERROR = 0xe0000002212};213214// error reporting helper functions215void report_vm_error(const char* file, int line, const char* error_msg,216const char* detail_msg = NULL);217void report_fatal(const char* file, int line, const char* message);218void report_vm_out_of_memory(const char* file, int line, size_t size,219VMErrorType vm_err_type, const char* message);220void report_should_not_call(const char* file, int line);221void report_should_not_reach_here(const char* file, int line);222void report_unimplemented(const char* file, int line);223void report_untested(const char* file, int line, const char* message);224void report_insufficient_metaspace(size_t required_size);225226void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);227228#ifdef ASSERT229// Compile-time asserts.230template <bool> struct StaticAssert;231template <> struct StaticAssert<true> {};232233// Only StaticAssert<true> is defined, so if cond evaluates to false we get234// a compile time exception when trying to use StaticAssert<false>.235#define STATIC_ASSERT(cond) \236do { \237StaticAssert<(cond)> DUMMY_STATIC_ASSERT; \238(void)DUMMY_STATIC_ASSERT; /* ignore */ \239} while (false)240#else241#define STATIC_ASSERT(cond)242#endif243244// out of shared space reporting245enum SharedSpaceType {246SharedPermGen,247SharedReadOnly,248SharedReadWrite,249SharedMiscData,250SharedMiscCode251};252253void report_out_of_shared_space(SharedSpaceType space_type);254255// out of memory reporting256void report_java_out_of_memory(const char* message);257258// Support for self-destruct259bool is_error_reported();260void set_error_reported();261262/* Test assert(), fatal(), guarantee(), etc. */263NOT_PRODUCT(void test_error_handler();)264265void pd_ps(frame f);266void pd_obfuscate_location(char *buf, size_t buflen);267268class outputStream;269void print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size);270271#endif // SHARE_VM_UTILITIES_DEBUG_HPP272273274