hotspot/test/gc/g1/TestG1TraceEagerReclaimHumongousObjects.java
author tschatzl
Wed, 07 Jan 2015 15:15:37 +0100
changeset 28379 e6784fc8fff2
parent 27151 hotspot/test/gc/g1/TestG1TraceReclaimDeadHumongousObjectsAtYoungGC.java@46c8a68473f0
child 29678 dd2f3932c21e
permissions -rw-r--r--
8048179: Early reclaim of large objects that are referenced by a few objects Summary: Push the remembered sets of large objects with few referenced into the dirty card queue at the beginning of the evacuation so that they may end up with zero remembered set entries at the end of the collection, and are potentially reclaimed. Also improve timing measurements of the early reclaim mechanism, and shorten flag names. Reviewed-by: brutisso, jmasa, dfazunen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27151
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     1
/*
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     4
 *
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     8
 *
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    14
 *
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    18
 *
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    21
 * questions.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    22
 */
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    23
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    24
/*
28379
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    25
 * @test TestG1TraceEagerReclaimHumongousObjects
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    26
 * @bug 8058801 8048179
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    27
 * @summary Ensure that the output for a G1TraceEagerReclaimHumongousObjects
27151
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    28
 * includes the expected necessary messages.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    29
 * @key gc
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    30
 * @library /testlibrary
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    31
 */
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    32
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    33
import com.oracle.java.testlibrary.ProcessTools;
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    34
import com.oracle.java.testlibrary.OutputAnalyzer;
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    35
import java.util.LinkedList;
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    36
28379
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    37
public class TestG1TraceEagerReclaimHumongousObjects {
27151
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    38
  public static void main(String[] args) throws Exception {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    39
    testGCLogs();
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    40
    testHumongousObjectGCLogs();
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    41
  }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    42
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    43
  private static void testGCLogs() throws Exception {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    44
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    45
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    46
                                               "-Xms128M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    47
                                               "-Xmx128M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    48
                                               "-Xmn16M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    49
                                               "-XX:G1HeapRegionSize=1M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    50
                                               "-XX:+PrintGC",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    51
                                               "-XX:+UnlockExperimentalVMOptions",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    52
                                               "-XX:G1LogLevel=finest",
28379
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    53
                                               "-XX:+G1TraceEagerReclaimHumongousObjects",
27151
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    54
                                               GCTest.class.getName());
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    55
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    56
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    57
28379
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    58
    // As G1EagerReclaimHumongousObjects is set(default), below logs should be displayed.
27151
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    59
    // And GCTest doesn't have humongous objects, so values should be zero.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    60
    output.shouldContain("[Humongous Reclaim");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    61
    output.shouldContain("[Humongous Total: 0]");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    62
    output.shouldContain("[Humongous Candidate: 0]");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    63
    output.shouldContain("[Humongous Reclaimed: 0]");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    64
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    65
    output.shouldHaveExitValue(0);
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    66
  }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    67
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    68
  private static void testHumongousObjectGCLogs() throws Exception {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    69
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    70
                                               "-Xms128M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    71
                                               "-Xmx128M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    72
                                               "-Xmn16M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    73
                                               "-XX:G1HeapRegionSize=1M",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    74
                                               "-XX:+PrintGC",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    75
                                               "-XX:+UnlockExperimentalVMOptions",
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    76
                                               "-XX:G1LogLevel=finest",
28379
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    77
                                               "-XX:+G1TraceEagerReclaimHumongousObjects",
27151
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    78
                                               GCWithHumongousObjectTest.class.getName());
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    79
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    80
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    81
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    82
    // As G1ReclaimDeadHumongousObjectsAtYoungGC is set(default), below logs should be displayed.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    83
    output.shouldContain("[Humongous Reclaim");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    84
    output.shouldContain("[Humongous Total");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    85
    output.shouldContain("[Humongous Candidate");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    86
    output.shouldContain("[Humongous Reclaimed");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    87
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    88
    // As G1TraceReclaimDeadHumongousObjectsAtYoungGC is set and GCWithHumongousObjectTest has humongous objects,
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    89
    // these logs should be displayed.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    90
    output.shouldContain("Live humongous");
28379
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 27151
diff changeset
    91
    output.shouldContain("Dead humongous region");
27151
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    92
    output.shouldHaveExitValue(0);
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    93
  }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    94
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    95
  static class GCTest {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    96
    private static byte[] garbage;
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    97
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    98
    public static void main(String [] args) {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
    99
      System.out.println("Creating garbage");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   100
      // create 128MB of garbage. This should result in at least one GC
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   101
      for (int i = 0; i < 1024; i++) {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   102
        garbage = new byte[128 * 1024];
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   103
      }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   104
      System.out.println("Done");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   105
    }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   106
  }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   107
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   108
  static class GCWithHumongousObjectTest {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   109
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   110
    public static final int M = 1024*1024;
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   111
    public static LinkedList<Object> garbageList = new LinkedList<Object>();
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   112
    // A large object referenced by a static.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   113
    static int[] filler = new int[10 * M];
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   114
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   115
    public static void genGarbage() {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   116
      for (int i = 0; i < 32*1024; i++) {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   117
        garbageList.add(new int[100]);
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   118
      }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   119
      garbageList.clear();
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   120
    }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   121
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   122
    public static void main(String[] args) {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   123
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   124
      int[] large = new int[M];
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   125
      Object ref = large;
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   126
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   127
      System.out.println("Creating garbage");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   128
      for (int i = 0; i < 100; i++) {
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   129
        // A large object that will be reclaimed eagerly.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   130
        large = new int[6*M];
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   131
        genGarbage();
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   132
        // Make sure that the compiler cannot completely remove
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   133
        // the allocation of the large object until here.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   134
        System.out.println(large);
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   135
      }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   136
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   137
      // Keep the reference to the first object alive.
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   138
      System.out.println(ref);
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   139
      System.out.println("Done");
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   140
    }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   141
  }
46c8a68473f0 8058801: G1TraceReclaimDeadHumongousObjectsAtYoungGC only prints humongous object liveness output when there is at least one candidate humongous object
tschatzl
parents:
diff changeset
   142
}