src/share/vm/runtime/sweeper.cpp

Thu, 10 Apr 2008 15:49:16 -0400

author
sbohne
date
Thu, 10 Apr 2008 15:49:16 -0400
changeset 528
c6ff24ceec1c
parent 435
a61af66fc99e
child 1376
8b46c4d82093
child 1424
148e5441d916
permissions
-rw-r--r--

6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes

duke@435 1 /*
duke@435 2 * Copyright 1997-2005 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
duke@435 37 void NMethodSweeper::sweep() {
duke@435 38 assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint");
duke@435 39 if (!MethodFlushing) return;
duke@435 40
duke@435 41 // No need to synchronize access, since this is always executed at a
duke@435 42 // safepoint. If we aren't in the middle of scan and a rescan
duke@435 43 // hasn't been requested then just return.
duke@435 44 if (_current == NULL && !_rescan) return;
duke@435 45
duke@435 46 // Make sure CompiledIC_lock in unlocked, since we might update some
duke@435 47 // inline caches. If it is, we just bail-out and try later.
duke@435 48 if (CompiledIC_lock->is_locked() || Patching_lock->is_locked()) return;
duke@435 49
duke@435 50 // Check for restart
duke@435 51 assert(CodeCache::find_blob_unsafe(_current) == _current, "Sweeper nmethod cached state invalid");
duke@435 52 if (_current == NULL) {
duke@435 53 _seen = 0;
duke@435 54 _invocations = NmethodSweepFraction;
duke@435 55 _current = CodeCache::first();
duke@435 56 _traversals += 1;
duke@435 57 if (PrintMethodFlushing) {
duke@435 58 tty->print_cr("### Sweep: stack traversal %d", _traversals);
duke@435 59 }
duke@435 60 Threads::nmethods_do();
duke@435 61
duke@435 62 // reset the flags since we started a scan from the beginning.
duke@435 63 _rescan = false;
duke@435 64 _locked_seen = 0;
duke@435 65 _not_entrant_seen_on_stack = 0;
duke@435 66 }
duke@435 67
duke@435 68 if (PrintMethodFlushing && Verbose) {
duke@435 69 tty->print_cr("### Sweep at %d out of %d. Invocations left: %d", _seen, CodeCache::nof_blobs(), _invocations);
duke@435 70 }
duke@435 71
duke@435 72 // We want to visit all nmethods after NmethodSweepFraction invocations.
duke@435 73 // If invocation is 1 we do the rest
duke@435 74 int todo = CodeCache::nof_blobs();
duke@435 75 if (_invocations != 1) {
duke@435 76 todo = (CodeCache::nof_blobs() - _seen) / _invocations;
duke@435 77 _invocations--;
duke@435 78 }
duke@435 79
duke@435 80 for(int i = 0; i < todo && _current != NULL; i++) {
duke@435 81 CodeBlob* next = CodeCache::next(_current); // Read next before we potentially delete current
duke@435 82 if (_current->is_nmethod()) {
duke@435 83 process_nmethod((nmethod *)_current);
duke@435 84 }
duke@435 85 _seen++;
duke@435 86 _current = next;
duke@435 87 }
duke@435 88 // Because we could stop on a codeBlob other than an nmethod we skip forward
duke@435 89 // to the next nmethod (if any). codeBlobs other than nmethods can be freed
duke@435 90 // async to us and make _current invalid while we sleep.
duke@435 91 while (_current != NULL && !_current->is_nmethod()) {
duke@435 92 _current = CodeCache::next(_current);
duke@435 93 }
duke@435 94
duke@435 95 if (_current == NULL && !_rescan && (_locked_seen || _not_entrant_seen_on_stack)) {
duke@435 96 // we've completed a scan without making progress but there were
duke@435 97 // nmethods we were unable to process either because they were
duke@435 98 // locked or were still on stack. We don't have to aggresively
duke@435 99 // clean them up so just stop scanning. We could scan once more
duke@435 100 // but that complicates the control logic and it's unlikely to
duke@435 101 // matter much.
duke@435 102 if (PrintMethodFlushing) {
duke@435 103 tty->print_cr("### Couldn't make progress on some nmethods so stopping sweep");
duke@435 104 }
duke@435 105 }
duke@435 106 }
duke@435 107
duke@435 108
duke@435 109 void NMethodSweeper::process_nmethod(nmethod *nm) {
duke@435 110 // Skip methods that are currently referenced by the VM
duke@435 111 if (nm->is_locked_by_vm()) {
duke@435 112 // But still remember to clean-up inline caches for alive nmethods
duke@435 113 if (nm->is_alive()) {
duke@435 114 // Clean-up all inline caches that points to zombie/non-reentrant methods
duke@435 115 nm->cleanup_inline_caches();
duke@435 116 } else {
duke@435 117 _locked_seen++;
duke@435 118 }
duke@435 119 return;
duke@435 120 }
duke@435 121
duke@435 122 if (nm->is_zombie()) {
duke@435 123 // If it is first time, we see nmethod then we mark it. Otherwise,
duke@435 124 // we reclame it. When we have seen a zombie method twice, we know that
duke@435 125 // there are no inline caches that referes to it.
duke@435 126 if (nm->is_marked_for_reclamation()) {
duke@435 127 assert(!nm->is_locked_by_vm(), "must not flush locked nmethods");
duke@435 128 nm->flush();
duke@435 129 } else {
duke@435 130 nm->mark_for_reclamation();
duke@435 131 _rescan = true;
duke@435 132 }
duke@435 133 } else if (nm->is_not_entrant()) {
duke@435 134 // If there is no current activations of this method on the
duke@435 135 // stack we can safely convert it to a zombie method
duke@435 136 if (nm->can_not_entrant_be_converted()) {
duke@435 137 nm->make_zombie();
duke@435 138 _rescan = true;
duke@435 139 } else {
duke@435 140 // Still alive, clean up its inline caches
duke@435 141 nm->cleanup_inline_caches();
duke@435 142 // we coudn't transition this nmethod so don't immediately
duke@435 143 // request a rescan. If this method stays on the stack for a
duke@435 144 // long time we don't want to keep rescanning at every safepoint.
duke@435 145 _not_entrant_seen_on_stack++;
duke@435 146 }
duke@435 147 } else if (nm->is_unloaded()) {
duke@435 148 // Unloaded code, just make it a zombie
duke@435 149 if (nm->is_osr_only_method()) {
duke@435 150 // No inline caches will ever point to osr methods, so we can just remove it
duke@435 151 nm->flush();
duke@435 152 } else {
duke@435 153 nm->make_zombie();
duke@435 154 _rescan = true;
duke@435 155 }
duke@435 156 } else {
duke@435 157 assert(nm->is_alive(), "should be alive");
duke@435 158 // Clean-up all inline caches that points to zombie/non-reentrant methods
duke@435 159 nm->cleanup_inline_caches();
duke@435 160 }
duke@435 161 }

mercurial