jmasa@698: /* mikael@4153: * Copyright (c) 2002, 2012, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. jmasa@698: * jmasa@698: */ jmasa@698: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_SPACEDECORATOR_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_SHARED_SPACEDECORATOR_HPP stefank@2314: stefank@2314: #include "gc_implementation/shared/mutableSpace.hpp" stefank@2314: #include "memory/space.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: jmasa@698: class SpaceDecorator: public AllStatic { jmasa@698: public: jmasa@698: // Initialization flags. jmasa@698: static const bool Clear = true; jmasa@698: static const bool DontClear = false; jmasa@698: static const bool Mangle = true; jmasa@698: static const bool DontMangle = false; jmasa@698: }; jmasa@698: jmasa@698: // Functionality for use with class Space and class MutableSpace. jmasa@698: // The approach taken with the mangling is to mangle all jmasa@698: // the space initially and then to mangle areas that have jmasa@698: // been allocated since the last collection. Mangling is jmasa@698: // done in the context of a generation and in the context jmasa@698: // of a space. jmasa@698: // The space in a generation is mangled when it is first jmasa@698: // initialized and when the generation grows. The spaces jmasa@698: // are not necessarily up-to-date when this mangling occurs jmasa@698: // and the method mangle_region() is used. jmasa@698: // After allocations have been done in a space, the space generally jmasa@698: // need to be remangled. Remangling is only done on the jmasa@698: // recently allocated regions in the space. Typically, that is jmasa@698: // the region between the new top and the top just before a jmasa@698: // garbage collection. jmasa@698: // An exception to the usual mangling in a space is done when the jmasa@698: // space is used for an extraordinary purpose. Specifically, when jmasa@698: // to-space is used as scratch space for a mark-sweep-compact jmasa@698: // collection. jmasa@698: // Spaces are mangled after a collection. If the generation jmasa@698: // grows after a collection, the added space is mangled as part of jmasa@698: // the growth of the generation. No additional mangling is needed when the jmasa@698: // spaces are resized after an expansion. jmasa@698: // The class SpaceMangler keeps a pointer to the top of the allocated jmasa@698: // area and provides the methods for doing the piece meal mangling. jmasa@698: // Methods for doing sparces and full checking of the mangling are jmasa@698: // included. The full checking is done if DEBUG_MANGLING is defined. jmasa@698: // GenSpaceMangler is used with the GenCollectedHeap collectors and jmasa@698: // MutableSpaceMangler is used with the ParallelScavengeHeap collectors. jmasa@698: // These subclasses abstract the differences in the types of spaces used jmasa@698: // by each heap. jmasa@698: zgu@3900: class SpaceMangler: public CHeapObj { jmasa@698: friend class VMStructs; jmasa@698: jmasa@698: // High water mark for allocations. Typically, the space above jmasa@698: // this point have been mangle previously and don't need to be jmasa@698: // touched again. Space belows this point has been allocated jmasa@698: // and remangling is needed between the current top and this jmasa@698: // high water mark. jmasa@698: HeapWord* _top_for_allocations; jmasa@698: HeapWord* top_for_allocations() { return _top_for_allocations; } jmasa@698: jmasa@698: public: jmasa@698: jmasa@698: // Setting _top_for_allocations to NULL at initialization jmasa@698: // makes it always below top so that mangling done as part jmasa@698: // of the initialize() call of a space does nothing (as it jmasa@698: // should since the mangling is done as part of the constructor jmasa@698: // for the space. jmasa@698: SpaceMangler() : _top_for_allocations(NULL) {} jmasa@698: jmasa@698: // Methods for top and end that delegate to the specific jmasa@698: // space type. jmasa@698: virtual HeapWord* top() const = 0; jmasa@698: virtual HeapWord* end() const = 0; jmasa@698: jmasa@698: // Return true if q matches the mangled pattern. jmasa@698: static bool is_mangled(HeapWord* q) PRODUCT_RETURN0; jmasa@698: jmasa@698: // Used to save the an address in a space for later use during mangling. jmasa@698: void set_top_for_allocations(HeapWord* v); jmasa@698: jmasa@698: // Overwrites the unused portion of this space. jmasa@698: // Mangle only the region not previously mangled [top, top_previously_mangled) jmasa@698: void mangle_unused_area(); jmasa@698: // Mangle all the unused region [top, end) jmasa@698: void mangle_unused_area_complete(); jmasa@698: // Do some sparse checking on the area that should have been mangled. jmasa@698: void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN; jmasa@698: // Do a complete check of the area that should be mangled. jmasa@698: void check_mangled_unused_area_complete() PRODUCT_RETURN; jmasa@698: jmasa@698: // Mangle the MemRegion. This is a non-space specific mangler. It jmasa@698: // is used during the initial mangling of a space before the space jmasa@698: // is fully constructed. Also is used when a generation is expanded jmasa@698: // and possibly before the spaces have been reshaped to to the new jmasa@698: // size of the generation. jcoomes@1902: static void mangle_region(MemRegion mr) PRODUCT_RETURN; jmasa@698: }; jmasa@698: jmasa@698: class ContiguousSpace; jmasa@698: jmasa@698: // For use with GenCollectedHeap's jmasa@698: class GenSpaceMangler: public SpaceMangler { jmasa@698: ContiguousSpace* _sp; jmasa@698: jmasa@698: ContiguousSpace* sp() { return _sp; } jmasa@698: jmasa@698: HeapWord* top() const { return _sp->top(); } jmasa@698: HeapWord* end() const { return _sp->end(); } jmasa@698: jmasa@698: public: jmasa@698: GenSpaceMangler(ContiguousSpace* sp) : SpaceMangler(), _sp(sp) {} jmasa@698: }; jmasa@698: jmasa@698: // For use with ParallelScavengeHeap's. jmasa@698: class MutableSpaceMangler: public SpaceMangler { jmasa@698: MutableSpace* _sp; jmasa@698: jmasa@698: MutableSpace* sp() { return _sp; } jmasa@698: jmasa@698: HeapWord* top() const { return _sp->top(); } jmasa@698: HeapWord* end() const { return _sp->end(); } jmasa@698: jmasa@698: public: jmasa@698: MutableSpaceMangler(MutableSpace* sp) : SpaceMangler(), _sp(sp) {} jmasa@698: }; stefank@2314: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_SPACEDECORATOR_HPP