src/share/vm/gc_implementation/g1/heapRegionSets.cpp

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

author
johnc
date
Thu, 07 Apr 2011 09:53:20 -0700
changeset 2781
e1162778c1c8
parent 2643
1216415d8e35
child 2974
e8b0b0392037
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) 2011, 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 #include "precompiled.hpp"
    26 #include "gc_implementation/g1/heapRegionSets.hpp"
    28 //////////////////// FreeRegionList ////////////////////
    30 const char* FreeRegionList::verify_region_extra(HeapRegion* hr) {
    31   if (hr->is_young()) {
    32     return "the region should not be young";
    33   }
    34   // The superclass will check that the region is empty and
    35   // not-humongous.
    36   return HeapRegionLinkedList::verify_region_extra(hr);
    37 }
    39 //////////////////// MasterFreeRegionList ////////////////////
    41 bool MasterFreeRegionList::check_mt_safety() {
    42   // Master Free List MT safety protocol:
    43   // (a) If we're at a safepoint, operations on the master free list
    44   // should be invoked by either the VM thread (which will serialize
    45   // them) or by the GC workers while holding the
    46   // FreeList_lock.
    47   // (b) If we're not at a safepoint, operations on the master free
    48   // list should be invoked while holding the Heap_lock.
    50   guarantee((SafepointSynchronize::is_at_safepoint() &&
    51                (Thread::current()->is_VM_thread() ||
    52                                             FreeList_lock->owned_by_self())) ||
    53             (!SafepointSynchronize::is_at_safepoint() &&
    54                                                 Heap_lock->owned_by_self()),
    55             hrs_ext_msg(this, "master free list MT safety protocol"));
    57   return FreeRegionList::check_mt_safety();
    58 }
    60 //////////////////// SecondaryFreeRegionList ////////////////////
    62 bool SecondaryFreeRegionList::check_mt_safety() {
    63   // Secondary Free List MT safety protocol:
    64   // Operations on the secondary free list should always be invoked
    65   // while holding the SecondaryFreeList_lock.
    67   guarantee(SecondaryFreeList_lock->owned_by_self(),
    68             hrs_ext_msg(this, "secondary free list MT safety protocol"));
    70   return FreeRegionList::check_mt_safety();
    71 }
    73 //////////////////// HumongousRegionSet ////////////////////
    75 const char* HumongousRegionSet::verify_region_extra(HeapRegion* hr) {
    76   if (hr->is_young()) {
    77     return "the region should not be young";
    78   }
    79   // The superclass will check that the region is not empty and
    80   // humongous.
    81   return HeapRegionSet::verify_region_extra(hr);
    82 }
    84 //////////////////// MasterHumongousRegionSet ////////////////////
    86 bool MasterHumongousRegionSet::check_mt_safety() {
    87   // Master Humongous Set MT safety protocol:
    88   // (a) If we're at a safepoint, operations on the master humongous
    89   // set should be invoked by either the VM thread (which will
    90   // serialize them) or by the GC workers while holding the
    91   // OldSets_lock.
    92   // (b) If we're not at a safepoint, operations on the master
    93   // humongous set should be invoked while holding the Heap_lock.
    95   guarantee((SafepointSynchronize::is_at_safepoint() &&
    96                (Thread::current()->is_VM_thread() ||
    97                                              OldSets_lock->owned_by_self())) ||
    98             (!SafepointSynchronize::is_at_safepoint() &&
    99                                                  Heap_lock->owned_by_self()),
   100             hrs_ext_msg(this, "master humongous set MT safety protocol"));
   101   return HumongousRegionSet::check_mt_safety();
   102 }

mercurial