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

changeset 698
12eea04c8b06
child 706
818a18cd69a8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/shared/spaceDecorator.cpp	Wed Jul 09 15:08:55 2008 -0700
     1.3 @@ -0,0 +1,140 @@
     1.4 +/*
     1.5 + * Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +# include "incls/_precompiled.incl"
    1.29 +# include "incls/_spaceDecorator.cpp.incl"
    1.30 +
    1.31 +// Catch-all file for utility classes
    1.32 +
    1.33 +#ifndef PRODUCT
    1.34 +
    1.35 +// Returns true is the location q matches the mangling
    1.36 +// pattern.
    1.37 +bool SpaceMangler::is_mangled(HeapWord* q) {
    1.38 +  // This test loses precision but is good enough
    1.39 +  return badHeapWord == (max_juint & (uintptr_t) q->value());
    1.40 +}
    1.41 +
    1.42 +
    1.43 +void SpaceMangler::set_top_for_allocations(HeapWord* v)  {
    1.44 +  if (v < end()) {
    1.45 +    assert(is_mangled(v), "The high water mark is not mangled");
    1.46 +  }
    1.47 +  _top_for_allocations = v;
    1.48 +}
    1.49 +
    1.50 +// Mangle only the unused space that has not previously
    1.51 +// been mangled and that has not been allocated since being
    1.52 +// mangled.
    1.53 +void SpaceMangler::mangle_unused_area() {
    1.54 +  assert(ZapUnusedHeapArea, "Mangling should not be in use");
    1.55 +  // Mangle between top and the high water mark.  Safeguard
    1.56 +  // against the space changing since top_for_allocations was
    1.57 +  // set.
    1.58 +  HeapWord* mangled_end = MIN2(top_for_allocations(), end());
    1.59 +  if (top() < mangled_end) {
    1.60 +    MemRegion mangle_mr(top(), mangled_end);
    1.61 +    SpaceMangler::mangle_region(mangle_mr);
    1.62 +    // Light weight check of mangling.
    1.63 +    check_mangled_unused_area(end());
    1.64 +  }
    1.65 +  // Complete check of unused area which is functional when
    1.66 +  // DEBUG_MANGLING is defined.
    1.67 +  check_mangled_unused_area_complete();
    1.68 +}
    1.69 +
    1.70 +// A complete mangle is expected in the
    1.71 +// exceptional case where top_for_allocations is not
    1.72 +// properly tracking the high water mark for mangling.
    1.73 +// This can be the case when to-space is being used for
    1.74 +// scratch space during a mark-sweep-compact.  See
    1.75 +// contribute_scratch() and PSMarkSweep::allocate_stacks().
    1.76 +void SpaceMangler::mangle_unused_area_complete() {
    1.77 +  assert(ZapUnusedHeapArea, "Mangling should not be in use");
    1.78 +  MemRegion mangle_mr(top(), end());
    1.79 +  SpaceMangler::mangle_region(mangle_mr);
    1.80 +}
    1.81 +
    1.82 +// Simply mangle the MemRegion mr.
    1.83 +void SpaceMangler::mangle_region(MemRegion mr) {
    1.84 +  assert(ZapUnusedHeapArea, "Mangling should not be in use");
    1.85 +#ifdef ASSERT
    1.86 +  if(TraceZapUnusedHeapArea) {
    1.87 +    gclog_or_tty->print("Mangling [0x%x to 0x%x)", mr.start(), mr.end());
    1.88 +  }
    1.89 +  Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord);
    1.90 +  if(TraceZapUnusedHeapArea) {
    1.91 +    gclog_or_tty->print_cr(" done");
    1.92 +  }
    1.93 +#endif
    1.94 +}
    1.95 +
    1.96 +// Check that top, top_for_allocations and the last
    1.97 +// word of the space are mangled.  In a tight memory
    1.98 +// situation even this light weight mangling could
    1.99 +// cause paging by touching the end of the space.
   1.100 +void  SpaceMangler::check_mangled_unused_area(HeapWord* limit) {
   1.101 +  if (CheckZapUnusedHeapArea) {
   1.102 +    // This method can be called while the spaces are
   1.103 +    // being reshaped so skip the test if the end of the
   1.104 +    // space is beyond the specified limit;
   1.105 +    if (end() > limit) return;
   1.106 +
   1.107 +    assert(top() == end() ||
   1.108 +           (is_mangled(top())), "Top not mangled");
   1.109 +    assert((top_for_allocations() < top()) ||
   1.110 +           (top_for_allocations() >= end()) ||
   1.111 +           (is_mangled(top_for_allocations())),
   1.112 +           "Older unused not mangled");
   1.113 +    assert(top() == end() ||
   1.114 +           (is_mangled(end() - 1)), "End not properly mangled");
   1.115 +    // Only does checking when DEBUG_MANGLING is defined.
   1.116 +    check_mangled_unused_area_complete();
   1.117 +  }
   1.118 +}
   1.119 +
   1.120 +#undef DEBUG_MANGLING
   1.121 +// This should only be used while debugging the mangling
   1.122 +// because of the high cost of checking the completeness.
   1.123 +void  SpaceMangler::check_mangled_unused_area_complete() {
   1.124 +  if (CheckZapUnusedHeapArea) {
   1.125 +    assert(ZapUnusedHeapArea, "Not mangling unused area");
   1.126 +#ifdef DEBUG_MANGLING
   1.127 +    HeapWord* q = top();
   1.128 +    HeapWord* limit = end();
   1.129 +
   1.130 +    bool passed = true;
   1.131 +    while (q < limit) {
   1.132 +      if (!is_mangled(q)) {
   1.133 +        passed = false;
   1.134 +        break;
   1.135 +      }
   1.136 +      q++;
   1.137 +    }
   1.138 +    assert(passed, "Mangling is not complete");
   1.139 +#endif
   1.140 +  }
   1.141 +}
   1.142 +#undef DEBUG_MANGLING
   1.143 +#endif // not PRODUCT

mercurial