test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/resetPeakUsage/reset001.java
author iignatyev
Wed, 02 May 2018 16:43:56 -0700
changeset 49958 cc29d7717e3a
permissions -rw-r--r--
8199375: [TESTBUG] Open source vm testbase monitoring tests Reviewed-by: kvn, ihse, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49958
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     1
/*
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     4
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     8
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    14
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    18
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    21
 * questions.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    22
 */
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    23
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    24
package nsk.monitoring.MemoryPoolMBean.resetPeakUsage;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    25
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    26
import java.io.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    27
import java.util.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    28
import nsk.share.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    29
import nsk.monitoring.share.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    30
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    31
public class reset001 {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    32
    private static boolean testFailed = false;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    33
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    34
    public static void main(String[] argv) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    35
        System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    36
    }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    37
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    38
    public static int run(String[] argv, PrintStream out) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    39
        ArgumentHandler argHandler = new ArgumentHandler(argv);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    40
        Log log = new Log(out, argHandler);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    41
        MemoryMonitor monitor = Monitor.getMemoryMonitor(log, argHandler);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    42
        List pools = monitor.getMemoryPoolMBeans();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    43
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    44
        for (int i = 0; i < pools.size(); i++) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    45
            byte[] b = new byte[10 * 1024]; // Eat 10K
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    46
            Object pool = pools.get(i);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    47
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    48
            // No exceptions should be thrown
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    49
            try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    50
                monitor.resetPeakUsage(pool);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    51
            } catch (Throwable t) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    52
                if (t instanceof ThreadDeath)
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    53
                    throw (ThreadDeath) t;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    54
                log.complain("Unexpected exception in pool "
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    55
                           + monitor.getName(pool));
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    56
                t.printStackTrace(log.getOutStream());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    57
                testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    58
            }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    59
        } // for i
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    60
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    61
        if (testFailed)
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    62
            out.println("TEST FAILED");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    63
        return (testFailed) ? Consts.TEST_FAILED : Consts.TEST_PASSED;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    64
    }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    65
}