28 class WhiteBox; 29 30 #include "code/codeCache.hpp" 31 #include "utilities/ticks.hpp" 32 33 // An NmethodSweeper is an incremental cleaner for: 34 // - cleanup inline caches 35 // - reclamation of nmethods 36 // Removing nmethods from the code cache includes two operations 37 // 1) mark active nmethods 38 // Is done in 'mark_active_nmethods()'. This function is called at a 39 // safepoint and marks all nmethods that are active on a thread's stack. 40 // 2) sweep nmethods 41 // Is done in sweep_code_cache(). This function is the only place in the 42 // sweeper where memory is reclaimed. Note that sweep_code_cache() is not 43 // called at a safepoint. However, sweep_code_cache() stops executing if 44 // another thread requests a safepoint. Consequently, 'mark_active_nmethods()' 45 // and sweep_code_cache() cannot execute at the same time. 46 // To reclaim memory, nmethods are first marked as 'not-entrant'. Methods can 47 // be made not-entrant by (i) the sweeper, (ii) deoptimization, (iii) dependency 48 // invalidation, and (iv) being replaced be a different method version (tiered 49 // compilation). Not-entrant nmethod cannot be called by Java threads, but they 50 // can still be active on the stack. To ensure that active nmethod are not reclaimed, 51 // we have to wait until the next marking phase has completed. If a not-entrant 52 // nmethod was NOT marked as active, it can be converted to 'zombie' state. To safely 53 // remove the nmethod, all inline caches (IC) that point to the the nmethod must be 54 // cleared. After that, the nmethod can be evicted from the code cache. Each nmethod's 55 // state change happens during separate sweeps. It may take at least 3 sweeps before an 56 // nmethod's space is freed. 57 58 class NMethodSweeper : public AllStatic { 59 private: 60 enum MethodStateChange { 61 None, 62 MadeZombie, 63 MarkedForReclamation, 64 Flushed 65 }; 66 static long _traversals; // Stack scan count, also sweep ID. 67 static long _total_nof_code_cache_sweeps; // Total number of full sweeps of the code cache 68 static long _time_counter; // Virtual time used to periodically invoke sweeper 69 static long _last_sweep; // Value of _time_counter when the last sweep happened 70 static NMethodIterator _current; // Current nmethod 71 static int _seen; // Nof. nmethod we have currently processed in current pass of CodeCache 72 73 static volatile int _sweep_started; // Flag to control conc sweeper | 28 class WhiteBox; 29 30 #include "code/codeCache.hpp" 31 #include "utilities/ticks.hpp" 32 33 // An NmethodSweeper is an incremental cleaner for: 34 // - cleanup inline caches 35 // - reclamation of nmethods 36 // Removing nmethods from the code cache includes two operations 37 // 1) mark active nmethods 38 // Is done in 'mark_active_nmethods()'. This function is called at a 39 // safepoint and marks all nmethods that are active on a thread's stack. 40 // 2) sweep nmethods 41 // Is done in sweep_code_cache(). This function is the only place in the 42 // sweeper where memory is reclaimed. Note that sweep_code_cache() is not 43 // called at a safepoint. However, sweep_code_cache() stops executing if 44 // another thread requests a safepoint. Consequently, 'mark_active_nmethods()' 45 // and sweep_code_cache() cannot execute at the same time. 46 // To reclaim memory, nmethods are first marked as 'not-entrant'. Methods can 47 // be made not-entrant by (i) the sweeper, (ii) deoptimization, (iii) dependency 48 // invalidation, and (iv) being replaced by a different method version (tiered 49 // compilation). Not-entrant nmethods cannot be called by Java threads, but they 50 // can still be active on the stack. To ensure that active nmethods are not reclaimed, 51 // we have to wait until the next marking phase has completed. If a not-entrant 52 // nmethod was NOT marked as active, it can be converted to 'zombie' state. To safely 53 // remove the nmethod, all inline caches (IC) that point to the nmethod must be 54 // cleared. After that, the nmethod can be evicted from the code cache. Each nmethod's 55 // state change happens during separate sweeps. It may take at least 3 sweeps before an 56 // nmethod's space is freed. 57 58 class NMethodSweeper : public AllStatic { 59 private: 60 enum MethodStateChange { 61 None, 62 MadeZombie, 63 MarkedForReclamation, 64 Flushed 65 }; 66 static long _traversals; // Stack scan count, also sweep ID. 67 static long _total_nof_code_cache_sweeps; // Total number of full sweeps of the code cache 68 static long _time_counter; // Virtual time used to periodically invoke sweeper 69 static long _last_sweep; // Value of _time_counter when the last sweep happened 70 static NMethodIterator _current; // Current nmethod 71 static int _seen; // Nof. nmethod we have currently processed in current pass of CodeCache 72 73 static volatile int _sweep_started; // Flag to control conc sweeper |