1 /*
   2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 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 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP
  26 
  27 #include "oops/oop.hpp"
  28 #include "utilities/debug.hpp"
  29 
  30 typedef FormatBuffer<8192> ShenandoahMessageBuffer;
  31 
  32 class ShenandoahAsserts {
  33 public:
  34   enum SafeLevel {
  35     _safe_unknown,
  36     _safe_oop,
  37     _safe_oop_fwd,
  38     _safe_all
  39   };
  40 
  41   static void print_obj(ShenandoahMessageBuffer &msg, oop obj);
  42 
  43   static void print_non_obj(ShenandoahMessageBuffer &msg, void *loc);
  44 
  45   static void print_obj_safe(ShenandoahMessageBuffer &msg, void *loc);
  46 
  47   static void print_failure(SafeLevel level, oop obj, void *interior_loc, oop loc,
  48                             const char *phase, const char *label,
  49                             const char *file, int line);
  50 
  51   static void print_rp_failure(const char *label, BoolObjectClosure* actual,
  52                                const char *file, int line);
  53 
  54   static void assert_in_heap(void* interior_loc, oop obj, const char* file, int line);
  55   static void assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line);
  56 
  57   static void assert_correct(void* interior_loc, oop obj, const char* file, int line);
  58   static void assert_forwarded(void* interior_loc, oop obj, const char* file, int line);
  59   static void assert_not_forwarded(void* interior_loc, oop obj, const char* file, int line);
  60   static void assert_marked(void* interior_loc, oop obj, const char* file, int line);
  61   static void assert_in_cset(void* interior_loc, oop obj, const char* file, int line);
  62   static void assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line);
  63   static void assert_not_in_cset_loc(void* interior_loc, const char* file, int line);
  64 
  65   static void assert_rp_isalive_not_installed(const char *file, int line);
  66   static void assert_rp_isalive_installed(const char *file, int line);
  67 
  68   static void assert_heaplocked(const char* file, int line);
  69   static void assert_not_heaplocked(const char* file, int line);
  70   static void assert_heaplocked_or_safepoint(const char* file, int line);
  71 
  72 #ifdef ASSERT
  73 #define shenandoah_assert_in_heap(interior_loc, obj) \
  74                     ShenandoahAsserts::assert_in_heap(interior_loc, obj, __FILE__, __LINE__)
  75 #define shenandoah_assert_in_correct_region(interior_loc, obj) \
  76                     ShenandoahAsserts::assert_in_correct_region(interior_loc, obj, __FILE__, __LINE__)
  77 
  78 #define shenandoah_assert_correct_if(interior_loc, obj, condition) \
  79   if (condition)    ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__)
  80 #define shenandoah_assert_correct_except(interior_loc, obj, exception) \
  81   if (!(exception)) ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__)
  82 #define shenandoah_assert_correct(interior_loc, obj) \
  83                     ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__)
  84 
  85 #define shenandoah_assert_forwarded_if(interior_loc, obj, condition) \
  86   if (condition)    ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__)
  87 #define shenandoah_assert_forwarded_except(interior_loc, obj, exception) \
  88   if (!(exception)) ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__)
  89 #define shenandoah_assert_forwarded(interior_loc, obj) \
  90                     ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__)
  91 
  92 #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition) \
  93   if (condition)    ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__)
  94 #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception) \
  95   if (!(exception)) ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__)
  96 #define shenandoah_assert_not_forwarded(interior_loc, obj) \
  97                     ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__)
  98 
  99 #define shenandoah_assert_marked_if(interior_loc, obj, condition) \
 100   if (condition)    ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__)
 101 #define shenandoah_assert_marked_except(interior_loc, obj, exception) \
 102   if (!(exception)) ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__)
 103 #define shenandoah_assert_marked(interior_loc, obj) \
 104                     ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__)
 105 
 106 #define shenandoah_assert_in_cset_if(interior_loc, obj, condition) \
 107   if (condition)    ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__)
 108 #define shenandoah_assert_in_cset_except(interior_loc, obj, exception) \
 109   if (!(exception)) ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__)
 110 #define shenandoah_assert_in_cset(interior_loc, obj) \
 111                     ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__)
 112 
 113 #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition) \
 114   if (condition)    ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__)
 115 #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception) \
 116   if (!(exception)) ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__)
 117 #define shenandoah_assert_not_in_cset(interior_loc, obj) \
 118                     ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__)
 119 
 120 #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition) \
 121   if (condition)    ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__)
 122 #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception) \
 123   if (!(exception)) ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__)
 124 #define shenandoah_assert_not_in_cset_loc(interior_loc) \
 125                     ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__)
 126 
 127 #define shenandoah_assert_rp_isalive_installed() \
 128                     ShenandoahAsserts::assert_rp_isalive_installed(__FILE__, __LINE__)
 129 #define shenandoah_assert_rp_isalive_not_installed() \
 130                     ShenandoahAsserts::assert_rp_isalive_not_installed(__FILE__, __LINE__)
 131 
 132 #define shenandoah_assert_heaplocked() \
 133                     ShenandoahAsserts::assert_heaplocked(__FILE__, __LINE__)
 134 
 135 #define shenandoah_assert_not_heaplocked() \
 136                     ShenandoahAsserts::assert_not_heaplocked(__FILE__, __LINE__)
 137 
 138 #define shenandoah_assert_heaplocked_or_safepoint() \
 139                     ShenandoahAsserts::assert_heaplocked_or_safepoint(__FILE__, __LINE__)
 140 #else
 141 #define shenandoah_assert_in_heap(interior_loc, obj)
 142 #define shenandoah_assert_in_correct_region(interior_loc, obj)
 143 
 144 #define shenandoah_assert_correct_if(interior_loc, obj, condition)
 145 #define shenandoah_assert_correct_except(interior_loc, obj, exception)
 146 #define shenandoah_assert_correct(interior_loc, obj)
 147 
 148 #define shenandoah_assert_forwarded_if(interior_loc, obj, condition)
 149 #define shenandoah_assert_forwarded_except(interior_loc, obj, exception)
 150 #define shenandoah_assert_forwarded(interior_loc, obj)
 151 
 152 #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition)
 153 #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception)
 154 #define shenandoah_assert_not_forwarded(interior_loc, obj)
 155 
 156 #define shenandoah_assert_marked_if(interior_loc, obj, condition)
 157 #define shenandoah_assert_marked_except(interior_loc, obj, exception)
 158 #define shenandoah_assert_marked(interior_loc, obj)
 159 
 160 #define shenandoah_assert_in_cset_if(interior_loc, obj, condition)
 161 #define shenandoah_assert_in_cset_except(interior_loc, obj, exception)
 162 #define shenandoah_assert_in_cset(interior_loc, obj)
 163 
 164 #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition)
 165 #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception)
 166 #define shenandoah_assert_not_in_cset(interior_loc, obj)
 167 
 168 #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition)
 169 #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception)
 170 #define shenandoah_assert_not_in_cset_loc(interior_loc)
 171 
 172 #define shenandoah_assert_rp_isalive_installed()
 173 #define shenandoah_assert_rp_isalive_not_installed()
 174 
 175 #define shenandoah_assert_heaplocked()
 176 #define shenandoah_assert_not_heaplocked()
 177 #define shenandoah_assert_heaplocked_or_safepoint()
 178 #endif
 179 
 180 #define shenandoah_not_implemented \
 181                     { fatal("Deliberately not implemented."); }
 182 #define shenandoah_not_implemented_return(v) \
 183                     { fatal("Deliberately not implemented."); return v; }
 184 
 185 };
 186 
 187 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP