Tue, 16 Nov 2010 14:07:33 -0800
6978187: G1: assert(ParallelGCThreads> 1 || n_yielded() == _hrrs->occupied()) strikes again
Summary: An evacuation failure while copying the roots caused an object, A, to be forwarded to itself. During the subsequent RSet updating a reference to A was processed causing the reference to be added to the RSet of A's heap region. As a result of adding to the remembered set we ran into the issue described in 6930581 - the sparse table expanded and the RSet scanning code walked the cards in one instance of RHashTable (_cur) while the occupied() counts the cards in the expanded table (_next).
Reviewed-by: tonyp, iveresov
1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 inline size_t G1RemSet::n_workers() {
26 if (_g1->workers() != NULL) {
27 return _g1->workers()->total_workers();
28 } else {
29 return 1;
30 }
31 }
33 template <class T>
34 inline void G1RemSet::write_ref(HeapRegion* from, T* p) {
35 par_write_ref(from, p, 0);
36 }
38 template <class T>
39 inline void G1RemSet::par_write_ref(HeapRegion* from, T* p, int tid) {
40 oop obj = oopDesc::load_decode_heap_oop(p);
41 #ifdef ASSERT
42 // can't do because of races
43 // assert(obj == NULL || obj->is_oop(), "expected an oop");
45 // Do the safe subset of is_oop
46 if (obj != NULL) {
47 #ifdef CHECK_UNHANDLED_OOPS
48 oopDesc* o = obj.obj();
49 #else
50 oopDesc* o = obj;
51 #endif // CHECK_UNHANDLED_OOPS
52 assert((intptr_t)o % MinObjAlignmentInBytes == 0, "not oop aligned");
53 assert(Universe::heap()->is_in_reserved(obj), "must be in heap");
54 }
55 #endif // ASSERT
57 assert(from == NULL || from->is_in_reserved(p), "p is not in from");
59 HeapRegion* to = _g1->heap_region_containing(obj);
60 if (to != NULL && from != to) {
61 #if G1_REM_SET_LOGGING
62 gclog_or_tty->print_cr("Adding " PTR_FORMAT " (" PTR_FORMAT ") to RS"
63 " for region [" PTR_FORMAT ", " PTR_FORMAT ")",
64 p, obj,
65 to->bottom(), to->end());
66 #endif
67 assert(to->rem_set() != NULL, "Need per-region 'into' remsets.");
68 to->rem_set()->add_reference(p, tid);
69 }
70 }
72 template <class T>
73 inline void UpdateRSOopClosure::do_oop_work(T* p) {
74 assert(_from != NULL, "from region must be non-NULL");
75 _rs->par_write_ref(_from, p, _worker_i);
76 }
78 template <class T>
79 inline void UpdateRSetImmediate::do_oop_work(T* p) {
80 assert(_from->is_in_reserved(p), "paranoia");
81 T heap_oop = oopDesc::load_heap_oop(p);
82 if (!oopDesc::is_null(heap_oop) && !_from->is_survivor()) {
83 _g1_rem_set->par_write_ref(_from, p, 0);
84 }
85 }
87 template <class T>
88 inline void UpdateRSOrPushRefOopClosure::do_oop_work(T* p) {
89 oop obj = oopDesc::load_decode_heap_oop(p);
90 #ifdef ASSERT
91 // can't do because of races
92 // assert(obj == NULL || obj->is_oop(), "expected an oop");
94 // Do the safe subset of is_oop
95 if (obj != NULL) {
96 #ifdef CHECK_UNHANDLED_OOPS
97 oopDesc* o = obj.obj();
98 #else
99 oopDesc* o = obj;
100 #endif // CHECK_UNHANDLED_OOPS
101 assert((intptr_t)o % MinObjAlignmentInBytes == 0, "not oop aligned");
102 assert(Universe::heap()->is_in_reserved(obj), "must be in heap");
103 }
104 #endif // ASSERT
106 assert(_from != NULL, "from region must be non-NULL");
108 HeapRegion* to = _g1->heap_region_containing(obj);
109 if (to != NULL && _from != to) {
110 // The _record_refs_into_cset flag is true during the RSet
111 // updating part of an evacuation pause. It is false at all
112 // other times:
113 // * rebuilding the rembered sets after a full GC
114 // * during concurrent refinement.
115 // * updating the remembered sets of regions in the collection
116 // set in the event of an evacuation failure (when deferred
117 // updates are enabled).
119 if (_record_refs_into_cset && to->in_collection_set()) {
120 // We are recording references that point into the collection
121 // set and this particular reference does exactly that...
122 // If the referenced object has already been forwarded
123 // to itself, we are handling an evacuation failure and
124 // we have already visited/tried to copy this object
125 // there is no need to retry.
126 if (!self_forwarded(obj)) {
127 assert(_push_ref_cl != NULL, "should not be null");
128 // Push the reference in the refs queue of the G1ParScanThreadState
129 // instance for this worker thread.
130 _push_ref_cl->do_oop(p);
131 }
133 // Deferred updates to the CSet are either discarded (in the normal case),
134 // or processed (if an evacuation failure occurs) at the end
135 // of the collection.
136 // See G1RemSet::cleanup_after_oops_into_collection_set_do().
137 } else {
138 // We either don't care about pushing references that point into the
139 // collection set (i.e. we're not during an evacuation pause) _or_
140 // the reference doesn't point into the collection set. Either way
141 // we add the reference directly to the RSet of the region containing
142 // the referenced object.
143 _g1_rem_set->par_write_ref(_from, p, _worker_i);
144 }
145 }
146 }