hotspot/test/serviceability/sa/TestClassLoaderStats.java
author ykantser
Fri, 22 May 2015 08:47:27 +0200
changeset 30860 ae6117e23669
child 31018 794e08f6dad4
permissions -rw-r--r--
8080828: Create sanity test for JDK-8080155 Reviewed-by: sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30860
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     1
/*
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     4
 *
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     8
 *
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    13
 * accompanied this code).
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    14
 *
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    18
 *
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    21
 * questions.
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    22
 */
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    23
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    24
import jdk.test.lib.Platform;
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    25
import jdk.test.lib.ProcessTools;
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    26
import jdk.test.lib.OutputAnalyzer;
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    27
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    28
/*
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    29
 * @test
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    30
 * @library /testlibrary
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    31
 * @build jdk.test.lib.*
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    32
 * @run main TestClassLoaderStats
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    33
 */
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    34
public class TestClassLoaderStats {
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    35
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    36
    public static void main(String[] args) throws Exception {
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    37
        if (!Platform.shouldSAAttach()) {
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    38
            System.out.println("SA attach not expected to work - test skipped.");
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    39
            return;
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    40
        }
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    41
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    42
        ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    43
                "-XX:+UsePerfData",
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    44
                "sun.jvm.hotspot.tools.ClassLoaderStats",
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    45
                Integer.toString(ProcessTools.getProcessId()));
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    46
        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    47
        System.out.println(output.getOutput());
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    48
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    49
        output.shouldHaveExitValue(0);
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    50
        output.shouldContain("Debugger attached successfully.");
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    51
        // The class loader stats header needs to be presented in the output:
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    52
        output.shouldMatch("class_loader\\W+classes\\W+bytes\\W+parent_loader\\W+alive?\\W+type");
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    53
        output.stderrShouldNotMatch("[E|e]xception");
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    54
        output.stderrShouldNotMatch("[E|e]rror");
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    55
    }
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    56
ae6117e23669 8080828: Create sanity test for JDK-8080155
ykantser
parents:
diff changeset
    57
}