src/share/vm/gc_implementation/g1/bufferingOopClosure.hpp

Mon, 02 Aug 2010 12:51:43 -0700

author
johnc
date
Mon, 02 Aug 2010 12:51:43 -0700
changeset 2060
2d160770d2e5
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6814437: G1: remove the _new_refs array
Summary: The per-worker _new_refs array is used to hold references that point into the collection set. It is populated during RSet updating and subsequently processed. In the event of an evacuation failure it processed again to recreate the RSets of regions in the collection set. Remove the per-worker _new_refs array by processing the references directly. Use a DirtyCardQueue to hold the cards containing the references so that the RSets of regions in the collection set can be recreated when handling an evacuation failure.
Reviewed-by: iveresov, jmasa, tonyp

ysr@777 1 /*
trims@1907 2 * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
ysr@777 25 // A BufferingOops closure tries to separate out the cost of finding roots
ysr@777 26 // from the cost of applying closures to them. It maintains an array of
ysr@777 27 // ref-containing locations. Until the array is full, applying the closure
ysr@777 28 // to an oop* merely records that location in the array. Since this
ysr@777 29 // closure app cost is small, an elapsed timer can approximately attribute
ysr@777 30 // all of this cost to the cost of finding the roots. When the array fills
ysr@777 31 // up, the wrapped closure is applied to all elements, keeping track of
ysr@777 32 // this elapsed time of this process, and leaving the array empty.
ysr@777 33 // The caller must be sure to call "done" to process any unprocessed
ysr@777 34 // buffered entriess.
ysr@777 35
ysr@777 36 class Generation;
ysr@777 37 class HeapRegion;
ysr@777 38
ysr@777 39 class BufferingOopClosure: public OopClosure {
ysr@777 40 protected:
ysr@777 41 enum PrivateConstants {
ysr@777 42 BufferLength = 1024
ysr@777 43 };
ysr@777 44
ysr@1280 45 StarTask _buffer[BufferLength];
ysr@1280 46 StarTask* _buffer_top;
ysr@1280 47 StarTask* _buffer_curr;
ysr@777 48
ysr@1280 49 OopClosure* _oc;
ysr@1280 50 double _closure_app_seconds;
ysr@777 51
ysr@777 52 void process_buffer () {
ysr@777 53 double start = os::elapsedTime();
ysr@1280 54 for (StarTask* curr = _buffer; curr < _buffer_curr; ++curr) {
ysr@1280 55 if (curr->is_narrow()) {
ysr@1280 56 assert(UseCompressedOops, "Error");
ysr@1280 57 _oc->do_oop((narrowOop*)(*curr));
ysr@1280 58 } else {
ysr@1280 59 _oc->do_oop((oop*)(*curr));
ysr@1280 60 }
ysr@777 61 }
ysr@777 62 _buffer_curr = _buffer;
ysr@777 63 _closure_app_seconds += (os::elapsedTime() - start);
ysr@777 64 }
ysr@777 65
ysr@1280 66 template <class T> inline void do_oop_work(T* p) {
ysr@777 67 if (_buffer_curr == _buffer_top) {
ysr@777 68 process_buffer();
ysr@777 69 }
ysr@1280 70 StarTask new_ref(p);
ysr@1280 71 *_buffer_curr = new_ref;
ysr@777 72 ++_buffer_curr;
ysr@777 73 }
ysr@1280 74
ysr@1280 75 public:
ysr@1280 76 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
ysr@1280 77 virtual void do_oop(oop* p) { do_oop_work(p); }
ysr@1280 78
ysr@777 79 void done () {
ysr@777 80 if (_buffer_curr > _buffer) {
ysr@777 81 process_buffer();
ysr@777 82 }
ysr@777 83 }
ysr@777 84 double closure_app_seconds () {
ysr@777 85 return _closure_app_seconds;
ysr@777 86 }
ysr@777 87 BufferingOopClosure (OopClosure *oc) :
ysr@777 88 _oc(oc),
ysr@777 89 _buffer_curr(_buffer), _buffer_top(_buffer + BufferLength),
ysr@777 90 _closure_app_seconds(0.0) { }
ysr@777 91 };
ysr@777 92
ysr@777 93 class BufferingOopsInGenClosure: public OopsInGenClosure {
ysr@777 94 BufferingOopClosure _boc;
ysr@777 95 OopsInGenClosure* _oc;
ysr@1280 96 protected:
ysr@1280 97 template <class T> inline void do_oop_work(T* p) {
ysr@1280 98 assert(generation()->is_in_reserved((void*)p), "Must be in!");
ysr@1280 99 _boc.do_oop(p);
ysr@1280 100 }
ysr@1280 101 public:
ysr@777 102 BufferingOopsInGenClosure(OopsInGenClosure *oc) :
ysr@777 103 _boc(oc), _oc(oc) {}
ysr@777 104
ysr@1280 105 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
ysr@1280 106 virtual void do_oop(oop* p) { do_oop_work(p); }
ysr@777 107
ysr@777 108 void done() {
ysr@777 109 _boc.done();
ysr@777 110 }
ysr@777 111
ysr@777 112 double closure_app_seconds () {
ysr@777 113 return _boc.closure_app_seconds();
ysr@777 114 }
ysr@777 115
ysr@777 116 void set_generation(Generation* gen) {
ysr@777 117 OopsInGenClosure::set_generation(gen);
ysr@777 118 _oc->set_generation(gen);
ysr@777 119 }
ysr@777 120
ysr@777 121 void reset_generation() {
ysr@777 122 // Make sure we finish the current work with the current generation.
ysr@777 123 _boc.done();
ysr@777 124 OopsInGenClosure::reset_generation();
ysr@777 125 _oc->reset_generation();
ysr@777 126 }
ysr@777 127
ysr@777 128 };
ysr@777 129
ysr@777 130
ysr@777 131 class BufferingOopsInHeapRegionClosure: public OopsInHeapRegionClosure {
ysr@777 132 private:
ysr@777 133 enum PrivateConstants {
ysr@777 134 BufferLength = 1024
ysr@777 135 };
ysr@777 136
ysr@1280 137 StarTask _buffer[BufferLength];
ysr@1280 138 StarTask* _buffer_top;
ysr@1280 139 StarTask* _buffer_curr;
ysr@777 140
ysr@1280 141 HeapRegion* _hr_buffer[BufferLength];
ysr@1280 142 HeapRegion** _hr_curr;
ysr@777 143
ysr@1280 144 OopsInHeapRegionClosure* _oc;
ysr@777 145 double _closure_app_seconds;
ysr@777 146
ysr@777 147 void process_buffer () {
ysr@777 148
ysr@777 149 assert((_hr_curr - _hr_buffer) == (_buffer_curr - _buffer),
ysr@777 150 "the two lengths should be the same");
ysr@777 151
ysr@777 152 double start = os::elapsedTime();
ysr@1280 153 HeapRegion** hr_curr = _hr_buffer;
ysr@1280 154 HeapRegion* hr_prev = NULL;
ysr@1280 155 for (StarTask* curr = _buffer; curr < _buffer_curr; ++curr) {
ysr@1280 156 HeapRegion* region = *hr_curr;
ysr@777 157 if (region != hr_prev) {
ysr@777 158 _oc->set_region(region);
ysr@777 159 hr_prev = region;
ysr@777 160 }
ysr@1280 161 if (curr->is_narrow()) {
ysr@1280 162 assert(UseCompressedOops, "Error");
ysr@1280 163 _oc->do_oop((narrowOop*)(*curr));
ysr@1280 164 } else {
ysr@1280 165 _oc->do_oop((oop*)(*curr));
ysr@1280 166 }
ysr@777 167 ++hr_curr;
ysr@777 168 }
ysr@777 169 _buffer_curr = _buffer;
ysr@777 170 _hr_curr = _hr_buffer;
ysr@777 171 _closure_app_seconds += (os::elapsedTime() - start);
ysr@777 172 }
ysr@777 173
ysr@777 174 public:
ysr@1280 175 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
ysr@1280 176 virtual void do_oop( oop* p) { do_oop_work(p); }
ysr@777 177
ysr@1280 178 template <class T> void do_oop_work(T* p) {
ysr@777 179 if (_buffer_curr == _buffer_top) {
ysr@777 180 assert(_hr_curr > _hr_buffer, "_hr_curr should be consistent with _buffer_curr");
ysr@777 181 process_buffer();
ysr@777 182 }
ysr@1280 183 StarTask new_ref(p);
ysr@1280 184 *_buffer_curr = new_ref;
ysr@777 185 ++_buffer_curr;
ysr@777 186 *_hr_curr = _from;
ysr@777 187 ++_hr_curr;
ysr@777 188 }
ysr@777 189 void done () {
ysr@777 190 if (_buffer_curr > _buffer) {
ysr@777 191 assert(_hr_curr > _hr_buffer, "_hr_curr should be consistent with _buffer_curr");
ysr@777 192 process_buffer();
ysr@777 193 }
ysr@777 194 }
ysr@777 195 double closure_app_seconds () {
ysr@777 196 return _closure_app_seconds;
ysr@777 197 }
ysr@777 198 BufferingOopsInHeapRegionClosure (OopsInHeapRegionClosure *oc) :
ysr@777 199 _oc(oc),
ysr@777 200 _buffer_curr(_buffer), _buffer_top(_buffer + BufferLength),
ysr@777 201 _hr_curr(_hr_buffer),
ysr@777 202 _closure_app_seconds(0.0) { }
ysr@777 203 };

mercurial