jmasa@698: /* xdono@772: * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. jmasa@698: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jmasa@698: * jmasa@698: * This code is free software; you can redistribute it and/or modify it jmasa@698: * under the terms of the GNU General Public License version 2 only, as jmasa@698: * published by the Free Software Foundation. jmasa@698: * jmasa@698: * This code is distributed in the hope that it will be useful, but WITHOUT jmasa@698: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jmasa@698: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jmasa@698: * version 2 for more details (a copy is included in the LICENSE file that jmasa@698: * accompanied this code). jmasa@698: * jmasa@698: * You should have received a copy of the GNU General Public License version jmasa@698: * 2 along with this work; if not, write to the Free Software Foundation, jmasa@698: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jmasa@698: * jmasa@698: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jmasa@698: * CA 95054 USA or visit www.sun.com if you need additional information or jmasa@698: * have any questions. jmasa@698: * jmasa@698: */ jmasa@698: jmasa@698: # include "incls/_precompiled.incl" jmasa@698: # include "incls/_spaceDecorator.cpp.incl" jmasa@698: jmasa@698: // Catch-all file for utility classes jmasa@698: jmasa@698: #ifndef PRODUCT jmasa@698: jmasa@698: // Returns true is the location q matches the mangling jmasa@698: // pattern. jmasa@698: bool SpaceMangler::is_mangled(HeapWord* q) { jmasa@698: // This test loses precision but is good enough jmasa@698: return badHeapWord == (max_juint & (uintptr_t) q->value()); jmasa@698: } jmasa@698: jmasa@698: jmasa@698: void SpaceMangler::set_top_for_allocations(HeapWord* v) { jmasa@698: if (v < end()) { jmasa@706: assert(!CheckZapUnusedHeapArea || is_mangled(v), jmasa@706: "The high water mark is not mangled"); jmasa@698: } jmasa@698: _top_for_allocations = v; jmasa@698: } jmasa@698: jmasa@698: // Mangle only the unused space that has not previously jmasa@698: // been mangled and that has not been allocated since being jmasa@698: // mangled. jmasa@698: void SpaceMangler::mangle_unused_area() { jmasa@698: assert(ZapUnusedHeapArea, "Mangling should not be in use"); jmasa@698: // Mangle between top and the high water mark. Safeguard jmasa@698: // against the space changing since top_for_allocations was jmasa@698: // set. jmasa@698: HeapWord* mangled_end = MIN2(top_for_allocations(), end()); jmasa@698: if (top() < mangled_end) { jmasa@698: MemRegion mangle_mr(top(), mangled_end); jmasa@698: SpaceMangler::mangle_region(mangle_mr); jmasa@698: // Light weight check of mangling. jmasa@698: check_mangled_unused_area(end()); jmasa@698: } jmasa@698: // Complete check of unused area which is functional when jmasa@698: // DEBUG_MANGLING is defined. jmasa@698: check_mangled_unused_area_complete(); jmasa@698: } jmasa@698: jmasa@698: // A complete mangle is expected in the jmasa@698: // exceptional case where top_for_allocations is not jmasa@698: // properly tracking the high water mark for mangling. jmasa@698: // This can be the case when to-space is being used for jmasa@698: // scratch space during a mark-sweep-compact. See jmasa@698: // contribute_scratch() and PSMarkSweep::allocate_stacks(). jmasa@698: void SpaceMangler::mangle_unused_area_complete() { jmasa@698: assert(ZapUnusedHeapArea, "Mangling should not be in use"); jmasa@698: MemRegion mangle_mr(top(), end()); jmasa@698: SpaceMangler::mangle_region(mangle_mr); jmasa@698: } jmasa@698: jmasa@698: // Simply mangle the MemRegion mr. jmasa@698: void SpaceMangler::mangle_region(MemRegion mr) { jmasa@698: assert(ZapUnusedHeapArea, "Mangling should not be in use"); jmasa@698: #ifdef ASSERT jmasa@698: if(TraceZapUnusedHeapArea) { jmasa@698: gclog_or_tty->print("Mangling [0x%x to 0x%x)", mr.start(), mr.end()); jmasa@698: } jmasa@698: Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord); jmasa@698: if(TraceZapUnusedHeapArea) { jmasa@698: gclog_or_tty->print_cr(" done"); jmasa@698: } jmasa@698: #endif jmasa@698: } jmasa@698: jmasa@698: // Check that top, top_for_allocations and the last jmasa@698: // word of the space are mangled. In a tight memory jmasa@698: // situation even this light weight mangling could jmasa@698: // cause paging by touching the end of the space. jmasa@698: void SpaceMangler::check_mangled_unused_area(HeapWord* limit) { jmasa@698: if (CheckZapUnusedHeapArea) { jmasa@698: // This method can be called while the spaces are jmasa@698: // being reshaped so skip the test if the end of the jmasa@698: // space is beyond the specified limit; jmasa@698: if (end() > limit) return; jmasa@698: jmasa@698: assert(top() == end() || jmasa@698: (is_mangled(top())), "Top not mangled"); jmasa@698: assert((top_for_allocations() < top()) || jmasa@698: (top_for_allocations() >= end()) || jmasa@698: (is_mangled(top_for_allocations())), jmasa@698: "Older unused not mangled"); jmasa@698: assert(top() == end() || jmasa@698: (is_mangled(end() - 1)), "End not properly mangled"); jmasa@698: // Only does checking when DEBUG_MANGLING is defined. jmasa@698: check_mangled_unused_area_complete(); jmasa@698: } jmasa@698: } jmasa@698: jmasa@698: #undef DEBUG_MANGLING jmasa@698: // This should only be used while debugging the mangling jmasa@698: // because of the high cost of checking the completeness. jmasa@698: void SpaceMangler::check_mangled_unused_area_complete() { jmasa@698: if (CheckZapUnusedHeapArea) { jmasa@698: assert(ZapUnusedHeapArea, "Not mangling unused area"); jmasa@698: #ifdef DEBUG_MANGLING jmasa@698: HeapWord* q = top(); jmasa@698: HeapWord* limit = end(); jmasa@698: jmasa@698: bool passed = true; jmasa@698: while (q < limit) { jmasa@698: if (!is_mangled(q)) { jmasa@698: passed = false; jmasa@698: break; jmasa@698: } jmasa@698: q++; jmasa@698: } jmasa@698: assert(passed, "Mangling is not complete"); jmasa@698: #endif jmasa@698: } jmasa@698: } jmasa@698: #undef DEBUG_MANGLING jmasa@698: #endif // not PRODUCT