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

changeset 698
12eea04c8b06
child 772
9ee9cf798b59
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/shared/spaceDecorator.hpp	Wed Jul 09 15:08:55 2008 -0700
     1.3 @@ -0,0 +1,141 @@
     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 +class SpaceDecorator: public AllStatic {
    1.29 + public:
    1.30 +  // Initialization flags.
    1.31 +  static const bool Clear               = true;
    1.32 +  static const bool DontClear           = false;
    1.33 +  static const bool Mangle              = true;
    1.34 +  static const bool DontMangle          = false;
    1.35 +};
    1.36 +
    1.37 +// Functionality for use with class Space and class MutableSpace.
    1.38 +//   The approach taken with the mangling is to mangle all
    1.39 +// the space initially and then to mangle areas that have
    1.40 +// been allocated since the last collection.  Mangling is
    1.41 +// done in the context of a generation and in the context
    1.42 +// of a space.
    1.43 +//   The space in a generation is mangled when it is first
    1.44 +// initialized and when the generation grows.  The spaces
    1.45 +// are not necessarily up-to-date when this mangling occurs
    1.46 +// and the method mangle_region() is used.
    1.47 +//   After allocations have been done in a space, the space generally
    1.48 +// need to be remangled.  Remangling is only done on the
    1.49 +// recently allocated regions in the space.  Typically, that is
    1.50 +// the region between the new top and the top just before a
    1.51 +// garbage collection.
    1.52 +//   An exception to the usual mangling in a space is done when the
    1.53 +// space is used for an extraordinary purpose.  Specifically, when
    1.54 +// to-space is used as scratch space for a mark-sweep-compact
    1.55 +// collection.
    1.56 +//   Spaces are mangled after a collection.  If the generation
    1.57 +// grows after a collection, the added space is mangled as part of
    1.58 +// the growth of the generation.  No additional mangling is needed when the
    1.59 +// spaces are resized after an expansion.
    1.60 +//   The class SpaceMangler keeps a pointer to the top of the allocated
    1.61 +// area and provides the methods for doing the piece meal mangling.
    1.62 +// Methods for doing sparces and full checking of the mangling are
    1.63 +// included.  The full checking is done if DEBUG_MANGLING is defined.
    1.64 +//   GenSpaceMangler is used with the GenCollectedHeap collectors and
    1.65 +// MutableSpaceMangler is used with the ParallelScavengeHeap collectors.
    1.66 +// These subclasses abstract the differences in the types of spaces used
    1.67 +// by each heap.
    1.68 +
    1.69 +class SpaceMangler: public CHeapObj {
    1.70 +  friend class VMStructs;
    1.71 +
    1.72 +  // High water mark for allocations.  Typically, the space above
    1.73 +  // this point have been mangle previously and don't need to be
    1.74 +  // touched again.  Space belows this point has been allocated
    1.75 +  // and remangling is needed between the current top and this
    1.76 +  // high water mark.
    1.77 +  HeapWord* _top_for_allocations;
    1.78 +  HeapWord* top_for_allocations() { return _top_for_allocations; }
    1.79 +
    1.80 + public:
    1.81 +
    1.82 +  // Setting _top_for_allocations to NULL at initialization
    1.83 +  // makes it always below top so that mangling done as part
    1.84 +  // of the initialize() call of a space does nothing (as it
    1.85 +  // should since the mangling is done as part of the constructor
    1.86 +  // for the space.
    1.87 +  SpaceMangler() : _top_for_allocations(NULL) {}
    1.88 +
    1.89 +  // Methods for top and end that delegate to the specific
    1.90 +  // space type.
    1.91 +  virtual HeapWord* top() const = 0;
    1.92 +  virtual HeapWord* end() const = 0;
    1.93 +
    1.94 +  // Return true if q matches the mangled pattern.
    1.95 +  static bool is_mangled(HeapWord* q) PRODUCT_RETURN0;
    1.96 +
    1.97 +  // Used to save the an address in a space for later use during mangling.
    1.98 +  void set_top_for_allocations(HeapWord* v);
    1.99 +
   1.100 +  // Overwrites the unused portion of this space.
   1.101 +  // Mangle only the region not previously mangled [top, top_previously_mangled)
   1.102 +  void mangle_unused_area();
   1.103 +  // Mangle all the unused region [top, end)
   1.104 +  void mangle_unused_area_complete();
   1.105 +  // Do some sparse checking on the area that should have been mangled.
   1.106 +  void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN;
   1.107 +  // Do a complete check of the area that should be mangled.
   1.108 +  void check_mangled_unused_area_complete() PRODUCT_RETURN;
   1.109 +
   1.110 +  // Mangle the MemRegion.  This is a non-space specific mangler.  It
   1.111 +  // is used during the initial mangling of a space before the space
   1.112 +  // is fully constructed.  Also is used when a generation is expanded
   1.113 +  // and possibly before the spaces have been reshaped to to the new
   1.114 +  // size of the generation.
   1.115 +  static void mangle_region(MemRegion mr);
   1.116 +};
   1.117 +
   1.118 +class ContiguousSpace;
   1.119 +
   1.120 +// For use with GenCollectedHeap's
   1.121 +class GenSpaceMangler: public SpaceMangler {
   1.122 +  ContiguousSpace* _sp;
   1.123 +
   1.124 +  ContiguousSpace* sp() { return _sp; }
   1.125 +
   1.126 +  HeapWord* top() const { return _sp->top(); }
   1.127 +  HeapWord* end() const { return _sp->end(); }
   1.128 +
   1.129 + public:
   1.130 +  GenSpaceMangler(ContiguousSpace* sp) : SpaceMangler(), _sp(sp) {}
   1.131 +};
   1.132 +
   1.133 +// For use with ParallelScavengeHeap's.
   1.134 +class MutableSpaceMangler: public SpaceMangler {
   1.135 +  MutableSpace* _sp;
   1.136 +
   1.137 +  MutableSpace* sp() { return _sp; }
   1.138 +
   1.139 +  HeapWord* top() const { return _sp->top(); }
   1.140 +  HeapWord* end() const { return _sp->end(); }
   1.141 +
   1.142 + public:
   1.143 +  MutableSpaceMangler(MutableSpace* sp) : SpaceMangler(), _sp(sp) {}
   1.144 +};

mercurial