1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/bufferingOopClosure.hpp Thu Jun 05 15:57:56 2008 -0700 1.3 @@ -0,0 +1,195 @@ 1.4 +/* 1.5 + * Copyright 2001-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// A BufferingOops closure tries to separate out the cost of finding roots 1.29 +// from the cost of applying closures to them. It maintains an array of 1.30 +// ref-containing locations. Until the array is full, applying the closure 1.31 +// to an oop* merely records that location in the array. Since this 1.32 +// closure app cost is small, an elapsed timer can approximately attribute 1.33 +// all of this cost to the cost of finding the roots. When the array fills 1.34 +// up, the wrapped closure is applied to all elements, keeping track of 1.35 +// this elapsed time of this process, and leaving the array empty. 1.36 +// The caller must be sure to call "done" to process any unprocessed 1.37 +// buffered entriess. 1.38 + 1.39 +class Generation; 1.40 +class HeapRegion; 1.41 + 1.42 +class BufferingOopClosure: public OopClosure { 1.43 +protected: 1.44 + enum PrivateConstants { 1.45 + BufferLength = 1024 1.46 + }; 1.47 + 1.48 + oop *_buffer[BufferLength]; 1.49 + oop **_buffer_top; 1.50 + oop **_buffer_curr; 1.51 + 1.52 + OopClosure *_oc; 1.53 + double _closure_app_seconds; 1.54 + 1.55 + void process_buffer () { 1.56 + 1.57 + double start = os::elapsedTime(); 1.58 + for (oop **curr = _buffer; curr < _buffer_curr; ++curr) { 1.59 + _oc->do_oop(*curr); 1.60 + } 1.61 + _buffer_curr = _buffer; 1.62 + _closure_app_seconds += (os::elapsedTime() - start); 1.63 + } 1.64 + 1.65 +public: 1.66 + virtual void do_oop(narrowOop* p) { 1.67 + guarantee(false, "NYI"); 1.68 + } 1.69 + virtual void do_oop(oop *p) { 1.70 + if (_buffer_curr == _buffer_top) { 1.71 + process_buffer(); 1.72 + } 1.73 + 1.74 + *_buffer_curr = p; 1.75 + ++_buffer_curr; 1.76 + } 1.77 + void done () { 1.78 + if (_buffer_curr > _buffer) { 1.79 + process_buffer(); 1.80 + } 1.81 + } 1.82 + double closure_app_seconds () { 1.83 + return _closure_app_seconds; 1.84 + } 1.85 + BufferingOopClosure (OopClosure *oc) : 1.86 + _oc(oc), 1.87 + _buffer_curr(_buffer), _buffer_top(_buffer + BufferLength), 1.88 + _closure_app_seconds(0.0) { } 1.89 +}; 1.90 + 1.91 +class BufferingOopsInGenClosure: public OopsInGenClosure { 1.92 + BufferingOopClosure _boc; 1.93 + OopsInGenClosure* _oc; 1.94 +public: 1.95 + BufferingOopsInGenClosure(OopsInGenClosure *oc) : 1.96 + _boc(oc), _oc(oc) {} 1.97 + 1.98 + virtual void do_oop(narrowOop* p) { 1.99 + guarantee(false, "NYI"); 1.100 + } 1.101 + 1.102 + virtual void do_oop(oop* p) { 1.103 + assert(generation()->is_in_reserved(p), "Must be in!"); 1.104 + _boc.do_oop(p); 1.105 + } 1.106 + 1.107 + void done() { 1.108 + _boc.done(); 1.109 + } 1.110 + 1.111 + double closure_app_seconds () { 1.112 + return _boc.closure_app_seconds(); 1.113 + } 1.114 + 1.115 + void set_generation(Generation* gen) { 1.116 + OopsInGenClosure::set_generation(gen); 1.117 + _oc->set_generation(gen); 1.118 + } 1.119 + 1.120 + void reset_generation() { 1.121 + // Make sure we finish the current work with the current generation. 1.122 + _boc.done(); 1.123 + OopsInGenClosure::reset_generation(); 1.124 + _oc->reset_generation(); 1.125 + } 1.126 + 1.127 +}; 1.128 + 1.129 + 1.130 +class BufferingOopsInHeapRegionClosure: public OopsInHeapRegionClosure { 1.131 +private: 1.132 + enum PrivateConstants { 1.133 + BufferLength = 1024 1.134 + }; 1.135 + 1.136 + oop *_buffer[BufferLength]; 1.137 + oop **_buffer_top; 1.138 + oop **_buffer_curr; 1.139 + 1.140 + HeapRegion *_hr_buffer[BufferLength]; 1.141 + HeapRegion **_hr_curr; 1.142 + 1.143 + OopsInHeapRegionClosure *_oc; 1.144 + double _closure_app_seconds; 1.145 + 1.146 + void process_buffer () { 1.147 + 1.148 + assert((_hr_curr - _hr_buffer) == (_buffer_curr - _buffer), 1.149 + "the two lengths should be the same"); 1.150 + 1.151 + double start = os::elapsedTime(); 1.152 + HeapRegion **hr_curr = _hr_buffer; 1.153 + HeapRegion *hr_prev = NULL; 1.154 + for (oop **curr = _buffer; curr < _buffer_curr; ++curr) { 1.155 + HeapRegion *region = *hr_curr; 1.156 + if (region != hr_prev) { 1.157 + _oc->set_region(region); 1.158 + hr_prev = region; 1.159 + } 1.160 + _oc->do_oop(*curr); 1.161 + ++hr_curr; 1.162 + } 1.163 + _buffer_curr = _buffer; 1.164 + _hr_curr = _hr_buffer; 1.165 + _closure_app_seconds += (os::elapsedTime() - start); 1.166 + } 1.167 + 1.168 +public: 1.169 + virtual void do_oop(narrowOop *p) { 1.170 + guarantee(false, "NYI"); 1.171 + } 1.172 + 1.173 + virtual void do_oop(oop *p) { 1.174 + if (_buffer_curr == _buffer_top) { 1.175 + assert(_hr_curr > _hr_buffer, "_hr_curr should be consistent with _buffer_curr"); 1.176 + process_buffer(); 1.177 + } 1.178 + 1.179 + *_buffer_curr = p; 1.180 + ++_buffer_curr; 1.181 + *_hr_curr = _from; 1.182 + ++_hr_curr; 1.183 + } 1.184 + void done () { 1.185 + if (_buffer_curr > _buffer) { 1.186 + assert(_hr_curr > _hr_buffer, "_hr_curr should be consistent with _buffer_curr"); 1.187 + process_buffer(); 1.188 + } 1.189 + } 1.190 + double closure_app_seconds () { 1.191 + return _closure_app_seconds; 1.192 + } 1.193 + BufferingOopsInHeapRegionClosure (OopsInHeapRegionClosure *oc) : 1.194 + _oc(oc), 1.195 + _buffer_curr(_buffer), _buffer_top(_buffer + BufferLength), 1.196 + _hr_curr(_hr_buffer), 1.197 + _closure_app_seconds(0.0) { } 1.198 +};