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