2362N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. 2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// Sweeper logging code 0N/A // skip empty records 0N/A // skip empty records 0N/A // If we see an activation belonging to a non_entrant nmethod, we mark it. 0N/A // No need to synchronize access, since this is always executed at a 0N/A // safepoint. If we aren't in the middle of scan and a rescan 0N/A // hasn't been requested then just return. If UseCodeCacheFlushing is on and 0N/A // code cache flushing is in progress, don't skip sweeping to help make progress 0N/A // clearing space in the code cache. 0N/A // Make sure CompiledIC_lock in unlocked, since we might update some 0N/A // inline caches. If it is, we just bail-out and try later. 0N/A // Check for restart 0N/A // reset the flags since we started a scan from the beginning. 0N/A // scan_stacks() runs during a safepoint, no race with setters 0N/A // There was some progress so attempt to restart the compiler 0N/A // Update the _last_was_full time so we can tell how fast the 0N/A // code cache is filling up 0N/A // Only one thread at a time will sweep // Create the ring buffer for the logging code // We want to visit all nmethods after NmethodSweepFraction // invocations so divide the remaining number of nmethods by the // remaining number of invocations. This is only an estimate since // the number of nmethods changes during the sweep so the final // stage must iterate until it there are no more nmethods. // The last invocation iterates until there are no more nmethods // Since we will give up the CodeCache_lock, always skip ahead // to the next nmethod. Other blobs can be deleted by other // threads but nmethods are only reclaimed by the sweeper. // Now ready to process nmethod and give up CodeCache_lock // we've completed a scan without making progress but there were // nmethods we were unable to process either because they were // locked or were still on stack. We don't have to aggresively // clean them up so just stop scanning. We could scan once more // but that complicates the control logic and it's unlikely to tty->
print_cr(
"### Couldn't make progress on some nmethods so stopping sweep");
// Make sure this nmethod doesn't get unloaded during the scan, // since the locks acquired below might safepoint. // Skip methods that are currently referenced by the VM // But still remember to clean-up inline caches for alive nmethods // If it is first time, we see nmethod then we mark it. Otherwise, // we reclame it. When we have seen a zombie method twice, we know that // there are no inline caches that refer to it. // If there is no current activations of this method on the // stack we can safely convert it to a zombie method // Still alive, clean up its inline caches // we coudn't transition this nmethod so don't immediately // request a rescan. If this method stays on the stack for a // long time we don't want to keep rescanning the code cache. // Unloaded code, just make it a zombie // No inline caches will ever point to osr methods, so we can just remove it // This method has not been called since the forced cleanup happened // Code cache unloading: when compilers notice the code cache is getting full, // they will call a vm op that comes here. This code attempts to speculatively // unload the oldest half of the nmethods (based on the compile job id) by // saving the old code in a list in the CodeCache. Then // execution resumes. If a method so marked is not called by the second sweeper // stack traversal after the current one, the nmethod will be marked non-entrant and // got rid of by normal sweeping. If the method is called, the methodOop's // go back to their normal state. // Only the first one to notice can advise us to start early cleaning // Since code cache is full, immediately stop new compiles // only the first to notice can start the cleaning, // others will go back and block // If we run out within MinCodeCacheFlushingInterval of the last unload time, give up // rescan again as soon as possible // If there was a race in detecting full code cache, only run // one vm op for it or keep the compiler shut off // Traverse the code cache trying to dump the oldest nmethods // OSR methods cannot be flushed like this. Also, don't flush native methods // since they are part of the JDK in most cases // This method has not been previously considered for // unloading or it was restored already // This method was previously considered for preemptive unloading and was not called since then // Shut off compiler. Sweeper will start over with a new stack scan and // traversal cycle and turn it back on if it clears enough space. // After two more traversals the sweeper will get rid of unrestored nmethods // Print out some state information about the current sweep and the // state of the code cache if it's requested. // Dump code cache state into a buffer before locking the tty, // because log_state() will use locks causing lock conflicts. // Dump code cache state into a buffer before locking the tty, // because log_state() will use locks causing lock conflicts.