8184452: Add bounds checking for FromCardCache
Reviewed-by: shade, rkennke
This commit is contained in:
parent
b3be255469
commit
82fe2c0759
@ -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);
|
||||
|
@ -40,6 +40,14 @@ class G1FromCardCache : public AllStatic {
|
||||
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 @@ class G1FromCardCache : public AllStatic {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user