Path: blob/master/src/hotspot/share/jfr/leakprofiler/chains/bitset.inline.hpp
41153 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_INLINE_HPP25#define SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_INLINE_HPP2627#include "jfr/leakprofiler/chains/bitset.hpp"2829#include "jfr/recorder/storage/jfrVirtualMemory.hpp"30#include "memory/memRegion.hpp"31#include "utilities/bitMap.inline.hpp"32#include "utilities/hashtable.inline.hpp"3334inline BitSet::BitMapFragmentTable::Entry* BitSet::BitMapFragmentTable::bucket(int i) const {35return (Entry*)BasicHashtable<mtTracing>::bucket(i);36}3738inline BitSet::BitMapFragmentTable::Entry* BitSet::BitMapFragmentTable::new_entry(unsigned int hash,39uintptr_t key,40CHeapBitMap* value) {41Entry* entry = (Entry*)BasicHashtable<mtTracing>::new_entry(hash);42entry->_key = key;43entry->_value = value;44return entry;45}4647inline void BitSet::BitMapFragmentTable::add(uintptr_t key, CHeapBitMap* value) {48unsigned hash = hash_segment(key);49Entry* entry = new_entry(hash, key, value);50BasicHashtable<mtTracing>::add_entry(hash_to_index(hash), entry);51}5253inline CHeapBitMap** BitSet::BitMapFragmentTable::lookup(uintptr_t key) {54unsigned hash = hash_segment(key);55int index = hash_to_index(hash);56for (Entry* e = bucket(index); e != NULL; e = e->next()) {57if (e->hash() == hash && e->_key == key) {58return &(e->_value);59}60}61return NULL;62}6364inline BitMap::idx_t BitSet::addr_to_bit(uintptr_t addr) const {65return (addr & _bitmap_granularity_mask) >> LogMinObjAlignmentInBytes;66}6768inline CHeapBitMap* BitSet::get_fragment_bits(uintptr_t addr) {69uintptr_t granule = addr >> _bitmap_granularity_shift;70if (granule == _last_fragment_granule) {71return _last_fragment_bits;72}73CHeapBitMap* bits = NULL;7475CHeapBitMap** found = _bitmap_fragments.lookup(granule);76if (found != NULL) {77bits = *found;78} else {79BitMapFragment* fragment = new BitMapFragment(granule, _fragment_list);80bits = fragment->bits();81_fragment_list = fragment;82if (_bitmap_fragments.number_of_entries() * 100 / _bitmap_fragments.table_size() > 25) {83_bitmap_fragments.resize(_bitmap_fragments.table_size() * 2);84}85_bitmap_fragments.add(granule, bits);86}8788_last_fragment_bits = bits;89_last_fragment_granule = granule;9091return bits;92}9394inline void BitSet::mark_obj(uintptr_t addr) {95CHeapBitMap* bits = get_fragment_bits(addr);96const BitMap::idx_t bit = addr_to_bit(addr);97bits->set_bit(bit);98}99100inline bool BitSet::is_marked(uintptr_t addr) {101CHeapBitMap* bits = get_fragment_bits(addr);102const BitMap::idx_t bit = addr_to_bit(addr);103return bits->at(bit);104}105106#endif // SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_INLINE_HPP107108109