00001 /* Copyright 1994-1996 LongView Technologies L.L.C. $Revision: 1.9 $ */ 00002 /* Copyright (c) 2006, Sun Microsystems, Inc. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 00006 following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 00010 disclaimer in the documentation and/or other materials provided with the distribution. 00011 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 00012 from this software without specific prior written permission. 00013 00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00020 00021 00022 */ 00023 00024 // This is where the dirty work takes places. 00025 00026 // A Sweeper is an incremental cleaner for 00027 // Decaying invocation counters and cleanup inline caches in methodOops (MethodSweeper). 00028 00029 class Sweeper : public CHeapObj { 00030 // Static part 00031 private: 00032 static Sweeper* _head; 00033 static Sweeper* head() { return _head; } 00034 static int sweep_seconds; 00035 static bool _is_running; 00036 static methodOop _active_method; 00037 static nmethod* _active_nmethod; 00038 public: 00039 static bool register_active_frame(frame fr); 00040 static void clear_active_frame(); 00041 00042 static void print_all(); 00043 static void step_all(); 00044 static void add(Sweeper* sweeper); 00045 00046 static methodOop active_method() { return _active_method; } 00047 static nmethod* active_nmethod() { return _active_nmethod; } 00048 00049 // Tells is the sweeper is running 00050 static bool is_running() { return _is_running; } 00051 protected: 00052 Sweeper* _next; 00053 Sweeper* next() const { return _next; } 00054 int _sweep_start; // time of last activation 00055 bool _is_active; // are we waiting to do something? 00056 00057 bool is_active() const { return _is_active; } 00058 void set_active(bool value) { _is_active = value; } 00059 00060 virtual void step(); 00061 virtual void activate(); 00062 virtual void deactivate(); 00063 virtual int interval() const = 0; 00064 virtual char* name() const = 0; 00065 public: 00066 Sweeper(); 00067 virtual void task() = 0; 00068 void print() const; 00069 }; 00070 00071 // Sweeps through the heap for cleaning blockOops 00072 class HeapSweeper : public Sweeper { 00073 private: 00074 OldWaterMark mark; 00075 private: 00076 void task(); 00077 void activate(); 00078 int interval() const { return HeapSweeperInterval; } 00079 char* name() const { return "HeapSweeper"; } 00080 }; 00081 00082 class CodeSweeper : public Sweeper { 00083 protected: 00084 int CodeSweeperInterval; // time interval (sec) between starting zone sweep; computed from half-life time 00085 double decayFactor; // decay factor for invocation counts 00086 int oldHalfLifeTime; // old half-life time (to dectect changes in half-life setting) 00087 int fractionPerTask; // a task invocation does (1 / fractionPerTask) of the entire work 00088 00089 void updateInterval(); // check for change in half-life setting 00090 public: 00091 CodeSweeper() { oldHalfLifeTime = -1; CodeSweeperInterval = 1; decayFactor = 1; } 00092 int interval() const; 00093 }; 00094 00095 // Sweeps through the methods and decay counters and cleanup inline caches. 00096 // Traverses all methodOops by traversing the system dictionary. 00097 class MethodSweeper : public CodeSweeper { 00098 private: 00099 int index; // next index in systemDictionary to process 00100 private: 00101 methodOop excluded_method() { return Universe::sweeper_method(); } 00102 void set_excluded_method(methodOop method) { Universe::set_sweeper_method(method); } 00103 00104 void task(); 00105 void method_task(methodOop method); 00106 int method_dict_task(objArrayOop methods); 00107 int klass_task(klassOop klass); 00108 void activate(); 00109 char* name() const { return "MethodSweeper"; } 00110 friend class Recompilation; 00111 }; 00112 00113 extern MethodSweeper* methodSweeper; // single instance 00114 00115 class ZoneSweeper : public CodeSweeper { 00116 private: 00117 nmethod* _excluded_nmethod; 00118 nmethod* next; 00119 private: 00120 nmethod* excluded_nmethod() { return _excluded_nmethod; } 00121 void set_excluded_nmethod(nmethod* nm) { _excluded_nmethod = nm; } 00122 00123 void nmethod_task(nmethod* nm); 00124 void task(); 00125 void activate(); 00126 char* name() const { return "ZoneSweeper"; } 00127 };