hotspot/src/share/vm/gc/g1/g1HeapVerifier.cpp
author jprovino
Tue, 02 Aug 2016 16:39:33 -0400
changeset 40328 a2851f5f1cf6
parent 39698 4016de4e596b
child 46285 5b673a9fa682
permissions -rw-r--r--
8071770: G1 does not implement millis_since_last_gc which is needed by RMI GC Summary: G1 does not return a correct value for the CollectedHeap::millis_since_last_gc Reviewed-by: jmasa, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     1
/*
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    26
#include "logging/log.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    27
#include "gc/g1/concurrentMarkThread.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    28
#include "gc/g1/g1CollectedHeap.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    29
#include "gc/g1/g1CollectedHeap.inline.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    30
#include "gc/g1/g1HeapVerifier.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    31
#include "gc/g1/g1MarkSweep.hpp"
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37242
diff changeset
    32
#include "gc/g1/g1Policy.hpp"
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    33
#include "gc/g1/g1RemSet.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    34
#include "gc/g1/g1RootProcessor.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    35
#include "gc/g1/heapRegion.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    36
#include "gc/g1/heapRegion.inline.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    37
#include "gc/g1/heapRegionRemSet.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    38
#include "gc/g1/g1StringDedup.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    39
#include "memory/resourceArea.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    40
#include "oops/oop.inline.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    41
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    42
class VerifyRootsClosure: public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    43
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    44
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    45
  VerifyOption     _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    46
  bool             _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    47
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    48
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    49
  // _vo == UseNextMarking -> use "next" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    50
  // _vo == UseMarkWord    -> use mark word from object header.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    51
  VerifyRootsClosure(VerifyOption vo) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    52
    _g1h(G1CollectedHeap::heap()),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    53
    _vo(vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    54
    _failures(false) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    55
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    56
  bool failures() { return _failures; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    57
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    58
  template <class T> void do_oop_nv(T* p) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    59
    T heap_oop = oopDesc::load_heap_oop(p);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    60
    if (!oopDesc::is_null(heap_oop)) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    61
      oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    62
      if (_g1h->is_obj_dead_cond(obj, _vo)) {
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36090
diff changeset
    63
        Log(gc, verify) log;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    64
        log.info("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    65
        if (_vo == VerifyOption_G1UseMarkWord) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
    66
          log.error("  Mark word: " PTR_FORMAT, p2i(obj->mark()));
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    67
        }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    68
        ResourceMark rm;
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
    69
        obj->print_on(log.error_stream());
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    70
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    71
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    72
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    73
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    74
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    75
  void do_oop(oop* p)       { do_oop_nv(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    76
  void do_oop(narrowOop* p) { do_oop_nv(p); }
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
class G1VerifyCodeRootOopClosure: public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    80
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    81
  OopClosure* _root_cl;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    82
  nmethod* _nm;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    83
  VerifyOption _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    84
  bool _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    85
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    86
  template <class T> void do_oop_work(T* p) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    87
    // First verify that this root is live
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    88
    _root_cl->do_oop(p);
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
    if (!G1VerifyHeapRegionCodeRoots) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    91
      // We're not verifying the code roots attached to heap region.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    92
      return;
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
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    95
    // Don't check the code roots during marking verification in a full GC
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    96
    if (_vo == VerifyOption_G1UseMarkWord) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    97
      return;
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
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   100
    // Now verify that the current nmethod (which contains p) is
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   101
    // in the code root list of the heap region containing the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   102
    // object referenced by p.
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
    T heap_oop = oopDesc::load_heap_oop(p);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   105
    if (!oopDesc::is_null(heap_oop)) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   106
      oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   107
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   108
      // Now fetch the region containing the object
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   109
      HeapRegion* hr = _g1h->heap_region_containing(obj);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   110
      HeapRegionRemSet* hrrs = hr->rem_set();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   111
      // Verify that the strong code root list for this region
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   112
      // contains the nmethod
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   113
      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
   114
        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
   115
                              "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
   116
                              "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
   117
                              p2i(p), p2i(_nm), p2i(hr->bottom()), p2i(hr->end()));
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   118
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   119
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   120
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   121
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   122
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   123
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   124
  G1VerifyCodeRootOopClosure(G1CollectedHeap* g1h, OopClosure* root_cl, VerifyOption vo):
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   125
    _g1h(g1h), _root_cl(root_cl), _vo(vo), _nm(NULL), _failures(false) {}
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
  void do_oop(oop* p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   128
  void do_oop(narrowOop* p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   129
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   130
  void set_nmethod(nmethod* nm) { _nm = nm; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   131
  bool failures() { return _failures; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   132
};
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
class G1VerifyCodeRootBlobClosure: public CodeBlobClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   135
  G1VerifyCodeRootOopClosure* _oop_cl;
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
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   138
  G1VerifyCodeRootBlobClosure(G1VerifyCodeRootOopClosure* oop_cl):
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   139
    _oop_cl(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
  void do_code_blob(CodeBlob* cb) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   142
    nmethod* nm = cb->as_nmethod_or_null();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   143
    if (nm != NULL) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   144
      _oop_cl->set_nmethod(nm);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   145
      nm->oops_do(_oop_cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   146
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   147
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   148
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   149
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   150
class YoungRefCounterClosure : public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   151
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   152
  int              _count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   153
 public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   154
  YoungRefCounterClosure(G1CollectedHeap* g1h) : _g1h(g1h), _count(0) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   155
  void do_oop(oop* p)       { if (_g1h->is_in_young(*p)) { _count++; } }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   156
  void do_oop(narrowOop* p) { ShouldNotReachHere(); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   157
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   158
  int count() { return _count; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   159
  void reset_count() { _count = 0; };
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   160
};
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
class VerifyKlassClosure: public KlassClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   163
  YoungRefCounterClosure _young_ref_counter_closure;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   164
  OopClosure *_oop_closure;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   165
 public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   166
  VerifyKlassClosure(G1CollectedHeap* g1h, OopClosure* cl) : _young_ref_counter_closure(g1h), _oop_closure(cl) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   167
  void do_klass(Klass* k) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   168
    k->oops_do(_oop_closure);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   169
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   170
    _young_ref_counter_closure.reset_count();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   171
    k->oops_do(&_young_ref_counter_closure);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   172
    if (_young_ref_counter_closure.count() > 0) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   173
      guarantee(k->has_modified_oops(), "Klass " PTR_FORMAT ", has young refs but is not dirty.", p2i(k));
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   174
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   175
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   176
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   177
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   178
class VerifyLivenessOopClosure: public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   179
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   180
  VerifyOption _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   181
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   182
  VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo):
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   183
    _g1h(g1h), _vo(vo)
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   184
  { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   185
  void do_oop(narrowOop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   186
  void do_oop(      oop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   187
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   188
  template <class T> void do_oop_work(T *p) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   189
    oop obj = oopDesc::load_decode_heap_oop(p);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   190
    guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   191
              "Dead object referenced by a not dead object");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   192
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   193
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   194
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   195
class VerifyObjsInRegionClosure: public ObjectClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   196
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   197
  G1CollectedHeap* _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   198
  size_t _live_bytes;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   199
  HeapRegion *_hr;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   200
  VerifyOption _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   201
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   202
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   203
  // _vo == UseNextMarking -> use "next" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   204
  // _vo == UseMarkWord    -> use mark word from object header.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   205
  VerifyObjsInRegionClosure(HeapRegion *hr, VerifyOption vo)
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   206
    : _live_bytes(0), _hr(hr), _vo(vo) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   207
    _g1h = G1CollectedHeap::heap();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   208
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   209
  void do_object(oop o) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   210
    VerifyLivenessOopClosure isLive(_g1h, _vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   211
    assert(o != NULL, "Huh?");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   212
    if (!_g1h->is_obj_dead_cond(o, _vo)) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   213
      // If the object is alive according to the mark word,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   214
      // then verify that the marking information agrees.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   215
      // Note we can't verify the contra-positive of the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   216
      // above: if the object is dead (according to the mark
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   217
      // word), it may not be marked, or may have been marked
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   218
      // but has since became dead, or may have been allocated
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   219
      // since the last marking.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   220
      if (_vo == VerifyOption_G1UseMarkWord) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   221
        guarantee(!_g1h->is_obj_dead(o), "mark word and concurrent mark mismatch");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   222
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   223
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   224
      o->oop_iterate_no_header(&isLive);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   225
      if (!_hr->obj_allocated_since_prev_marking(o)) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   226
        size_t obj_size = o->size();    // Make sure we don't overflow
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   227
        _live_bytes += (obj_size * HeapWordSize);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   228
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   229
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   230
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   231
  size_t live_bytes() { return _live_bytes; }
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
class VerifyArchiveOopClosure: public OopClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   235
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   236
  VerifyArchiveOopClosure(HeapRegion *hr) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   237
  void do_oop(narrowOop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   238
  void do_oop(      oop *p) { do_oop_work(p); }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   239
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   240
  template <class T> void do_oop_work(T *p) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   241
    oop obj = oopDesc::load_decode_heap_oop(p);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   242
    guarantee(obj == NULL || G1MarkSweep::in_archive_range(obj),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   243
              "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   244
              p2i(p), p2i(obj));
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
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   247
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   248
class VerifyArchiveRegionClosure: public ObjectClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   249
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   250
  VerifyArchiveRegionClosure(HeapRegion *hr) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   251
  // Verify that all object pointers are to archive regions.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   252
  void do_object(oop o) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   253
    VerifyArchiveOopClosure checkOop(NULL);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   254
    assert(o != NULL, "Should not be here for NULL oops");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   255
    o->oop_iterate_no_header(&checkOop);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   256
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   257
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   258
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   259
class VerifyRegionClosure: public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   260
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   261
  bool             _par;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   262
  VerifyOption     _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   263
  bool             _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   264
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   265
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   266
  // _vo == UseNextMarking -> use "next" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   267
  // _vo == UseMarkWord    -> use mark word from object header.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   268
  VerifyRegionClosure(bool par, VerifyOption vo)
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   269
    : _par(par),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   270
      _vo(vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   271
      _failures(false) {}
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
  bool failures() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   274
    return _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   275
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   276
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   277
  bool doHeapRegion(HeapRegion* r) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   278
    // For archive regions, verify there are no heap pointers to
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   279
    // non-pinned regions. For all others, verify liveness info.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   280
    if (r->is_archive()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   281
      VerifyArchiveRegionClosure verify_oop_pointers(r);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   282
      r->object_iterate(&verify_oop_pointers);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   283
      return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   284
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   285
    if (!r->is_continues_humongous()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   286
      bool failures = false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   287
      r->verify(_vo, &failures);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   288
      if (failures) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   289
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   290
      } else if (!r->is_starts_humongous()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   291
        VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   292
        r->object_iterate(&not_dead_yet_cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   293
        if (_vo != VerifyOption_G1UseNextMarking) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   294
          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
   295
            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
   296
                                  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
   297
            _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   298
          }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   299
        } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   300
          // When vo == UseNextMarking we cannot currently do a sanity
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   301
          // check on the live bytes as the calculation has not been
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   302
          // finalized yet.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   303
        }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   304
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   305
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   306
    return false; // stop the region iteration if we hit a failure
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   307
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   308
};
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
// This is the task used for parallel verification of the heap regions
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   311
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   312
class G1ParVerifyTask: public AbstractGangTask {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   313
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   314
  G1CollectedHeap*  _g1h;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   315
  VerifyOption      _vo;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   316
  bool              _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   317
  HeapRegionClaimer _hrclaimer;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   318
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   319
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   320
  // _vo == UsePrevMarking -> use "prev" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   321
  // _vo == UseNextMarking -> use "next" marking information,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   322
  // _vo == UseMarkWord    -> use mark word from object header.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   323
  G1ParVerifyTask(G1CollectedHeap* g1h, VerifyOption vo) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   324
      AbstractGangTask("Parallel verify task"),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   325
      _g1h(g1h),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   326
      _vo(vo),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   327
      _failures(false),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   328
      _hrclaimer(g1h->workers()->active_workers()) {}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   329
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   330
  bool failures() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   331
    return _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   332
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   333
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   334
  void work(uint worker_id) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   335
    HandleMark hm;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   336
    VerifyRegionClosure blk(true, _vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   337
    _g1h->heap_region_par_iterate(&blk, worker_id, &_hrclaimer);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   338
    if (blk.failures()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   339
      _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   340
    }
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
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   343
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   344
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   345
void G1HeapVerifier::verify(VerifyOption vo) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   346
  if (!SafepointSynchronize::is_at_safepoint()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   347
    log_info(gc, verify)("Skipping verification. Not at safepoint.");
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
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   350
  assert(Thread::current()->is_VM_thread(),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   351
         "Expected to be executed serially by the VM thread at this point");
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
  log_debug(gc, verify)("Roots");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   354
  VerifyRootsClosure rootsCl(vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   355
  VerifyKlassClosure klassCl(_g1h, &rootsCl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   356
  CLDToKlassAndOopClosure cldCl(&klassCl, &rootsCl, false);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   357
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   358
  // We apply the relevant closures to all the oops in the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   359
  // system dictionary, class loader data graph, the string table
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   360
  // and the nmethods in the code cache.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   361
  G1VerifyCodeRootOopClosure codeRootsCl(_g1h, &rootsCl, vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   362
  G1VerifyCodeRootBlobClosure blobsCl(&codeRootsCl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   363
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   364
  {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   365
    G1RootProcessor root_processor(_g1h, 1);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   366
    root_processor.process_all_roots(&rootsCl,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   367
                                     &cldCl,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   368
                                     &blobsCl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   369
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   370
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   371
  bool failures = rootsCl.failures() || codeRootsCl.failures();
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
  if (vo != VerifyOption_G1UseMarkWord) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   374
    // If we're verifying during a full GC then the region sets
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   375
    // will have been torn down at the start of the GC. Therefore
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   376
    // verifying the region sets will fail. So we only verify
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   377
    // the region sets when not in a full GC.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   378
    log_debug(gc, verify)("HeapRegionSets");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   379
    verify_region_sets();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   380
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   381
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   382
  log_debug(gc, verify)("HeapRegions");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   383
  if (GCParallelVerificationEnabled && ParallelGCThreads > 1) {
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
    G1ParVerifyTask task(_g1h, vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   386
    _g1h->workers()->run_task(&task);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   387
    if (task.failures()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   388
      failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   389
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   390
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   391
  } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   392
    VerifyRegionClosure blk(false, vo);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   393
    _g1h->heap_region_iterate(&blk);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   394
    if (blk.failures()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   395
      failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   396
    }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   397
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   398
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   399
  if (G1StringDedup::is_enabled()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   400
    log_debug(gc, verify)("StrDedup");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   401
    G1StringDedup::verify();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   402
  }
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
  if (failures) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   405
    log_error(gc, verify)("Heap after failed verification:");
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   406
    // It helps to have the per-region information in the output to
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   407
    // help us track down what went wrong. This is why we call
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   408
    // print_extended_on() instead of print_on().
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36090
diff changeset
   409
    Log(gc, verify) log;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   410
    ResourceMark rm;
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   411
    _g1h->print_extended_on(log.error_stream());
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   412
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   413
  guarantee(!failures, "there should not have been any failures");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   414
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   415
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   416
// Heap region set verification
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
class VerifyRegionListsClosure : public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   419
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   420
  HeapRegionSet*   _old_set;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   421
  HeapRegionSet*   _humongous_set;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   422
  HeapRegionManager*   _hrm;
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
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   425
  uint _old_count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   426
  uint _humongous_count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   427
  uint _free_count;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   428
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   429
  VerifyRegionListsClosure(HeapRegionSet* old_set,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   430
                           HeapRegionSet* humongous_set,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   431
                           HeapRegionManager* hrm) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   432
    _old_set(old_set), _humongous_set(humongous_set), _hrm(hrm),
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   433
    _old_count(), _humongous_count(), _free_count(){ }
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
  bool doHeapRegion(HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   436
    if (hr->is_young()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   437
      // TODO
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   438
    } else if (hr->is_humongous()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   439
      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
   440
      _humongous_count++;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   441
    } else if (hr->is_empty()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   442
      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
   443
      _free_count++;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   444
    } else if (hr->is_old()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   445
      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
   446
      _old_count++;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   447
    } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   448
      // There are no other valid region types. Check for one invalid
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   449
      // one we can identify: pinned without old or humongous set.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   450
      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
   451
      ShouldNotReachHere();
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
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   454
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   455
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   456
  void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   457
    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
   458
    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
   459
    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
   460
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   461
};
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   462
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   463
void G1HeapVerifier::verify_region_sets() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   464
  assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   465
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   466
  // First, check the explicit lists.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   467
  _g1h->_hrm.verify();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   468
  {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   469
    // Given that a concurrent operation might be adding regions to
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   470
    // the secondary free list we have to take the lock before
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   471
    // verifying it.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   472
    MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   473
    _g1h->_secondary_free_list.verify_list();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   474
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   475
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   476
  // If a concurrent region freeing operation is in progress it will
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   477
  // be difficult to correctly attributed any free regions we come
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   478
  // across to the correct free list given that they might belong to
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   479
  // one of several (free_list, secondary_free_list, any local lists,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   480
  // etc.). So, if that's the case we will skip the rest of the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   481
  // verification operation. Alternatively, waiting for the concurrent
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   482
  // operation to complete will have a non-trivial effect on the GC's
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   483
  // operation (no concurrent operation will last longer than the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   484
  // interval between two calls to verification) and it might hide
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   485
  // any issues that we would like to catch during testing.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   486
  if (_g1h->free_regions_coming()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   487
    return;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   488
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   489
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   490
  // Make sure we append the secondary_free_list on the free_list so
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   491
  // that all free regions we will come across can be safely
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   492
  // attributed to the free_list.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   493
  _g1h->append_secondary_free_list_if_not_empty_with_lock();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   494
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   495
  // Finally, make sure that the region accounting in the lists is
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   496
  // consistent with what we see in the heap.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   497
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   498
  VerifyRegionListsClosure cl(&_g1h->_old_set, &_g1h->_humongous_set, &_g1h->_hrm);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   499
  _g1h->heap_region_iterate(&cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   500
  cl.verify_counts(&_g1h->_old_set, &_g1h->_humongous_set, &_g1h->_hrm);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   501
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   502
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   503
void G1HeapVerifier::prepare_for_verify() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   504
  if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   505
    _g1h->ensure_parsability(false);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   506
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   507
  _g1h->g1_rem_set()->prepare_for_verify();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   508
}
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
double G1HeapVerifier::verify(bool guard, const char* msg) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   511
  double verify_time_ms = 0.0;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   512
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   513
  if (guard && _g1h->total_collections() >= VerifyGCStartAt) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   514
    double verify_start = os::elapsedTime();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   515
    HandleMark hm;  // Discard invalid handles created during verification
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   516
    prepare_for_verify();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   517
    Universe::verify(VerifyOption_G1UsePrevMarking, msg);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   518
    verify_time_ms = (os::elapsedTime() - verify_start) * 1000;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   519
  }
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
  return verify_time_ms;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   522
}
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
void G1HeapVerifier::verify_before_gc() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   525
  double verify_time_ms = verify(VerifyBeforeGC, "Before GC");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   526
  _g1h->g1_policy()->phase_times()->record_verify_before_time_ms(verify_time_ms);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   527
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   528
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   529
void G1HeapVerifier::verify_after_gc() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   530
  double verify_time_ms = verify(VerifyAfterGC, "After GC");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   531
  _g1h->g1_policy()->phase_times()->record_verify_after_time_ms(verify_time_ms);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   532
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   533
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   534
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   535
#ifndef PRODUCT
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   536
class G1VerifyCardTableCleanup: public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   537
  G1HeapVerifier* _verifier;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   538
  G1SATBCardTableModRefBS* _ct_bs;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   539
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   540
  G1VerifyCardTableCleanup(G1HeapVerifier* verifier, G1SATBCardTableModRefBS* ct_bs)
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   541
    : _verifier(verifier), _ct_bs(ct_bs) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   542
  virtual bool doHeapRegion(HeapRegion* r) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   543
    if (r->is_survivor()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   544
      _verifier->verify_dirty_region(r);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   545
    } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   546
      _verifier->verify_not_dirty_region(r);
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
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   549
  }
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
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   552
void G1HeapVerifier::verify_card_table_cleanup() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   553
  if (G1VerifyCTCleanup || VerifyAfterGC) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   554
    G1VerifyCardTableCleanup cleanup_verifier(this, _g1h->g1_barrier_set());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   555
    _g1h->heap_region_iterate(&cleanup_verifier);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   556
  }
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
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   559
void G1HeapVerifier::verify_not_dirty_region(HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   560
  // All of the region should be clean.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   561
  G1SATBCardTableModRefBS* ct_bs = _g1h->g1_barrier_set();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   562
  MemRegion mr(hr->bottom(), hr->end());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   563
  ct_bs->verify_not_dirty_region(mr);
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
void G1HeapVerifier::verify_dirty_region(HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   567
  // We cannot guarantee that [bottom(),end()] is dirty.  Threads
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   568
  // dirty allocated blocks as they allocate them. The thread that
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   569
  // 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
   570
  // maximal allocation to fill in [pre_dummy_top(),end()] but will
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   571
  // 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
   572
  // a lock). So we can only verify that [bottom(),pre_dummy_top()]
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   573
  // is dirty.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   574
  G1SATBCardTableModRefBS* ct_bs = _g1h->g1_barrier_set();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   575
  MemRegion mr(hr->bottom(), hr->pre_dummy_top());
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   576
  if (hr->is_young()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   577
    ct_bs->verify_g1_young_region(mr);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   578
  } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   579
    ct_bs->verify_dirty_region(mr);
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
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   583
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
   584
private:
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   585
  G1HeapVerifier* _verifier;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   586
public:
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   587
  G1VerifyDirtyYoungListClosure(G1HeapVerifier* verifier) : HeapRegionClosure(), _verifier(verifier) { }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   588
  virtual bool doHeapRegion(HeapRegion* r) {
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   589
    _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
   590
    return false;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   591
  }
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   592
};
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   593
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   594
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
   595
  G1VerifyDirtyYoungListClosure cl(this);
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38186
diff changeset
   596
  _g1h->collection_set()->iterate(&cl);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   597
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   598
35943
e726308008c0 8148973: Rename g1/concurrentMark.{hpp,cpp,inline.hpp} to g1/g1ConcurrentMark.{hpp,cpp,inline.hpp}
ehelin
parents: 35851
diff changeset
   599
bool G1HeapVerifier::verify_no_bits_over_tams(const char* bitmap_name, G1CMBitMapRO* bitmap,
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   600
                                               HeapWord* tams, HeapWord* end) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   601
  guarantee(tams <= end,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   602
            "tams: " PTR_FORMAT " end: " PTR_FORMAT, p2i(tams), p2i(end));
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   603
  HeapWord* result = bitmap->getNextMarkedWordAddress(tams, end);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   604
  if (result < end) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35943
diff changeset
   605
    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
   606
    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
   607
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   608
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   609
  return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   610
}
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
bool G1HeapVerifier::verify_bitmaps(const char* caller, HeapRegion* hr) {
35943
e726308008c0 8148973: Rename g1/concurrentMark.{hpp,cpp,inline.hpp} to g1/g1ConcurrentMark.{hpp,cpp,inline.hpp}
ehelin
parents: 35851
diff changeset
   613
  G1CMBitMapRO* prev_bitmap = _g1h->concurrent_mark()->prevMarkBitMap();
e726308008c0 8148973: Rename g1/concurrentMark.{hpp,cpp,inline.hpp} to g1/g1ConcurrentMark.{hpp,cpp,inline.hpp}
ehelin
parents: 35851
diff changeset
   614
  G1CMBitMapRO* next_bitmap = (G1CMBitMapRO*) _g1h->concurrent_mark()->nextMarkBitMap();
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   615
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   616
  HeapWord* bottom = hr->bottom();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   617
  HeapWord* ptams  = hr->prev_top_at_mark_start();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   618
  HeapWord* ntams  = hr->next_top_at_mark_start();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   619
  HeapWord* end    = hr->end();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   620
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   621
  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
   622
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   623
  bool res_n = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   624
  // We reset mark_in_progress() before we reset _cmThread->in_progress() and in this window
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   625
  // we do the clearing of the next bitmap concurrently. Thus, we can not verify the bitmap
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   626
  // if we happen to be in that state.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   627
  if (_g1h->collector_state()->mark_in_progress() || !_g1h->_cmThread->in_progress()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   628
    res_n = verify_no_bits_over_tams("next", next_bitmap, ntams, end);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   629
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   630
  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
   631
    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
   632
    log_error(gc, verify)("#### Caller: %s", caller);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   633
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   634
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   635
  return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   636
}
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   637
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   638
void G1HeapVerifier::check_bitmaps(const char* caller, HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   639
  if (!G1VerifyBitmaps) return;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   640
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   641
  guarantee(verify_bitmaps(caller, hr), "bitmap verification");
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
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   644
class G1VerifyBitmapClosure : public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   645
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   646
  const char* _caller;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   647
  G1HeapVerifier* _verifier;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   648
  bool _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   649
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   650
public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   651
  G1VerifyBitmapClosure(const char* caller, G1HeapVerifier* verifier) :
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   652
    _caller(caller), _verifier(verifier), _failures(false) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   653
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   654
  bool failures() { return _failures; }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   655
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   656
  virtual bool doHeapRegion(HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   657
    bool result = _verifier->verify_bitmaps(_caller, hr);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   658
    if (!result) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   659
      _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   660
    }
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
};
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
void G1HeapVerifier::check_bitmaps(const char* caller) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   666
  if (!G1VerifyBitmaps) return;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   667
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   668
  G1VerifyBitmapClosure cl(caller, this);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   669
  _g1h->heap_region_iterate(&cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   670
  guarantee(!cl.failures(), "bitmap verification");
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   671
}
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
class G1CheckCSetFastTableClosure : public HeapRegionClosure {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   674
 private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   675
  bool _failures;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   676
 public:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   677
  G1CheckCSetFastTableClosure() : HeapRegionClosure(), _failures(false) { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   678
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   679
  virtual bool doHeapRegion(HeapRegion* hr) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   680
    uint i = hr->hrm_index();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   681
    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
   682
    if (hr->is_humongous()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   683
      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
   684
        log_error(gc, verify)("## humongous region %u in CSet", i);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   685
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   686
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   687
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   688
      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
   689
        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
   690
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   691
        return true;
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
      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
   694
        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
   695
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   696
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   697
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   698
    } else {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   699
      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
   700
        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
   701
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   702
        return true;
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
      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
   705
        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
   706
                             hr->in_collection_set(), cset_state.value(), i);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   707
        _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   708
        return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   709
      }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   710
      if (cset_state.is_in_cset()) {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   711
        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
   712
          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
   713
                               hr->is_young(), cset_state.value(), i);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   714
          _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   715
          return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   716
        }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   717
        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
   718
          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
   719
                               hr->is_old(), cset_state.value(), i);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   720
          _failures = true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   721
          return true;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   722
        }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   723
      }
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
    return false;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   726
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   727
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   728
  bool failures() const { return _failures; }
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
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   731
bool G1HeapVerifier::check_cset_fast_test() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   732
  G1CheckCSetFastTableClosure cl;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   733
  _g1h->_hrm.iterate(&cl);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   734
  return !cl.failures();
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
#endif // PRODUCT