Path: blob/master/test/hotspot/jtreg/gc/g1/TestEagerReclaimHumongousRegionsClearMarkBits.java
40942 views
/*1* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.g1;2425/*26* @test TestEagerReclaimHumongousRegionsClearMarkBits27* @bug 805197328* @summary Test to make sure that eager reclaim of humongous objects correctly clears29* mark bitmaps at reclaim.30* @key randomness31* @requires vm.gc.G132* @library /test/lib33* @modules java.base/jdk.internal.misc34* java.management35* @run driver gc.g1.TestEagerReclaimHumongousRegionsClearMarkBits36*/3738import java.util.ArrayList;39import java.util.LinkedList;40import java.util.Random;4142import jdk.test.lib.process.OutputAnalyzer;43import jdk.test.lib.process.ProcessTools;44import jdk.test.lib.Utils;4546// An object that has a few references to other instances to slow down marking.47class ObjectWithSomeRefs {48public ObjectWithSomeRefs other1;49public ObjectWithSomeRefs other2;50public ObjectWithSomeRefs other3;51public ObjectWithSomeRefs other4;52}5354class TestEagerReclaimHumongousRegionsClearMarkBitsReclaimRegionFast {55public static final long MAX_MILLIS_FOR_RUN = 50 * 1000; // The maximum runtime for the actual test.5657public static final int M = 1024*1024;5859public static LinkedList<Object> garbageList = new LinkedList<Object>();6061public static void genGarbage(Object large) {62for (int i = 0; i < 64*1024; i++) {63Object[] garbage = new Object[50];64garbage[0] = large;65garbageList.add(garbage);66}67garbageList.clear();68}6970public static ArrayList<ObjectWithSomeRefs> longList = new ArrayList<ObjectWithSomeRefs>();7172public static void main(String[] args) {7374for (int i = 0; i < 16*1024; i++) {75longList.add(new ObjectWithSomeRefs());76}7778Random rnd = Utils.getRandomInstance();79for (int i = 0; i < longList.size(); i++) {80int len = longList.size();81longList.get(i).other1 = longList.get(rnd.nextInt(len));82longList.get(i).other2 = longList.get(rnd.nextInt(len));83longList.get(i).other3 = longList.get(rnd.nextInt(len));84longList.get(i).other4 = longList.get(rnd.nextInt(len));85}8687int[] large1 = new int[M];88int[] large2 = null;89int[] large3 = null;90int[] large4 = null;9192Object ref_from_stack = large1;9394long start_millis = System.currentTimeMillis();9596for (int i = 0; i < 20; i++) {97long current_millis = System.currentTimeMillis();98if ((current_millis - start_millis) > MAX_MILLIS_FOR_RUN) {99System.out.println("Finishing test because maximum runtime exceeded");100break;101}102// A set of large objects that will be reclaimed eagerly - and hopefully marked.103large1 = new int[M - 20];104large2 = new int[M - 20];105large3 = new int[M - 20];106large4 = new int[M - 20];107genGarbage(large1);108// Make sure that the compiler cannot completely remove109// the allocation of the large object until here.110System.out.println(large1 + " " + large2 + " " + large3 + " " + large4);111}112113// Keep the reference to the first object alive.114System.out.println(ref_from_stack);115}116}117118public class TestEagerReclaimHumongousRegionsClearMarkBits {119public static void main(String[] args) throws Exception {120ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(121"-XX:+UseG1GC",122"-Xms128M",123"-Xmx128M",124"-Xmn2M",125"-XX:G1HeapRegionSize=1M",126"-XX:InitiatingHeapOccupancyPercent=0", // Want to have as much as possible mark cycles.127"-Xlog:gc",128"-XX:+UnlockDiagnosticVMOptions",129"-XX:+VerifyAfterGC",130"-XX:ConcGCThreads=1", // Want to make marking as slow as possible.131"-XX:+IgnoreUnrecognizedVMOptions", // G1VerifyBitmaps is develop only.132"-XX:+G1VerifyBitmaps",133TestEagerReclaimHumongousRegionsClearMarkBitsReclaimRegionFast.class.getName());134OutputAnalyzer output = new OutputAnalyzer(pb.start());135output.shouldHaveExitValue(0);136}137}138139140141