Tue, 19 May 2009 04:05:31 -0700
6819065: G1: eliminate high serial card table clearing time
Reviewed-by: iveresov, tonyp
ysr@777 | 1 | /* |
ysr@777 | 2 | * Copyright 2001-2007 Sun Microsystems, Inc. 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 | * |
ysr@777 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
ysr@777 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
ysr@777 | 21 | * have any 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@777 | 45 | oop *_buffer[BufferLength]; |
ysr@777 | 46 | oop **_buffer_top; |
ysr@777 | 47 | oop **_buffer_curr; |
ysr@777 | 48 | |
ysr@777 | 49 | OopClosure *_oc; |
ysr@777 | 50 | double _closure_app_seconds; |
ysr@777 | 51 | |
ysr@777 | 52 | void process_buffer () { |
ysr@777 | 53 | |
ysr@777 | 54 | double start = os::elapsedTime(); |
ysr@777 | 55 | for (oop **curr = _buffer; curr < _buffer_curr; ++curr) { |
ysr@777 | 56 | _oc->do_oop(*curr); |
ysr@777 | 57 | } |
ysr@777 | 58 | _buffer_curr = _buffer; |
ysr@777 | 59 | _closure_app_seconds += (os::elapsedTime() - start); |
ysr@777 | 60 | } |
ysr@777 | 61 | |
ysr@777 | 62 | public: |
ysr@777 | 63 | virtual void do_oop(narrowOop* p) { |
ysr@777 | 64 | guarantee(false, "NYI"); |
ysr@777 | 65 | } |
ysr@777 | 66 | virtual void do_oop(oop *p) { |
ysr@777 | 67 | if (_buffer_curr == _buffer_top) { |
ysr@777 | 68 | process_buffer(); |
ysr@777 | 69 | } |
ysr@777 | 70 | |
ysr@777 | 71 | *_buffer_curr = p; |
ysr@777 | 72 | ++_buffer_curr; |
ysr@777 | 73 | } |
ysr@777 | 74 | void done () { |
ysr@777 | 75 | if (_buffer_curr > _buffer) { |
ysr@777 | 76 | process_buffer(); |
ysr@777 | 77 | } |
ysr@777 | 78 | } |
ysr@777 | 79 | double closure_app_seconds () { |
ysr@777 | 80 | return _closure_app_seconds; |
ysr@777 | 81 | } |
ysr@777 | 82 | BufferingOopClosure (OopClosure *oc) : |
ysr@777 | 83 | _oc(oc), |
ysr@777 | 84 | _buffer_curr(_buffer), _buffer_top(_buffer + BufferLength), |
ysr@777 | 85 | _closure_app_seconds(0.0) { } |
ysr@777 | 86 | }; |
ysr@777 | 87 | |
ysr@777 | 88 | class BufferingOopsInGenClosure: public OopsInGenClosure { |
ysr@777 | 89 | BufferingOopClosure _boc; |
ysr@777 | 90 | OopsInGenClosure* _oc; |
ysr@777 | 91 | public: |
ysr@777 | 92 | BufferingOopsInGenClosure(OopsInGenClosure *oc) : |
ysr@777 | 93 | _boc(oc), _oc(oc) {} |
ysr@777 | 94 | |
ysr@777 | 95 | virtual void do_oop(narrowOop* p) { |
ysr@777 | 96 | guarantee(false, "NYI"); |
ysr@777 | 97 | } |
ysr@777 | 98 | |
ysr@777 | 99 | virtual void do_oop(oop* p) { |
ysr@777 | 100 | assert(generation()->is_in_reserved(p), "Must be in!"); |
ysr@777 | 101 | _boc.do_oop(p); |
ysr@777 | 102 | } |
ysr@777 | 103 | |
ysr@777 | 104 | void done() { |
ysr@777 | 105 | _boc.done(); |
ysr@777 | 106 | } |
ysr@777 | 107 | |
ysr@777 | 108 | double closure_app_seconds () { |
ysr@777 | 109 | return _boc.closure_app_seconds(); |
ysr@777 | 110 | } |
ysr@777 | 111 | |
ysr@777 | 112 | void set_generation(Generation* gen) { |
ysr@777 | 113 | OopsInGenClosure::set_generation(gen); |
ysr@777 | 114 | _oc->set_generation(gen); |
ysr@777 | 115 | } |
ysr@777 | 116 | |
ysr@777 | 117 | void reset_generation() { |
ysr@777 | 118 | // Make sure we finish the current work with the current generation. |
ysr@777 | 119 | _boc.done(); |
ysr@777 | 120 | OopsInGenClosure::reset_generation(); |
ysr@777 | 121 | _oc->reset_generation(); |
ysr@777 | 122 | } |
ysr@777 | 123 | |
ysr@777 | 124 | }; |
ysr@777 | 125 | |
ysr@777 | 126 | |
ysr@777 | 127 | class BufferingOopsInHeapRegionClosure: public OopsInHeapRegionClosure { |
ysr@777 | 128 | private: |
ysr@777 | 129 | enum PrivateConstants { |
ysr@777 | 130 | BufferLength = 1024 |
ysr@777 | 131 | }; |
ysr@777 | 132 | |
ysr@777 | 133 | oop *_buffer[BufferLength]; |
ysr@777 | 134 | oop **_buffer_top; |
ysr@777 | 135 | oop **_buffer_curr; |
ysr@777 | 136 | |
ysr@777 | 137 | HeapRegion *_hr_buffer[BufferLength]; |
ysr@777 | 138 | HeapRegion **_hr_curr; |
ysr@777 | 139 | |
ysr@777 | 140 | OopsInHeapRegionClosure *_oc; |
ysr@777 | 141 | double _closure_app_seconds; |
ysr@777 | 142 | |
ysr@777 | 143 | void process_buffer () { |
ysr@777 | 144 | |
ysr@777 | 145 | assert((_hr_curr - _hr_buffer) == (_buffer_curr - _buffer), |
ysr@777 | 146 | "the two lengths should be the same"); |
ysr@777 | 147 | |
ysr@777 | 148 | double start = os::elapsedTime(); |
ysr@777 | 149 | HeapRegion **hr_curr = _hr_buffer; |
ysr@777 | 150 | HeapRegion *hr_prev = NULL; |
ysr@777 | 151 | for (oop **curr = _buffer; curr < _buffer_curr; ++curr) { |
ysr@777 | 152 | HeapRegion *region = *hr_curr; |
ysr@777 | 153 | if (region != hr_prev) { |
ysr@777 | 154 | _oc->set_region(region); |
ysr@777 | 155 | hr_prev = region; |
ysr@777 | 156 | } |
ysr@777 | 157 | _oc->do_oop(*curr); |
ysr@777 | 158 | ++hr_curr; |
ysr@777 | 159 | } |
ysr@777 | 160 | _buffer_curr = _buffer; |
ysr@777 | 161 | _hr_curr = _hr_buffer; |
ysr@777 | 162 | _closure_app_seconds += (os::elapsedTime() - start); |
ysr@777 | 163 | } |
ysr@777 | 164 | |
ysr@777 | 165 | public: |
ysr@777 | 166 | virtual void do_oop(narrowOop *p) { |
ysr@777 | 167 | guarantee(false, "NYI"); |
ysr@777 | 168 | } |
ysr@777 | 169 | |
ysr@777 | 170 | virtual void do_oop(oop *p) { |
ysr@777 | 171 | if (_buffer_curr == _buffer_top) { |
ysr@777 | 172 | assert(_hr_curr > _hr_buffer, "_hr_curr should be consistent with _buffer_curr"); |
ysr@777 | 173 | process_buffer(); |
ysr@777 | 174 | } |
ysr@777 | 175 | |
ysr@777 | 176 | *_buffer_curr = p; |
ysr@777 | 177 | ++_buffer_curr; |
ysr@777 | 178 | *_hr_curr = _from; |
ysr@777 | 179 | ++_hr_curr; |
ysr@777 | 180 | } |
ysr@777 | 181 | void done () { |
ysr@777 | 182 | if (_buffer_curr > _buffer) { |
ysr@777 | 183 | assert(_hr_curr > _hr_buffer, "_hr_curr should be consistent with _buffer_curr"); |
ysr@777 | 184 | process_buffer(); |
ysr@777 | 185 | } |
ysr@777 | 186 | } |
ysr@777 | 187 | double closure_app_seconds () { |
ysr@777 | 188 | return _closure_app_seconds; |
ysr@777 | 189 | } |
ysr@777 | 190 | BufferingOopsInHeapRegionClosure (OopsInHeapRegionClosure *oc) : |
ysr@777 | 191 | _oc(oc), |
ysr@777 | 192 | _buffer_curr(_buffer), _buffer_top(_buffer + BufferLength), |
ysr@777 | 193 | _hr_curr(_hr_buffer), |
ysr@777 | 194 | _closure_app_seconds(0.0) { } |
ysr@777 | 195 | }; |