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
never@2658 | 1 | /* |
never@2658 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
never@2658 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
never@2658 | 4 | * |
never@2658 | 5 | * This code is free software; you can redistribute it and/or modify it |
never@2658 | 6 | * under the terms of the GNU General Public License version 2 only, as |
never@2658 | 7 | * published by the Free Software Foundation. |
never@2658 | 8 | * |
never@2658 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
never@2658 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
never@2658 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
never@2658 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
never@2658 | 13 | * accompanied this code). |
never@2658 | 14 | * |
never@2658 | 15 | * You should have received a copy of the GNU General Public License version |
never@2658 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
never@2658 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
never@2658 | 18 | * |
never@2658 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
never@2658 | 20 | * or visit www.oracle.com if you need additional information or have any |
never@2658 | 21 | * questions. |
never@2658 | 22 | * |
never@2658 | 23 | */ |
never@2658 | 24 | |
never@2658 | 25 | #ifndef SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP |
never@2658 | 26 | #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP |
never@2658 | 27 | |
never@2658 | 28 | #include "oops/instanceKlass.hpp" |
never@2658 | 29 | |
never@2658 | 30 | // An instanceMirrorKlass is a specialized instanceKlass for |
never@2658 | 31 | // java.lang.Class instances. These instances are special because |
never@2658 | 32 | // they contain the static fields of the class in addition to the |
never@2658 | 33 | // normal fields of Class. This means they are variable sized |
never@2658 | 34 | // instances and need special logic for computing their size and for |
never@2658 | 35 | // iteration of their oops. |
never@2658 | 36 | |
never@2658 | 37 | |
never@2658 | 38 | class instanceMirrorKlass: public instanceKlass { |
never@2658 | 39 | private: |
never@2658 | 40 | static int _offset_of_static_fields; |
never@2658 | 41 | |
never@2658 | 42 | public: |
never@2658 | 43 | // Type testing |
never@2658 | 44 | bool oop_is_instanceMirror() const { return true; } |
never@2658 | 45 | |
never@2658 | 46 | // Casting from klassOop |
never@2658 | 47 | static instanceMirrorKlass* cast(klassOop k) { |
never@2658 | 48 | assert(k->klass_part()->oop_is_instanceMirror(), "cast to instanceMirrorKlass"); |
never@2658 | 49 | return (instanceMirrorKlass*) k->klass_part(); |
never@2658 | 50 | } |
never@2658 | 51 | |
never@2658 | 52 | // Returns the size of the instance including the extra static fields. |
never@2658 | 53 | virtual int oop_size(oop obj) const; |
never@2658 | 54 | |
never@2658 | 55 | // Static field offset is an offset into the Heap, should be converted by |
never@2658 | 56 | // based on UseCompressedOop for traversal |
never@2658 | 57 | static HeapWord* start_of_static_fields(oop obj) { |
never@2658 | 58 | return (HeapWord*)((intptr_t)obj + offset_of_static_fields()); |
never@2658 | 59 | } |
never@2658 | 60 | |
never@2658 | 61 | static void init_offset_of_static_fields() { |
never@2658 | 62 | // Cache the offset of the static fields in the Class instance |
never@2658 | 63 | assert(_offset_of_static_fields == 0, "once"); |
never@2658 | 64 | _offset_of_static_fields = instanceMirrorKlass::cast(SystemDictionary::Class_klass())->size_helper() << LogHeapWordSize; |
never@2658 | 65 | } |
never@2658 | 66 | |
never@2658 | 67 | static int offset_of_static_fields() { |
never@2658 | 68 | return _offset_of_static_fields; |
never@2658 | 69 | } |
never@2658 | 70 | |
never@2658 | 71 | int compute_static_oop_field_count(oop obj); |
never@2658 | 72 | |
never@2658 | 73 | // Given a Klass return the size of the instance |
never@2658 | 74 | int instance_size(KlassHandle k); |
never@2658 | 75 | |
never@2658 | 76 | // allocation |
never@2658 | 77 | DEFINE_ALLOCATE_PERMANENT(instanceMirrorKlass); |
never@2658 | 78 | instanceOop allocate_instance(KlassHandle k, TRAPS); |
never@2658 | 79 | |
never@2658 | 80 | // Garbage collection |
never@2658 | 81 | int oop_adjust_pointers(oop obj); |
never@2658 | 82 | void oop_follow_contents(oop obj); |
never@2658 | 83 | |
never@2658 | 84 | // Parallel Scavenge and Parallel Old |
never@2658 | 85 | PARALLEL_GC_DECLS |
never@2658 | 86 | |
never@2658 | 87 | int oop_oop_iterate(oop obj, OopClosure* blk) { |
never@2658 | 88 | return oop_oop_iterate_v(obj, blk); |
never@2658 | 89 | } |
never@2658 | 90 | int oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { |
never@2658 | 91 | return oop_oop_iterate_v_m(obj, blk, mr); |
never@2658 | 92 | } |
never@2658 | 93 | |
never@2658 | 94 | #define InstanceMirrorKlass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ |
never@2658 | 95 | int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk); \ |
never@2658 | 96 | int oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* blk, MemRegion mr); |
never@2658 | 97 | |
never@2658 | 98 | ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL) |
never@2658 | 99 | ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL) |
never@2658 | 100 | |
never@2658 | 101 | #ifndef SERIALGC |
never@2658 | 102 | #define InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \ |
never@2658 | 103 | int oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* blk); |
never@2658 | 104 | |
never@2658 | 105 | ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL) |
never@2658 | 106 | ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL) |
never@2658 | 107 | #endif // !SERIALGC |
never@2658 | 108 | }; |
never@2658 | 109 | |
never@2658 | 110 | #endif // SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP |