src/share/vm/oops/instanceRefKlass.hpp

Thu, 07 Apr 2011 09:53:20 -0700

author
johnc
date
Thu, 07 Apr 2011 09:53:20 -0700
changeset 2781
e1162778c1c8
parent 2363
7cf1a74771e8
child 4037
da91efe96a93
permissions
-rw-r--r--

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) 1997, 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_INSTANCEREFKLASS_HPP
    26 #define SHARE_VM_OOPS_INSTANCEREFKLASS_HPP
    28 #include "oops/instanceKlass.hpp"
    30 // An instanceRefKlass is a specialized instanceKlass for Java
    31 // classes that are subclasses of java/lang/ref/Reference.
    32 //
    33 // These classes are used to implement soft/weak/final/phantom
    34 // references and finalization, and need special treatment by the
    35 // garbage collector.
    36 //
    37 // During GC discovered reference objects are added (chained) to one
    38 // of the four lists below, depending on the type of reference.
    39 // The linked occurs through the next field in class java/lang/ref/Reference.
    40 //
    41 // Afterwards, the discovered references are processed in decreasing
    42 // order of reachability. Reference objects eligible for notification
    43 // are linked to the static pending_list in class java/lang/ref/Reference,
    44 // and the pending list lock object in the same class is notified.
    47 class instanceRefKlass: public instanceKlass {
    48  public:
    49   // Type testing
    50   bool oop_is_instanceRef() const             { return true; }
    52   // Casting from klassOop
    53   static instanceRefKlass* cast(klassOop k) {
    54     assert(k->klass_part()->oop_is_instanceRef(), "cast to instanceRefKlass");
    55     return (instanceRefKlass*) k->klass_part();
    56   }
    58   // allocation
    59   DEFINE_ALLOCATE_PERMANENT(instanceRefKlass);
    61   // Garbage collection
    62   int  oop_adjust_pointers(oop obj);
    63   void oop_follow_contents(oop obj);
    65   // Parallel Scavenge and Parallel Old
    66   PARALLEL_GC_DECLS
    68   int oop_oop_iterate(oop obj, OopClosure* blk) {
    69     return oop_oop_iterate_v(obj, blk);
    70   }
    71   int oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
    72     return oop_oop_iterate_v_m(obj, blk, mr);
    73   }
    75 #define InstanceRefKlass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix)                \
    76   int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk);                         \
    77   int oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* blk, MemRegion mr);
    79   ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceRefKlass_OOP_OOP_ITERATE_DECL)
    80   ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceRefKlass_OOP_OOP_ITERATE_DECL)
    82 #ifndef SERIALGC
    83 #define InstanceRefKlass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix)      \
    84   int oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* blk);
    86   ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceRefKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
    87   ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceRefKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
    88 #endif // !SERIALGC
    90   static void release_and_notify_pending_list_lock(BasicLock *pending_list_basic_lock);
    91   static void acquire_pending_list_lock(BasicLock *pending_list_basic_lock);
    92   static bool owns_pending_list_lock(JavaThread* thread);
    94   // Update non-static oop maps so 'referent', 'nextPending' and
    95   // 'discovered' will look like non-oops
    96   static void update_nonstatic_oop_maps(klassOop k);
    98  public:
    99   // Verification
   100   void oop_verify_on(oop obj, outputStream* st);
   101 };
   103 #endif // SHARE_VM_OOPS_INSTANCEREFKLASS_HPP

mercurial