Thu, 07 Apr 2011 09:53:20 -0700
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
Summary: A referent object that is only weakly reachable at the start of concurrent marking but is re-attached to the strongly reachable object graph during marking may not be marked as live. This can cause the reference object to be processed prematurely and leave dangling pointers to the referent object. Implement a read barrier for the java.lang.ref.Reference::referent field by intrinsifying the Reference.get() method, and intercepting accesses though JNI, reflection, and Unsafe, so that when a non-null referent object is read it is also logged in an SATB buffer.
Reviewed-by: kvn, iveresov, never, tonyp, dholmes
1 /*
2 * Copyright (c) 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 #ifndef SHARE_VM_OOPS_OBJARRAYKLASS_INLINE_HPP
26 #define SHARE_VM_OOPS_OBJARRAYKLASS_INLINE_HPP
28 #include "oops/objArrayKlass.hpp"
29 #ifndef SERIALGC
30 #include "gc_implementation/parallelScavenge/psCompactionManager.inline.hpp"
31 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
32 #endif
34 void objArrayKlass::oop_follow_contents(oop obj, int index) {
35 if (UseCompressedOops) {
36 objarray_follow_contents<narrowOop>(obj, index);
37 } else {
38 objarray_follow_contents<oop>(obj, index);
39 }
40 }
42 template <class T>
43 void objArrayKlass::objarray_follow_contents(oop obj, int index) {
44 objArrayOop a = objArrayOop(obj);
45 const size_t len = size_t(a->length());
46 const size_t beg_index = size_t(index);
47 assert(beg_index < len || len == 0, "index too large");
49 const size_t stride = MIN2(len - beg_index, ObjArrayMarkingStride);
50 const size_t end_index = beg_index + stride;
51 T* const base = (T*)a->base();
52 T* const beg = base + beg_index;
53 T* const end = base + end_index;
55 // Push the non-NULL elements of the next stride on the marking stack.
56 for (T* e = beg; e < end; e++) {
57 MarkSweep::mark_and_push<T>(e);
58 }
60 if (end_index < len) {
61 MarkSweep::push_objarray(a, end_index); // Push the continuation.
62 }
63 }
65 #ifndef SERIALGC
66 void objArrayKlass::oop_follow_contents(ParCompactionManager* cm, oop obj,
67 int index) {
68 if (UseCompressedOops) {
69 objarray_follow_contents<narrowOop>(cm, obj, index);
70 } else {
71 objarray_follow_contents<oop>(cm, obj, index);
72 }
73 }
75 template <class T>
76 void objArrayKlass::objarray_follow_contents(ParCompactionManager* cm, oop obj,
77 int index) {
78 objArrayOop a = objArrayOop(obj);
79 const size_t len = size_t(a->length());
80 const size_t beg_index = size_t(index);
81 assert(beg_index < len || len == 0, "index too large");
83 const size_t stride = MIN2(len - beg_index, ObjArrayMarkingStride);
84 const size_t end_index = beg_index + stride;
85 T* const base = (T*)a->base();
86 T* const beg = base + beg_index;
87 T* const end = base + end_index;
89 // Push the non-NULL elements of the next stride on the marking stack.
90 for (T* e = beg; e < end; e++) {
91 PSParallelCompact::mark_and_push<T>(cm, e);
92 }
94 if (end_index < len) {
95 cm->push_objarray(a, end_index); // Push the continuation.
96 }
97 }
98 #endif // #ifndef SERIALGC
100 #endif // SHARE_VM_OOPS_OBJARRAYKLASS_INLINE_HPP