changeset 46669:05296a16012a

8184452: Add bounds checking for FromCardCache Reviewed-by: shade, rkennke
author tschatzl
date Mon, 17 Jul 2017 10:32:36 +0200
parents f5a564180f37
children b7c2e9a24d49 dc24cb5e50a1
files hotspot/src/share/vm/gc/g1/g1FromCardCache.cpp hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/gc/g1/g1FromCardCache.cpp	Fri Jul 14 14:04:57 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1FromCardCache.cpp	Mon Jul 17 10:32:36 2017 +0200
@@ -31,12 +31,18 @@
 int**  G1FromCardCache::_cache = NULL;
 uint   G1FromCardCache::_max_regions = 0;
 size_t G1FromCardCache::_static_mem_size = 0;
+#ifdef ASSERT
+uint   G1FromCardCache::_max_workers = 0;
+#endif
 
 void G1FromCardCache::initialize(uint num_par_rem_sets, uint max_num_regions) {
   guarantee(max_num_regions > 0, "Heap size must be valid");
   guarantee(_cache == NULL, "Should not call this multiple times");
 
   _max_regions = max_num_regions;
+#ifdef ASSERT
+  _max_workers = num_par_rem_sets;
+#endif
   _cache = Padded2DArray<int, mtGC>::create_unfreeable(_max_regions,
                                                        num_par_rem_sets,
                                                        &_static_mem_size);
--- a/hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp	Fri Jul 14 14:04:57 2017 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp	Mon Jul 17 10:32:36 2017 +0200
@@ -40,6 +40,14 @@
   static int** _cache;
   static uint _max_regions;
   static size_t _static_mem_size;
+#ifdef ASSERT
+  static uint _max_workers;
+
+  static void check_bounds(uint worker_id, uint region_idx) {
+    assert(worker_id < _max_workers, "Worker_id %u is larger than maximum %u", worker_id, _max_workers);
+    assert(region_idx < _max_regions, "Region_idx %u is larger than maximum %u", region_idx, _max_regions);
+  }
+#endif
 
  public:
   enum {
@@ -61,10 +69,12 @@
   }
 
   static int at(uint worker_id, uint region_idx) {
+    DEBUG_ONLY(check_bounds(worker_id, region_idx);)
     return _cache[region_idx][worker_id];
   }
 
   static void set(uint worker_id, uint region_idx, int val) {
+    DEBUG_ONLY(check_bounds(worker_id, region_idx);)
     _cache[region_idx][worker_id] = val;
   }