annotate src/share/vm/gc_implementation/g1/g1ParScanThreadState.inline.hpp @ 22901:c132be0fb74d

8060025: Object copy time regressions after JDK-8031323 and JDK-8057536 Summary: Evaluate and improve object copy time by micro-optimizations and splitting out slow and fast paths aggressively. Reviewed-by: kbarrett, mgerdin, jmasa Contributed-by: Tony Printezis <tprintezis@twitter.com>, Thomas Schatzl <thomas.schatzl@oracle.com>
author tschatzl
date Fri, 19 Dec 2014 09:21:06 +0100
parents f2e3f0e1f97d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20223
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
1 /*
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
4 *
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
7 * published by the Free Software Foundation.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
8 *
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
13 * accompanied this code).
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
14 *
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
18 *
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
21 * questions.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
22 *
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
23 */
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
24
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_INLINE_HPP
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_INLINE_HPP
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
27
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
28 #include "gc_implementation/g1/g1ParScanThreadState.hpp"
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
29 #include "gc_implementation/g1/g1RemSet.inline.hpp"
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
30 #include "oops/oop.inline.hpp"
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
31
20224
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
32 template <class T> void G1ParScanThreadState::do_oop_evac(T* p, HeapRegion* from) {
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
33 assert(!oopDesc::is_null(oopDesc::load_decode_heap_oop(p)),
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
34 "Reference should not be NULL here as such are never pushed to the task queue.");
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
35 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
36
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
37 // Although we never intentionally push references outside of the collection
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
38 // set, due to (benign) races in the claim mechanism during RSet scanning more
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
39 // than one thread might claim the same card. So the same card may be
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
40 // processed multiple times. So redo this check.
22901
c132be0fb74d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 22895
diff changeset
41 const InCSetState in_cset_state = _g1h->in_cset_state(obj);
c132be0fb74d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 22895
diff changeset
42 if (in_cset_state.is_in_cset()) {
20224
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
43 oop forwardee;
22895
f2e3f0e1f97d 8064473: Improved handling of age during object copy in G1
sfriberg
parents: 20504
diff changeset
44 markOop m = obj->mark();
f2e3f0e1f97d 8064473: Improved handling of age during object copy in G1
sfriberg
parents: 20504
diff changeset
45 if (m->is_marked()) {
f2e3f0e1f97d 8064473: Improved handling of age during object copy in G1
sfriberg
parents: 20504
diff changeset
46 forwardee = (oop) m->decode_pointer();
20224
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
47 } else {
22901
c132be0fb74d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 22895
diff changeset
48 forwardee = copy_to_survivor_space(in_cset_state, obj, m);
20224
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
49 }
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
50 oopDesc::encode_store_heap_oop(p, forwardee);
22901
c132be0fb74d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 22895
diff changeset
51 } else if (in_cset_state.is_humongous()) {
20296
a3953c777565 8027959: Early reclamation of large objects in G1
tschatzl
parents: 20224
diff changeset
52 _g1h->set_humongous_is_live(obj);
a3953c777565 8027959: Early reclamation of large objects in G1
tschatzl
parents: 20224
diff changeset
53 } else {
22901
c132be0fb74d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 22895
diff changeset
54 assert(!in_cset_state.is_in_cset_or_humongous(),
c132be0fb74d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 22895
diff changeset
55 err_msg("In_cset_state must be NotInCSet here, but is " CSETSTATE_FORMAT, in_cset_state.value()));
20224
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
56 }
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
57
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
58 assert(obj != NULL, "Must be");
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
59 update_rs(from, p, queue_num());
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
60 }
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
61
20223
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
62 inline void G1ParScanThreadState::do_oop_partial_array(oop* p) {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
63 assert(has_partial_array_mask(p), "invariant");
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
64 oop from_obj = clear_partial_array_mask(p);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
65
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
66 assert(Universe::heap()->is_in_reserved(from_obj), "must be in heap.");
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
67 assert(from_obj->is_objArray(), "must be obj array");
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
68 objArrayOop from_obj_array = objArrayOop(from_obj);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
69 // The from-space object contains the real length.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
70 int length = from_obj_array->length();
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
71
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
72 assert(from_obj->is_forwarded(), "must be forwarded");
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
73 oop to_obj = from_obj->forwardee();
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
74 assert(from_obj != to_obj, "should not be chunking self-forwarded objects");
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
75 objArrayOop to_obj_array = objArrayOop(to_obj);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
76 // We keep track of the next start index in the length field of the
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
77 // to-space object.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
78 int next_index = to_obj_array->length();
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
79 assert(0 <= next_index && next_index < length,
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
80 err_msg("invariant, next index: %d, length: %d", next_index, length));
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
81
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
82 int start = next_index;
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
83 int end = length;
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
84 int remainder = end - start;
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
85 // We'll try not to push a range that's smaller than ParGCArrayScanChunk.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
86 if (remainder > 2 * ParGCArrayScanChunk) {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
87 end = start + ParGCArrayScanChunk;
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
88 to_obj_array->set_length(end);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
89 // Push the remainder before we process the range in case another
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
90 // worker has run out of things to do and can steal it.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
91 oop* from_obj_p = set_partial_array_mask(from_obj);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
92 push_on_queue(from_obj_p);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
93 } else {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
94 assert(length == end, "sanity");
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
95 // We'll process the final range for this object. Restore the length
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
96 // so that the heap remains parsable in case of evacuation failure.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
97 to_obj_array->set_length(end);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
98 }
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
99 _scanner.set_region(_g1h->heap_region_containing_raw(to_obj));
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
100 // Process indexes [start,end). It will also process the header
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
101 // along with the first chunk (i.e., the chunk with start == 0).
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
102 // Note that at this point the length field of to_obj_array is not
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
103 // correct given that we are using it to keep track of the next
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
104 // start index. oop_iterate_range() (thankfully!) ignores the length
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
105 // field and only relies on the start / end parameters. It does
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
106 // however return the size of the object which will be incorrect. So
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
107 // we have to ignore it even if we wanted to use it.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
108 to_obj_array->oop_iterate_range(&_scanner, start, end);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
109 }
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
110
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
111 template <class T> inline void G1ParScanThreadState::deal_with_reference(T* ref_to_scan) {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
112 if (!has_partial_array_mask(ref_to_scan)) {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
113 // Note: we can use "raw" versions of "region_containing" because
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
114 // "obj_to_scan" is definitely in the heap, and is not in a
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
115 // humongous region.
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
116 HeapRegion* r = _g1h->heap_region_containing_raw(ref_to_scan);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
117 do_oop_evac(ref_to_scan, r);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
118 } else {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
119 do_oop_partial_array((oop*)ref_to_scan);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
120 }
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
121 }
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
122
20224
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
123 inline void G1ParScanThreadState::dispatch_reference(StarTask ref) {
20223
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
124 assert(verify_task(ref), "sanity");
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
125 if (ref.is_narrow()) {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
126 deal_with_reference((narrowOop*)ref);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
127 } else {
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
128 deal_with_reference((oop*)ref);
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
129 }
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
130 }
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
131
20224
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
132 void G1ParScanThreadState::steal_and_trim_queue(RefToScanQueueSet *task_queues) {
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
133 StarTask stolen_task;
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
134 while (task_queues->steal(queue_num(), hash_seed(), stolen_task)) {
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
135 assert(verify_task(stolen_task), "sanity");
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
136 dispatch_reference(stolen_task);
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
137
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
138 // We've just processed a reference and we might have made
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
139 // available new entries on the queues. So we have to make sure
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
140 // we drain the queues as necessary.
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
141 trim_queue();
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
142 }
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
143 }
a2328cbebb23 8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents: 20223
diff changeset
144
20223
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
145 #endif /* SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_INLINE_HPP */
b0c374311c4e 8035400: Move G1ParScanThreadState into its own files
tschatzl
parents:
diff changeset
146