8184452: Add bounds checking for FromCardCache

Reviewed-by: shade, rkennke
This commit is contained in:
Thomas Schatzl 2017-07-17 10:32:36 +02:00
parent b3be255469
commit 82fe2c0759
2 changed files with 16 additions and 0 deletions

View File

@ -31,12 +31,18 @@
int** G1FromCardCache::_cache = NULL; int** G1FromCardCache::_cache = NULL;
uint G1FromCardCache::_max_regions = 0; uint G1FromCardCache::_max_regions = 0;
size_t G1FromCardCache::_static_mem_size = 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) { void G1FromCardCache::initialize(uint num_par_rem_sets, uint max_num_regions) {
guarantee(max_num_regions > 0, "Heap size must be valid"); guarantee(max_num_regions > 0, "Heap size must be valid");
guarantee(_cache == NULL, "Should not call this multiple times"); guarantee(_cache == NULL, "Should not call this multiple times");
_max_regions = max_num_regions; _max_regions = max_num_regions;
#ifdef ASSERT
_max_workers = num_par_rem_sets;
#endif
_cache = Padded2DArray<int, mtGC>::create_unfreeable(_max_regions, _cache = Padded2DArray<int, mtGC>::create_unfreeable(_max_regions,
num_par_rem_sets, num_par_rem_sets,
&_static_mem_size); &_static_mem_size);

View File

@ -40,6 +40,14 @@ class G1FromCardCache : public AllStatic {
static int** _cache; static int** _cache;
static uint _max_regions; static uint _max_regions;
static size_t _static_mem_size; 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: public:
enum { enum {
@ -61,10 +69,12 @@ class G1FromCardCache : public AllStatic {
} }
static int at(uint worker_id, uint region_idx) { static int at(uint worker_id, uint region_idx) {
DEBUG_ONLY(check_bounds(worker_id, region_idx);)
return _cache[region_idx][worker_id]; return _cache[region_idx][worker_id];
} }
static void set(uint worker_id, uint region_idx, int val) { 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; _cache[region_idx][worker_id] = val;
} }