src/share/vm/memory/genRemSet.cpp

Fri, 20 Sep 2013 10:53:28 +0200

author
stefank
date
Fri, 20 Sep 2013 10:53:28 +0200
changeset 5769
2c022e432e10
parent 4037
da91efe96a93
child 5818
ab68fc0101ce
permissions
-rw-r--r--

8024974: Incorrect use of GC_locker::is_active()
Summary: SymbolTable and StringTable can make calls to GC_locker::is_active() outside a safepoint. This isn't safe because the GC_locker active state (lock count) is only updated at a safepoint and only remains valid as long as _needs_gc is true. However, outside a safepoint_needs_gc can change to false at any time, which makes it impossible to do a correct call to is_active() in that context. In this case these calls can just be removed since the input argument to basic_add() should never be on the heap and so there's no need to check the GC_locker state. This change also adjusts the assert() in is_active() to makes sure all calls to this function are always done under a safepoint.
Reviewed-by: brutisso, dcubed
Contributed-by: per.liden@oracle.com

     1 /*
     2  * Copyright (c) 2001, 2012, 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 "classfile/classLoaderData.hpp"
    27 #include "memory/cardTableRS.hpp"
    28 #include "memory/genRemSet.hpp"
    30 // This kind of "BarrierSet" allows a "CollectedHeap" to detect and
    31 // enumerate ref fields that have been modified (since the last
    32 // enumeration.)
    34 uintx GenRemSet::max_alignment_constraint(Name nm) {
    35   switch (nm) {
    36   case GenRemSet::CardTable:
    37     return CardTableRS::ct_max_alignment_constraint();
    38   default:
    39     guarantee(false, "Unrecognized GenRemSet type.");
    40     return (0); // Make Windows compiler happy
    41   }
    42 }
    44 class HasAccumulatedModifiedOopsClosure : public KlassClosure {
    45   bool _found;
    46  public:
    47   HasAccumulatedModifiedOopsClosure() : _found(false) {}
    48   void do_klass(Klass* klass) {
    49     if (_found) {
    50       return;
    51     }
    53     if (klass->has_accumulated_modified_oops()) {
    54       _found = true;
    55     }
    56   }
    57   bool found() {
    58     return _found;
    59   }
    60 };
    62 bool KlassRemSet::mod_union_is_clear() {
    63   HasAccumulatedModifiedOopsClosure closure;
    64   ClassLoaderDataGraph::classes_do(&closure);
    66   return !closure.found();
    67 }
    70 class ClearKlassModUnionClosure : public KlassClosure {
    71  public:
    72   void do_klass(Klass* klass) {
    73     if (klass->has_accumulated_modified_oops()) {
    74       klass->clear_accumulated_modified_oops();
    75     }
    76   }
    77 };
    79 void KlassRemSet::clear_mod_union() {
    80   ClearKlassModUnionClosure closure;
    81   ClassLoaderDataGraph::classes_do(&closure);
    82 }

mercurial