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

Tue, 26 Nov 2013 14:35:38 +0100

author
sjohanss
date
Tue, 26 Nov 2013 14:35:38 +0100
changeset 6148
55a0da3d420b
parent 5237
f2110083203d
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8027675: Full collections with Serial slower in JDK 8 compared to 7u40
Summary: Reduced the number of calls to follow_class_loader and instead marked and pushed the klass holder directly. Also removed unneeded calls to adjust_klass.
Reviewed-by: coleenp, jmasa, mgerdin, tschatzl

     1 /*
     2  * Copyright (c) 1997, 2013, 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/gcTimer.hpp"
    28 #include "gc_implementation/shared/gcTrace.hpp"
    29 #include "gc_implementation/shared/markSweep.inline.hpp"
    30 #include "gc_interface/collectedHeap.inline.hpp"
    31 #include "oops/methodData.hpp"
    32 #include "oops/objArrayKlass.inline.hpp"
    33 #include "oops/oop.inline.hpp"
    35 uint                    MarkSweep::_total_invocations = 0;
    37 Stack<oop, mtGC>              MarkSweep::_marking_stack;
    38 Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
    40 Stack<oop, mtGC>              MarkSweep::_preserved_oop_stack;
    41 Stack<markOop, mtGC>          MarkSweep::_preserved_mark_stack;
    42 size_t                  MarkSweep::_preserved_count = 0;
    43 size_t                  MarkSweep::_preserved_count_max = 0;
    44 PreservedMark*          MarkSweep::_preserved_marks = NULL;
    45 ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
    46 STWGCTimer*             MarkSweep::_gc_timer        = NULL;
    47 SerialOldTracer*        MarkSweep::_gc_tracer       = NULL;
    49 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
    50 CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
    52 void MarkSweep::FollowRootClosure::do_oop(oop* p)       { follow_root(p); }
    53 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
    55 MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
    56 MarkSweep::FollowKlassClosure MarkSweep::follow_klass_closure;
    57 MarkSweep::AdjustKlassClosure MarkSweep::adjust_klass_closure;
    59 void MarkSweep::MarkAndPushClosure::do_oop(oop* p)       { mark_and_push(p); }
    60 void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
    62 void MarkSweep::FollowKlassClosure::do_klass(Klass* klass) {
    63   klass->oops_do(&MarkSweep::mark_and_push_closure);
    64 }
    65 void MarkSweep::AdjustKlassClosure::do_klass(Klass* klass) {
    66   klass->oops_do(&MarkSweep::adjust_pointer_closure);
    67 }
    69 void MarkSweep::follow_class_loader(ClassLoaderData* cld) {
    70   cld->oops_do(&MarkSweep::mark_and_push_closure, &MarkSweep::follow_klass_closure, true);
    71 }
    73 void MarkSweep::follow_stack() {
    74   do {
    75     while (!_marking_stack.is_empty()) {
    76       oop obj = _marking_stack.pop();
    77       assert (obj->is_gc_marked(), "p must be marked");
    78       obj->follow_contents();
    79     }
    80     // Process ObjArrays one at a time to avoid marking stack bloat.
    81     if (!_objarray_stack.is_empty()) {
    82       ObjArrayTask task = _objarray_stack.pop();
    83       ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass();
    84       k->oop_follow_contents(task.obj(), task.index());
    85     }
    86   } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
    87 }
    89 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
    91 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
    93 // We preserve the mark which should be replaced at the end and the location
    94 // that it will go.  Note that the object that this markOop belongs to isn't
    95 // currently at that address but it will be after phase4
    96 void MarkSweep::preserve_mark(oop obj, markOop mark) {
    97   // We try to store preserved marks in the to space of the new generation since
    98   // this is storage which should be available.  Most of the time this should be
    99   // sufficient space for the marks we need to preserve but if it isn't we fall
   100   // back to using Stacks to keep track of the overflow.
   101   if (_preserved_count < _preserved_count_max) {
   102     _preserved_marks[_preserved_count++].init(obj, mark);
   103   } else {
   104     _preserved_mark_stack.push(mark);
   105     _preserved_oop_stack.push(obj);
   106   }
   107 }
   109 MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure;
   111 void MarkSweep::AdjustPointerClosure::do_oop(oop* p)       { adjust_pointer(p); }
   112 void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p); }
   114 void MarkSweep::adjust_marks() {
   115   assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
   116          "inconsistent preserved oop stacks");
   118   // adjust the oops we saved earlier
   119   for (size_t i = 0; i < _preserved_count; i++) {
   120     _preserved_marks[i].adjust_pointer();
   121   }
   123   // deal with the overflow stack
   124   StackIterator<oop, mtGC> iter(_preserved_oop_stack);
   125   while (!iter.is_empty()) {
   126     oop* p = iter.next_addr();
   127     adjust_pointer(p);
   128   }
   129 }
   131 void MarkSweep::restore_marks() {
   132   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
   133          "inconsistent preserved oop stacks");
   134   if (PrintGC && Verbose) {
   135     gclog_or_tty->print_cr("Restoring %d marks",
   136                            _preserved_count + _preserved_oop_stack.size());
   137   }
   139   // restore the marks we saved earlier
   140   for (size_t i = 0; i < _preserved_count; i++) {
   141     _preserved_marks[i].restore();
   142   }
   144   // deal with the overflow
   145   while (!_preserved_oop_stack.is_empty()) {
   146     oop obj       = _preserved_oop_stack.pop();
   147     markOop mark  = _preserved_mark_stack.pop();
   148     obj->set_mark(mark);
   149   }
   150 }
   152 MarkSweep::IsAliveClosure   MarkSweep::is_alive;
   154 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
   156 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
   158 void MarkSweep::KeepAliveClosure::do_oop(oop* p)       { MarkSweep::KeepAliveClosure::do_oop_work(p); }
   159 void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
   161 void marksweep_init() {
   162   MarkSweep::_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer();
   163   MarkSweep::_gc_tracer = new (ResourceObj::C_HEAP, mtGC) SerialOldTracer();
   164 }
   166 #ifndef PRODUCT
   168 void MarkSweep::trace(const char* msg) {
   169   if (TraceMarkSweep)
   170     gclog_or_tty->print("%s", msg);
   171 }
   173 #endif

mercurial