test/gc/g1/TestG1TraceEagerReclaimHumongousObjects.java

Mon, 06 Nov 2017 16:51:47 +0800

author
aoqi
date
Mon, 06 Nov 2017 16:51:47 +0800
changeset 7997
6cbff0651f1a
parent 7828
cbc7c4c9e11c
permissions
-rw-r--r--

[Code Reorganization] remove trailing whitespace to pass jcheck test

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

mercurial