1 /* 2 * Copyright (c) 2018, Red Hat, Inc. All rights reserved. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #include "precompiled.hpp" 25 26 #include "gc/shenandoah/heuristics/shenandoahAggressiveHeuristics.hpp" 27 #include "gc/shenandoah/shenandoahCollectionSet.hpp" 28 #include "gc/shenandoah/shenandoahHeapRegion.hpp" 29 #include "logging/log.hpp" 30 #include "logging/logTag.hpp" 31 #include "runtime/os.hpp" 32 33 ShenandoahAggressiveHeuristics::ShenandoahAggressiveHeuristics() : ShenandoahHeuristics() { 34 // Do not shortcut evacuation 35 SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahImmediateThreshold, 100); 36 37 // Aggressive runs with max speed for allocation, to capture races against mutator 38 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahPacing); 39 40 // Aggressive evacuates everything, so it needs as much evac space as it can get 41 SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahEvacReserveOverflow); 42 43 // If class unloading is globally enabled, aggressive does unloading even with 44 // concurrent cycles. 45 if (ClassUnloading) { 46 SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahUnloadClassesFrequency, 1); 47 } 48 } 49 50 void ShenandoahAggressiveHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset, 51 RegionData* data, size_t size, 52 size_t free) { 53 for (size_t idx = 0; idx < size; idx++) { 54 ShenandoahHeapRegion* r = data[idx]._region; 55 if (r->garbage() > 0) { 56 cset->add_region(r); 57 } 58 } 59 } 60 61 bool ShenandoahAggressiveHeuristics::should_start_normal_gc() const { 62 log_info(gc)("Trigger: Start next cycle immediately"); 63 return true; 64 } 65 66 bool ShenandoahAggressiveHeuristics::should_process_references() { 67 if (!can_process_references()) return false; 68 // Randomly process refs with 50% chance. 69 return (os::random() & 1) == 1; 70 } 71 72 bool ShenandoahAggressiveHeuristics::should_unload_classes() { 73 if (!can_unload_classes_normal()) return false; 74 if (has_metaspace_oom()) return true; 75 // Randomly unload classes with 50% chance. 76 return (os::random() & 1) == 1; 77 } 78 79 const char* ShenandoahAggressiveHeuristics::name() { 80 return "aggressive"; 81 } 82 83 bool ShenandoahAggressiveHeuristics::is_diagnostic() { 84 return true; 85 } 86 87 bool ShenandoahAggressiveHeuristics::is_experimental() { 88 return false; 89 }