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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6231
889068b9a088
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_BUFFERINGOOPCLOSURE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_BUFFERINGOOPCLOSURE_HPP
aoqi@0 27
aoqi@0 28 #include "memory/genOopClosures.hpp"
aoqi@0 29 #include "memory/generation.hpp"
aoqi@0 30 #include "runtime/os.hpp"
aoqi@0 31 #include "utilities/taskqueue.hpp"
aoqi@0 32
aoqi@0 33 // A BufferingOops closure tries to separate out the cost of finding roots
aoqi@0 34 // from the cost of applying closures to them. It maintains an array of
aoqi@0 35 // ref-containing locations. Until the array is full, applying the closure
aoqi@0 36 // to an oop* merely records that location in the array. Since this
aoqi@0 37 // closure app cost is small, an elapsed timer can approximately attribute
aoqi@0 38 // all of this cost to the cost of finding the roots. When the array fills
aoqi@0 39 // up, the wrapped closure is applied to all elements, keeping track of
aoqi@0 40 // this elapsed time of this process, and leaving the array empty.
aoqi@0 41 // The caller must be sure to call "done" to process any unprocessed
aoqi@0 42 // buffered entriess.
aoqi@0 43
aoqi@0 44 class Generation;
aoqi@0 45 class HeapRegion;
aoqi@0 46
aoqi@0 47 class BufferingOopClosure: public OopClosure {
aoqi@0 48 protected:
aoqi@0 49 enum PrivateConstants {
aoqi@0 50 BufferLength = 1024
aoqi@0 51 };
aoqi@0 52
aoqi@0 53 StarTask _buffer[BufferLength];
aoqi@0 54 StarTask* _buffer_top;
aoqi@0 55 StarTask* _buffer_curr;
aoqi@0 56
aoqi@0 57 OopClosure* _oc;
aoqi@0 58 double _closure_app_seconds;
aoqi@0 59
aoqi@0 60 void process_buffer () {
aoqi@0 61 double start = os::elapsedTime();
aoqi@0 62 for (StarTask* curr = _buffer; curr < _buffer_curr; ++curr) {
aoqi@0 63 if (curr->is_narrow()) {
aoqi@0 64 assert(UseCompressedOops, "Error");
aoqi@0 65 _oc->do_oop((narrowOop*)(*curr));
aoqi@0 66 } else {
aoqi@0 67 _oc->do_oop((oop*)(*curr));
aoqi@0 68 }
aoqi@0 69 }
aoqi@0 70 _buffer_curr = _buffer;
aoqi@0 71 _closure_app_seconds += (os::elapsedTime() - start);
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 template <class T> inline void do_oop_work(T* p) {
aoqi@0 75 if (_buffer_curr == _buffer_top) {
aoqi@0 76 process_buffer();
aoqi@0 77 }
aoqi@0 78 StarTask new_ref(p);
aoqi@0 79 *_buffer_curr = new_ref;
aoqi@0 80 ++_buffer_curr;
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 public:
aoqi@0 84 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
aoqi@0 85 virtual void do_oop(oop* p) { do_oop_work(p); }
aoqi@0 86
aoqi@0 87 void done () {
aoqi@0 88 if (_buffer_curr > _buffer) {
aoqi@0 89 process_buffer();
aoqi@0 90 }
aoqi@0 91 }
aoqi@0 92 double closure_app_seconds () {
aoqi@0 93 return _closure_app_seconds;
aoqi@0 94 }
aoqi@0 95 BufferingOopClosure (OopClosure *oc) :
aoqi@0 96 _oc(oc),
aoqi@0 97 _buffer_curr(_buffer), _buffer_top(_buffer + BufferLength),
aoqi@0 98 _closure_app_seconds(0.0) { }
aoqi@0 99 };
aoqi@0 100
aoqi@0 101 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_BUFFERINGOOPCLOSURE_HPP

mercurial