hotspot/test/runtime/logging/MonitorInflationTest.java
author lana
Thu, 04 Feb 2016 11:28:20 -0800
changeset 35720 e66a02d55e71
parent 35221 9d8ada7b9fee
child 35858 6e704583a38f
permissions -rw-r--r--
Added tag jdk-9+104 for changeset a8ace34fedbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     1
/*
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     4
 *
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     8
 *
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.    See the GNU General Public License
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    13
 * accompanied this code).
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    14
 *
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    18
 *
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    21
 * questions.
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    22
 */
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    23
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    24
/*
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    25
 * @test
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    26
 * @bug 8133885
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    27
 * @summary monitorinflation=debug should have logging from each of the statements in the code
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    28
 * @library /testlibrary
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    29
 * @modules java.base/sun.misc
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    30
 *          java.management
35193
1e85994e9f56 8145445: [TESTBUG] runtime/logging tests need to properly build and import libraries
rprotacio
parents: 35181
diff changeset
    31
 * @build jdk.test.lib.OutputAnalyzer jdk.test.lib.ProcessTools
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    32
 * @run driver MonitorInflationTest
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    33
 */
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    34
35193
1e85994e9f56 8145445: [TESTBUG] runtime/logging tests need to properly build and import libraries
rprotacio
parents: 35181
diff changeset
    35
import jdk.test.lib.OutputAnalyzer;
1e85994e9f56 8145445: [TESTBUG] runtime/logging tests need to properly build and import libraries
rprotacio
parents: 35181
diff changeset
    36
import jdk.test.lib.ProcessTools;
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    37
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    38
public class MonitorInflationTest {
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    39
    static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    40
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    41
        output.shouldContain("Inflating object");
35221
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    42
        output.shouldContain("type MonitorInflationTest$Waiter");
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    43
        output.shouldContain("I've been waiting.");
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    44
        output.shouldHaveExitValue(0);
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    45
    }
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    46
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    47
    static void analyzeOutputOff(ProcessBuilder pb) throws Exception {
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    48
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    49
        output.shouldNotContain("[monitorinflation]");
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    50
        output.shouldHaveExitValue(0);
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    51
    }
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    52
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    53
    public static void main(String[] args) throws Exception {
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    54
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
35221
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    55
            "-Xlog:monitorinflation=debug", InnerClass.class.getName());
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    56
        analyzeOutputOn(pb);
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    57
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    58
        pb = ProcessTools.createJavaProcessBuilder(
35221
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    59
            "-XX:+TraceMonitorInflation", InnerClass.class.getName());
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    60
        analyzeOutputOn(pb);
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    61
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    62
        pb = ProcessTools.createJavaProcessBuilder(
35221
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    63
            "-Xlog:monitorinflation=off", InnerClass.class.getName());
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    64
        analyzeOutputOff(pb);
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    65
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    66
        pb = ProcessTools.createJavaProcessBuilder(
35221
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    67
            "-XX:-TraceMonitorInflation", InnerClass.class.getName());
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    68
        analyzeOutputOff(pb);
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    69
    }
35221
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    70
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    71
    public static class Waiter {
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    72
        public static void foo() {
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    73
            System.out.println("I've been waiting.");
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    74
        }
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    75
    }
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    76
    public static class InnerClass {
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    77
        public static void main(String[] args) throws Exception {
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    78
            Waiter w = new Waiter();
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    79
            synchronized (w) {
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    80
                w.wait(100);
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    81
                w.foo();
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    82
            }
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    83
        }
9d8ada7b9fee 8145606: [TESTBUG] MonitorInflationTest.java should be rewritten to be more predictable
rprotacio
parents: 35193
diff changeset
    84
    }
35171
cf7d5a1d0662 8145153: Convert TraceMonitorInflation to Unified Logging
rprotacio
parents:
diff changeset
    85
}