Path: blob/master/src/hotspot/share/jfr/leakprofiler/chains/bitset.hpp
41153 views
/*1* Copyright (c) 2014, 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_HPP25#define SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP2627#include "memory/allocation.hpp"28#include "oops/oop.hpp"29#include "oops/oopsHierarchy.hpp"30#include "utilities/bitMap.hpp"31#include "utilities/hashtable.hpp"3233class JfrVirtualMemory;34class MemRegion;3536class BitSet : public CHeapObj<mtTracing> {37const static size_t _bitmap_granularity_shift = 26; // 64M38const static size_t _bitmap_granularity_size = (size_t)1 << _bitmap_granularity_shift;39const static size_t _bitmap_granularity_mask = _bitmap_granularity_size - 1;4041class BitMapFragment;4243class BitMapFragmentTable : public BasicHashtable<mtTracing> {44class Entry : public BasicHashtableEntry<mtTracing> {45public:46uintptr_t _key;47CHeapBitMap* _value;4849Entry* next() {50return (Entry*)BasicHashtableEntry<mtTracing>::next();51}52};5354protected:55Entry* bucket(int i) const;5657Entry* new_entry(unsigned int hashValue, uintptr_t key, CHeapBitMap* value);5859unsigned hash_segment(uintptr_t key) {60unsigned hash = (unsigned)key;61return hash ^ (hash >> 3);62}6364unsigned hash_to_index(unsigned hash) {65return hash & (BasicHashtable<mtTracing>::table_size() - 1);66}6768public:69BitMapFragmentTable(int table_size) : BasicHashtable<mtTracing>(table_size, sizeof(Entry)) {}70void add(uintptr_t key, CHeapBitMap* value);71CHeapBitMap** lookup(uintptr_t key);72};7374CHeapBitMap* get_fragment_bits(uintptr_t addr);7576BitMapFragmentTable _bitmap_fragments;77BitMapFragment* _fragment_list;78CHeapBitMap* _last_fragment_bits;79uintptr_t _last_fragment_granule;8081public:82BitSet();83~BitSet();8485BitMap::idx_t addr_to_bit(uintptr_t addr) const;8687void mark_obj(uintptr_t addr);8889void mark_obj(oop obj) {90return mark_obj(cast_from_oop<uintptr_t>(obj));91}9293bool is_marked(uintptr_t addr);9495bool is_marked(oop obj) {96return is_marked(cast_from_oop<uintptr_t>(obj));97}98};99100class BitSet::BitMapFragment : public CHeapObj<mtTracing> {101CHeapBitMap _bits;102BitMapFragment* _next;103104public:105BitMapFragment(uintptr_t granule, BitMapFragment* next);106107BitMapFragment* next() const {108return _next;109}110111CHeapBitMap* bits() {112return &_bits;113}114};115116#endif // SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP117118119