0N/A/*
3157N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_UTILITIES_DEBUG_HPP
1879N/A#define SHARE_VM_UTILITIES_DEBUG_HPP
1879N/A
2208N/A#include "prims/jvm.h"
1879N/A#include "utilities/globalDefinitions.hpp"
1879N/A
1410N/A#include <stdarg.h>
1410N/A
1410N/A// Simple class to format the ctor arguments into a fixed-sized buffer.
3934N/Aclass FormatBufferBase {
3934N/A protected:
3934N/A char* _buf;
3934N/A inline FormatBufferBase(char* buf) : _buf(buf) {}
3934N/A public:
3934N/A operator const char *() const { return _buf; }
3934N/A};
3934N/A
3934N/A// Use resource area for buffer
3934N/A#define RES_BUFSZ 256
3934N/Aclass FormatBufferResource : public FormatBufferBase {
3934N/A public:
3934N/A FormatBufferResource(const char * format, ...);
3934N/A};
3934N/A
3934N/A// Use stack for buffer
1410N/Atemplate <size_t bufsz = 256>
3934N/Aclass FormatBuffer : public FormatBufferBase {
3157N/A public:
1410N/A inline FormatBuffer(const char * format, ...);
2037N/A inline void append(const char* format, ...);
3157N/A inline void print(const char* format, ...);
3157N/A inline void printv(const char* format, va_list ap);
1410N/A
3157N/A char* buffer() { return _buf; }
3157N/A int size() { return bufsz; }
3157N/A
3157N/A private:
1410N/A FormatBuffer(const FormatBuffer &); // prevent copies
3934N/A char _buffer[bufsz];
1410N/A
3157N/A protected:
3157N/A inline FormatBuffer();
1410N/A};
1410N/A
1410N/Atemplate <size_t bufsz>
3934N/AFormatBuffer<bufsz>::FormatBuffer(const char * format, ...) : FormatBufferBase(_buffer) {
1410N/A va_list argp;
1410N/A va_start(argp, format);
2208N/A jio_vsnprintf(_buf, bufsz, format, argp);
1410N/A va_end(argp);
1410N/A}
1410N/A
2037N/Atemplate <size_t bufsz>
3934N/AFormatBuffer<bufsz>::FormatBuffer() : FormatBufferBase(_buffer) {
3157N/A _buf[0] = '\0';
3157N/A}
3157N/A
3157N/Atemplate <size_t bufsz>
3157N/Avoid FormatBuffer<bufsz>::print(const char * format, ...) {
3157N/A va_list argp;
3157N/A va_start(argp, format);
3157N/A jio_vsnprintf(_buf, bufsz, format, argp);
3157N/A va_end(argp);
3157N/A}
3157N/A
3157N/Atemplate <size_t bufsz>
3157N/Avoid FormatBuffer<bufsz>::printv(const char * format, va_list argp) {
3157N/A jio_vsnprintf(_buf, bufsz, format, argp);
3157N/A}
3157N/A
3157N/Atemplate <size_t bufsz>
2037N/Avoid FormatBuffer<bufsz>::append(const char* format, ...) {
2037N/A // Given that the constructor does a vsnprintf we can assume that
2037N/A // _buf is already initialized.
2037N/A size_t len = strlen(_buf);
2037N/A char* buf_end = _buf + len;
2037N/A
2037N/A va_list argp;
2037N/A va_start(argp, format);
2208N/A jio_vsnprintf(buf_end, bufsz - len, format, argp);
2037N/A va_end(argp);
2037N/A}
2037N/A
1410N/A// Used to format messages for assert(), guarantee(), fatal(), etc.
1410N/Atypedef FormatBuffer<> err_msg;
3934N/Atypedef FormatBufferResource err_msg_res;
1410N/A
0N/A// assertions
0N/A#ifdef ASSERT
1410N/A#ifndef USE_REPEATED_ASSERTS
1410N/A#define assert(p, msg) \
1410N/Ado { \
1410N/A if (!(p)) { \
1410N/A report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \
1410N/A BREAKPOINT; \
1410N/A } \
1410N/A} while (0)
1410N/A#else // #ifndef USE_REPEATED_ASSERTS
1410N/A#define assert(p, msg)
1410N/Ado { \
1410N/A for (int __i = 0; __i < AssertRepeat; __i++) { \
1410N/A if (!(p)) { \
1410N/A report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \
1410N/A BREAKPOINT; \
1410N/A } \
1410N/A } \
1410N/A} while (0)
1410N/A#endif // #ifndef USE_REPEATED_ASSERTS
0N/A
0N/A// This version of assert is for use with checking return status from
0N/A// library calls that return actual error values eg. EINVAL,
0N/A// ENOMEM etc, rather than returning -1 and setting errno.
0N/A// When the status is not what is expected it is very useful to know
0N/A// what status was actually returned, so we pass the status variable as
0N/A// an extra arg and use strerror to convert it to a meaningful string
0N/A// like "Invalid argument", "out of memory" etc
1410N/A#define assert_status(p, status, msg) \
1410N/Ado { \
1410N/A if (!(p)) { \
1410N/A report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", \
1410N/A err_msg("error %s(%d) %s", strerror(status), \
1410N/A status, msg)); \
1410N/A BREAKPOINT; \
1410N/A } \
1410N/A} while (0)
0N/A
0N/A// Do not assert this condition if there's already another error reported.
0N/A#define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
1410N/A#else // #ifdef ASSERT
0N/A #define assert(p,msg)
0N/A #define assert_status(p,status,msg)
0N/A #define assert_if_no_error(cond,msg)
1410N/A#endif // #ifdef ASSERT
0N/A
0N/A// guarantee is like assert except it's always executed -- use it for
1410N/A// cheap tests that catch errors that would otherwise be hard to find.
0N/A// guarantee is also used for Verify options.
1410N/A#define guarantee(p, msg) \
1410N/Ado { \
1410N/A if (!(p)) { \
1410N/A report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg); \
1410N/A BREAKPOINT; \
1410N/A } \
1410N/A} while (0)
1410N/A
1410N/A#define fatal(msg) \
1410N/Ado { \
1410N/A report_fatal(__FILE__, __LINE__, msg); \
1410N/A BREAKPOINT; \
1410N/A} while (0)
1410N/A
1410N/A// out of memory
1410N/A#define vm_exit_out_of_memory(size, msg) \
1410N/Ado { \
1410N/A report_vm_out_of_memory(__FILE__, __LINE__, size, msg); \
1410N/A BREAKPOINT; \
1410N/A} while (0)
0N/A
1410N/A#define ShouldNotCallThis() \
1410N/Ado { \
1410N/A report_should_not_call(__FILE__, __LINE__); \
1410N/A BREAKPOINT; \
1410N/A} while (0)
1410N/A
1410N/A#define ShouldNotReachHere() \
1410N/Ado { \
1410N/A report_should_not_reach_here(__FILE__, __LINE__); \
1410N/A BREAKPOINT; \
1410N/A} while (0)
1410N/A
1410N/A#define Unimplemented() \
1410N/Ado { \
1410N/A report_unimplemented(__FILE__, __LINE__); \
1410N/A BREAKPOINT; \
1410N/A} while (0)
1410N/A
1410N/A#define Untested(msg) \
1410N/Ado { \
1410N/A report_untested(__FILE__, __LINE__, msg); \
1410N/A BREAKPOINT; \
1410N/A} while (0);
0N/A
0N/A// error reporting helper functions
1410N/Avoid report_vm_error(const char* file, int line, const char* error_msg,
1410N/A const char* detail_msg = NULL);
1410N/Avoid report_fatal(const char* file, int line, const char* message);
1410N/Avoid report_vm_out_of_memory(const char* file, int line, size_t size,
1410N/A const char* message);
1410N/Avoid report_should_not_call(const char* file, int line);
1410N/Avoid report_should_not_reach_here(const char* file, int line);
1410N/Avoid report_unimplemented(const char* file, int line);
1410N/Avoid report_untested(const char* file, int line, const char* message);
1410N/A
0N/Avoid warning(const char* format, ...);
0N/A
2062N/A// out of shared space reporting
2062N/Aenum SharedSpaceType {
2062N/A SharedPermGen,
2062N/A SharedReadOnly,
2062N/A SharedReadWrite,
2062N/A SharedMiscData
2062N/A};
2062N/A
2062N/Avoid report_out_of_shared_space(SharedSpaceType space_type);
2062N/A
0N/A// out of memory reporting
0N/Avoid report_java_out_of_memory(const char* message);
0N/A
0N/A// Support for self-destruct
0N/Abool is_error_reported();
0N/Avoid set_error_reported();
0N/A
1410N/A/* Test assert(), fatal(), guarantee(), etc. */
1410N/ANOT_PRODUCT(void test_error_handler(size_t test_num);)
1410N/A
0N/Avoid pd_ps(frame f);
0N/Avoid pd_obfuscate_location(char *buf, size_t buflen);
1879N/A
1879N/A#endif // SHARE_VM_UTILITIES_DEBUG_HPP