1 /* 2 * Copyright (c) 2016, 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 /* 25 * @test TestAllocHumongousFragment 26 * @summary Make sure Shenandoah can recover from humongous allocation fragmentation 27 * @key gc 28 * @requires vm.gc.Shenandoah & !vm.graal.enabled 29 * 30 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 31 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 32 * -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify 33 * TestAllocHumongousFragment 34 * 35 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 36 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 37 * -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify 38 * TestAllocHumongousFragment 39 * 40 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 41 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 42 * -XX:-ShenandoahDegeneratedGC 43 * TestAllocHumongousFragment 44 * 45 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 46 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 47 * -XX:+ShenandoahDegeneratedGC 48 * TestAllocHumongousFragment 49 */ 50 51 /* 52 * @test TestAllocHumongousFragment 53 * @summary Make sure Shenandoah can recover from humongous allocation fragmentation 54 * @key gc 55 * @requires vm.gc.Shenandoah & !vm.graal.enabled 56 * 57 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 58 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 59 * -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify 60 * TestAllocHumongousFragment 61 * 62 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 63 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 64 * -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify 65 * TestAllocHumongousFragment 66 * 67 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 68 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 69 * -XX:+ShenandoahOOMDuringEvacALot 70 * TestAllocHumongousFragment 71 * 72 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 73 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 74 * -XX:+ShenandoahAllocFailureALot 75 * TestAllocHumongousFragment 76 * 77 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 78 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive 79 * -XX:+ShenandoahVerify 80 * TestAllocHumongousFragment 81 * 82 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 83 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive 84 * TestAllocHumongousFragment 85 * 86 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 87 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static 88 * TestAllocHumongousFragment 89 * 90 * @run main/othervm -Xmx1g -Xms1g -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahTargetNumRegions=2048 91 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact 92 * TestAllocHumongousFragment 93 */ 94 95 /* 96 * @test TestAllocHumongousFragment 97 * @summary Make sure Shenandoah can recover from humongous allocation fragmentation 98 * @key gc 99 * @requires vm.gc.Shenandoah & !vm.graal.enabled 100 * 101 * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 102 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 103 * -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify 104 * TestAllocHumongousFragment 105 * 106 * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 107 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 108 * -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify 109 * TestAllocHumongousFragment 110 * 111 * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 112 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 113 * -XX:+ShenandoahOOMDuringEvacALot 114 * TestAllocHumongousFragment 115 * 116 * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 117 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 118 * -XX:+ShenandoahAllocFailureALot 119 * TestAllocHumongousFragment 120 * 121 * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 122 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 123 * -XX:+ShenandoahVerify 124 * TestAllocHumongousFragment 125 * 126 * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 127 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 128 * TestAllocHumongousFragment 129 */ 130 131 import java.util.*; 132 import java.util.concurrent.*; 133 134 public class TestAllocHumongousFragment { 135 136 static final long TARGET_MB = Long.getLong("target", 30_000); // 30 Gb allocations 137 static final long LIVE_MB = Long.getLong("occupancy", 700); // 700 Mb alive 138 139 static volatile Object sink; 140 141 static List<int[]> objects; 142 143 public static void main(String[] args) throws Exception { 144 final int min = 128 * 1024; 145 final int max = 16 * 1024 * 1024; 146 final long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2)); 147 148 objects = new ArrayList<>(); 149 long current = 0; 150 151 Random r = new Random(); 152 for (long c = 0; c < count; c++) { 153 while (current > LIVE_MB * 1024 * 1024) { 154 int idx = ThreadLocalRandom.current().nextInt(objects.size()); 155 int[] remove = objects.remove(idx); 156 current -= remove.length * 4 + 16; 157 } 158 159 int[] newObj = new int[min + r.nextInt(max - min)]; 160 current += newObj.length * 4 + 16; 161 objects.add(newObj); 162 sink = new Object(); 163 164 System.out.println("Allocated: " + (current / 1024 / 1024) + " Mb"); 165 } 166 } 167 168 }