TestEagerReclaimHumongousRegionsClearMarkBits.java 4.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
25
 * @test TestEagerReclaimHumongousRegionsClearMarkBits
26 27 28 29 30
 * @bug 8051973
 * @summary Test to make sure that eager reclaim of humongous objects correctly clears
 * mark bitmaps at reclaim.
 * @key gc
 * @library /testlibrary
31 32
 * @modules java.base/sun.misc
 *          java.management
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
 */

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Random;

import com.oracle.java.testlibrary.OutputAnalyzer;
import com.oracle.java.testlibrary.ProcessTools;

// An object that has a few references to other instances to slow down marking.
class ObjectWithSomeRefs {
    public ObjectWithSomeRefs other1;
    public ObjectWithSomeRefs other2;
    public ObjectWithSomeRefs other3;
    public ObjectWithSomeRefs other4;
}

class ReclaimRegionFast {
51 52
    public static final long MAX_MILLIS_FOR_RUN = 50 * 1000; // The maximum runtime for the actual test.

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    public static final int M = 1024*1024;

    public static LinkedList<Object> garbageList = new LinkedList<Object>();

    public static void genGarbage(Object large) {
        for (int i = 0; i < 64*1024; i++) {
            Object[] garbage = new Object[50];
            garbage[0] = large;
            garbageList.add(garbage);
        }
        garbageList.clear();
    }

    public static ArrayList<ObjectWithSomeRefs> longList = new ArrayList<ObjectWithSomeRefs>();

    public static void main(String[] args) {

        for (int i = 0; i < 16*1024; i++) {
             longList.add(new ObjectWithSomeRefs());
        }

        Random rnd = new Random();
        for (int i = 0; i < longList.size(); i++) {
             int len = longList.size();
             longList.get(i).other1 = longList.get(rnd.nextInt(len));
             longList.get(i).other2 = longList.get(rnd.nextInt(len));
             longList.get(i).other3 = longList.get(rnd.nextInt(len));
             longList.get(i).other4 = longList.get(rnd.nextInt(len));
        }

        int[] large1 = new int[M];
        int[] large2 = null;
        int[] large3 = null;
        int[] large4 = null;

        Object ref_from_stack = large1;

90 91
        long start_millis = System.currentTimeMillis();

92
        for (int i = 0; i < 20; i++) {
93 94 95 96 97
            long current_millis = System.currentTimeMillis();
            if ((current_millis - start_millis) > MAX_MILLIS_FOR_RUN) {
              System.out.println("Finishing test because maximum runtime exceeded");
              break;
            }
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
            // A set of large objects that will be reclaimed eagerly - and hopefully marked.
            large1 = new int[M - 20];
            large2 = new int[M - 20];
            large3 = new int[M - 20];
            large4 = new int[M - 20];
            genGarbage(large1);
            // Make sure that the compiler cannot completely remove
            // the allocation of the large object until here.
            System.out.println(large1 + " " + large2 + " " + large3 + " " + large4);
        }

        // Keep the reference to the first object alive.
        System.out.println(ref_from_stack);
    }
}

114
public class TestEagerReclaimHumongousRegionsClearMarkBits {
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    public static void main(String[] args) throws Exception {
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
            "-XX:+UseG1GC",
            "-Xms128M",
            "-Xmx128M",
            "-Xmn2M",
            "-XX:G1HeapRegionSize=1M",
            "-XX:InitiatingHeapOccupancyPercent=0", // Want to have as much as possible initial marks.
            "-XX:+PrintGC",
            "-XX:+VerifyAfterGC",
            "-XX:ConcGCThreads=1", // Want to make marking as slow as possible.
            "-XX:+IgnoreUnrecognizedVMOptions", // G1VerifyBitmaps is develop only.
            "-XX:+G1VerifyBitmaps",
            ReclaimRegionFast.class.getName());
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldHaveExitValue(0);
    }
}