src/hotspot/share/jfr/leakprofiler/chains/bitset.hpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58014 aba258cd7df8
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50113
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50113
diff changeset
    25
#ifndef SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50113
diff changeset
    26
#define SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "memory/allocation.hpp"
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    29
#include "oops/oop.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "oops/oopsHierarchy.hpp"
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    31
#include "utilities/bitMap.hpp"
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    32
#include "utilities/hashtable.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
class JfrVirtualMemory;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
class MemRegion;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
class BitSet : public CHeapObj<mtTracing> {
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    38
  const static size_t _bitmap_granularity_shift = 26; // 64M
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    39
  const static size_t _bitmap_granularity_size = (size_t)1 << _bitmap_granularity_shift;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    40
  const static size_t _bitmap_granularity_mask = _bitmap_granularity_size - 1;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    41
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    42
  class BitMapFragment;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    43
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    44
  class BitMapFragmentTable : public BasicHashtable<mtTracing> {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    45
    class Entry : public BasicHashtableEntry<mtTracing> {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    46
    public:
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    47
      uintptr_t _key;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    48
      CHeapBitMap* _value;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    49
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    50
      Entry* next() {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    51
        return (Entry*)BasicHashtableEntry<mtTracing>::next();
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    52
      }
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    53
    };
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    54
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    55
  protected:
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    56
    Entry* bucket(int i) const;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    57
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    58
    Entry* new_entry(unsigned int hashValue, uintptr_t key, CHeapBitMap* value);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    59
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    60
    unsigned hash_segment(uintptr_t key) {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    61
      unsigned hash = (unsigned)key;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    62
      return hash ^ (hash >> 3);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    63
    }
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    64
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    65
    unsigned hash_to_index(unsigned hash) {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    66
      return hash & (BasicHashtable<mtTracing>::table_size() - 1);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    67
    }
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    68
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    69
  public:
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    70
    BitMapFragmentTable(int table_size) : BasicHashtable<mtTracing>(table_size, sizeof(Entry)) {}
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    71
    void add(uintptr_t key, CHeapBitMap* value);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    72
    CHeapBitMap** lookup(uintptr_t key);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    73
  };
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    74
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    75
  CHeapBitMap* get_fragment_bits(uintptr_t addr);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    76
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    77
  BitMapFragmentTable _bitmap_fragments;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    78
  BitMapFragment* _fragment_list;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    79
  CHeapBitMap* _last_fragment_bits;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    80
  uintptr_t _last_fragment_granule;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
 public:
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    83
  BitSet();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
  ~BitSet();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    86
  BitMap::idx_t addr_to_bit(uintptr_t addr) const;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    88
  void mark_obj(uintptr_t addr);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    89
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    90
  void mark_obj(oop obj) {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    91
    return mark_obj(cast_from_oop<uintptr_t>(obj));
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    94
  bool is_marked(uintptr_t addr);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    95
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    96
  bool is_marked(oop obj) {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    97
    return is_marked(cast_from_oop<uintptr_t>(obj));
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
  }
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
    99
};
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   101
class BitSet::BitMapFragment : public CHeapObj<mtTracing> {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   102
  CHeapBitMap _bits;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   103
  BitMapFragment* _next;
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   104
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   105
public:
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   106
  BitMapFragment(uintptr_t granule, BitMapFragment* next);
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   107
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   108
  BitMapFragment* next() const {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   109
    return _next;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
58014
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   112
  CHeapBitMap* bits() {
aba258cd7df8 8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents: 55571
diff changeset
   113
    return &_bits;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50113
diff changeset
   117
#endif // SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP