Tue, 31 Mar 2015 11:36:37 +0200
8068036: assert(is_available(index)) failed in G1 cset
Summary: Some verification code iterated over the heap using the region mapping array. This is not allowed. Changed to use the regular iteration method with closure.
Reviewed-by: jwilhelm, brutisso
tschatzl@7651 | 1 | /* |
tschatzl@7651 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
tschatzl@7651 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
tschatzl@7651 | 4 | * |
tschatzl@7651 | 5 | * This code is free software; you can redistribute it and/or modify it |
tschatzl@7651 | 6 | * under the terms of the GNU General Public License version 2 only, as |
tschatzl@7651 | 7 | * published by the Free Software Foundation. |
tschatzl@7651 | 8 | * |
tschatzl@7651 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
tschatzl@7651 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
tschatzl@7651 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
tschatzl@7651 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
tschatzl@7651 | 13 | * accompanied this code). |
tschatzl@7651 | 14 | * |
tschatzl@7651 | 15 | * You should have received a copy of the GNU General Public License version |
tschatzl@7651 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
tschatzl@7651 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
tschatzl@7651 | 18 | * |
tschatzl@7651 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
tschatzl@7651 | 20 | * or visit www.oracle.com if you need additional information or have any |
tschatzl@7651 | 21 | * questions. |
tschatzl@7651 | 22 | * |
tschatzl@7651 | 23 | */ |
tschatzl@7651 | 24 | |
tschatzl@7651 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP |
tschatzl@7651 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP |
tschatzl@7651 | 27 | |
tschatzl@7651 | 28 | #include "gc_implementation/g1/g1BiasedArray.hpp" |
tschatzl@7651 | 29 | #include "memory/allocation.hpp" |
tschatzl@7651 | 30 | |
tschatzl@7651 | 31 | // Per-region state during garbage collection. |
tschatzl@7651 | 32 | struct InCSetState { |
tschatzl@7651 | 33 | public: |
tschatzl@7651 | 34 | // We use different types to represent the state value. Particularly SPARC puts |
tschatzl@7651 | 35 | // values in structs from "left to right", i.e. MSB to LSB. This results in many |
tschatzl@7651 | 36 | // unnecessary shift operations when loading and storing values of this type. |
tschatzl@7651 | 37 | // This degrades performance significantly (>10%) on that platform. |
tschatzl@7651 | 38 | // Other tested ABIs do not seem to have this problem, and actually tend to |
tschatzl@7651 | 39 | // favor smaller types, so we use the smallest usable type there. |
tschatzl@7651 | 40 | #ifdef SPARC |
tschatzl@7651 | 41 | #define CSETSTATE_FORMAT INTPTR_FORMAT |
tschatzl@7651 | 42 | typedef intptr_t in_cset_state_t; |
tschatzl@7651 | 43 | #else |
tschatzl@7651 | 44 | #define CSETSTATE_FORMAT "%d" |
tschatzl@7651 | 45 | typedef int8_t in_cset_state_t; |
tschatzl@7651 | 46 | #endif |
tschatzl@7651 | 47 | private: |
tschatzl@7651 | 48 | in_cset_state_t _value; |
tschatzl@7651 | 49 | public: |
tschatzl@7651 | 50 | enum { |
tschatzl@7651 | 51 | // Selection of the values were driven to micro-optimize the encoding and |
tschatzl@7651 | 52 | // frequency of the checks. |
tschatzl@7651 | 53 | // The most common check is whether the region is in the collection set or not. |
tschatzl@7651 | 54 | // This encoding allows us to use an != 0 check which in some architectures |
tschatzl@7651 | 55 | // (x86*) can be encoded slightly more efficently than a normal comparison |
tschatzl@7651 | 56 | // against zero. |
tschatzl@7651 | 57 | // The same situation occurs when checking whether the region is humongous |
tschatzl@7651 | 58 | // or not, which is encoded by values < 0. |
tschatzl@7651 | 59 | // The other values are simply encoded in increasing generation order, which |
tschatzl@7651 | 60 | // makes getting the next generation fast by a simple increment. |
tschatzl@7651 | 61 | Humongous = -1, // The region is humongous - note that actually any value < 0 would be possible here. |
tschatzl@7651 | 62 | NotInCSet = 0, // The region is not in the collection set. |
tschatzl@7651 | 63 | Young = 1, // The region is in the collection set and a young region. |
tschatzl@7651 | 64 | Old = 2, // The region is in the collection set and an old region. |
tschatzl@7651 | 65 | Num |
tschatzl@7651 | 66 | }; |
tschatzl@7651 | 67 | |
tschatzl@7651 | 68 | InCSetState(in_cset_state_t value = NotInCSet) : _value(value) { |
tschatzl@7651 | 69 | assert(is_valid(), err_msg("Invalid state %d", _value)); |
tschatzl@7651 | 70 | } |
tschatzl@7651 | 71 | |
tschatzl@7651 | 72 | in_cset_state_t value() const { return _value; } |
tschatzl@7651 | 73 | |
tschatzl@7651 | 74 | void set_old() { _value = Old; } |
tschatzl@7651 | 75 | |
tschatzl@7651 | 76 | bool is_in_cset_or_humongous() const { return _value != NotInCSet; } |
tschatzl@7651 | 77 | bool is_in_cset() const { return _value > NotInCSet; } |
tschatzl@7651 | 78 | bool is_humongous() const { return _value < NotInCSet; } |
tschatzl@7651 | 79 | bool is_young() const { return _value == Young; } |
tschatzl@7651 | 80 | bool is_old() const { return _value == Old; } |
tschatzl@7651 | 81 | |
tschatzl@7651 | 82 | #ifdef ASSERT |
tschatzl@7651 | 83 | bool is_default() const { return !is_in_cset_or_humongous(); } |
tschatzl@7651 | 84 | bool is_valid() const { return (_value >= Humongous) && (_value < Num); } |
tschatzl@7651 | 85 | bool is_valid_gen() const { return (_value >= Young && _value <= Old); } |
tschatzl@7651 | 86 | #endif |
tschatzl@7651 | 87 | }; |
tschatzl@7651 | 88 | |
tschatzl@7651 | 89 | // Instances of this class are used for quick tests on whether a reference points |
tschatzl@7651 | 90 | // into the collection set and into which generation or is a humongous object |
tschatzl@7651 | 91 | // |
tschatzl@7651 | 92 | // Each of the array's elements indicates whether the corresponding region is in |
tschatzl@7651 | 93 | // the collection set and if so in which generation, or a humongous region. |
tschatzl@7651 | 94 | // |
tschatzl@7651 | 95 | // We use this to speed up reference processing during young collection and |
tschatzl@7651 | 96 | // quickly reclaim humongous objects. For the latter, by making a humongous region |
tschatzl@7651 | 97 | // succeed this test, we sort-of add it to the collection set. During the reference |
tschatzl@7651 | 98 | // iteration closures, when we see a humongous region, we then simply mark it as |
tschatzl@7651 | 99 | // referenced, i.e. live. |
tschatzl@7651 | 100 | class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> { |
tschatzl@7651 | 101 | protected: |
tschatzl@7651 | 102 | InCSetState default_value() const { return InCSetState::NotInCSet; } |
tschatzl@7651 | 103 | public: |
tschatzl@7651 | 104 | void set_humongous(uintptr_t index) { |
tschatzl@7651 | 105 | assert(get_by_index(index).is_default(), |
tschatzl@7651 | 106 | err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value())); |
tschatzl@7651 | 107 | set_by_index(index, InCSetState::Humongous); |
tschatzl@7651 | 108 | } |
tschatzl@7651 | 109 | |
tschatzl@7651 | 110 | void clear_humongous(uintptr_t index) { |
tschatzl@7651 | 111 | set_by_index(index, InCSetState::NotInCSet); |
tschatzl@7651 | 112 | } |
tschatzl@7651 | 113 | |
tschatzl@7651 | 114 | void set_in_young(uintptr_t index) { |
tschatzl@7651 | 115 | assert(get_by_index(index).is_default(), |
tschatzl@7651 | 116 | err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value())); |
tschatzl@7651 | 117 | set_by_index(index, InCSetState::Young); |
tschatzl@7651 | 118 | } |
tschatzl@7651 | 119 | |
tschatzl@7651 | 120 | void set_in_old(uintptr_t index) { |
tschatzl@7651 | 121 | assert(get_by_index(index).is_default(), |
tschatzl@7651 | 122 | err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value())); |
tschatzl@7651 | 123 | set_by_index(index, InCSetState::Old); |
tschatzl@7651 | 124 | } |
tschatzl@7651 | 125 | |
tschatzl@7651 | 126 | bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); } |
tschatzl@7651 | 127 | bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); } |
tschatzl@7651 | 128 | InCSetState at(HeapWord* addr) const { return get_by_address(addr); } |
tschatzl@7651 | 129 | void clear() { G1BiasedMappedArray<InCSetState>::clear(); } |
tschatzl@7651 | 130 | }; |
tschatzl@7651 | 131 | |
tschatzl@7651 | 132 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1INCSETSTATE_HPP |