src/hotspot/share/utilities/debug.hpp
changeset 49653 a569cb4425f3
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
equal deleted inserted replaced
49652:a74836b05c28 49653:a569cb4425f3
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    28 #include "utilities/breakpoint.hpp"
    28 #include "utilities/breakpoint.hpp"
    29 #include "utilities/compilerWarnings.hpp"
    29 #include "utilities/compilerWarnings.hpp"
    30 #include "utilities/macros.hpp"
    30 #include "utilities/macros.hpp"
    31 
    31 
    32 #include <stddef.h>
    32 #include <stddef.h>
       
    33 
       
    34 // ShowRegistersOnAssert support (for now Linux only)
       
    35 #if defined(LINUX) && !defined(ZERO)
       
    36 #define CAN_SHOW_REGISTERS_ON_ASSERT
       
    37 extern char* g_assert_poison;
       
    38 #define TOUCH_ASSERT_POISON (*g_assert_poison) = 'X';
       
    39 void initialize_assert_poison();
       
    40 bool handle_assert_poison_fault(const void* ucVoid, const void* faulting_address);
       
    41 #else
       
    42 #define TOUCH_ASSERT_POISON
       
    43 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
    33 
    44 
    34 // assertions
    45 // assertions
    35 #ifndef ASSERT
    46 #ifndef ASSERT
    36 #define vmassert(p, ...)
    47 #define vmassert(p, ...)
    37 #else
    48 #else
    40 // Note: The signature is vmassert(p, format, ...), but the solaris
    51 // Note: The signature is vmassert(p, format, ...), but the solaris
    41 // compiler can't handle an empty ellipsis in a macro without a warning.
    52 // compiler can't handle an empty ellipsis in a macro without a warning.
    42 #define vmassert(p, ...)                                                       \
    53 #define vmassert(p, ...)                                                       \
    43 do {                                                                           \
    54 do {                                                                           \
    44   if (!(p)) {                                                                  \
    55   if (!(p)) {                                                                  \
       
    56     TOUCH_ASSERT_POISON;                                                       \
    45     if (is_executing_unit_tests()) {                                           \
    57     if (is_executing_unit_tests()) {                                           \
    46       report_assert_msg(__VA_ARGS__);                                          \
    58       report_assert_msg(__VA_ARGS__);                                          \
    47     }                                                                          \
    59     }                                                                          \
    48     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", __VA_ARGS__); \
    60     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", __VA_ARGS__); \
    49     BREAKPOINT;                                                                \
    61     BREAKPOINT;                                                                \
    65 // an extra arg and use strerror to convert it to a meaningful string
    77 // an extra arg and use strerror to convert it to a meaningful string
    66 // like "Invalid argument", "out of memory" etc
    78 // like "Invalid argument", "out of memory" etc
    67 #define vmassert_status(p, status, msg) \
    79 #define vmassert_status(p, status, msg) \
    68 do {                                                                           \
    80 do {                                                                           \
    69   if (!(p)) {                                                                  \
    81   if (!(p)) {                                                                  \
       
    82     TOUCH_ASSERT_POISON;                                                       \
    70     report_vm_status_error(__FILE__, __LINE__, "assert(" #p ") failed",        \
    83     report_vm_status_error(__FILE__, __LINE__, "assert(" #p ") failed",        \
    71                            status, msg);                                       \
    84                            status, msg);                                       \
    72     BREAKPOINT;                                                                \
    85     BREAKPOINT;                                                                \
    73   }                                                                            \
    86   }                                                                            \
    74 } while (0)
    87 } while (0)
    81 // cheap tests that catch errors that would otherwise be hard to find.
    94 // cheap tests that catch errors that would otherwise be hard to find.
    82 // guarantee is also used for Verify options.
    95 // guarantee is also used for Verify options.
    83 #define guarantee(p, ...)                                                         \
    96 #define guarantee(p, ...)                                                         \
    84 do {                                                                              \
    97 do {                                                                              \
    85   if (!(p)) {                                                                     \
    98   if (!(p)) {                                                                     \
       
    99     TOUCH_ASSERT_POISON;                                                          \
    86     report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", __VA_ARGS__); \
   100     report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", __VA_ARGS__); \
    87     BREAKPOINT;                                                                   \
   101     BREAKPOINT;                                                                   \
    88   }                                                                               \
   102   }                                                                               \
    89 } while (0)
   103 } while (0)
    90 
   104 
    91 #define fatal(...)                                                                \
   105 #define fatal(...)                                                                \
    92 do {                                                                              \
   106 do {                                                                              \
       
   107   TOUCH_ASSERT_POISON;                                                            \
    93   report_fatal(__FILE__, __LINE__, __VA_ARGS__);                                  \
   108   report_fatal(__FILE__, __LINE__, __VA_ARGS__);                                  \
    94   BREAKPOINT;                                                                     \
   109   BREAKPOINT;                                                                     \
    95 } while (0)
   110 } while (0)
    96 
   111 
    97 // out of memory
   112 // out of memory
   101   BREAKPOINT;                                                                     \
   116   BREAKPOINT;                                                                     \
   102 } while (0)
   117 } while (0)
   103 
   118 
   104 #define ShouldNotCallThis()                                                       \
   119 #define ShouldNotCallThis()                                                       \
   105 do {                                                                              \
   120 do {                                                                              \
       
   121   TOUCH_ASSERT_POISON;                                                            \
   106   report_should_not_call(__FILE__, __LINE__);                                     \
   122   report_should_not_call(__FILE__, __LINE__);                                     \
   107   BREAKPOINT;                                                                     \
   123   BREAKPOINT;                                                                     \
   108 } while (0)
   124 } while (0)
   109 
   125 
   110 #define ShouldNotReachHere()                                                      \
   126 #define ShouldNotReachHere()                                                      \
   111 do {                                                                              \
   127 do {                                                                              \
       
   128   TOUCH_ASSERT_POISON;                                                            \
   112   report_should_not_reach_here(__FILE__, __LINE__);                               \
   129   report_should_not_reach_here(__FILE__, __LINE__);                               \
   113   BREAKPOINT;                                                                     \
   130   BREAKPOINT;                                                                     \
   114 } while (0)
   131 } while (0)
   115 
   132 
   116 #define Unimplemented()                                                           \
   133 #define Unimplemented()                                                           \
   117 do {                                                                              \
   134 do {                                                                              \
       
   135   TOUCH_ASSERT_POISON;                                                            \
   118   report_unimplemented(__FILE__, __LINE__);                                       \
   136   report_unimplemented(__FILE__, __LINE__);                                       \
   119   BREAKPOINT;                                                                     \
   137   BREAKPOINT;                                                                     \
   120 } while (0)
   138 } while (0)
   121 
   139 
   122 #define Untested(msg)                                                             \
   140 #define Untested(msg)                                                             \