hotspot/test/gc/g1/logging/TestG1LoggingFailure.java
author mchernov
Tue, 15 Nov 2016 14:04:39 +0300
changeset 42567 fd103115da89
parent 42067 34b99c8faa51
permissions -rw-r--r--
8168934: [TESTBUG] gc/g1/logging/TestG1LoggingFailure.java failed Reviewed-by: tschatzl, dfazunen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     1
/*
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     4
 *
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     7
 * published by the Free Software Foundation.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     8
 *
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    13
 * accompanied this code).
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    14
 *
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    18
 *
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    21
 * questions.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    22
 */
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    23
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    24
 /*
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    25
 * @test TestG1LoggingFailure
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    26
 * @bug 8151034
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    27
 * @summary Regression test for G1 logging at OOME
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    28
 * @requires vm.gc.G1
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    29
 * @library /test/lib
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    30
 * @modules java.management
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    31
 * @build gc.g1.logging.TestG1LoggingFailure
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    32
 * @run main/timeout=300 gc.g1.logging.TestG1LoggingFailure
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    33
 */
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    34
package gc.g1.logging;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    35
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    36
import java.util.ArrayList;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    37
import java.util.Collections;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    38
import java.util.List;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    39
import jdk.test.lib.process.OutputAnalyzer;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    40
import jdk.test.lib.process.ProcessTools;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    41
import jdk.test.lib.Utils;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    42
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    43
public class TestG1LoggingFailure {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    44
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    45
    public static void main(String[] args) throws Throwable {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    46
        List<String> options = new ArrayList<>();
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    47
        Collections.addAll(options, Utils.getTestJavaOpts());
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    48
        Collections.addAll(options,
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    49
                "-XX:+UseG1GC",
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    50
                "-Xmx20m",
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    51
                "-Xmn10m",
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    52
                "-Xlog:gc=info",
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    53
                "-XX:G1HeapRegionSize=1m"
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    54
        );
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    55
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    56
        options.add(Alloc.class.getName());
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    57
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    58
        // According to https://bugs.openjdk.java.net/browse/JDK-8146009 failure happens not every time.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    59
        // Will try to reproduce this failure.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    60
        for (int iteration = 0; iteration < 40; ++iteration) {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    61
            startVM(options);
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    62
        }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    63
    }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    64
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    65
    private static void startVM(List<String> options) throws Throwable, RuntimeException {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    66
        OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()]));
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    67
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    68
        out.shouldNotContain("pure virtual method called");
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    69
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    70
        if (out.getExitValue() == 0) {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    71
            System.out.println(out.getOutput());
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    72
            throw new RuntimeException("Expects Alloc failure.");
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    73
        }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    74
    }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    75
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    76
    // Simple class to be executed in separate VM.
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    77
    static class Alloc {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    78
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    79
        public static final int CHUNK = 1024;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    80
        public static ArrayList<Object> arr = new ArrayList<>();
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    81
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    82
        public static void main(String[] args) {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    83
            try {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    84
                while (true) {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    85
                    arr.add(new byte[CHUNK]);
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    86
                }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    87
            } catch (OutOfMemoryError oome) {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    88
            }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    89
            while (true) {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    90
                arr.add(new byte[CHUNK]);
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    91
            }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    92
        }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    93
    }
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents:
diff changeset
    94
}