src/share/vm/memory/genOopClosures.hpp

Wed, 03 Mar 2010 14:48:26 -0800

author
jcoomes
date
Wed, 03 Mar 2010 14:48:26 -0800
changeset 1746
2a1472c30599
parent 1280
df6caf649ff7
child 1907
c18cbe5936b8
permissions
-rw-r--r--

4396719: Mark Sweep stack overflow on deeply nested Object arrays
Summary: Use an explicit stack for object arrays and process them in chunks.
Reviewed-by: iveresov, apetrusenko

duke@435 1 /*
xdono@631 2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class Generation;
duke@435 26 class HeapWord;
duke@435 27 class CardTableRS;
duke@435 28 class CardTableModRefBS;
duke@435 29 class DefNewGeneration;
duke@435 30
jcoomes@1746 31 template<class E, unsigned int N> class GenericTaskQueue;
jcoomes@1746 32 typedef GenericTaskQueue<oop, TASKQUEUE_SIZE> OopTaskQueue;
jcoomes@1746 33 template<class T> class GenericTaskQueueSet;
jcoomes@1746 34 typedef GenericTaskQueueSet<OopTaskQueue> OopTaskQueueSet;
coleenp@548 35
duke@435 36 // Closure for iterating roots from a particular generation
duke@435 37 // Note: all classes deriving from this MUST call this do_barrier
duke@435 38 // method at the end of their own do_oop method!
duke@435 39 // Note: no do_oop defined, this is an abstract class.
duke@435 40
duke@435 41 class OopsInGenClosure : public OopClosure {
duke@435 42 private:
coleenp@548 43 Generation* _orig_gen; // generation originally set in ctor
coleenp@548 44 Generation* _gen; // generation being scanned
duke@435 45
duke@435 46 protected:
duke@435 47 // Some subtypes need access.
coleenp@548 48 HeapWord* _gen_boundary; // start of generation
coleenp@548 49 CardTableRS* _rs; // remembered set
duke@435 50
duke@435 51 // For assertions
duke@435 52 Generation* generation() { return _gen; }
duke@435 53 CardTableRS* rs() { return _rs; }
duke@435 54
duke@435 55 // Derived classes that modify oops so that they might be old-to-young
duke@435 56 // pointers must call the method below.
coleenp@548 57 template <class T> void do_barrier(T* p);
duke@435 58
ysr@777 59 // Version for use by closures that may be called in parallel code.
ysr@1280 60 template <class T> void par_do_barrier(T* p);
ysr@777 61
duke@435 62 public:
duke@435 63 OopsInGenClosure() : OopClosure(NULL),
duke@435 64 _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {};
duke@435 65
duke@435 66 OopsInGenClosure(Generation* gen);
duke@435 67 void set_generation(Generation* gen);
duke@435 68
duke@435 69 void reset_generation() { _gen = _orig_gen; }
duke@435 70
duke@435 71 // Problem with static closures: must have _gen_boundary set at some point,
duke@435 72 // but cannot do this until after the heap is initialized.
duke@435 73 void set_orig_generation(Generation* gen) {
duke@435 74 _orig_gen = gen;
duke@435 75 set_generation(gen);
duke@435 76 }
duke@435 77
duke@435 78 HeapWord* gen_boundary() { return _gen_boundary; }
duke@435 79 };
duke@435 80
duke@435 81 // Closure for scanning DefNewGeneration.
duke@435 82 //
duke@435 83 // This closure will perform barrier store calls for ALL
duke@435 84 // pointers in scanned oops.
duke@435 85 class ScanClosure: public OopsInGenClosure {
coleenp@548 86 protected:
duke@435 87 DefNewGeneration* _g;
coleenp@548 88 HeapWord* _boundary;
coleenp@548 89 bool _gc_barrier;
coleenp@548 90 template <class T> inline void do_oop_work(T* p);
coleenp@548 91 public:
duke@435 92 ScanClosure(DefNewGeneration* g, bool gc_barrier);
coleenp@548 93 virtual void do_oop(oop* p);
coleenp@548 94 virtual void do_oop(narrowOop* p);
coleenp@548 95 inline void do_oop_nv(oop* p);
coleenp@548 96 inline void do_oop_nv(narrowOop* p);
duke@435 97 bool do_header() { return false; }
duke@435 98 Prefetch::style prefetch_style() {
duke@435 99 return Prefetch::do_write;
duke@435 100 }
duke@435 101 };
duke@435 102
duke@435 103 // Closure for scanning DefNewGeneration.
duke@435 104 //
duke@435 105 // This closure only performs barrier store calls on
duke@435 106 // pointers into the DefNewGeneration. This is less
duke@435 107 // precise, but faster, than a ScanClosure
duke@435 108 class FastScanClosure: public OopsInGenClosure {
coleenp@548 109 protected:
duke@435 110 DefNewGeneration* _g;
coleenp@548 111 HeapWord* _boundary;
coleenp@548 112 bool _gc_barrier;
coleenp@548 113 template <class T> inline void do_oop_work(T* p);
coleenp@548 114 public:
duke@435 115 FastScanClosure(DefNewGeneration* g, bool gc_barrier);
coleenp@548 116 virtual void do_oop(oop* p);
coleenp@548 117 virtual void do_oop(narrowOop* p);
coleenp@548 118 inline void do_oop_nv(oop* p);
coleenp@548 119 inline void do_oop_nv(narrowOop* p);
duke@435 120 bool do_header() { return false; }
duke@435 121 Prefetch::style prefetch_style() {
duke@435 122 return Prefetch::do_write;
duke@435 123 }
duke@435 124 };
duke@435 125
duke@435 126 class FilteringClosure: public OopClosure {
coleenp@548 127 private:
coleenp@548 128 HeapWord* _boundary;
duke@435 129 OopClosure* _cl;
coleenp@548 130 protected:
coleenp@548 131 template <class T> inline void do_oop_work(T* p) {
coleenp@548 132 T heap_oop = oopDesc::load_heap_oop(p);
coleenp@548 133 if (!oopDesc::is_null(heap_oop)) {
coleenp@548 134 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
coleenp@548 135 if ((HeapWord*)obj < _boundary) {
coleenp@548 136 _cl->do_oop(p);
coleenp@548 137 }
coleenp@548 138 }
coleenp@548 139 }
coleenp@548 140 public:
duke@435 141 FilteringClosure(HeapWord* boundary, OopClosure* cl) :
duke@435 142 OopClosure(cl->_ref_processor), _boundary(boundary),
duke@435 143 _cl(cl) {}
coleenp@548 144 virtual void do_oop(oop* p);
coleenp@548 145 virtual void do_oop(narrowOop* p);
coleenp@548 146 inline void do_oop_nv(oop* p) { FilteringClosure::do_oop_work(p); }
coleenp@548 147 inline void do_oop_nv(narrowOop* p) { FilteringClosure::do_oop_work(p); }
duke@435 148 bool do_header() { return false; }
duke@435 149 };
duke@435 150
duke@435 151 // Closure for scanning DefNewGeneration's weak references.
duke@435 152 // NOTE: very much like ScanClosure but not derived from
duke@435 153 // OopsInGenClosure -- weak references are processed all
duke@435 154 // at once, with no notion of which generation they were in.
duke@435 155 class ScanWeakRefClosure: public OopClosure {
coleenp@548 156 protected:
coleenp@548 157 DefNewGeneration* _g;
coleenp@548 158 HeapWord* _boundary;
coleenp@548 159 template <class T> inline void do_oop_work(T* p);
coleenp@548 160 public:
duke@435 161 ScanWeakRefClosure(DefNewGeneration* g);
coleenp@548 162 virtual void do_oop(oop* p);
coleenp@548 163 virtual void do_oop(narrowOop* p);
coleenp@548 164 inline void do_oop_nv(oop* p);
coleenp@548 165 inline void do_oop_nv(narrowOop* p);
duke@435 166 };
duke@435 167
duke@435 168 class VerifyOopClosure: public OopClosure {
coleenp@548 169 protected:
coleenp@548 170 template <class T> inline void do_oop_work(T* p) {
coleenp@548 171 oop obj = oopDesc::load_decode_heap_oop(p);
coleenp@548 172 guarantee(obj->is_oop_or_null(), "invalid oop");
duke@435 173 }
coleenp@548 174 public:
coleenp@548 175 virtual void do_oop(oop* p);
coleenp@548 176 virtual void do_oop(narrowOop* p);
duke@435 177 static VerifyOopClosure verify_oop;
duke@435 178 };

mercurial