src/hotspot/share/gc/g1/g1HeapVerifier.cpp
author tschatzl
Wed, 18 Apr 2018 11:36:48 +0200
changeset 49806 2d62570a615c
parent 49664 9a04cc89dde0
child 50565 69e82329ad01
permissions -rw-r--r--
8200426: Make G1 code use _g1h members Summary: Consistently use _g1h member names for cached G1CollectedHeap* variables. Reviewed-by: sangheki, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     1
/*
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     4
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     8
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    13
 * accompanied this code).
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    14
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    18
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    21
 * questions.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    22
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    23
 */
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    24
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    25
#include "precompiled.hpp"
46285
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 39698
diff changeset
    26
#include "gc/g1/g1Allocator.inline.hpp"
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    27
#include "gc/g1/g1CollectedHeap.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    28
#include "gc/g1/g1CollectedHeap.inline.hpp"
49659
0ed1370f52bb 8200371: In g1, rename ConcurrentMarkThread to G1ConcurrentMarkThread
lkorinth
parents: 49643
diff changeset
    29
#include "gc/g1/g1ConcurrentMarkThread.hpp"
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    30
#include "gc/g1/g1HeapVerifier.hpp"
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37242
diff changeset
    31
#include "gc/g1/g1Policy.hpp"
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    32
#include "gc/g1/g1RemSet.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    33
#include "gc/g1/g1RootProcessor.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    34
#include "gc/g1/heapRegion.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    35
#include "gc/g1/heapRegion.inline.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    36
#include "gc/g1/heapRegionRemSet.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    37
#include "gc/g1/g1StringDedup.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46611
diff changeset
    38
#include "logging/log.hpp"
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46611
diff changeset
    39
#include "logging/logStream.hpp"
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    40
#include "memory/resourceArea.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
    41
#include "oops/access.inline.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
    42
#include "oops/compressedOops.inline.hpp"
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    43
#include "oops/oop.inline.hpp"
49361
1956d0ec092a 8199319: Remove handles.inline.hpp include from reflectionUtils.hpp
stefank
parents: 49164
diff changeset
    44
#include "runtime/handles.inline.hpp"
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    45
49602
db050c11c3b5 8199850: Move parsing of VerifyGCType to G1
pliden
parents: 49592
diff changeset
    46
int G1HeapVerifier::_enabled_verification_types = G1HeapVerifier::G1VerifyAll;
db050c11c3b5 8199850: Move parsing of VerifyGCType to G1
pliden
parents: 49592
diff changeset
    47
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    48
class VerifyRootsClosure: public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    49
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    50
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    51
  VerifyOption     _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    52
  bool             _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    53
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    54
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    55
  // _vo == UseNextMarking -> use "next" marking information,
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
    56
  // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    57
  VerifyRootsClosure(VerifyOption vo) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    58
    _g1h(G1CollectedHeap::heap()),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    59
    _vo(vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    60
    _failures(false) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    61
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    62
  bool failures() { return _failures; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    63
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    64
  template <class T> void do_oop_nv(T* p) {
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
    65
    T heap_oop = RawAccess<>::oop_load(p);
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
    66
    if (!CompressedOops::is_null(heap_oop)) {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
    67
      oop obj = CompressedOops::decode_not_null(heap_oop);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    68
      if (_g1h->is_obj_dead_cond(obj, _vo)) {
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36090
diff changeset
    69
        Log(gc, verify) log;
47088
03cfedd40b53 8185624: G1HeapVerifier's VerifyRootsClosure prints important information on info log level
dbuck
parents: 46810
diff changeset
    70
        log.error("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    71
        ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46611
diff changeset
    72
        LogStream ls(log.error());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46611
diff changeset
    73
        obj->print_on(&ls);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    74
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    75
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    76
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    77
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    78
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    79
  void do_oop(oop* p)       { do_oop_nv(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    80
  void do_oop(narrowOop* p) { do_oop_nv(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    81
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    82
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    83
class G1VerifyCodeRootOopClosure: public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    84
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    85
  OopClosure* _root_cl;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    86
  nmethod* _nm;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    87
  VerifyOption _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    88
  bool _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    89
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    90
  template <class T> void do_oop_work(T* p) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    91
    // First verify that this root is live
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    92
    _root_cl->do_oop(p);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    93
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    94
    if (!G1VerifyHeapRegionCodeRoots) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    95
      // We're not verifying the code roots attached to heap region.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    96
      return;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    97
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    98
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    99
    // Don't check the code roots during marking verification in a full GC
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   100
    if (_vo == VerifyOption_G1UseFullMarking) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   101
      return;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   102
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   103
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   104
    // Now verify that the current nmethod (which contains p) is
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   105
    // in the code root list of the heap region containing the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   106
    // object referenced by p.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   107
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
   108
    T heap_oop = RawAccess<>::oop_load(p);
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
   109
    if (!CompressedOops::is_null(heap_oop)) {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
   110
      oop obj = CompressedOops::decode_not_null(heap_oop);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   111
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   112
      // Now fetch the region containing the object
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   113
      HeapRegion* hr = _g1h->heap_region_containing(obj);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   114
      HeapRegionRemSet* hrrs = hr->rem_set();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   115
      // Verify that the strong code root list for this region
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   116
      // contains the nmethod
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   117
      if (!hrrs->strong_code_roots_list_contains(_nm)) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   118
        log_error(gc, verify)("Code root location " PTR_FORMAT " "
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   119
                              "from nmethod " PTR_FORMAT " not in strong "
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   120
                              "code roots for region [" PTR_FORMAT "," PTR_FORMAT ")",
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   121
                              p2i(p), p2i(_nm), p2i(hr->bottom()), p2i(hr->end()));
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   122
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   123
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   124
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   125
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   126
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   127
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   128
  G1VerifyCodeRootOopClosure(G1CollectedHeap* g1h, OopClosure* root_cl, VerifyOption vo):
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   129
    _g1h(g1h), _root_cl(root_cl), _vo(vo), _nm(NULL), _failures(false) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   130
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   131
  void do_oop(oop* p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   132
  void do_oop(narrowOop* p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   133
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   134
  void set_nmethod(nmethod* nm) { _nm = nm; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   135
  bool failures() { return _failures; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   136
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   137
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   138
class G1VerifyCodeRootBlobClosure: public CodeBlobClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   139
  G1VerifyCodeRootOopClosure* _oop_cl;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   140
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   141
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   142
  G1VerifyCodeRootBlobClosure(G1VerifyCodeRootOopClosure* oop_cl):
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   143
    _oop_cl(oop_cl) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   144
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   145
  void do_code_blob(CodeBlob* cb) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   146
    nmethod* nm = cb->as_nmethod_or_null();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   147
    if (nm != NULL) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   148
      _oop_cl->set_nmethod(nm);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   149
      nm->oops_do(_oop_cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   150
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   151
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   152
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   153
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   154
class YoungRefCounterClosure : public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   155
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   156
  int              _count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   157
 public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   158
  YoungRefCounterClosure(G1CollectedHeap* g1h) : _g1h(g1h), _count(0) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   159
  void do_oop(oop* p)       { if (_g1h->is_in_young(*p)) { _count++; } }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   160
  void do_oop(narrowOop* p) { ShouldNotReachHere(); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   161
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   162
  int count() { return _count; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   163
  void reset_count() { _count = 0; };
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   164
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   165
47580
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   166
class VerifyCLDClosure: public CLDClosure {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   167
  YoungRefCounterClosure _young_ref_counter_closure;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   168
  OopClosure *_oop_closure;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   169
 public:
47580
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   170
  VerifyCLDClosure(G1CollectedHeap* g1h, OopClosure* cl) : _young_ref_counter_closure(g1h), _oop_closure(cl) {}
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   171
  void do_cld(ClassLoaderData* cld) {
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   172
    cld->oops_do(_oop_closure, false);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   173
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   174
    _young_ref_counter_closure.reset_count();
47580
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   175
    cld->oops_do(&_young_ref_counter_closure, false);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   176
    if (_young_ref_counter_closure.count() > 0) {
47580
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   177
      guarantee(cld->has_modified_oops(), "CLD " PTR_FORMAT ", has young %d refs but is not dirty.", p2i(cld), _young_ref_counter_closure.count());
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   178
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   179
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   180
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   181
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   182
class VerifyLivenessOopClosure: public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   183
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   184
  VerifyOption _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   185
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   186
  VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo):
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   187
    _g1h(g1h), _vo(vo)
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   188
  { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   189
  void do_oop(narrowOop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   190
  void do_oop(      oop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   191
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   192
  template <class T> void do_oop_work(T *p) {
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
   193
    oop obj = RawAccess<>::oop_load(p);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   194
    guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   195
              "Dead object referenced by a not dead object");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   196
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   197
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   198
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   199
class VerifyObjsInRegionClosure: public ObjectClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   200
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   201
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   202
  size_t _live_bytes;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   203
  HeapRegion *_hr;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   204
  VerifyOption _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   205
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   206
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   207
  // _vo == UseNextMarking -> use "next" marking information,
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   208
  // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS.
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   209
  VerifyObjsInRegionClosure(HeapRegion *hr, VerifyOption vo)
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   210
    : _live_bytes(0), _hr(hr), _vo(vo) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   211
    _g1h = G1CollectedHeap::heap();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   212
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   213
  void do_object(oop o) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   214
    VerifyLivenessOopClosure isLive(_g1h, _vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   215
    assert(o != NULL, "Huh?");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   216
    if (!_g1h->is_obj_dead_cond(o, _vo)) {
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   217
      // If the object is alive according to the full gc mark,
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   218
      // then verify that the marking information agrees.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   219
      // Note we can't verify the contra-positive of the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   220
      // above: if the object is dead (according to the mark
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   221
      // word), it may not be marked, or may have been marked
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   222
      // but has since became dead, or may have been allocated
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   223
      // since the last marking.
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   224
      if (_vo == VerifyOption_G1UseFullMarking) {
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   225
        guarantee(!_g1h->is_obj_dead(o), "Full GC marking and concurrent mark mismatch");
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   226
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   227
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   228
      o->oop_iterate_no_header(&isLive);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   229
      if (!_hr->obj_allocated_since_prev_marking(o)) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   230
        size_t obj_size = o->size();    // Make sure we don't overflow
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   231
        _live_bytes += (obj_size * HeapWordSize);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   232
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   233
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   234
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   235
  size_t live_bytes() { return _live_bytes; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   236
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   237
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   238
class VerifyArchiveOopClosure: public OopClosure {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   239
  HeapRegion* _hr;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   240
public:
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   241
  VerifyArchiveOopClosure(HeapRegion *hr)
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   242
    : _hr(hr) { }
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   243
  void do_oop(narrowOop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   244
  void do_oop(      oop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   245
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   246
  template <class T> void do_oop_work(T *p) {
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49361
diff changeset
   247
    oop obj = RawAccess<>::oop_load(p);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   248
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   249
    if (_hr->is_open_archive()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   250
      guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj),
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   251
                "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   252
                p2i(p), p2i(obj));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   253
    } else {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   254
      assert(_hr->is_closed_archive(), "should be closed archive region");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   255
      guarantee(obj == NULL || G1ArchiveAllocator::is_closed_archive_object(obj),
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   256
                "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   257
                p2i(p), p2i(obj));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   258
    }
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   259
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   260
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   261
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   262
class VerifyObjectInArchiveRegionClosure: public ObjectClosure {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   263
  HeapRegion* _hr;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   264
public:
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   265
  VerifyObjectInArchiveRegionClosure(HeapRegion *hr, bool verbose)
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   266
    : _hr(hr) { }
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   267
  // Verify that all object pointers are to archive regions.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   268
  void do_object(oop o) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   269
    VerifyArchiveOopClosure checkOop(_hr);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   270
    assert(o != NULL, "Should not be here for NULL oops");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   271
    o->oop_iterate_no_header(&checkOop);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   272
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   273
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   274
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   275
// Should be only used at CDS dump time
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   276
class VerifyArchivePointerRegionClosure: public HeapRegionClosure {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   277
private:
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   278
  G1CollectedHeap* _g1h;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   279
public:
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   280
  VerifyArchivePointerRegionClosure(G1CollectedHeap* g1h) { }
48969
jwilhelm
parents: 48890
diff changeset
   281
  virtual bool do_heap_region(HeapRegion* r) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   282
   if (r->is_archive()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   283
      VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   284
      r->object_iterate(&verify_oop_pointers);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   285
    }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   286
    return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   287
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   288
};
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   289
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   290
void G1HeapVerifier::verify_archive_regions() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   291
  G1CollectedHeap*  g1h = G1CollectedHeap::heap();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   292
  VerifyArchivePointerRegionClosure cl(NULL);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   293
  g1h->heap_region_iterate(&cl);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   294
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   295
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   296
class VerifyRegionClosure: public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   297
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   298
  bool             _par;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   299
  VerifyOption     _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   300
  bool             _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   301
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   302
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   303
  // _vo == UseNextMarking -> use "next" marking information,
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   304
  // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   305
  VerifyRegionClosure(bool par, VerifyOption vo)
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   306
    : _par(par),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   307
      _vo(vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   308
      _failures(false) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   309
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   310
  bool failures() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   311
    return _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   312
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   313
48969
jwilhelm
parents: 48890
diff changeset
   314
  bool do_heap_region(HeapRegion* r) {
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49602
diff changeset
   315
    guarantee(!r->is_young() || r->rem_set()->is_complete(), "Remembered set for Young region %u must be complete, is %s", r->hrm_index(), r->rem_set()->get_state_str());
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49602
diff changeset
   316
    // Humongous and old regions regions might be of any state, so can't check here.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49602
diff changeset
   317
    guarantee(!r->is_free() || !r->rem_set()->is_tracked(), "Remembered set for free region %u must be untracked, is %s", r->hrm_index(), r->rem_set()->get_state_str());
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   318
    // For archive regions, verify there are no heap pointers to
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   319
    // non-pinned regions. For all others, verify liveness info.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   320
    if (r->is_closed_archive()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   321
      VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   322
      r->object_iterate(&verify_oop_pointers);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   323
      return true;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   324
    } else if (r->is_open_archive()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   325
      VerifyObjsInRegionClosure verify_open_archive_oop(r, _vo);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   326
      r->object_iterate(&verify_open_archive_oop);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   327
      return true;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   328
    } else if (!r->is_continues_humongous()) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   329
      bool failures = false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   330
      r->verify(_vo, &failures);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   331
      if (failures) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   332
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   333
      } else if (!r->is_starts_humongous()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   334
        VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   335
        r->object_iterate(&not_dead_yet_cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   336
        if (_vo != VerifyOption_G1UseNextMarking) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   337
          if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   338
            log_error(gc, verify)("[" PTR_FORMAT "," PTR_FORMAT "] max_live_bytes " SIZE_FORMAT " < calculated " SIZE_FORMAT,
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   339
                                  p2i(r->bottom()), p2i(r->end()), r->max_live_bytes(), not_dead_yet_cl.live_bytes());
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   340
            _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   341
          }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   342
        } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   343
          // When vo == UseNextMarking we cannot currently do a sanity
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   344
          // check on the live bytes as the calculation has not been
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   345
          // finalized yet.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   346
        }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   347
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   348
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   349
    return false; // stop the region iteration if we hit a failure
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   350
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   351
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   352
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   353
// This is the task used for parallel verification of the heap regions
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   354
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   355
class G1ParVerifyTask: public AbstractGangTask {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   356
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   357
  G1CollectedHeap*  _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   358
  VerifyOption      _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   359
  bool              _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   360
  HeapRegionClaimer _hrclaimer;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   361
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   362
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   363
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   364
  // _vo == UseNextMarking -> use "next" marking information,
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   365
  // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   366
  G1ParVerifyTask(G1CollectedHeap* g1h, VerifyOption vo) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   367
      AbstractGangTask("Parallel verify task"),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   368
      _g1h(g1h),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   369
      _vo(vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   370
      _failures(false),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   371
      _hrclaimer(g1h->workers()->active_workers()) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   372
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   373
  bool failures() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   374
    return _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   375
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   376
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   377
  void work(uint worker_id) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   378
    HandleMark hm;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   379
    VerifyRegionClosure blk(true, _vo);
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47678
diff changeset
   380
    _g1h->heap_region_par_iterate_from_worker_offset(&blk, &_hrclaimer, worker_id);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   381
    if (blk.failures()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   382
      _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   383
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   384
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   385
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   386
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   387
void G1HeapVerifier::enable_verification_type(G1VerifyType type) {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   388
  // First enable will clear _enabled_verification_types.
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   389
  if (_enabled_verification_types == G1VerifyAll) {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   390
    _enabled_verification_types = type;
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   391
  } else {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   392
    _enabled_verification_types |= type;
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   393
  }
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   394
}
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   395
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   396
bool G1HeapVerifier::should_verify(G1VerifyType type) {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   397
  return (_enabled_verification_types & type) == type;
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   398
}
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   399
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   400
void G1HeapVerifier::verify(VerifyOption vo) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   401
  if (!SafepointSynchronize::is_at_safepoint()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   402
    log_info(gc, verify)("Skipping verification. Not at safepoint.");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   403
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   404
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   405
  assert(Thread::current()->is_VM_thread(),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   406
         "Expected to be executed serially by the VM thread at this point");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   407
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   408
  log_debug(gc, verify)("Roots");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   409
  VerifyRootsClosure rootsCl(vo);
47580
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   410
  VerifyCLDClosure cldCl(_g1h, &rootsCl);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   411
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   412
  // We apply the relevant closures to all the oops in the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   413
  // system dictionary, class loader data graph, the string table
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   414
  // and the nmethods in the code cache.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   415
  G1VerifyCodeRootOopClosure codeRootsCl(_g1h, &rootsCl, vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   416
  G1VerifyCodeRootBlobClosure blobsCl(&codeRootsCl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   417
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   418
  {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   419
    G1RootProcessor root_processor(_g1h, 1);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   420
    root_processor.process_all_roots(&rootsCl,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   421
                                     &cldCl,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   422
                                     &blobsCl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   423
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   424
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   425
  bool failures = rootsCl.failures() || codeRootsCl.failures();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   426
49643
a3453bbd5418 8199742: Clean up state flags in G1CollectorState
tschatzl
parents: 49632
diff changeset
   427
  if (!_g1h->g1_policy()->collector_state()->in_full_gc()) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   428
    // If we're verifying during a full GC then the region sets
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   429
    // will have been torn down at the start of the GC. Therefore
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   430
    // verifying the region sets will fail. So we only verify
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   431
    // the region sets when not in a full GC.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   432
    log_debug(gc, verify)("HeapRegionSets");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   433
    verify_region_sets();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   434
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   435
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   436
  log_debug(gc, verify)("HeapRegions");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   437
  if (GCParallelVerificationEnabled && ParallelGCThreads > 1) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   438
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   439
    G1ParVerifyTask task(_g1h, vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   440
    _g1h->workers()->run_task(&task);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   441
    if (task.failures()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   442
      failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   443
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   444
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   445
  } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   446
    VerifyRegionClosure blk(false, vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   447
    _g1h->heap_region_iterate(&blk);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   448
    if (blk.failures()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   449
      failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   450
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   451
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   452
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   453
  if (G1StringDedup::is_enabled()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   454
    log_debug(gc, verify)("StrDedup");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   455
    G1StringDedup::verify();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   456
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   457
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   458
  if (failures) {
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49602
diff changeset
   459
    log_error(gc, verify)("Heap after failed verification (kind %d):", vo);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   460
    // It helps to have the per-region information in the output to
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   461
    // help us track down what went wrong. This is why we call
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   462
    // print_extended_on() instead of print_on().
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36090
diff changeset
   463
    Log(gc, verify) log;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   464
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46611
diff changeset
   465
    LogStream ls(log.error());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46611
diff changeset
   466
    _g1h->print_extended_on(&ls);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   467
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   468
  guarantee(!failures, "there should not have been any failures");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   469
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   470
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   471
// Heap region set verification
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   472
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   473
class VerifyRegionListsClosure : public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   474
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   475
  HeapRegionSet*   _old_set;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   476
  HeapRegionSet*   _humongous_set;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   477
  HeapRegionManager*   _hrm;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   478
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   479
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   480
  uint _old_count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   481
  uint _humongous_count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   482
  uint _free_count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   483
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   484
  VerifyRegionListsClosure(HeapRegionSet* old_set,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   485
                           HeapRegionSet* humongous_set,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   486
                           HeapRegionManager* hrm) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   487
    _old_set(old_set), _humongous_set(humongous_set), _hrm(hrm),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   488
    _old_count(), _humongous_count(), _free_count(){ }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   489
48969
jwilhelm
parents: 48890
diff changeset
   490
  bool do_heap_region(HeapRegion* hr) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   491
    if (hr->is_young()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   492
      // TODO
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   493
    } else if (hr->is_humongous()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   494
      assert(hr->containing_set() == _humongous_set, "Heap region %u is humongous but not in humongous set.", hr->hrm_index());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   495
      _humongous_count++;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   496
    } else if (hr->is_empty()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   497
      assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   498
      _free_count++;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   499
    } else if (hr->is_old()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   500
      assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   501
      _old_count++;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   502
    } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   503
      // There are no other valid region types. Check for one invalid
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   504
      // one we can identify: pinned without old or humongous set.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   505
      assert(!hr->is_pinned(), "Heap region %u is pinned but not old (archive) or humongous.", hr->hrm_index());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   506
      ShouldNotReachHere();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   507
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   508
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   509
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   510
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   511
  void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   512
    guarantee(old_set->length() == _old_count, "Old set count mismatch. Expected %u, actual %u.", old_set->length(), _old_count);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   513
    guarantee(humongous_set->length() == _humongous_count, "Hum set count mismatch. Expected %u, actual %u.", humongous_set->length(), _humongous_count);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   514
    guarantee(free_list->num_free_regions() == _free_count, "Free list count mismatch. Expected %u, actual %u.", free_list->num_free_regions(), _free_count);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   515
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   516
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   517
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   518
void G1HeapVerifier::verify_region_sets() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   519
  assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   520
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   521
  // First, check the explicit lists.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   522
  _g1h->_hrm.verify();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   523
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   524
  // Finally, make sure that the region accounting in the lists is
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   525
  // consistent with what we see in the heap.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   526
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   527
  VerifyRegionListsClosure cl(&_g1h->_old_set, &_g1h->_humongous_set, &_g1h->_hrm);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   528
  _g1h->heap_region_iterate(&cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   529
  cl.verify_counts(&_g1h->_old_set, &_g1h->_humongous_set, &_g1h->_hrm);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   530
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   531
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   532
void G1HeapVerifier::prepare_for_verify() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   533
  if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   534
    _g1h->ensure_parsability(false);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   535
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   536
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   537
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   538
double G1HeapVerifier::verify(G1VerifyType type, VerifyOption vo, const char* msg) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   539
  double verify_time_ms = 0.0;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   540
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   541
  if (should_verify(type) && _g1h->total_collections() >= VerifyGCStartAt) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   542
    double verify_start = os::elapsedTime();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   543
    HandleMark hm;  // Discard invalid handles created during verification
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   544
    prepare_for_verify();
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   545
    Universe::verify(vo, msg);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   546
    verify_time_ms = (os::elapsedTime() - verify_start) * 1000;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   547
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   548
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   549
  return verify_time_ms;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   550
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   551
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   552
void G1HeapVerifier::verify_before_gc(G1VerifyType type) {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   553
  if (VerifyBeforeGC) {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   554
    double verify_time_ms = verify(type, VerifyOption_G1UsePrevMarking, "Before GC");
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   555
    _g1h->g1_policy()->phase_times()->record_verify_before_time_ms(verify_time_ms);
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   556
  }
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   557
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   558
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   559
void G1HeapVerifier::verify_after_gc(G1VerifyType type) {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   560
  if (VerifyAfterGC) {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   561
    double verify_time_ms = verify(type, VerifyOption_G1UsePrevMarking, "After GC");
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   562
    _g1h->g1_policy()->phase_times()->record_verify_after_time_ms(verify_time_ms);
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
   563
  }
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   564
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   565
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   566
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   567
#ifndef PRODUCT
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   568
class G1VerifyCardTableCleanup: public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   569
  G1HeapVerifier* _verifier;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   570
public:
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   571
  G1VerifyCardTableCleanup(G1HeapVerifier* verifier)
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   572
    : _verifier(verifier) { }
48969
jwilhelm
parents: 48890
diff changeset
   573
  virtual bool do_heap_region(HeapRegion* r) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   574
    if (r->is_survivor()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   575
      _verifier->verify_dirty_region(r);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   576
    } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   577
      _verifier->verify_not_dirty_region(r);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   578
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   579
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   580
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   581
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   582
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   583
void G1HeapVerifier::verify_card_table_cleanup() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   584
  if (G1VerifyCTCleanup || VerifyAfterGC) {
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   585
    G1VerifyCardTableCleanup cleanup_verifier(this);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   586
    _g1h->heap_region_iterate(&cleanup_verifier);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   587
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   588
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   589
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   590
void G1HeapVerifier::verify_not_dirty_region(HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   591
  // All of the region should be clean.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   592
  G1CardTable* ct = _g1h->card_table();
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   593
  MemRegion mr(hr->bottom(), hr->end());
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   594
  ct->verify_not_dirty_region(mr);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   595
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   596
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   597
void G1HeapVerifier::verify_dirty_region(HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   598
  // We cannot guarantee that [bottom(),end()] is dirty.  Threads
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   599
  // dirty allocated blocks as they allocate them. The thread that
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   600
  // retires each region and replaces it with a new one will do a
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   601
  // maximal allocation to fill in [pre_dummy_top(),end()] but will
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   602
  // not dirty that area (one less thing to have to do while holding
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   603
  // a lock). So we can only verify that [bottom(),pre_dummy_top()]
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   604
  // is dirty.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   605
  G1CardTable* ct = _g1h->card_table();
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   606
  MemRegion mr(hr->bottom(), hr->pre_dummy_top());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   607
  if (hr->is_young()) {
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   608
    ct->verify_g1_young_region(mr);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   609
  } else {
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   610
    ct->verify_dirty_region(mr);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   611
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   612
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   613
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   614
class G1VerifyDirtyYoungListClosure : public HeapRegionClosure {
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   615
private:
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   616
  G1HeapVerifier* _verifier;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   617
public:
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   618
  G1VerifyDirtyYoungListClosure(G1HeapVerifier* verifier) : HeapRegionClosure(), _verifier(verifier) { }
48969
jwilhelm
parents: 48890
diff changeset
   619
  virtual bool do_heap_region(HeapRegion* r) {
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   620
    _verifier->verify_dirty_region(r);
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   621
    return false;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   622
  }
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   623
};
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   624
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   625
void G1HeapVerifier::verify_dirty_young_regions() {
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   626
  G1VerifyDirtyYoungListClosure cl(this);
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   627
  _g1h->collection_set()->iterate(&cl);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   628
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   629
46750
bcab0128a16f 8184346: Clean up G1CMBitmap
tschatzl
parents: 46701
diff changeset
   630
bool G1HeapVerifier::verify_no_bits_over_tams(const char* bitmap_name, const G1CMBitMap* const bitmap,
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   631
                                               HeapWord* tams, HeapWord* end) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   632
  guarantee(tams <= end,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   633
            "tams: " PTR_FORMAT " end: " PTR_FORMAT, p2i(tams), p2i(end));
46750
bcab0128a16f 8184346: Clean up G1CMBitmap
tschatzl
parents: 46701
diff changeset
   634
  HeapWord* result = bitmap->get_next_marked_addr(tams, end);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   635
  if (result < end) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   636
    log_error(gc, verify)("## wrong marked address on %s bitmap: " PTR_FORMAT, bitmap_name, p2i(result));
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   637
    log_error(gc, verify)("## %s tams: " PTR_FORMAT " end: " PTR_FORMAT, bitmap_name, p2i(tams), p2i(end));
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   638
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   639
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   640
  return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   641
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   642
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   643
bool G1HeapVerifier::verify_bitmaps(const char* caller, HeapRegion* hr) {
47678
c84eeb55c55e 8184667: Clean up G1ConcurrentMark files
tschatzl
parents: 47580
diff changeset
   644
  const G1CMBitMap* const prev_bitmap = _g1h->concurrent_mark()->prev_mark_bitmap();
c84eeb55c55e 8184667: Clean up G1ConcurrentMark files
tschatzl
parents: 47580
diff changeset
   645
  const G1CMBitMap* const next_bitmap = _g1h->concurrent_mark()->next_mark_bitmap();
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   646
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   647
  HeapWord* ptams  = hr->prev_top_at_mark_start();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   648
  HeapWord* ntams  = hr->next_top_at_mark_start();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   649
  HeapWord* end    = hr->end();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   650
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   651
  bool res_p = verify_no_bits_over_tams("prev", prev_bitmap, ptams, end);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   652
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   653
  bool res_n = true;
49664
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   654
  // We cannot verify the next bitmap while we are about to clear it.
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   655
  if (!_g1h->collector_state()->clearing_next_bitmap()) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   656
    res_n = verify_no_bits_over_tams("next", next_bitmap, ntams, end);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   657
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   658
  if (!res_p || !res_n) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   659
    log_error(gc, verify)("#### Bitmap verification failed for " HR_FORMAT, HR_FORMAT_PARAMS(hr));
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   660
    log_error(gc, verify)("#### Caller: %s", caller);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   661
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   662
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   663
  return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   664
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   665
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   666
void G1HeapVerifier::check_bitmaps(const char* caller, HeapRegion* hr) {
49664
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   667
  if (!G1VerifyBitmaps) {
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   668
    return;
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   669
  }
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   670
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   671
  guarantee(verify_bitmaps(caller, hr), "bitmap verification");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   672
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   673
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   674
class G1VerifyBitmapClosure : public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   675
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   676
  const char* _caller;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   677
  G1HeapVerifier* _verifier;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   678
  bool _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   679
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   680
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   681
  G1VerifyBitmapClosure(const char* caller, G1HeapVerifier* verifier) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   682
    _caller(caller), _verifier(verifier), _failures(false) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   683
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   684
  bool failures() { return _failures; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   685
48969
jwilhelm
parents: 48890
diff changeset
   686
  virtual bool do_heap_region(HeapRegion* hr) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   687
    bool result = _verifier->verify_bitmaps(_caller, hr);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   688
    if (!result) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   689
      _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   690
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   691
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   692
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   693
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   694
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   695
void G1HeapVerifier::check_bitmaps(const char* caller) {
49664
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   696
  if (!G1VerifyBitmaps) {
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   697
    return;
9a04cc89dde0 8200234: Cleanup Remark and Cleanup pause code
tschatzl
parents: 49659
diff changeset
   698
  }
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   699
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   700
  G1VerifyBitmapClosure cl(caller, this);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   701
  _g1h->heap_region_iterate(&cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   702
  guarantee(!cl.failures(), "bitmap verification");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   703
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   704
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   705
class G1CheckCSetFastTableClosure : public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   706
 private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   707
  bool _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   708
 public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   709
  G1CheckCSetFastTableClosure() : HeapRegionClosure(), _failures(false) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   710
48969
jwilhelm
parents: 48890
diff changeset
   711
  virtual bool do_heap_region(HeapRegion* hr) {
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   712
    uint i = hr->hrm_index();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   713
    InCSetState cset_state = (InCSetState) G1CollectedHeap::heap()->_in_cset_fast_test.get_by_index(i);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   714
    if (hr->is_humongous()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   715
      if (hr->in_collection_set()) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   716
        log_error(gc, verify)("## humongous region %u in CSet", i);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   717
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   718
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   719
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   720
      if (cset_state.is_in_cset()) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   721
        log_error(gc, verify)("## inconsistent cset state " CSETSTATE_FORMAT " for humongous region %u", cset_state.value(), i);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   722
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   723
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   724
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   725
      if (hr->is_continues_humongous() && cset_state.is_humongous()) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   726
        log_error(gc, verify)("## inconsistent cset state " CSETSTATE_FORMAT " for continues humongous region %u", cset_state.value(), i);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   727
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   728
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   729
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   730
    } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   731
      if (cset_state.is_humongous()) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   732
        log_error(gc, verify)("## inconsistent cset state " CSETSTATE_FORMAT " for non-humongous region %u", cset_state.value(), i);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   733
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   734
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   735
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   736
      if (hr->in_collection_set() != cset_state.is_in_cset()) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   737
        log_error(gc, verify)("## in CSet %d / cset state " CSETSTATE_FORMAT " inconsistency for region %u",
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   738
                             hr->in_collection_set(), cset_state.value(), i);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   739
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   740
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   741
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   742
      if (cset_state.is_in_cset()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   743
        if (hr->is_young() != (cset_state.is_young())) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   744
          log_error(gc, verify)("## is_young %d / cset state " CSETSTATE_FORMAT " inconsistency for region %u",
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   745
                               hr->is_young(), cset_state.value(), i);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   746
          _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   747
          return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   748
        }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   749
        if (hr->is_old() != (cset_state.is_old())) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   750
          log_error(gc, verify)("## is_old %d / cset state " CSETSTATE_FORMAT " inconsistency for region %u",
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   751
                               hr->is_old(), cset_state.value(), i);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   752
          _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   753
          return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   754
        }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   755
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   756
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   757
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   758
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   759
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   760
  bool failures() const { return _failures; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   761
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   762
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   763
bool G1HeapVerifier::check_cset_fast_test() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   764
  G1CheckCSetFastTableClosure cl;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   765
  _g1h->_hrm.iterate(&cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   766
  return !cl.failures();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   767
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   768
#endif // PRODUCT