src/hotspot/share/gc/shared/markBitMap.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 52577 5b87d3fc1093
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51578
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52577
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
51578
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     4
 *
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     8
 *
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    13
 * accompanied this code).
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    14
 *
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    18
 *
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    21
 * questions.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    22
 *
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    23
 */
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52577
diff changeset
    25
#ifndef SHARE_GC_SHARED_MARKBITMAP_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52577
diff changeset
    26
#define SHARE_GC_SHARED_MARKBITMAP_HPP
51578
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    27
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    28
#include "memory/memRegion.hpp"
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    29
#include "oops/oopsHierarchy.hpp"
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    30
#include "utilities/bitMap.hpp"
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    31
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    32
// A generic mark bitmap for concurrent marking.  This is essentially a wrapper
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    33
// around the BitMap class that is based on HeapWords, with one bit per (1 << _shifter) HeapWords.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    34
class MarkBitMap {
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    35
protected:
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    36
  MemRegion _covered;    // The heap area covered by this bitmap.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    37
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    38
  const int _shifter;    // Shift amount from heap index to bit index in the bitmap.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    39
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    40
  BitMapView _bm;        // The actual bitmap.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    41
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    42
  virtual void check_mark(HeapWord* addr) NOT_DEBUG_RETURN;
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    43
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    44
  // Convert from bit offset to address.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    45
  HeapWord* offset_to_addr(size_t offset) const {
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    46
    return _covered.start() + (offset << _shifter);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    47
  }
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    48
  // Convert from address to bit offset.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    49
  size_t addr_to_offset(const HeapWord* addr) const {
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    50
    return pointer_delta(addr, _covered.start()) >> _shifter;
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    51
  }
52577
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    52
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    53
  // Clear bitmap range
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    54
  void do_clear(MemRegion mr, bool large);
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    55
51578
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    56
public:
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    57
  static size_t compute_size(size_t heap_size);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    58
  // Returns the amount of bytes on the heap between two marks in the bitmap.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    59
  static size_t mark_distance();
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    60
  // Returns how many bytes (or bits) of the heap a single byte (or bit) of the
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    61
  // mark bitmap corresponds to. This is the same as the mark distance above.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    62
  static size_t heap_map_factor() {
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    63
    return mark_distance();
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    64
  }
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    65
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    66
  MarkBitMap() : _covered(), _shifter(LogMinObjAlignment), _bm() {}
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    67
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    68
  // Initializes the underlying BitMap to cover the given area.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    69
  void initialize(MemRegion heap, MemRegion storage);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    70
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    71
  // Read marks
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    72
  bool is_marked(oop obj) const;
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    73
  bool is_marked(HeapWord* addr) const {
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    74
    assert(_covered.contains(addr),
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    75
           "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT,
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    76
           p2i(addr), p2i(_covered.start()), p2i(_covered.end()));
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    77
    return _bm.at(addr_to_offset(addr));
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    78
  }
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    79
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    80
  // Return the address corresponding to the next marked bit at or after
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    81
  // "addr", and before "limit", if "limit" is non-NULL.  If there is no
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    82
  // such bit, returns "limit" if that is non-NULL, or else "endWord()".
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    83
  inline HeapWord* get_next_marked_addr(const HeapWord* addr,
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    84
                                        const HeapWord* limit) const;
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    85
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    86
  void print_on_error(outputStream* st, const char* prefix) const;
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    87
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    88
  // Write marks.
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    89
  inline void mark(HeapWord* addr);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    90
  inline void clear(HeapWord* addr);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    91
  inline void clear(oop obj);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    92
  inline bool par_mark(HeapWord* addr);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    93
  inline bool par_mark(oop obj);
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    94
52577
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    95
  // Clear bitmap.
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    96
  void clear()                         { do_clear(_covered, true); }
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    97
  void clear_range(MemRegion mr)       { do_clear(mr, false);      }
5b87d3fc1093 8213373: Bulk MarkBitMap clearing methods
shade
parents: 51578
diff changeset
    98
  void clear_range_large(MemRegion mr) { do_clear(mr, true);       }
51578
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
    99
};
31b159f30fb2 8180193: Make marking bitmap code available to other GCs
rkennke
parents:
diff changeset
   100
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52577
diff changeset
   101
#endif // SHARE_GC_SHARED_MARKBITMAP_HPP