hotspot/src/share/vm/utilities/debug.hpp
author dcubed
Wed, 12 Mar 2008 18:07:46 -0700
changeset 221 ec745a0fe922
parent 1 489c9b5090e2
child 5403 6b0dd9c75dde
permissions -rw-r--r--
6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure Summary: Add should_not_be_cached() to markOop and methodOop and query that status inOopMapCache::lookup() Reviewed-by: coleenp, sspitsyn, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// assertions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// Turn this off by default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//#define USE_REPEATED_ASSERTS
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
#ifdef USE_REPEATED_ASSERTS
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  #define assert(p,msg)                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
    { for (int __i = 0; __i < AssertRepeat; __i++) {                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
        if (!(p)) {                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
          report_assertion_failure(__FILE__, __LINE__,               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
                                  "assert(" XSTR(p) ",\"" msg "\")");\
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
          BREAKPOINT;                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
        }                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
      }                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  #define assert(p,msg)                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    if (!(p)) {                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
      report_assertion_failure(__FILE__, __LINE__,               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                              "assert(" XSTR(p) ",\"" msg "\")");\
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
      BREAKPOINT;                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// This version of assert is for use with checking return status from
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// library calls that return actual error values eg. EINVAL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// ENOMEM etc, rather than returning -1 and setting errno.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// When the status is not what is expected it is very useful to know
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// what status was actually returned, so we pass the status variable as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// an extra arg and use strerror to convert it to a meaningful string
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// like "Invalid argument", "out of memory" etc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
#define assert_status(p, status, msg)                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
   do {                                                                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    if (!(p)) {                                                           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      char buf[128];                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      snprintf(buf, 127,                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
               "assert_status(" XSTR(p) ", error: %s(%d), \"" msg "\")" , \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
               strerror((status)), (status));                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      report_assertion_failure(__FILE__, __LINE__, buf);                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      BREAKPOINT;                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    }                                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  } while (0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// Another version of assert where the message is not a string literal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// The boolean condition is not printed out because cpp doesn't like it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
#define assert_msg(p, msg)                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    if (!(p)) {                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      report_assertion_failure(__FILE__, __LINE__, msg);         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      BREAKPOINT;                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// Do not assert this condition if there's already another error reported.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
#define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  #define assert(p,msg)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  #define assert_status(p,status,msg)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  #define assert_if_no_error(cond,msg)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  #define assert_msg(cond,msg)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// fatals
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
#define fatal(m)                             { report_fatal(__FILE__, __LINE__, m                          ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
#define fatal1(m,x1)                         { report_fatal_vararg(__FILE__, __LINE__, m, x1               ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
#define fatal2(m,x1,x2)                      { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2           ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
#define fatal3(m,x1,x2,x3)                   { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3       ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
#define fatal4(m,x1,x2,x3,x4)                { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3, x4   ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// out of memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
#define vm_exit_out_of_memory(s,m)              { report_vm_out_of_memory(__FILE__, __LINE__, s, m                       ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#define vm_exit_out_of_memory1(s,m,x1)          { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1            ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
#define vm_exit_out_of_memory2(s,m,x1,x2)       { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2        ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#define vm_exit_out_of_memory3(s,m,x1,x2,x3)    { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3    ); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
#define vm_exit_out_of_memory4(s,m,x1,x2,x3,x4) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3, x4); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
// guarantee is like assert except it's always executed -- use it for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// cheap tests that catch errors that would otherwise be hard to find
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// guarantee is also used for Verify options.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
#define guarantee(b,msg)         { if (!(b)) fatal("guarantee(" XSTR(b) ",\"" msg "\")"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
#define ShouldNotCallThis()      { report_should_not_call        (__FILE__, __LINE__); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
#define ShouldNotReachHere()     { report_should_not_reach_here  (__FILE__, __LINE__); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
#define Unimplemented()          { report_unimplemented          (__FILE__, __LINE__); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
#define Untested(msg)            { report_untested               (__FILE__, __LINE__, msg); BREAKPOINT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
// error reporting helper functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void report_assertion_failure(const char* file_name, int line_no, const char* message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
void report_fatal_vararg(const char* file_name, int line_no, const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
void report_fatal(const char* file_name, int line_no, const char* message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
void report_vm_out_of_memory_vararg(const char* file_name, int line_no, size_t size, const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
void report_vm_out_of_memory(const char* file_name, int line_no, size_t size, const char* message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
void report_should_not_call(const char* file_name, int line_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
void report_should_not_reach_here(const char* file_name, int line_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
void report_unimplemented(const char* file_name, int line_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
void report_untested(const char* file_name, int line_no, const char* msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
void warning(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// out of memory reporting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void report_java_out_of_memory(const char* message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// Support for self-destruct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
bool is_error_reported();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
void set_error_reported();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
void pd_ps(frame f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
void pd_obfuscate_location(char *buf, size_t buflen);