test/jdk/sun/management/HotspotClassLoadingMBean/GetInitializedClassCount.java
author chegar
Thu, 17 Oct 2019 20:27:44 +0100
branchdatagramsocketimpl-branch
changeset 58677 13588c901957
parent 47216 71c04702a3d5
permissions -rw-r--r--
Initial changes for datagramsocketimpl-branch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 21803
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug     4858522
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Basic unit test of HotspotClassLoadingMBean.getInitializedClassCount()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author  Steve Bohne
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    29
 *
21803
791d8485f6ed 8028433: [TESTBUG] add -XX:+UsePerfData to some sun.management tests
jbachorik
parents: 5506
diff changeset
    30
 * @run main/othervm -XX:+UsePerfData GetInitializedClassCount
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This test is just a sanity check and does not check for the correct value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class GetInitializedClassCount {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static HotspotClassLoadingMBean mbean =
403
dc6f4ca08b81 6687508: Update test/sun/management jtreg tests due to sun.management.ManagementFactory class rename
mchung
parents: 2
diff changeset
    42
        (HotspotClassLoadingMBean)ManagementFactoryHelper.getHotspotClassLoadingMBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // Careful with these values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final long MIN_VALUE_FOR_PASS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static boolean trace = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (args.length > 0 && args[0].equals("trace")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            trace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        long value = mbean.getInitializedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (trace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            System.out.println("Initialized class count: " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            throw new RuntimeException("Initialized class count " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                       "illegal value: " + value + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                       "(MIN = " + MIN_VALUE_FOR_PASS + "; " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                       "MAX = " + MAX_VALUE_FOR_PASS + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // Initialize a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        Class.forName("ClassToInitialize0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        long value2 = mbean.getInitializedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (trace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            System.out.println("Initialized class count2: " + value2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // If new count does not reflect that at least one class has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // been initialized, throw an exception.  We don't check that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // _exactly_ one class has been initialized because another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // thread may (rarely) have also done some class initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (value2 < value + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new RuntimeException("Initialized class count " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                       "did not increase " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                       "(value = " + value + "; " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                       "value2 = " + value2 + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        System.out.println("Test passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
class ClassToInitialize0 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    static int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}