Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestEagerReclaimHumongousRegionsClearMarkBits.java
32284 views
/*1* Copyright (c) 2014, 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*/2223/*24* @test TestEagerReclaimHumongousRegionsClearMarkBits25* @bug 805197326* @summary Test to make sure that eager reclaim of humongous objects correctly clears27* mark bitmaps at reclaim.28* @key gc29* @library /testlibrary30*/3132import java.util.ArrayList;33import java.util.LinkedList;34import java.util.Random;3536import com.oracle.java.testlibrary.OutputAnalyzer;37import com.oracle.java.testlibrary.ProcessTools;3839// An object that has a few references to other instances to slow down marking.40class ObjectWithSomeRefs {41public ObjectWithSomeRefs other1;42public ObjectWithSomeRefs other2;43public ObjectWithSomeRefs other3;44public ObjectWithSomeRefs other4;45}4647class ReclaimRegionFast {48public static final long MAX_MILLIS_FOR_RUN = 50 * 1000; // The maximum runtime for the actual test.4950public static final int M = 1024*1024;5152public static LinkedList<Object> garbageList = new LinkedList<Object>();5354public static void genGarbage(Object large) {55for (int i = 0; i < 64*1024; i++) {56Object[] garbage = new Object[50];57garbage[0] = large;58garbageList.add(garbage);59}60garbageList.clear();61}6263public static ArrayList<ObjectWithSomeRefs> longList = new ArrayList<ObjectWithSomeRefs>();6465public static void main(String[] args) {6667for (int i = 0; i < 16*1024; i++) {68longList.add(new ObjectWithSomeRefs());69}7071Random rnd = new Random();72for (int i = 0; i < longList.size(); i++) {73int len = longList.size();74longList.get(i).other1 = longList.get(rnd.nextInt(len));75longList.get(i).other2 = longList.get(rnd.nextInt(len));76longList.get(i).other3 = longList.get(rnd.nextInt(len));77longList.get(i).other4 = longList.get(rnd.nextInt(len));78}7980int[] large1 = new int[M];81int[] large2 = null;82int[] large3 = null;83int[] large4 = null;8485Object ref_from_stack = large1;8687long start_millis = System.currentTimeMillis();8889for (int i = 0; i < 20; i++) {90long current_millis = System.currentTimeMillis();91if ((current_millis - start_millis) > MAX_MILLIS_FOR_RUN) {92System.out.println("Finishing test because maximum runtime exceeded");93break;94}95// A set of large objects that will be reclaimed eagerly - and hopefully marked.96large1 = new int[M - 20];97large2 = new int[M - 20];98large3 = new int[M - 20];99large4 = new int[M - 20];100genGarbage(large1);101// Make sure that the compiler cannot completely remove102// the allocation of the large object until here.103System.out.println(large1 + " " + large2 + " " + large3 + " " + large4);104}105106// Keep the reference to the first object alive.107System.out.println(ref_from_stack);108}109}110111public class TestEagerReclaimHumongousRegionsClearMarkBits {112public static void main(String[] args) throws Exception {113ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(114"-XX:+UseG1GC",115"-Xms128M",116"-Xmx128M",117"-Xmn2M",118"-XX:G1HeapRegionSize=1M",119"-XX:InitiatingHeapOccupancyPercent=0", // Want to have as much as possible initial marks.120"-XX:+PrintGC",121"-XX:+VerifyAfterGC",122"-XX:ConcGCThreads=1", // Want to make marking as slow as possible.123"-XX:+IgnoreUnrecognizedVMOptions", // G1VerifyBitmaps is develop only.124"-XX:+G1VerifyBitmaps",125ReclaimRegionFast.class.getName());126OutputAnalyzer output = new OutputAnalyzer(pb.start());127output.shouldHaveExitValue(0);128}129}130131132133