src/share/vm/runtime/sweeper.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File sweeper-safepoints Sdiff src/share/vm/runtime

src/share/vm/runtime/sweeper.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, 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  *


 249 #endif
 250   if (PrintMethodFlushing && Verbose) {
 251     tty->print_cr("### Sweep at %d out of %d. Invocations left: %d", _seen, CodeCache::nof_nmethods(), _invocations);
 252   }
 253 
 254   // We want to visit all nmethods after NmethodSweepFraction
 255   // invocations so divide the remaining number of nmethods by the
 256   // remaining number of invocations.  This is only an estimate since
 257   // the number of nmethods changes during the sweep so the final
 258   // stage must iterate until it there are no more nmethods.
 259   int todo = (CodeCache::nof_nmethods() - _seen) / _invocations;
 260 
 261   assert(!SafepointSynchronize::is_at_safepoint(), "should not be in safepoint when we get here");
 262   assert(!CodeCache_lock->owned_by_self(), "just checking");
 263 
 264   {
 265     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 266 
 267     // The last invocation iterates until there are no more nmethods
 268     for (int i = 0; (i < todo || _invocations == 1) && _current != NULL; i++) {
 269 






 270       // Since we will give up the CodeCache_lock, always skip ahead
 271       // to the next nmethod.  Other blobs can be deleted by other
 272       // threads but nmethods are only reclaimed by the sweeper.
 273       nmethod* next = CodeCache::next_nmethod(_current);
 274 
 275       // Now ready to process nmethod and give up CodeCache_lock
 276       {
 277         MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 278         process_nmethod(_current);
 279       }
 280       _seen++;
 281       _current = next;
 282     }
 283   }
 284 
 285   assert(_invocations > 1 || _current == NULL, "must have scanned the whole cache");
 286 
 287   if (_current == NULL && !_rescan && (_locked_seen || _not_entrant_seen_on_stack)) {
 288     // we've completed a scan without making progress but there were
 289     // nmethods we were unable to process either because they were


   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  *


 249 #endif
 250   if (PrintMethodFlushing && Verbose) {
 251     tty->print_cr("### Sweep at %d out of %d. Invocations left: %d", _seen, CodeCache::nof_nmethods(), _invocations);
 252   }
 253 
 254   // We want to visit all nmethods after NmethodSweepFraction
 255   // invocations so divide the remaining number of nmethods by the
 256   // remaining number of invocations.  This is only an estimate since
 257   // the number of nmethods changes during the sweep so the final
 258   // stage must iterate until it there are no more nmethods.
 259   int todo = (CodeCache::nof_nmethods() - _seen) / _invocations;
 260 
 261   assert(!SafepointSynchronize::is_at_safepoint(), "should not be in safepoint when we get here");
 262   assert(!CodeCache_lock->owned_by_self(), "just checking");
 263 
 264   {
 265     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 266 
 267     // The last invocation iterates until there are no more nmethods
 268     for (int i = 0; (i < todo || _invocations == 1) && _current != NULL; i++) {
 269       if (SafepointSynchronize::is_synchronizing()) { // Safepoint request
 270         if (PrintMethodFlushing && Verbose) {
 271           tty->print_cr("### Sweep at %d out of %d, aborting due to safepoint request", CodeCache::nof_nmethods(), _invocations);
 272         }
 273         _invocations++;                    // Restart this iteration later
 274         break;                             // Bail out
 275       }
 276       // Since we will give up the CodeCache_lock, always skip ahead
 277       // to the next nmethod.  Other blobs can be deleted by other
 278       // threads but nmethods are only reclaimed by the sweeper.
 279       nmethod* next = CodeCache::next_nmethod(_current);
 280 
 281       // Now ready to process nmethod and give up CodeCache_lock
 282       {
 283         MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 284         process_nmethod(_current);
 285       }
 286       _seen++;
 287       _current = next;
 288     }
 289   }
 290 
 291   assert(_invocations > 1 || _current == NULL, "must have scanned the whole cache");
 292 
 293   if (_current == NULL && !_rescan && (_locked_seen || _not_entrant_seen_on_stack)) {
 294     // we've completed a scan without making progress but there were
 295     // nmethods we were unable to process either because they were


src/share/vm/runtime/sweeper.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File