src/share/vm/gc_implementation/shared/spaceDecorator.cpp

Tue, 13 Apr 2010 13:52:10 -0700

author
jmasa
date
Tue, 13 Apr 2010 13:52:10 -0700
changeset 1822
0bfd3fb24150
parent 772
9ee9cf798b59
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
Summary: Ensure a full GC that clears SoftReferences before throwing an out-of-memory
Reviewed-by: ysr, jcoomes

jmasa@698 1 /*
xdono@772 2 * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
jmasa@698 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jmasa@698 4 *
jmasa@698 5 * This code is free software; you can redistribute it and/or modify it
jmasa@698 6 * under the terms of the GNU General Public License version 2 only, as
jmasa@698 7 * published by the Free Software Foundation.
jmasa@698 8 *
jmasa@698 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jmasa@698 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jmasa@698 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jmasa@698 12 * version 2 for more details (a copy is included in the LICENSE file that
jmasa@698 13 * accompanied this code).
jmasa@698 14 *
jmasa@698 15 * You should have received a copy of the GNU General Public License version
jmasa@698 16 * 2 along with this work; if not, write to the Free Software Foundation,
jmasa@698 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jmasa@698 18 *
jmasa@698 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jmasa@698 20 * CA 95054 USA or visit www.sun.com if you need additional information or
jmasa@698 21 * have any questions.
jmasa@698 22 *
jmasa@698 23 */
jmasa@698 24
jmasa@698 25 # include "incls/_precompiled.incl"
jmasa@698 26 # include "incls/_spaceDecorator.cpp.incl"
jmasa@698 27
jmasa@698 28 // Catch-all file for utility classes
jmasa@698 29
jmasa@698 30 #ifndef PRODUCT
jmasa@698 31
jmasa@698 32 // Returns true is the location q matches the mangling
jmasa@698 33 // pattern.
jmasa@698 34 bool SpaceMangler::is_mangled(HeapWord* q) {
jmasa@698 35 // This test loses precision but is good enough
jmasa@698 36 return badHeapWord == (max_juint & (uintptr_t) q->value());
jmasa@698 37 }
jmasa@698 38
jmasa@698 39
jmasa@698 40 void SpaceMangler::set_top_for_allocations(HeapWord* v) {
jmasa@698 41 if (v < end()) {
jmasa@706 42 assert(!CheckZapUnusedHeapArea || is_mangled(v),
jmasa@706 43 "The high water mark is not mangled");
jmasa@698 44 }
jmasa@698 45 _top_for_allocations = v;
jmasa@698 46 }
jmasa@698 47
jmasa@698 48 // Mangle only the unused space that has not previously
jmasa@698 49 // been mangled and that has not been allocated since being
jmasa@698 50 // mangled.
jmasa@698 51 void SpaceMangler::mangle_unused_area() {
jmasa@698 52 assert(ZapUnusedHeapArea, "Mangling should not be in use");
jmasa@698 53 // Mangle between top and the high water mark. Safeguard
jmasa@698 54 // against the space changing since top_for_allocations was
jmasa@698 55 // set.
jmasa@698 56 HeapWord* mangled_end = MIN2(top_for_allocations(), end());
jmasa@698 57 if (top() < mangled_end) {
jmasa@698 58 MemRegion mangle_mr(top(), mangled_end);
jmasa@698 59 SpaceMangler::mangle_region(mangle_mr);
jmasa@698 60 // Light weight check of mangling.
jmasa@698 61 check_mangled_unused_area(end());
jmasa@698 62 }
jmasa@698 63 // Complete check of unused area which is functional when
jmasa@698 64 // DEBUG_MANGLING is defined.
jmasa@698 65 check_mangled_unused_area_complete();
jmasa@698 66 }
jmasa@698 67
jmasa@698 68 // A complete mangle is expected in the
jmasa@698 69 // exceptional case where top_for_allocations is not
jmasa@698 70 // properly tracking the high water mark for mangling.
jmasa@698 71 // This can be the case when to-space is being used for
jmasa@698 72 // scratch space during a mark-sweep-compact. See
jmasa@698 73 // contribute_scratch() and PSMarkSweep::allocate_stacks().
jmasa@698 74 void SpaceMangler::mangle_unused_area_complete() {
jmasa@698 75 assert(ZapUnusedHeapArea, "Mangling should not be in use");
jmasa@698 76 MemRegion mangle_mr(top(), end());
jmasa@698 77 SpaceMangler::mangle_region(mangle_mr);
jmasa@698 78 }
jmasa@698 79
jmasa@698 80 // Simply mangle the MemRegion mr.
jmasa@698 81 void SpaceMangler::mangle_region(MemRegion mr) {
jmasa@698 82 assert(ZapUnusedHeapArea, "Mangling should not be in use");
jmasa@698 83 #ifdef ASSERT
jmasa@698 84 if(TraceZapUnusedHeapArea) {
jmasa@698 85 gclog_or_tty->print("Mangling [0x%x to 0x%x)", mr.start(), mr.end());
jmasa@698 86 }
jmasa@698 87 Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord);
jmasa@698 88 if(TraceZapUnusedHeapArea) {
jmasa@698 89 gclog_or_tty->print_cr(" done");
jmasa@698 90 }
jmasa@698 91 #endif
jmasa@698 92 }
jmasa@698 93
jmasa@698 94 // Check that top, top_for_allocations and the last
jmasa@698 95 // word of the space are mangled. In a tight memory
jmasa@698 96 // situation even this light weight mangling could
jmasa@698 97 // cause paging by touching the end of the space.
jmasa@698 98 void SpaceMangler::check_mangled_unused_area(HeapWord* limit) {
jmasa@698 99 if (CheckZapUnusedHeapArea) {
jmasa@698 100 // This method can be called while the spaces are
jmasa@698 101 // being reshaped so skip the test if the end of the
jmasa@698 102 // space is beyond the specified limit;
jmasa@698 103 if (end() > limit) return;
jmasa@698 104
jmasa@698 105 assert(top() == end() ||
jmasa@698 106 (is_mangled(top())), "Top not mangled");
jmasa@698 107 assert((top_for_allocations() < top()) ||
jmasa@698 108 (top_for_allocations() >= end()) ||
jmasa@698 109 (is_mangled(top_for_allocations())),
jmasa@698 110 "Older unused not mangled");
jmasa@698 111 assert(top() == end() ||
jmasa@698 112 (is_mangled(end() - 1)), "End not properly mangled");
jmasa@698 113 // Only does checking when DEBUG_MANGLING is defined.
jmasa@698 114 check_mangled_unused_area_complete();
jmasa@698 115 }
jmasa@698 116 }
jmasa@698 117
jmasa@698 118 #undef DEBUG_MANGLING
jmasa@698 119 // This should only be used while debugging the mangling
jmasa@698 120 // because of the high cost of checking the completeness.
jmasa@698 121 void SpaceMangler::check_mangled_unused_area_complete() {
jmasa@698 122 if (CheckZapUnusedHeapArea) {
jmasa@698 123 assert(ZapUnusedHeapArea, "Not mangling unused area");
jmasa@698 124 #ifdef DEBUG_MANGLING
jmasa@698 125 HeapWord* q = top();
jmasa@698 126 HeapWord* limit = end();
jmasa@698 127
jmasa@698 128 bool passed = true;
jmasa@698 129 while (q < limit) {
jmasa@698 130 if (!is_mangled(q)) {
jmasa@698 131 passed = false;
jmasa@698 132 break;
jmasa@698 133 }
jmasa@698 134 q++;
jmasa@698 135 }
jmasa@698 136 assert(passed, "Mangling is not complete");
jmasa@698 137 #endif
jmasa@698 138 }
jmasa@698 139 }
jmasa@698 140 #undef DEBUG_MANGLING
jmasa@698 141 #endif // not PRODUCT

mercurial