Mon, 29 Apr 2013 16:13:57 -0400
8011773: Some tests on Interned String crashed JVM with OOM
Summary: Instead of terminating the VM, throw OutOfMemoryError exceptions.
Reviewed-by: coleenp, dholmes
duke@435 | 1 | /* |
dcubed@4967 | 2 | * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_MEMORY_CARDTABLERS_HPP |
stefank@2314 | 26 | #define SHARE_VM_MEMORY_CARDTABLERS_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "memory/cardTableModRefBS.hpp" |
stefank@2314 | 29 | #include "memory/genRemSet.hpp" |
stefank@2314 | 30 | #include "memory/memRegion.hpp" |
stefank@2314 | 31 | |
duke@435 | 32 | class Space; |
duke@435 | 33 | class OopsInGenClosure; |
duke@435 | 34 | |
duke@435 | 35 | // This kind of "GenRemSet" uses a card table both as shared data structure |
duke@435 | 36 | // for a mod ref barrier set and for the rem set information. |
duke@435 | 37 | |
duke@435 | 38 | class CardTableRS: public GenRemSet { |
duke@435 | 39 | friend class VMStructs; |
duke@435 | 40 | // Below are private classes used in impl. |
duke@435 | 41 | friend class VerifyCTSpaceClosure; |
duke@435 | 42 | friend class ClearNoncleanCardWrapper; |
duke@435 | 43 | |
duke@435 | 44 | static jbyte clean_card_val() { |
duke@435 | 45 | return CardTableModRefBS::clean_card; |
duke@435 | 46 | } |
duke@435 | 47 | |
brutisso@3642 | 48 | static intptr_t clean_card_row() { |
brutisso@3642 | 49 | return CardTableModRefBS::clean_card_row; |
brutisso@3642 | 50 | } |
brutisso@3642 | 51 | |
duke@435 | 52 | static bool |
duke@435 | 53 | card_is_dirty_wrt_gen_iter(jbyte cv) { |
duke@435 | 54 | return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv); |
duke@435 | 55 | } |
duke@435 | 56 | |
ysr@777 | 57 | CardTableModRefBSForCTRS* _ct_bs; |
duke@435 | 58 | |
duke@435 | 59 | virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl); |
duke@435 | 60 | |
duke@435 | 61 | void verify_space(Space* s, HeapWord* gen_start); |
duke@435 | 62 | |
duke@435 | 63 | enum ExtendedCardValue { |
duke@435 | 64 | youngergen_card = CardTableModRefBS::CT_MR_BS_last_reserved + 1, |
duke@435 | 65 | // These are for parallel collection. |
duke@435 | 66 | // There are three P (parallel) youngergen card values. In general, this |
duke@435 | 67 | // needs to be more than the number of generations (including the perm |
duke@435 | 68 | // gen) that might have younger_refs_do invoked on them separately. So |
duke@435 | 69 | // if we add more gens, we have to add more values. |
duke@435 | 70 | youngergenP1_card = CardTableModRefBS::CT_MR_BS_last_reserved + 2, |
duke@435 | 71 | youngergenP2_card = CardTableModRefBS::CT_MR_BS_last_reserved + 3, |
duke@435 | 72 | youngergenP3_card = CardTableModRefBS::CT_MR_BS_last_reserved + 4, |
duke@435 | 73 | cur_youngergen_and_prev_nonclean_card = |
duke@435 | 74 | CardTableModRefBS::CT_MR_BS_last_reserved + 5 |
duke@435 | 75 | }; |
duke@435 | 76 | |
duke@435 | 77 | // An array that contains, for each generation, the card table value last |
duke@435 | 78 | // used as the current value for a younger_refs_do iteration of that |
duke@435 | 79 | // portion of the table. (The perm gen is index 0; other gens are at |
duke@435 | 80 | // their level plus 1. They youngest gen is in the table, but will |
duke@435 | 81 | // always have the value "clean_card".) |
duke@435 | 82 | jbyte* _last_cur_val_in_gen; |
duke@435 | 83 | |
duke@435 | 84 | jbyte _cur_youngergen_card_val; |
duke@435 | 85 | |
ysr@777 | 86 | int _regions_to_iterate; |
ysr@777 | 87 | |
duke@435 | 88 | jbyte cur_youngergen_card_val() { |
duke@435 | 89 | return _cur_youngergen_card_val; |
duke@435 | 90 | } |
duke@435 | 91 | void set_cur_youngergen_card_val(jbyte v) { |
duke@435 | 92 | _cur_youngergen_card_val = v; |
duke@435 | 93 | } |
duke@435 | 94 | bool is_prev_youngergen_card_val(jbyte v) { |
duke@435 | 95 | return |
duke@435 | 96 | youngergen_card <= v && |
duke@435 | 97 | v < cur_youngergen_and_prev_nonclean_card && |
duke@435 | 98 | v != _cur_youngergen_card_val; |
duke@435 | 99 | } |
duke@435 | 100 | // Return a youngergen_card_value that is not currently in use. |
duke@435 | 101 | jbyte find_unused_youngergenP_card_value(); |
duke@435 | 102 | |
duke@435 | 103 | public: |
duke@435 | 104 | CardTableRS(MemRegion whole_heap, int max_covered_regions); |
duke@435 | 105 | |
duke@435 | 106 | // *** GenRemSet functions. |
duke@435 | 107 | GenRemSet::Name rs_kind() { return GenRemSet::CardTable; } |
duke@435 | 108 | |
duke@435 | 109 | CardTableRS* as_CardTableRS() { return this; } |
duke@435 | 110 | |
ysr@777 | 111 | CardTableModRefBS* ct_bs() { return _ct_bs; } |
duke@435 | 112 | |
duke@435 | 113 | // Override. |
duke@435 | 114 | void prepare_for_younger_refs_iterate(bool parallel); |
duke@435 | 115 | |
duke@435 | 116 | // Card table entries are cleared before application; "blk" is |
duke@435 | 117 | // responsible for dirtying if the oop is still older-to-younger after |
duke@435 | 118 | // closure application. |
duke@435 | 119 | void younger_refs_iterate(Generation* g, OopsInGenClosure* blk); |
duke@435 | 120 | |
coleenp@548 | 121 | void inline_write_ref_field_gc(void* field, oop new_val) { |
ysr@777 | 122 | jbyte* byte = _ct_bs->byte_for(field); |
duke@435 | 123 | *byte = youngergen_card; |
duke@435 | 124 | } |
coleenp@548 | 125 | void write_ref_field_gc_work(void* field, oop new_val) { |
duke@435 | 126 | inline_write_ref_field_gc(field, new_val); |
duke@435 | 127 | } |
duke@435 | 128 | |
duke@435 | 129 | // Override. Might want to devirtualize this in the same fashion as |
duke@435 | 130 | // above. Ensures that the value of the card for field says that it's |
duke@435 | 131 | // a younger card in the current collection. |
coleenp@548 | 132 | virtual void write_ref_field_gc_par(void* field, oop new_val); |
duke@435 | 133 | |
duke@435 | 134 | void resize_covered_region(MemRegion new_region); |
duke@435 | 135 | |
duke@435 | 136 | bool is_aligned(HeapWord* addr) { |
ysr@777 | 137 | return _ct_bs->is_card_aligned(addr); |
duke@435 | 138 | } |
duke@435 | 139 | |
duke@435 | 140 | void verify(); |
jmasa@441 | 141 | void verify_aligned_region_empty(MemRegion mr); |
duke@435 | 142 | |
ysr@777 | 143 | void clear(MemRegion mr) { _ct_bs->clear(mr); } |
coleenp@4037 | 144 | void clear_into_younger(Generation* gen); |
duke@435 | 145 | |
ysr@777 | 146 | void invalidate(MemRegion mr, bool whole_heap = false) { |
ysr@777 | 147 | _ct_bs->invalidate(mr, whole_heap); |
ysr@777 | 148 | } |
coleenp@4037 | 149 | void invalidate_or_clear(Generation* gen, bool younger); |
duke@435 | 150 | |
duke@435 | 151 | static uintx ct_max_alignment_constraint() { |
duke@435 | 152 | return CardTableModRefBS::ct_max_alignment_constraint(); |
duke@435 | 153 | } |
duke@435 | 154 | |
ysr@777 | 155 | jbyte* byte_for(void* p) { return _ct_bs->byte_for(p); } |
ysr@777 | 156 | jbyte* byte_after(void* p) { return _ct_bs->byte_after(p); } |
ysr@777 | 157 | HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); } |
duke@435 | 158 | |
duke@435 | 159 | bool is_prev_nonclean_card_val(jbyte v) { |
duke@435 | 160 | return |
duke@435 | 161 | youngergen_card <= v && |
duke@435 | 162 | v <= cur_youngergen_and_prev_nonclean_card && |
duke@435 | 163 | v != _cur_youngergen_card_val; |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | static bool youngergen_may_have_been_dirty(jbyte cv) { |
duke@435 | 167 | return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card; |
duke@435 | 168 | } |
duke@435 | 169 | |
duke@435 | 170 | }; |
stefank@2314 | 171 | |
ysr@2819 | 172 | class ClearNoncleanCardWrapper: public MemRegionClosure { |
ysr@2889 | 173 | DirtyCardToOopClosure* _dirty_card_closure; |
ysr@2819 | 174 | CardTableRS* _ct; |
ysr@2819 | 175 | bool _is_par; |
ysr@2819 | 176 | private: |
ysr@2819 | 177 | // Clears the given card, return true if the corresponding card should be |
ysr@2819 | 178 | // processed. |
ysr@2819 | 179 | inline bool clear_card(jbyte* entry); |
ysr@2819 | 180 | // Work methods called by the clear_card() |
ysr@2819 | 181 | inline bool clear_card_serial(jbyte* entry); |
ysr@2819 | 182 | inline bool clear_card_parallel(jbyte* entry); |
brutisso@3642 | 183 | // check alignment of pointer |
brutisso@3642 | 184 | bool is_word_aligned(jbyte* entry); |
ysr@2819 | 185 | |
ysr@2819 | 186 | public: |
ysr@2889 | 187 | ClearNoncleanCardWrapper(DirtyCardToOopClosure* dirty_card_closure, CardTableRS* ct); |
ysr@2819 | 188 | void do_MemRegion(MemRegion mr); |
ysr@2819 | 189 | }; |
ysr@2819 | 190 | |
stefank@2314 | 191 | #endif // SHARE_VM_MEMORY_CARDTABLERS_HPP |