test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadInfo/isSuspended/issuspended001.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 49958 cc29d7717e3a
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
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.ThreadInfo.isSuspended;
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.lang.management.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    27
import java.io.*;
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
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    30
public class issuspended001 {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    31
    private static Wicket mainEntrance = new Wicket();
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
        ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    40
        MyThread thread = new MyThread(out);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    41
        thread.start();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    42
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    43
        // Wait for MyThread to start
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    44
        mainEntrance.waitFor();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    45
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    46
        long id = thread.getId();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    47
        ThreadInfo info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    48
        boolean isSuspended = info.isSuspended();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    49
        if (isSuspended) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    50
            out.println("Failure 1.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    51
            out.println("ThreadInfo.isSuspended() returned true, before "
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    52
                      + "Thread.suspend() was invoked.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    53
            testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    54
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    55
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    56
        thread.suspend();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    57
        info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    58
        isSuspended = info.isSuspended();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    59
        if (!isSuspended) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    60
            out.println("Failure 2.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    61
            out.println("ThreadInfo.isSuspended() returned false, after "
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    62
                      + "Thread.suspend() was invoked.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    63
            testFailed = true;
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
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    66
        thread.resume();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    67
        info = mbean.getThreadInfo(id, Integer.MAX_VALUE);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    68
        isSuspended = info.isSuspended();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    69
        if (isSuspended) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    70
            out.println("Failure 3.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    71
            out.println("ThreadInfo.isSuspended() returned true, after "
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    72
                      + "Thread.resume() was invoked.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    73
            testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    74
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    75
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    76
        thread.die = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    77
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    78
        if (testFailed)
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    79
            out.println("TEST FAILED");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    80
        return (testFailed) ? Consts.TEST_FAILED : Consts.TEST_PASSED;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    81
    }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    82
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    83
    private static class MyThread extends Thread {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    84
        final static long WAIT_TIME = 500; // Milliseconds
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    85
        Object object = new Object();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    86
        boolean die = false;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    87
        PrintStream out;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    88
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    89
        MyThread(PrintStream out) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    90
            this.out = out;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    91
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    92
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    93
        public void run() {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    94
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    95
            // Notify "main" thread that MyThread has started
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    96
            mainEntrance.unlock();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    97
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    98
            while (!die) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    99
                synchronized(object) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   100
                    try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   101
                        object.wait(WAIT_TIME);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   102
                    } catch (InterruptedException e) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   103
                        out.println("Unexpected exception.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   104
                        e.printStackTrace(out);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   105
                        testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   106
                    }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   107
                } // synchronized
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   108
            }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   109
        } // run()
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   110
    } // MyThread
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   111
}