src/hotspot/share/gc/g1/g1HeapVerifier.hpp
author sjohanss
Fri, 01 Dec 2017 08:56:22 +0100
changeset 48179 34fe70d22e9c
parent 47885 5caa1d5f74c1
child 49602 db050c11c3b5
permissions -rw-r--r--
8191821: Finer granularity for GC verification Reviewed-by: tschatzl, poonam, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     1
/*
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     4
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     8
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    13
 * accompanied this code).
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    14
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    18
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    21
 * questions.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    22
 *
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    23
 */
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    24
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1HEAPVERIFIER_HPP
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    26
#define SHARE_VM_GC_G1_G1HEAPVERIFIER_HPP
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    27
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    28
#include "gc/g1/heapRegionSet.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    29
#include "memory/allocation.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    30
#include "memory/universe.hpp"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    31
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    32
class G1CollectedHeap;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    33
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    34
class G1HeapVerifier : public CHeapObj<mtGC> {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    35
private:
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    36
  G1CollectedHeap* _g1h;
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    37
  int _enabled_verification_types;
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    38
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    39
  // verify_region_sets() performs verification over the region
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    40
  // lists. It will be compiled in the product code to be used when
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    41
  // necessary (i.e., during heap verification).
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    42
  void verify_region_sets();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    43
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    44
public:
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    45
  enum G1VerifyType {
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    46
    G1VerifyYoungOnly   =  1, // -XX:VerifyGCType=young-only
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    47
    G1VerifyInitialMark =  2, // -XX:VerifyGCType=initial-mark
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    48
    G1VerifyMixed       =  4, // -XX:VerifyGCType=mixed
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    49
    G1VerifyRemark      =  8, // -XX:VerifyGCType=remark
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    50
    G1VerifyCleanup     = 16, // -XX:VerifyGCType=cleanup
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    51
    G1VerifyFull        = 32, // -XX:VerifyGCType=full
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    52
    G1VerifyAll         = -1
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    53
  };
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    54
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    55
  G1HeapVerifier(G1CollectedHeap* heap) : _g1h(heap), _enabled_verification_types(G1VerifyAll) { }
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    56
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    57
  void parse_verification_type(const char* type);
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    58
  void enable_verification_type(G1VerifyType type);
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    59
  bool should_verify(G1VerifyType type);
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    60
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    61
  // Perform verification.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    62
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
    63
  // vo == UsePrevMarking -> use "prev" marking information,
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    64
  // vo == UseNextMarking -> use "next" marking information
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
    65
  // vo == UseFullMarking -> use "next" marking bitmap but no TAMS
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    66
  //
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    67
  // NOTE: Only the "prev" marking information is guaranteed to be
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    68
  // consistent most of the time, so most calls to this should use
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    69
  // vo == UsePrevMarking.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    70
  // Currently, there is only one case where this is called with
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    71
  // vo == UseNextMarking, which is to verify the "next" marking
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    72
  // information at the end of remark.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    73
  // Currently there is only one place where this is called with
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
    74
  // vo == UseFullMarking, which is to verify the marking during a
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    75
  // full GC.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    76
  void verify(VerifyOption vo);
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
  // verify_region_sets_optional() is planted in the code for
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    79
  // list verification in non-product builds (and it can be enabled in
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    80
  // product builds by defining HEAP_REGION_SET_FORCE_VERIFY to be 1).
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    81
#if HEAP_REGION_SET_FORCE_VERIFY
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    82
  void verify_region_sets_optional() {
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    83
    verify_region_sets();
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    84
  }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    85
#else // HEAP_REGION_SET_FORCE_VERIFY
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    86
  void verify_region_sets_optional() { }
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    87
#endif // HEAP_REGION_SET_FORCE_VERIFY
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    88
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    89
  void prepare_for_verify();
48179
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    90
  double verify(G1VerifyType type, VerifyOption vo, const char* msg);
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    91
  void verify_before_gc(G1VerifyType type);
34fe70d22e9c 8191821: Finer granularity for GC verification
sjohanss
parents: 47885
diff changeset
    92
  void verify_after_gc(G1VerifyType type);
35851
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
#ifndef PRODUCT
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    95
  // Make sure that the given bitmap has no marked objects in the
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    96
  // range [from,limit). If it does, print an error message and return
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    97
  // false. Otherwise, just return true. bitmap_name should be "prev"
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
    98
  // or "next".
46750
bcab0128a16f 8184346: Clean up G1CMBitmap
tschatzl
parents: 39698
diff changeset
    99
  bool verify_no_bits_over_tams(const char* bitmap_name, const G1CMBitMap* const bitmap,
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   100
                                HeapWord* from, HeapWord* limit);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   101
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   102
  // Verify that the prev / next bitmap range [tams,end) for the given
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   103
  // region has no marks. Return true if all is well, false if errors
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   104
  // are detected.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   105
  bool verify_bitmaps(const char* caller, HeapRegion* hr);
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   106
#endif // PRODUCT
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
  // If G1VerifyBitmaps is set, verify that the marking bitmaps for
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   109
  // the given region do not have any spurious marks. If errors are
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   110
  // detected, print appropriate error messages and crash.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   111
  void check_bitmaps(const char* caller, HeapRegion* hr) PRODUCT_RETURN;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   112
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   113
  // If G1VerifyBitmaps is set, verify that the marking bitmaps do not
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   114
  // have any spurious marks. If errors are detected, print
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   115
  // appropriate error messages and crash.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   116
  void check_bitmaps(const char* caller) PRODUCT_RETURN;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   117
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   118
  // Do sanity check on the contents of the in-cset fast test table.
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   119
  bool check_cset_fast_test() PRODUCT_RETURN_( return true; );
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
  void verify_card_table_cleanup() PRODUCT_RETURN;
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
  void verify_not_dirty_region(HeapRegion* hr) PRODUCT_RETURN;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   124
  void verify_dirty_region(HeapRegion* hr) PRODUCT_RETURN;
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   125
  void verify_dirty_young_regions() PRODUCT_RETURN;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   126
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46750
diff changeset
   127
  static void verify_archive_regions();
35851
5451ff646f8e 8147814: Move verification code out of g1collectedheap
david
parents:
diff changeset
   128
};
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
#endif // SHARE_VM_GC_G1_G1HEAPVERIFIER_HPP