test/hotspot/jtreg/serviceability/tmtools/jstack/WaitNotifyThreadTest.java
author pchilanomate
Fri, 07 Dec 2018 13:59:19 -0500
changeset 52906 06fd6cb23acd
parent 47216 71c04702a3d5
child 52933 13173122094f
permissions -rw-r--r--
8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected Summary: Fixed the logic for checking method name and added checks for thread status Reviewed-by: dholmes, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     1
/*
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     4
 *
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     7
 * published by the Free Software Foundation.
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     8
 *
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    13
 * accompanied this code).
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    14
 *
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    18
 *
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    21
 * questions.
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    22
 */
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    23
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    24
/*
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    25
 * @test
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    26
 * @summary  Call Object.wait() method. Check that monitor information
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    27
 *           presented in the stack is correct. Call notifyAll method
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    28
 *           monitor info have to disappear from the stack.
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    29
 *           Repeats the same scenario calling interrupt() method
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 35874
diff changeset
    30
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    31
 * @library /test/lib
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    32
 * @library ../share
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    33
 * @run main/othervm -XX:+UsePerfData WaitNotifyThreadTest
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    34
 */
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    35
import common.ToolResults;
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    36
import java.util.Iterator;
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    37
import utils.*;
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    38
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    39
public class WaitNotifyThreadTest {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    40
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    41
    private Object monitor = new Object();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    42
    private final String OBJECT = "a java.lang.Object";
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    43
    private final String OBJECT_WAIT = "java.lang.Object.wait";
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
    44
    private final String RUN_METHOD = "WaitNotifyThreadTest$WaitThread.run";
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    45
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    46
    interface Action {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    47
        void doAction(Thread thread);
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    48
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    49
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    50
    class ActionNotify implements Action {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    51
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    52
        @Override
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    53
        public void doAction(Thread thread) {
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
    54
            // Notify the waiting thread, so it stops waiting and sleeps
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    55
            synchronized (monitor) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    56
                monitor.notifyAll();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    57
            }
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
    58
            // Wait until MyWaitingThread exits the monitor and sleeps
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
    59
            while (thread.getState() != Thread.State.TIMED_WAITING) {}
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    60
        }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    61
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    62
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    63
    class ActionInterrupt implements Action {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    64
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    65
        @Override
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    66
        public void doAction(Thread thread) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    67
            // Interrupt the thread
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    68
            thread.interrupt();
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
    69
            // Wait until MyWaitingThread exits the monitor and sleeps
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
    70
            while (thread.getState() != Thread.State.TIMED_WAITING) {}
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    71
        }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    72
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    73
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    74
    class WaitThread extends Thread {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    75
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    76
        @Override
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    77
        public void run() {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    78
            try {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    79
                synchronized (monitor) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    80
                    monitor.wait();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    81
                }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    82
            } catch (InterruptedException x) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    83
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    84
            }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    85
            Utils.sleep();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    86
        }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    87
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    88
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    89
    public static void main(String[] args) throws Exception {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    90
        new WaitNotifyThreadTest().doTest();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    91
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    92
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    93
    private void doTest() throws Exception {
35874
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
    94
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    95
        // Verify stack trace consistency when notifying the thread
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    96
        doTest(new ActionNotify());
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    97
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    98
        // Verify stack trace consistency when interrupting the thread
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
    99
        doTest(new ActionInterrupt());
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   100
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   101
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   102
    private void doTest(Action action) throws Exception {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   103
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   104
        final String WAITING_THREAD_NAME = "MyWaitingThread";
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   105
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   106
        // Start a thread that just waits
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   107
        WaitThread waitThread = new WaitThread();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   108
        waitThread.setName(WAITING_THREAD_NAME);
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   109
        waitThread.start();
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   110
        // Wait until MyWaitingThread enters the monitor
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   111
        while (waitThread.getState() != Thread.State.WAITING) {}
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   112
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   113
        // Collect output from the jstack tool
44633
d2f5e8921045 8178347: Process and ProcessHandle getPid method name inconsistency
rriggs
parents: 40631
diff changeset
   114
        JstackTool jstackTool = new JstackTool(ProcessHandle.current().pid());
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   115
        ToolResults results = jstackTool.measure();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   116
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   117
        // Analyze the jstack output for the patterns needed
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   118
        JStack jstack1 = new DefaultFormat().parse(results.getStdoutString());
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   119
        ThreadStack ti1 = jstack1.getThreadStack(WAITING_THREAD_NAME);
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   120
        analyzeThreadStackWaiting(ti1);
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   121
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   122
        action.doAction(waitThread);
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   123
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   124
        // Collect output from the jstack tool again
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   125
        results = jstackTool.measure();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   126
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   127
        // Analyze the output again
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   128
        JStack jstack2 = new DefaultFormat().parse(results.getStdoutString());
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   129
        ThreadStack ti2 = jstack2.getThreadStack(WAITING_THREAD_NAME);
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   130
        analyzeThreadStackNoWaiting(ti2);
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   131
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   132
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   133
    private void analyzeThreadStackWaiting(ThreadStack ti1) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   134
        Iterator<MethodInfo> it = ti1.getStack().iterator();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   135
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   136
        String monitorAddress = null;
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   137
        while (it.hasNext()) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   138
            MethodInfo mi = it.next();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   139
            if (mi.getName().startsWith(OBJECT_WAIT) && mi.getCompilationUnit() == null /*native method*/) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   140
                if (mi.getLocks().size() == 1) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   141
                    MonitorInfo monInfo = mi.getLocks().getFirst();
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   142
                    monitorAddress = monInfo.getMonitorAddress();
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   143
                    assertMonitorInfo("waiting on", monInfo, monitorAddress, OBJECT_WAIT);
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   144
                } else {
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   145
                    throw new RuntimeException(OBJECT_WAIT + " method has to contain one lock record but it contains "
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   146
                                               + mi.getLocks().size());
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   147
                }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   148
            }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   149
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   150
            if (mi.getName().startsWith(RUN_METHOD)) {
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   151
                if (monitorAddress == null) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   152
                    throw new RuntimeException("Cannot found monitor info associated with " + OBJECT_WAIT + " method");
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   153
                }
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   154
                if (mi.getLocks().size() == 1) {
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   155
                    assertMonitorInfo("locked", mi.getLocks().getLast(), monitorAddress, RUN_METHOD);
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   156
                }
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   157
                else {
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   158
                    throw new RuntimeException(RUN_METHOD + " method has to contain one lock record but it contains "
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   159
                                               + mi.getLocks().size());
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   160
                }
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   161
            }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   162
        }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   163
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   164
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   165
    private void assertMonitorInfo(String expectedMessage, MonitorInfo monInfo, String monitorAddress, String method) {
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   166
        if (monInfo.getType().equals(expectedMessage)
35874
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   167
                && compareMonitorClass(monInfo)
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   168
                && monInfo.getMonitorAddress().equals(
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   169
                        monitorAddress)) {
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   170
            System.out.println("Correct monitor info found in " + method + " method");
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   171
        } else {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   172
            System.err.println("Error: incorrect monitor info: " + monInfo.getType() + ", " + monInfo.getMonitorClass() + ", " + monInfo.getMonitorAddress());
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   173
            System.err.println("Expected: " + expectedMessage + ", a java.lang.Object, " + monitorAddress);
52906
06fd6cb23acd 8214148: [TESTBUG] serviceability/tmtools/jstack/WaitNotifyThreadTest.java is not doing what is expected
pchilanomate
parents: 47216
diff changeset
   174
            throw new RuntimeException("Incorrect lock record in " + method + " method");
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   175
        }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   176
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   177
35874
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   178
    private boolean compareMonitorClass(MonitorInfo monInfo) {
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   179
        // If monitor class info is present in the jstack output
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   180
        // then compare it with the class of the actual monitor object
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   181
        // If there is no monitor class info available then return true
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   182
        return OBJECT.equals(monInfo.getMonitorClass()) || (monInfo.getMonitorClass() == null);
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   183
    }
6c93eabea7c2 8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
akulyakh
parents: 35493
diff changeset
   184
35493
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   185
    private void analyzeThreadStackNoWaiting(ThreadStack ti2) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   186
        Iterator<MethodInfo> it = ti2.getStack().iterator();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   187
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   188
        while (it.hasNext()) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   189
            MethodInfo mi = it.next();
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   190
            if (mi.getLocks().size() != 0) {
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   191
                throw new RuntimeException("Unexpected lock record in "
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   192
                        + mi.getName() + " method");
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   193
            }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   194
        }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   195
    }
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   196
863fb33f9940 8130063: Refactoring tmtools jstat and jstack tests to jtreg
akulyakh
parents:
diff changeset
   197
}