annotate src/share/vm/gc_implementation/g1/bufferingOopClosure.hpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 02e61cf08ab3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
1 /*
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
4 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
7 * published by the Free Software Foundation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
8 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
13 * accompanied this code).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
14 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 845
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 845
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 845
diff changeset
21 * questions.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
22 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
23 */
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_BUFFERINGOOPCLOSURE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_BUFFERINGOOPCLOSURE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
28 #include "memory/iterator.hpp"
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
29 #include "oops/oopsHierarchy.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/os.hpp"
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
31 #include "utilities/debug.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
33 // A BufferingOops closure tries to separate out the cost of finding roots
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
34 // from the cost of applying closures to them. It maintains an array of
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
35 // ref-containing locations. Until the array is full, applying the closure
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
36 // to an oop* merely records that location in the array. Since this
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
37 // closure app cost is small, an elapsed timer can approximately attribute
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
38 // all of this cost to the cost of finding the roots. When the array fills
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
39 // up, the wrapped closure is applied to all elements, keeping track of
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
40 // this elapsed time of this process, and leaving the array empty.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
41 // The caller must be sure to call "done" to process any unprocessed
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
42 // buffered entriess.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
43
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
44 class BufferingOopClosure: public OopClosure {
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
45 friend class TestBufferingOopClosure;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
46 protected:
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
47 static const size_t BufferLength = 1024;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
48
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
49 // We need to know if the buffered addresses contain oops or narrowOops.
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
50 // We can't tag the addresses the way StarTask does, because we need to
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
51 // be able to handle unaligned addresses coming from oops embedded in code.
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
52 //
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
53 // The addresses for the full-sized oops are filled in from the bottom,
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
54 // while the addresses for the narrowOops are filled in from the top.
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
55 OopOrNarrowOopStar _buffer[BufferLength];
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
56 OopOrNarrowOopStar* _oop_top;
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
57 OopOrNarrowOopStar* _narrowOop_bottom;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
58
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 342
diff changeset
59 OopClosure* _oc;
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 342
diff changeset
60 double _closure_app_seconds;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
61
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
62
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
63 bool is_buffer_empty() {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
64 return _oop_top == _buffer && _narrowOop_bottom == (_buffer + BufferLength - 1);
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
65 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
66
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
67 bool is_buffer_full() {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
68 return _narrowOop_bottom < _oop_top;
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
69 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
70
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
71 // Process addresses containing full-sized oops.
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
72 void process_oops() {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
73 for (OopOrNarrowOopStar* curr = _buffer; curr < _oop_top; ++curr) {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
74 _oc->do_oop((oop*)(*curr));
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
75 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
76 _oop_top = _buffer;
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
77 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
78
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
79 // Process addresses containing narrow oops.
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
80 void process_narrowOops() {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
81 for (OopOrNarrowOopStar* curr = _buffer + BufferLength - 1; curr > _narrowOop_bottom; --curr) {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
82 _oc->do_oop((narrowOop*)(*curr));
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
83 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
84 _narrowOop_bottom = _buffer + BufferLength - 1;
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
85 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
86
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
87 // Apply the closure to all oops and clear the buffer.
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
88 // Accumulate the time it took.
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
89 void process_buffer() {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
90 double start = os::elapsedTime();
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
91
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
92 process_oops();
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
93 process_narrowOops();
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
94
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
95 _closure_app_seconds += (os::elapsedTime() - start);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
96 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
97
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
98 void process_buffer_if_full() {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
99 if (is_buffer_full()) {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
100 process_buffer();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
101 }
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
102 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
103
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
104 void add_narrowOop(narrowOop* p) {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
105 assert(!is_buffer_full(), "Buffer should not be full");
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
106 *_narrowOop_bottom = (OopOrNarrowOopStar)p;
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
107 _narrowOop_bottom--;
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
108 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
109
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
110 void add_oop(oop* p) {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
111 assert(!is_buffer_full(), "Buffer should not be full");
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
112 *_oop_top = (OopOrNarrowOopStar)p;
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
113 _oop_top++;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
114 }
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 342
diff changeset
115
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 342
diff changeset
116 public:
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
117 virtual void do_oop(narrowOop* p) {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
118 process_buffer_if_full();
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
119 add_narrowOop(p);
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
120 }
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 342
diff changeset
121
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
122 virtual void do_oop(oop* p) {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
123 process_buffer_if_full();
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
124 add_oop(p);
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
125 }
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
126
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
127 void done() {
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
128 if (!is_buffer_empty()) {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
129 process_buffer();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
130 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
131 }
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
132
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
133 double closure_app_seconds() {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
134 return _closure_app_seconds;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
135 }
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
136
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
137 BufferingOopClosure(OopClosure *oc) :
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
138 _oc(oc),
20255
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
139 _oop_top(_buffer),
02e61cf08ab3 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents: 14305
diff changeset
140 _narrowOop_bottom(_buffer + BufferLength - 1),
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
141 _closure_app_seconds(0.0) { }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
142 };
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
143
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
144 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_BUFFERINGOOPCLOSURE_HPP