src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.hpp
author sjohanss
Tue, 14 Nov 2017 11:33:23 +0100
changeset 47885 5caa1d5f74c1
parent 47216 71c04702a3d5
child 49392 2956d0ece7a9
permissions -rw-r--r--
8186571: Implementation: JEP 307: Parallel Full GC for G1 Summary: Improve G1 worst-case latencies by making the full GC parallel. Reviewed-by: tschatzl, sangheki, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46751
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     1
/*
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     4
 *
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     8
 *
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    14
 *
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    18
 *
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    21
 * questions.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    22
 *
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    23
 */
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    24
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    26
#define SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    27
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    28
#include "gc/g1/g1RegionToSpaceMapper.hpp"
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    29
#include "memory/allocation.hpp"
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    30
#include "memory/memRegion.hpp"
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
    31
#include "oops/oopsHierarchy.hpp"
46751
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    32
#include "utilities/bitMap.hpp"
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    34
#include "utilities/macros.hpp"
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    35
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    36
class G1CMBitMap;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    37
class G1CMTask;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    38
class G1ConcurrentMark;
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
    39
class HeapRegion;
46751
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    40
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    41
// Closure for iteration over bitmaps
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    42
class G1CMBitMapClosure VALUE_OBJ_CLASS_SPEC {
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    43
private:
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    44
  G1ConcurrentMark* const _cm;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    45
  G1CMTask* const _task;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    46
public:
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    47
  G1CMBitMapClosure(G1CMTask *task, G1ConcurrentMark* cm) : _task(task), _cm(cm) { }
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    48
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    49
  bool do_addr(HeapWord* const addr);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    50
};
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    51
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    52
class G1CMBitMapMappingChangedListener : public G1MappingChangedListener {
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    53
 private:
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    54
  G1CMBitMap* _bm;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    55
 public:
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    56
  G1CMBitMapMappingChangedListener() : _bm(NULL) {}
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    57
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    58
  void set_bitmap(G1CMBitMap* bm) { _bm = bm; }
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    59
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    60
  virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    61
};
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    62
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    63
// A generic mark bitmap for concurrent marking.  This is essentially a wrapper
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    64
// around the BitMap class that is based on HeapWords, with one bit per (1 << _shifter) HeapWords.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    65
class G1CMBitMap VALUE_OBJ_CLASS_SPEC {
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    66
private:
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    67
  MemRegion _covered;    // The heap area covered by this bitmap.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    68
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    69
  const int _shifter;    // Shift amount from heap index to bit index in the bitmap.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    70
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    71
  BitMapView _bm;        // The actual bitmap.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    72
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    73
  G1CMBitMapMappingChangedListener _listener;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    74
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    75
  inline void check_mark(HeapWord* addr) NOT_DEBUG_RETURN;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    76
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    77
  // Convert from bit offset to address.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    78
  HeapWord* offset_to_addr(size_t offset) const {
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    79
    return _covered.start() + (offset << _shifter);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    80
  }
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    81
  // Convert from address to bit offset.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    82
  size_t addr_to_offset(const HeapWord* addr) const {
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    83
    return pointer_delta(addr, _covered.start()) >> _shifter;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    84
  }
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    85
public:
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    86
  static size_t compute_size(size_t heap_size);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    87
  // Returns the amount of bytes on the heap between two marks in the bitmap.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    88
  static size_t mark_distance();
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    89
  // Returns how many bytes (or bits) of the heap a single byte (or bit) of the
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    90
  // mark bitmap corresponds to. This is the same as the mark distance above.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    91
  static size_t heap_map_factor() {
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    92
    return mark_distance();
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    93
  }
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    94
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    95
  G1CMBitMap() : _covered(), _bm(), _shifter(LogMinObjAlignment), _listener() { _listener.set_bitmap(this); }
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    96
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    97
  // Initializes the underlying BitMap to cover the given area.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    98
  void initialize(MemRegion heap, G1RegionToSpaceMapper* storage);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
    99
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   100
  // Read marks
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
   101
  bool is_marked(oop obj) const;
46751
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   102
  bool is_marked(HeapWord* addr) const {
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   103
    assert(_covered.contains(addr),
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   104
           "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT,
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   105
           p2i(addr), p2i(_covered.start()), p2i(_covered.end()));
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   106
    return _bm.at(addr_to_offset(addr));
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   107
  }
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   108
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   109
  // Apply the closure to the addresses that correspond to marked bits in the bitmap.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   110
  inline bool iterate(G1CMBitMapClosure* cl, MemRegion mr);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   111
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   112
  // Return the address corresponding to the next marked bit at or after
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   113
  // "addr", and before "limit", if "limit" is non-NULL.  If there is no
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   114
  // such bit, returns "limit" if that is non-NULL, or else "endWord()".
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   115
  inline HeapWord* get_next_marked_addr(const HeapWord* addr,
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   116
                                        const HeapWord* limit) const;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   117
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   118
  // The argument addr should be the start address of a valid object
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   119
  inline HeapWord* addr_after_obj(HeapWord* addr);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   120
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   121
  void print_on_error(outputStream* st, const char* prefix) const;
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   122
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   123
  // Write marks.
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   124
  inline void mark(HeapWord* addr);
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   125
  inline void clear(HeapWord* addr);
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
   126
  inline void clear(oop obj);
46751
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   127
  inline bool par_mark(HeapWord* addr);
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
   128
  inline bool par_mark(oop obj);
46751
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   129
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   130
  void clear_range(MemRegion mr);
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
   131
  void clear_region(HeapRegion* hr);
46751
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   132
};
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   133
d2e0cecdbcb0 8184347: Move G1CMBitMap and support classes into their own files
tschatzl
parents:
diff changeset
   134
#endif // SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP