hotspot/test/gc/g1/mixedgc/TestLogging.java
author kzhaldyb
Thu, 24 Sep 2015 18:48:50 +0300
changeset 33102 81a6fd1ab98d
child 33140 7ff907b9d377
permissions -rw-r--r--
8136398: Create test that checks that G1 MixedGC produces correct output to logfile Summary: Added test that checks that G1 MixedGC produces correct output to logfile Reviewed-by: tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33102
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     1
/*
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     4
 *
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     8
 *
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    14
 *
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    18
 *
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    21
 * questions.
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    22
 */
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    23
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    24
/*
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    25
 * @test TestLogging
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    26
 * @summary Check that a mixed GC is reflected in the gc logs
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    27
 * @requires vm.gc=="G1" | vm.gc=="null"
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    28
 * @library /testlibrary /../../test/lib
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    29
 * @modules java.management
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    30
 * @build sun.hotspot.WhiteBox gc.g1.mixedgc.TestLogging
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    31
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    32
 * @run driver gc.g1.mixedgc.TestLogging
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    33
 */
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    34
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    35
package gc.g1.mixedgc;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    36
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    37
import jdk.test.lib.OutputAnalyzer;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    38
import jdk.test.lib.ProcessTools;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    39
import jdk.test.lib.Asserts;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    40
import sun.hotspot.WhiteBox;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    41
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    42
import java.util.ArrayList;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    43
import java.util.List;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    44
import java.util.Collections;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    45
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    46
/**
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    47
 * Test spawns MixedGCProvoker in a separate VM and expects to find a message
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    48
 * telling that a mixed gc has happened
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    49
 */
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    50
public class TestLogging {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    51
    private static final String[] COMMON_OPTIONS = new String[]{
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    52
            "-Xbootclasspath/a:.", "-XX:+UseG1GC",
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    53
            "-XX:+UnlockExperimentalVMOptions",
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    54
            "-XX:+UnlockDiagnosticVMOptions",
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    55
            "-XX:+WhiteBoxAPI",
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    56
            "-XX:SurvivorRatio=1", // Survivor-to-eden ratio is 1:1
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    57
            "-Xms10M", "-Xmx10M",
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    58
            "-XX:MaxTenuringThreshold=1", // promote objects after first gc
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    59
            "-XX:InitiatingHeapOccupancyPercent=0", // marking cycle happens
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    60
            // each time
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    61
            "-XX:G1MixedGCCountTarget=4",
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    62
            "-XX:MaxGCPauseMillis=30000", // to have enough time
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    63
            "-XX:G1HeapRegionSize=1m", "-XX:G1HeapWastePercent=0",
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    64
            "-XX:G1MixedGCLiveThresholdPercent=100"};
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    65
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    66
    public static final int ALLOCATION_SIZE = 20000;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    67
    public static final int ALLOCATION_COUNT = 15;
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    68
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    69
    public static void main(String args[]) throws Exception {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    70
        // Test turns logging on by giving -XX:+PrintGC flag
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    71
        test("-XX:+PrintGC");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    72
        // Test turns logging on by giving -XX:+PrintGCDetails
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    73
        test("-XX:+PrintGCDetails");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    74
    }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    75
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    76
    private static void test(String vmFlag) throws Exception {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    77
        System.out.println(String.format("%s: running with %s flag", TestLogging.class.getSimpleName(), vmFlag));
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    78
        OutputAnalyzer output = spawnMixedGCProvoker(vmFlag);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    79
        System.out.println(output.getStdout());
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    80
        output.shouldHaveExitValue(0);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    81
        output.shouldContain("GC pause (G1 Evacuation Pause) (mixed)");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    82
    }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    83
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    84
    /**
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    85
     * Method spawns MixedGCProvoker with addition flags set
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    86
     *
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    87
     * @parameter extraFlags -flags to be added to the common options set
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    88
     */
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    89
    private static OutputAnalyzer spawnMixedGCProvoker(String... extraFlags)
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    90
            throws Exception {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    91
        List<String> testOpts = new ArrayList<>();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    92
        Collections.addAll(testOpts, COMMON_OPTIONS);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    93
        Collections.addAll(testOpts, extraFlags);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    94
        testOpts.add(MixedGCProvoker.class.getName());
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    95
        System.out.println(testOpts);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    96
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false,
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    97
                testOpts.toArray(new String[testOpts.size()]));
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    98
        return new OutputAnalyzer(pb.start());
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
    99
    }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   100
}
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   101
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   102
/**
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   103
 * Utility class to guarantee a mixed GC. The class allocates several arrays and
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   104
 * promotes them to the oldgen. After that it tries to provoke mixed GC by
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   105
 * allocating new objects.
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   106
 *
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   107
 * The necessary condition for guaranteed mixed GC is running MixedGCProvoker is
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   108
 * running in VM with the following flags: -XX:MaxTenuringThreshold=1, -Xms10M,
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   109
 * -Xmx10M, -XX:G1MixedGCLiveThresholdPercent=100, -XX:G1HeapWastePercent=0,
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   110
 * -XX:G1HeapRegionSize=1m
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   111
 */
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   112
class MixedGCProvoker {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   113
    private static final WhiteBox WB = WhiteBox.getWhiteBox();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   114
    private static final List<byte[]> liveOldObjects = new ArrayList<>();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   115
    private static final List<byte[]> newObjects = new ArrayList<>();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   116
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   117
    private static void allocateOldObjects() throws Exception {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   118
        List<byte[]> deadOldObjects = new ArrayList<>();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   119
        // Allocates buffer and promotes it to the old gen. Mix live and dead old
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   120
        // objects
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   121
        for (int i = 0; i < TestLogging.ALLOCATION_COUNT; ++i) {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   122
            liveOldObjects.add(new byte[TestLogging.ALLOCATION_SIZE * 10]);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   123
            deadOldObjects.add(new byte[TestLogging.ALLOCATION_SIZE * 10]);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   124
        }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   125
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   126
        // need only 2 promotions to promote objects to the old gen
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   127
        WB.youngGC();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   128
        WB.youngGC();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   129
        // check it is promoted & keep alive
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   130
        Asserts.assertTrue(WB.isObjectInOldGen(liveOldObjects),
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   131
                "List of the objects is suppose to be in OldGen");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   132
        Asserts.assertTrue(WB.isObjectInOldGen(deadOldObjects),
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   133
                "List of the objects is suppose to be in OldGen");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   134
    }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   135
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   136
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   137
    /**
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   138
     * Waits until Concurent Mark Cycle finishes
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   139
     * @param wb  Whitebox instance
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   140
     * @param sleepTime sleep time
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   141
     */
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   142
    public static void waitTillCMCFinished(WhiteBox wb, int sleepTime) {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   143
        while (wb.g1InConcurrentMark()) {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   144
            if (sleepTime > -1) {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   145
                try {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   146
                    Thread.sleep(sleepTime);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   147
                } catch (InterruptedException e) {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   148
                    System.out.println("Got InterruptedException while waiting for ConcMarkCycle to finish");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   149
                }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   150
            }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   151
        }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   152
    }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   153
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   154
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   155
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   156
    public static void main(String args[]) throws Exception {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   157
        // allocate old objects
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   158
        allocateOldObjects();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   159
        waitTillCMCFinished(WB, 0);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   160
        WB.g1StartConcMarkCycle();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   161
        waitTillCMCFinished(WB, 0);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   162
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   163
        WB.youngGC();
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   164
        System.out.println("Allocating new objects to provoke mixed GC");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   165
        // allocate more objects to provoke GC
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   166
        for (int i = 0; i < (TestLogging.ALLOCATION_COUNT * 20); i++) {
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   167
            newObjects.add(new byte[TestLogging.ALLOCATION_SIZE]);
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   168
        }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   169
        // check that liveOldObjects still alive
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   170
        Asserts.assertTrue(WB.isObjectInOldGen(liveOldObjects),
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   171
                "List of the objects is suppose to be in OldGen");
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   172
    }
81a6fd1ab98d 8136398: Create test that checks that G1 MixedGC produces correct output to logfile
kzhaldyb
parents:
diff changeset
   173
}