# HG changeset patch # User tschatzl # Date 1450695728 -3600 # Node ID a12e8d5aa2f7bfc62f80cd894bb9b0d133ad34fe # Parent 1365be812a7d0138293886e65917698323cbcd70 8145667: Move FromCardCache into separate files Reviewed-by: mgerdin, stefank diff -r 1365be812a7d -r a12e8d5aa2f7 hotspot/src/share/vm/gc/g1/g1FromCardCache.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/src/share/vm/gc/g1/g1FromCardCache.cpp Mon Dec 21 12:02:08 2015 +0100 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "precompiled.hpp" +#include "gc/g1/g1FromCardCache.hpp" +#include "gc/g1/heapRegionRemSet.hpp" +#include "memory/padded.inline.hpp" +#include "utilities/debug.hpp" + +int** FromCardCache::_cache = NULL; +uint FromCardCache::_max_regions = 0; +size_t FromCardCache::_static_mem_size = 0; + +void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) { + guarantee(_cache == NULL, "Should not call this multiple times"); + + _max_regions = max_num_regions; + _cache = Padded2DArray::create_unfreeable(n_par_rs, + _max_regions, + &_static_mem_size); + + invalidate(0, _max_regions); +} + +void FromCardCache::invalidate(uint start_idx, size_t new_num_regions) { + guarantee((size_t)start_idx + new_num_regions <= max_uintx, + "Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT, + start_idx, new_num_regions); + for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { + uint end_idx = (start_idx + (uint)new_num_regions); + assert(end_idx <= _max_regions, "Must be within max."); + for (uint j = start_idx; j < end_idx; j++) { + set(i, j, InvalidCard); + } + } +} + +#ifndef PRODUCT +void FromCardCache::print(outputStream* out) { + for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { + for (uint j = 0; j < _max_regions; j++) { + out->print_cr("_from_card_cache[%u][%u] = %d.", + i, j, at(i, j)); + } + } +} +#endif + +void FromCardCache::clear(uint region_idx) { + uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets(); + for (uint i = 0; i < num_par_remsets; i++) { + set(i, region_idx, InvalidCard); + } +} diff -r 1365be812a7d -r a12e8d5aa2f7 hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp Mon Dec 21 12:02:08 2015 +0100 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP +#define SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP + +#include "memory/allocation.hpp" +#include "utilities/ostream.hpp" + +// The FromCardCache remembers the most recently processed card on the heap on +// a per-region and per-thread basis. +class FromCardCache : public AllStatic { + private: + // Array of card indices. Indexed by thread X and heap region to minimize + // thread contention. + static int** _cache; + static uint _max_regions; + static size_t _static_mem_size; + + public: + enum { + InvalidCard = -1 // Card value of an invalid card, i.e. a card index not otherwise used. + }; + + static void clear(uint region_idx); + + // Returns true if the given card is in the cache at the given location, or + // replaces the card at that location and returns false. + static bool contains_or_replace(uint worker_id, uint region_idx, int card) { + int card_in_cache = at(worker_id, region_idx); + if (card_in_cache == card) { + return true; + } else { + set(worker_id, region_idx, card); + return false; + } + } + + static int at(uint worker_id, uint region_idx) { + return _cache[worker_id][region_idx]; + } + + static void set(uint worker_id, uint region_idx, int val) { + _cache[worker_id][region_idx] = val; + } + + static void initialize(uint n_par_rs, uint max_num_regions); + + static void invalidate(uint start_idx, size_t num_regions); + + static void print(outputStream* out = tty) PRODUCT_RETURN; + + static size_t static_mem_size() { + return _static_mem_size; + } +}; + +#endif // SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP diff -r 1365be812a7d -r a12e8d5aa2f7 hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp --- a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp Mon Dec 21 12:02:03 2015 +0100 +++ b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp Mon Dec 21 12:02:08 2015 +0100 @@ -351,52 +351,6 @@ "just checking"); } -int** FromCardCache::_cache = NULL; -uint FromCardCache::_max_regions = 0; -size_t FromCardCache::_static_mem_size = 0; - -void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) { - guarantee(_cache == NULL, "Should not call this multiple times"); - - _max_regions = max_num_regions; - _cache = Padded2DArray::create_unfreeable(n_par_rs, - _max_regions, - &_static_mem_size); - - invalidate(0, _max_regions); -} - -void FromCardCache::invalidate(uint start_idx, size_t new_num_regions) { - guarantee((size_t)start_idx + new_num_regions <= max_uintx, - "Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT, - start_idx, new_num_regions); - for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { - uint end_idx = (start_idx + (uint)new_num_regions); - assert(end_idx <= _max_regions, "Must be within max."); - for (uint j = start_idx; j < end_idx; j++) { - set(i, j, InvalidCard); - } - } -} - -#ifndef PRODUCT -void FromCardCache::print(outputStream* out) { - for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { - for (uint j = 0; j < _max_regions; j++) { - out->print_cr("_from_card_cache[%u][%u] = %d.", - i, j, at(i, j)); - } - } -} -#endif - -void FromCardCache::clear(uint region_idx) { - uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets(); - for (uint i = 0; i < num_par_remsets; i++) { - set(i, region_idx, InvalidCard); - } -} - void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) { uint cur_hrm_ind = _hr->hrm_index(); diff -r 1365be812a7d -r a12e8d5aa2f7 hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp --- a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp Mon Dec 21 12:02:03 2015 +0100 +++ b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp Mon Dec 21 12:02:08 2015 +0100 @@ -26,6 +26,7 @@ #define SHARE_VM_GC_G1_HEAPREGIONREMSET_HPP #include "gc/g1/g1CodeCacheRemSet.hpp" +#include "gc/g1/g1FromCardCache.hpp" #include "gc/g1/sparsePRT.hpp" // Remembered set for a heap region. Represent a set of "cards" that @@ -45,54 +46,6 @@ class HRRSCleanupTask : public SparsePRTCleanupTask { }; -// The FromCardCache remembers the most recently processed card on the heap on -// a per-region and per-thread basis. -class FromCardCache : public AllStatic { - private: - // Array of card indices. Indexed by thread X and heap region to minimize - // thread contention. - static int** _cache; - static uint _max_regions; - static size_t _static_mem_size; - - public: - enum { - InvalidCard = -1 // Card value of an invalid card, i.e. a card index not otherwise used. - }; - - static void clear(uint region_idx); - - // Returns true if the given card is in the cache at the given location, or - // replaces the card at that location and returns false. - static bool contains_or_replace(uint worker_id, uint region_idx, int card) { - int card_in_cache = at(worker_id, region_idx); - if (card_in_cache == card) { - return true; - } else { - set(worker_id, region_idx, card); - return false; - } - } - - static int at(uint worker_id, uint region_idx) { - return _cache[worker_id][region_idx]; - } - - static void set(uint worker_id, uint region_idx, int val) { - _cache[worker_id][region_idx] = val; - } - - static void initialize(uint n_par_rs, uint max_num_regions); - - static void invalidate(uint start_idx, size_t num_regions); - - static void print(outputStream* out = tty) PRODUCT_RETURN; - - static size_t static_mem_size() { - return _static_mem_size; - } -}; - // The "_coarse_map" is a bitmap with one bit for each region, where set // bits indicate that the corresponding region may contain some pointer // into the owning region.