Mon, 25 Jan 2010 18:03:29 -0500
6919980: G1: remove +UseG1GC from under experimental options (second attempt)
Summary: Trying this again, as the original change was lost.
Reviewed-by: ysr, jmasa
duke@435 | 1 | /* |
xdono@1383 | 2 | * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_sweeper.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | long NMethodSweeper::_traversals = 0; // No. of stack traversals performed |
duke@435 | 29 | CodeBlob* NMethodSweeper::_current = NULL; // Current nmethod |
duke@435 | 30 | int NMethodSweeper::_seen = 0 ; // No. of blobs we have currently processed in current pass of CodeCache |
duke@435 | 31 | int NMethodSweeper::_invocations = 0; // No. of invocations left until we are completed with this pass |
duke@435 | 32 | |
duke@435 | 33 | jint NMethodSweeper::_locked_seen = 0; |
duke@435 | 34 | jint NMethodSweeper::_not_entrant_seen_on_stack = 0; |
duke@435 | 35 | bool NMethodSweeper::_rescan = false; |
duke@435 | 36 | |
jrose@1424 | 37 | class MarkActivationClosure: public CodeBlobClosure { |
jrose@1424 | 38 | public: |
jrose@1424 | 39 | virtual void do_code_blob(CodeBlob* cb) { |
jrose@1424 | 40 | // If we see an activation belonging to a non_entrant nmethod, we mark it. |
jrose@1424 | 41 | if (cb->is_nmethod() && ((nmethod*)cb)->is_not_entrant()) { |
jrose@1424 | 42 | ((nmethod*)cb)->mark_as_seen_on_stack(); |
jrose@1424 | 43 | } |
jrose@1424 | 44 | } |
jrose@1424 | 45 | }; |
jrose@1424 | 46 | static MarkActivationClosure mark_activation_closure; |
jrose@1424 | 47 | |
duke@435 | 48 | void NMethodSweeper::sweep() { |
duke@435 | 49 | assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint"); |
duke@435 | 50 | if (!MethodFlushing) return; |
duke@435 | 51 | |
duke@435 | 52 | // No need to synchronize access, since this is always executed at a |
duke@435 | 53 | // safepoint. If we aren't in the middle of scan and a rescan |
duke@435 | 54 | // hasn't been requested then just return. |
duke@435 | 55 | if (_current == NULL && !_rescan) return; |
duke@435 | 56 | |
duke@435 | 57 | // Make sure CompiledIC_lock in unlocked, since we might update some |
duke@435 | 58 | // inline caches. If it is, we just bail-out and try later. |
duke@435 | 59 | if (CompiledIC_lock->is_locked() || Patching_lock->is_locked()) return; |
duke@435 | 60 | |
duke@435 | 61 | // Check for restart |
duke@435 | 62 | assert(CodeCache::find_blob_unsafe(_current) == _current, "Sweeper nmethod cached state invalid"); |
duke@435 | 63 | if (_current == NULL) { |
duke@435 | 64 | _seen = 0; |
duke@435 | 65 | _invocations = NmethodSweepFraction; |
duke@435 | 66 | _current = CodeCache::first(); |
duke@435 | 67 | _traversals += 1; |
duke@435 | 68 | if (PrintMethodFlushing) { |
duke@435 | 69 | tty->print_cr("### Sweep: stack traversal %d", _traversals); |
duke@435 | 70 | } |
jrose@1424 | 71 | Threads::nmethods_do(&mark_activation_closure); |
duke@435 | 72 | |
duke@435 | 73 | // reset the flags since we started a scan from the beginning. |
duke@435 | 74 | _rescan = false; |
duke@435 | 75 | _locked_seen = 0; |
duke@435 | 76 | _not_entrant_seen_on_stack = 0; |
duke@435 | 77 | } |
duke@435 | 78 | |
duke@435 | 79 | if (PrintMethodFlushing && Verbose) { |
duke@435 | 80 | tty->print_cr("### Sweep at %d out of %d. Invocations left: %d", _seen, CodeCache::nof_blobs(), _invocations); |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | // We want to visit all nmethods after NmethodSweepFraction invocations. |
duke@435 | 84 | // If invocation is 1 we do the rest |
duke@435 | 85 | int todo = CodeCache::nof_blobs(); |
duke@435 | 86 | if (_invocations != 1) { |
duke@435 | 87 | todo = (CodeCache::nof_blobs() - _seen) / _invocations; |
duke@435 | 88 | _invocations--; |
duke@435 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | for(int i = 0; i < todo && _current != NULL; i++) { |
duke@435 | 92 | CodeBlob* next = CodeCache::next(_current); // Read next before we potentially delete current |
duke@435 | 93 | if (_current->is_nmethod()) { |
duke@435 | 94 | process_nmethod((nmethod *)_current); |
duke@435 | 95 | } |
duke@435 | 96 | _seen++; |
duke@435 | 97 | _current = next; |
duke@435 | 98 | } |
duke@435 | 99 | // Because we could stop on a codeBlob other than an nmethod we skip forward |
duke@435 | 100 | // to the next nmethod (if any). codeBlobs other than nmethods can be freed |
duke@435 | 101 | // async to us and make _current invalid while we sleep. |
duke@435 | 102 | while (_current != NULL && !_current->is_nmethod()) { |
duke@435 | 103 | _current = CodeCache::next(_current); |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | if (_current == NULL && !_rescan && (_locked_seen || _not_entrant_seen_on_stack)) { |
duke@435 | 107 | // we've completed a scan without making progress but there were |
duke@435 | 108 | // nmethods we were unable to process either because they were |
duke@435 | 109 | // locked or were still on stack. We don't have to aggresively |
duke@435 | 110 | // clean them up so just stop scanning. We could scan once more |
duke@435 | 111 | // but that complicates the control logic and it's unlikely to |
duke@435 | 112 | // matter much. |
duke@435 | 113 | if (PrintMethodFlushing) { |
duke@435 | 114 | tty->print_cr("### Couldn't make progress on some nmethods so stopping sweep"); |
duke@435 | 115 | } |
duke@435 | 116 | } |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | |
duke@435 | 120 | void NMethodSweeper::process_nmethod(nmethod *nm) { |
duke@435 | 121 | // Skip methods that are currently referenced by the VM |
duke@435 | 122 | if (nm->is_locked_by_vm()) { |
duke@435 | 123 | // But still remember to clean-up inline caches for alive nmethods |
duke@435 | 124 | if (nm->is_alive()) { |
duke@435 | 125 | // Clean-up all inline caches that points to zombie/non-reentrant methods |
duke@435 | 126 | nm->cleanup_inline_caches(); |
duke@435 | 127 | } else { |
duke@435 | 128 | _locked_seen++; |
duke@435 | 129 | } |
duke@435 | 130 | return; |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | if (nm->is_zombie()) { |
duke@435 | 134 | // If it is first time, we see nmethod then we mark it. Otherwise, |
duke@435 | 135 | // we reclame it. When we have seen a zombie method twice, we know that |
duke@435 | 136 | // there are no inline caches that referes to it. |
duke@435 | 137 | if (nm->is_marked_for_reclamation()) { |
duke@435 | 138 | assert(!nm->is_locked_by_vm(), "must not flush locked nmethods"); |
ysr@1376 | 139 | if (PrintMethodFlushing && Verbose) { |
ysr@1376 | 140 | tty->print_cr("### Nmethod 0x%x (marked for reclamation) being flushed", nm); |
ysr@1376 | 141 | } |
duke@435 | 142 | nm->flush(); |
duke@435 | 143 | } else { |
ysr@1376 | 144 | if (PrintMethodFlushing && Verbose) { |
ysr@1376 | 145 | tty->print_cr("### Nmethod 0x%x (zombie) being marked for reclamation", nm); |
ysr@1376 | 146 | } |
duke@435 | 147 | nm->mark_for_reclamation(); |
duke@435 | 148 | _rescan = true; |
duke@435 | 149 | } |
duke@435 | 150 | } else if (nm->is_not_entrant()) { |
duke@435 | 151 | // If there is no current activations of this method on the |
duke@435 | 152 | // stack we can safely convert it to a zombie method |
duke@435 | 153 | if (nm->can_not_entrant_be_converted()) { |
ysr@1376 | 154 | if (PrintMethodFlushing && Verbose) { |
ysr@1376 | 155 | tty->print_cr("### Nmethod 0x%x (not entrant) being made zombie", nm); |
ysr@1376 | 156 | } |
duke@435 | 157 | nm->make_zombie(); |
duke@435 | 158 | _rescan = true; |
duke@435 | 159 | } else { |
duke@435 | 160 | // Still alive, clean up its inline caches |
duke@435 | 161 | nm->cleanup_inline_caches(); |
duke@435 | 162 | // we coudn't transition this nmethod so don't immediately |
duke@435 | 163 | // request a rescan. If this method stays on the stack for a |
duke@435 | 164 | // long time we don't want to keep rescanning at every safepoint. |
duke@435 | 165 | _not_entrant_seen_on_stack++; |
duke@435 | 166 | } |
duke@435 | 167 | } else if (nm->is_unloaded()) { |
duke@435 | 168 | // Unloaded code, just make it a zombie |
ysr@1376 | 169 | if (PrintMethodFlushing && Verbose) |
ysr@1376 | 170 | tty->print_cr("### Nmethod 0x%x (unloaded) being made zombie", nm); |
ysr@1376 | 171 | if (nm->is_osr_method()) { |
duke@435 | 172 | // No inline caches will ever point to osr methods, so we can just remove it |
duke@435 | 173 | nm->flush(); |
duke@435 | 174 | } else { |
duke@435 | 175 | nm->make_zombie(); |
duke@435 | 176 | _rescan = true; |
duke@435 | 177 | } |
duke@435 | 178 | } else { |
duke@435 | 179 | assert(nm->is_alive(), "should be alive"); |
duke@435 | 180 | // Clean-up all inline caches that points to zombie/non-reentrant methods |
duke@435 | 181 | nm->cleanup_inline_caches(); |
duke@435 | 182 | } |
duke@435 | 183 | } |