g1FromCardCache.cpp revision 9865:a8f8a794a896
1/* 2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25#include "precompiled.hpp" 26#include "gc/g1/g1FromCardCache.hpp" 27#include "gc/g1/heapRegionRemSet.hpp" 28#include "memory/padded.inline.hpp" 29#include "utilities/debug.hpp" 30 31int** FromCardCache::_cache = NULL; 32uint FromCardCache::_max_regions = 0; 33size_t FromCardCache::_static_mem_size = 0; 34 35void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) { 36 guarantee(_cache == NULL, "Should not call this multiple times"); 37 38 _max_regions = max_num_regions; 39 _cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs, 40 _max_regions, 41 &_static_mem_size); 42 43 invalidate(0, _max_regions); 44} 45 46void FromCardCache::invalidate(uint start_idx, size_t new_num_regions) { 47 guarantee((size_t)start_idx + new_num_regions <= max_uintx, 48 "Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT, 49 start_idx, new_num_regions); 50 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { 51 uint end_idx = (start_idx + (uint)new_num_regions); 52 assert(end_idx <= _max_regions, "Must be within max."); 53 for (uint j = start_idx; j < end_idx; j++) { 54 set(i, j, InvalidCard); 55 } 56 } 57} 58 59#ifndef PRODUCT 60void FromCardCache::print(outputStream* out) { 61 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { 62 for (uint j = 0; j < _max_regions; j++) { 63 out->print_cr("_from_card_cache[%u][%u] = %d.", 64 i, j, at(i, j)); 65 } 66 } 67} 68#endif 69 70void FromCardCache::clear(uint region_idx) { 71 uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets(); 72 for (uint i = 0; i < num_par_remsets; i++) { 73 set(i, region_idx, InvalidCard); 74 } 75} 76