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_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP
  25 #define SHARE_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP
  26 
  27 #include "memory/iterator.hpp"
  28 #include "utilities/formatBuffer.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 #ifdef ASSERT
  69 #define shenandoah_assert_in_heap(interior_loc, obj) \
  70                     ShenandoahAsserts::assert_in_heap(interior_loc, obj, __FILE__, __LINE__);
  71 #define shenandoah_assert_in_correct_region(interior_loc, obj) \
  72                     ShenandoahAsserts::assert_in_correct_region(interior_loc, obj, __FILE__, __LINE__);
  73 
  74 #define shenandoah_assert_correct_if(interior_loc, obj, condition) \
  75   if (condition)    ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__);
  76 #define shenandoah_assert_correct_except(interior_loc, obj, exception) \
  77   if (!(exception)) ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__);
  78 #define shenandoah_assert_correct(interior_loc, obj) \
  79                     ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__);
  80 
  81 #define shenandoah_assert_forwarded_if(interior_loc, obj, condition) \
  82   if (condition)    ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__);
  83 #define shenandoah_assert_forwarded_except(interior_loc, obj, exception) \
  84   if (!(exception)) ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__);
  85 #define shenandoah_assert_forwarded(interior_loc, obj) \
  86                     ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__);
  87 
  88 #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition) \
  89   if (condition)    ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__);
  90 #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception) \
  91   if (!(exception)) ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__);
  92 #define shenandoah_assert_not_forwarded(interior_loc, obj) \
  93                     ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__);
  94 
  95 #define shenandoah_assert_marked_if(interior_loc, obj, condition) \
  96   if (condition)    ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__);
  97 #define shenandoah_assert_marked_except(interior_loc, obj, exception) \
  98   if (!(exception)) ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__);
  99 #define shenandoah_assert_marked(interior_loc, obj) \
 100                     ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__);
 101 
 102 #define shenandoah_assert_in_cset_if(interior_loc, obj, condition) \
 103   if (condition)    ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__);
 104 #define shenandoah_assert_in_cset_except(interior_loc, obj, exception) \
 105   if (!(exception)) ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__);
 106 #define shenandoah_assert_in_cset(interior_loc, obj) \
 107                     ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__);
 108 
 109 #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition) \
 110   if (condition)    ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__);
 111 #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception) \
 112   if (!(exception)) ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__);
 113 #define shenandoah_assert_not_in_cset(interior_loc, obj) \
 114                     ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__);
 115 
 116 #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition) \
 117   if (condition)    ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__);
 118 #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception) \
 119   if (!(exception)) ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__);
 120 #define shenandoah_assert_not_in_cset_loc(interior_loc) \
 121                     ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__);
 122 
 123 #define shenandoah_assert_rp_isalive_installed() \
 124                     ShenandoahAsserts::assert_rp_isalive_installed(__FILE__, __LINE__);
 125 #define shenandoah_assert_rp_isalive_not_installed() \
 126                     ShenandoahAsserts::assert_rp_isalive_not_installed(__FILE__, __LINE__);
 127 #else
 128 #define shenandoah_assert_in_heap(interior_loc, obj)
 129 #define shenandoah_assert_in_correct_region(interior_loc, obj)
 130 
 131 #define shenandoah_assert_correct_if(interior_loc, obj, condition)
 132 #define shenandoah_assert_correct_except(interior_loc, obj, exception)
 133 #define shenandoah_assert_correct(interior_loc, obj)
 134 
 135 #define shenandoah_assert_forwarded_if(interior_loc, obj, condition)
 136 #define shenandoah_assert_forwarded_except(interior_loc, obj, exception)
 137 #define shenandoah_assert_forwarded(interior_loc, obj)
 138 
 139 #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition)
 140 #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception)
 141 #define shenandoah_assert_not_forwarded(interior_loc, obj)
 142 
 143 #define shenandoah_assert_marked_if(interior_loc, obj, condition)
 144 #define shenandoah_assert_marked_except(interior_loc, obj, exception)
 145 #define shenandoah_assert_marked(interior_loc, obj)
 146 
 147 #define shenandoah_assert_in_cset_if(interior_loc, obj, condition)
 148 #define shenandoah_assert_in_cset_except(interior_loc, obj, exception)
 149 #define shenandoah_assert_in_cset(interior_loc, obj)
 150 
 151 #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition)
 152 #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception)
 153 #define shenandoah_assert_not_in_cset(interior_loc, obj)
 154 
 155 #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition)
 156 #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception)
 157 #define shenandoah_assert_not_in_cset_loc(interior_loc)
 158 
 159 #define shenandoah_assert_rp_isalive_installed()
 160 #define shenandoah_assert_rp_isalive_not_installed()
 161 #endif
 162 
 163 #define shenandoah_not_implemented \
 164                     { fatal("Deliberately not implemented."); }
 165 #define shenandoah_not_implemented_return(v) \
 166                     { fatal("Deliberately not implemented."); return v; }
 167 
 168 };
 169 
 170 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP