src/share/vm/gc_implementation/shared/markSweep.cpp

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 4384
b735136e0d82
child 5011
a08c80e9e1e5
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

     1 /*
     2  * Copyright (c) 1997, 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 "compiler/compileBroker.hpp"
    27 #include "gc_implementation/shared/markSweep.inline.hpp"
    28 #include "gc_interface/collectedHeap.inline.hpp"
    29 #include "oops/methodData.hpp"
    30 #include "oops/objArrayKlass.inline.hpp"
    31 #include "oops/oop.inline.hpp"
    33 unsigned int            MarkSweep::_total_invocations = 0;
    35 Stack<oop, mtGC>              MarkSweep::_marking_stack;
    36 Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
    38 Stack<oop, mtGC>              MarkSweep::_preserved_oop_stack;
    39 Stack<markOop, mtGC>          MarkSweep::_preserved_mark_stack;
    40 size_t                  MarkSweep::_preserved_count = 0;
    41 size_t                  MarkSweep::_preserved_count_max = 0;
    42 PreservedMark*          MarkSweep::_preserved_marks = NULL;
    43 ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
    45 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
    46 CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
    48 void MarkSweep::FollowRootClosure::do_oop(oop* p)       { follow_root(p); }
    49 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
    51 MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
    52 MarkSweep::FollowKlassClosure MarkSweep::follow_klass_closure;
    53 MarkSweep::AdjustKlassClosure MarkSweep::adjust_klass_closure;
    55 void MarkSweep::MarkAndPushClosure::do_oop(oop* p)       { mark_and_push(p); }
    56 void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
    58 void MarkSweep::FollowKlassClosure::do_klass(Klass* klass) {
    59   klass->oops_do(&MarkSweep::mark_and_push_closure);
    60 }
    61 void MarkSweep::AdjustKlassClosure::do_klass(Klass* klass) {
    62   klass->oops_do(&MarkSweep::adjust_pointer_closure);
    63 }
    65 void MarkSweep::follow_klass(Klass* klass) {
    66   ClassLoaderData* cld = klass->class_loader_data();
    67   // The actual processing of the klass is done when we
    68   // traverse the list of Klasses in the class loader data.
    69   MarkSweep::follow_class_loader(cld);
    70 }
    72 void MarkSweep::adjust_klass(Klass* klass) {
    73   ClassLoaderData* cld = klass->class_loader_data();
    74   // The actual processing of the klass is done when we
    75   // traverse the list of Klasses in the class loader data.
    76   MarkSweep::adjust_class_loader(cld);
    77 }
    79 void MarkSweep::follow_class_loader(ClassLoaderData* cld) {
    80   cld->oops_do(&MarkSweep::mark_and_push_closure, &MarkSweep::follow_klass_closure, true);
    81 }
    83 void MarkSweep::adjust_class_loader(ClassLoaderData* cld) {
    84   cld->oops_do(&MarkSweep::adjust_root_pointer_closure, &MarkSweep::adjust_klass_closure, true);
    85 }
    88 void MarkSweep::follow_stack() {
    89   do {
    90     while (!_marking_stack.is_empty()) {
    91       oop obj = _marking_stack.pop();
    92       assert (obj->is_gc_marked(), "p must be marked");
    93       obj->follow_contents();
    94     }
    95     // Process ObjArrays one at a time to avoid marking stack bloat.
    96     if (!_objarray_stack.is_empty()) {
    97       ObjArrayTask task = _objarray_stack.pop();
    98       ObjArrayKlass* const k = (ObjArrayKlass*)task.obj()->klass();
    99       k->oop_follow_contents(task.obj(), task.index());
   100     }
   101   } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
   102 }
   104 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
   106 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
   108 // We preserve the mark which should be replaced at the end and the location
   109 // that it will go.  Note that the object that this markOop belongs to isn't
   110 // currently at that address but it will be after phase4
   111 void MarkSweep::preserve_mark(oop obj, markOop mark) {
   112   // We try to store preserved marks in the to space of the new generation since
   113   // this is storage which should be available.  Most of the time this should be
   114   // sufficient space for the marks we need to preserve but if it isn't we fall
   115   // back to using Stacks to keep track of the overflow.
   116   if (_preserved_count < _preserved_count_max) {
   117     _preserved_marks[_preserved_count++].init(obj, mark);
   118   } else {
   119     _preserved_mark_stack.push(mark);
   120     _preserved_oop_stack.push(obj);
   121   }
   122 }
   124 MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true);
   125 MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false);
   127 void MarkSweep::AdjustPointerClosure::do_oop(oop* p)       { adjust_pointer(p, _is_root); }
   128 void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); }
   130 void MarkSweep::adjust_marks() {
   131   assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
   132          "inconsistent preserved oop stacks");
   134   // adjust the oops we saved earlier
   135   for (size_t i = 0; i < _preserved_count; i++) {
   136     _preserved_marks[i].adjust_pointer();
   137   }
   139   // deal with the overflow stack
   140   StackIterator<oop, mtGC> iter(_preserved_oop_stack);
   141   while (!iter.is_empty()) {
   142     oop* p = iter.next_addr();
   143     adjust_pointer(p);
   144   }
   145 }
   147 void MarkSweep::restore_marks() {
   148   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
   149          "inconsistent preserved oop stacks");
   150   if (PrintGC && Verbose) {
   151     gclog_or_tty->print_cr("Restoring %d marks",
   152                            _preserved_count + _preserved_oop_stack.size());
   153   }
   155   // restore the marks we saved earlier
   156   for (size_t i = 0; i < _preserved_count; i++) {
   157     _preserved_marks[i].restore();
   158   }
   160   // deal with the overflow
   161   while (!_preserved_oop_stack.is_empty()) {
   162     oop obj       = _preserved_oop_stack.pop();
   163     markOop mark  = _preserved_mark_stack.pop();
   164     obj->set_mark(mark);
   165   }
   166 }
   168 MarkSweep::IsAliveClosure   MarkSweep::is_alive;
   170 void MarkSweep::IsAliveClosure::do_object(oop p)   { ShouldNotReachHere(); }
   171 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
   173 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
   175 void MarkSweep::KeepAliveClosure::do_oop(oop* p)       { MarkSweep::KeepAliveClosure::do_oop_work(p); }
   176 void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
   178 void marksweep_init() { /* empty */ }
   180 #ifndef PRODUCT
   182 void MarkSweep::trace(const char* msg) {
   183   if (TraceMarkSweep)
   184     gclog_or_tty->print("%s", msg);
   185 }
   187 #endif

mercurial