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