test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEventsDebuggee.java
author jlahoda
Tue, 12 Nov 2019 06:32:13 +0000
changeset 59021 cfc7bb9a5a92
parent 49934 44839fbb20db
permissions -rw-r--r--
8232684: Make switch expressions final Reviewed-by: alanb, mcimadamore, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     1
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     4
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     8
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    14
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    18
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    21
 * questions.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    22
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    23
package nsk.share.jdi;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    24
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    25
import java.util.*;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    26
import nsk.share.TestBug;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    27
import nsk.share.locks.MonitorLockingThread;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    28
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    29
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    30
 * This class generates MonitorWaitEvent and MonitorWaitedEvent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    31
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    32
class MonitorWaitExecutor extends EventActionsExecutor {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    33
    // MonitorWaited event may occurs when waiting thread was interrupted,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    34
    // notified by notify or notifyAll, or when timeout expired
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    35
    enum ExitFromWaitType {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    36
        EXIT_WITH_TIMEOUT,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    37
        INTERRUPT,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    38
        NOTIFY,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    39
        NOTIFY_ALL
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    40
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    41
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    42
    // this thread forces MonitorWaitExecutor to exit from wait()
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    43
    class AuxiliaryThread extends Thread {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    44
        private Thread threadToInterrupt;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    45
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    46
        private Object monitor;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    47
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    48
        public AuxiliaryThread(Thread threadToInterrupt, Object monitor) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    49
            this.threadToInterrupt = threadToInterrupt;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    50
            this.monitor = monitor;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    51
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    52
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    53
        public void run() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    54
            // wait when interrupted thread switches state to 'TIMED_WAITING'
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    55
            while ((threadToInterrupt.getState() != Thread.State.WAITING) && !exitedFromWait) {
59021
cfc7bb9a5a92 8232684: Make switch expressions final
jlahoda
parents: 49934
diff changeset
    56
                Thread.yield();
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    57
            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    58
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    59
            // threadToInterrupt 'spuriously' exited from wait()
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    60
            if(exitedFromWait)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    61
                return;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    62
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    63
            if (exitFromWaitType == ExitFromWaitType.INTERRUPT) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    64
                threadToInterrupt.interrupt();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    65
            } else if ((exitFromWaitType == ExitFromWaitType.NOTIFY)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    66
                    || (exitFromWaitType == ExitFromWaitType.NOTIFY_ALL)) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    67
                /*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    68
                 * NOTE: thread's state WAITING doesn't guarantee that thread released
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    69
                 * monitor, and entering to the next synchronized block may cause MonitorContentedEnterEvent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    70
                 * (if corresponding request was created).
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    71
                 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    72
                 * Debugger should take in account this issue.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    73
                 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    74
                synchronized (monitor) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    75
                    if (exitFromWaitType == ExitFromWaitType.NOTIFY)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    76
                        monitor.notify();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    77
                    else if (exitFromWaitType == ExitFromWaitType.NOTIFY_ALL)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    78
                        monitor.notifyAll();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    79
                }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    80
            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    81
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    82
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    83
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    84
    // thread may 'spuriously' exit from wait(), in this case AuxiliaryThread shouldn't wait 'WAITING' state
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    85
    private volatile boolean exitedFromWait;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    86
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    87
    // save data about MonitorWait events
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    88
    private boolean monitorWait;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    89
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    90
    // save data about MonitorWaited events
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    91
    private boolean monitorWaited;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    92
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    93
    public MonitorWaitExecutor(boolean monitorWait, boolean monitorWaited) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    94
        this.monitorWait = monitorWait;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    95
        this.monitorWaited = monitorWaited;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    96
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    97
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    98
    protected ExitFromWaitType exitFromWaitType;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    99
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   100
    public void doEventAction() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   101
        for (ExitFromWaitType exitType : ExitFromWaitType.values()) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   102
            exitFromWaitType = exitType;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   103
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   104
            monitorWait();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   105
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   106
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   107
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   108
    protected void monitorWait() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   109
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   110
        exitedFromWait = false;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   111
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   112
        long timeout;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   113
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   114
        if (exitFromWaitType == ExitFromWaitType.EXIT_WITH_TIMEOUT)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   115
            timeout = 100;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   116
        else
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   117
            timeout = 0;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   118
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   119
        if (monitorWait) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   120
            DebuggeeEventData.DebugMonitorWaitEventData eventData = new DebuggeeEventData.DebugMonitorWaitEventData(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   121
                    this, Thread.currentThread(), timeout, this);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   122
            addEventData(eventData);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   123
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   124
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   125
        if (monitorWaited) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   126
            DebuggeeEventData.DebugMonitorWaitedEventData eventData = new DebuggeeEventData.DebugMonitorWaitedEventData(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   127
                    this, Thread.currentThread(),
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   128
                    (exitFromWaitType == ExitFromWaitType.EXIT_WITH_TIMEOUT),
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   129
                    this);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   130
            addEventData(eventData);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   131
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   132
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   133
        AuxiliaryThread auxiliaryThread = null;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   134
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   135
        if (exitFromWaitType != ExitFromWaitType.EXIT_WITH_TIMEOUT) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   136
            auxiliaryThread = new AuxiliaryThread(Thread.currentThread(), this);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   137
            auxiliaryThread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   138
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   139
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   140
        try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   141
            eventMethod(timeout);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   142
        } catch (InterruptedException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   143
            // expected exception
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   144
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   145
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   146
        exitedFromWait = true;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   147
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   148
        if (auxiliaryThread != null) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   149
            // don't using join, because of join is realized with using of
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   150
            // wait(), and this method can generate unexpected events
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   151
            while (auxiliaryThread.getState() != Thread.State.TERMINATED)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   152
                Thread.yield();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   153
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   154
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   155
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   156
    // move event actions to the separate method to simplify method redifinition
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   157
    // in subclasses
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   158
    synchronized protected void eventMethod(long timeout)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   159
            throws InterruptedException {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   160
        wait(timeout);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   161
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   162
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   163
}
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   164
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   165
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   166
 * Subclass of MonitorWaitExecutor, define its own event method(copy of parent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   167
 * method), intended for event filters test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   168
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   169
class MonitorWaitExecutor_1Subclass extends MonitorWaitExecutor {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   170
    public MonitorWaitExecutor_1Subclass(boolean monitorWait,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   171
            boolean monitorWaited) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   172
        super(monitorWait, monitorWaited);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   173
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   174
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   175
    synchronized protected void eventMethod(long timeout)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   176
            throws InterruptedException {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   177
        wait(timeout);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   178
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   179
}
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   180
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   181
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   182
 * Subclass of MonitorWaitExecutor, define its own event method(copy of parent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   183
 * method), intended for event filters test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   184
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   185
class MonitorWaitExecutor_2Subclass extends MonitorWaitExecutor_1Subclass {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   186
    public MonitorWaitExecutor_2Subclass(boolean monitorWait,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   187
            boolean monitorWaited) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   188
        super(monitorWait, monitorWaited);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   189
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   190
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   191
    synchronized protected void eventMethod(long timeout)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   192
            throws InterruptedException {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   193
        wait(timeout);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   194
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   195
}
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   196
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   197
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   198
 * This class generates MonitorContendedEnterEvent and
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   199
 * MonitorContendedEnteredEvent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   200
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   201
class MonitorEnterExecutor extends EventActionsExecutor {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   202
    /*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   203
     * Types of monitor acquiring:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   204
     * - through synchronized block
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   205
     * - through synchronized method
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   206
     * - through JNI MonitorEnter
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   207
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   208
    static enum MonitorAcquireType {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   209
        SYNCHRONIZED_BLOCK,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   210
        SYNCHRONIZED_METHOD,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   211
        JNI_MONITOR_ENTER
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   212
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   213
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   214
    // native method uses this class
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   215
    private static final Class<?> jniError = nsk.share.TestJNIError.class;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   216
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   217
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   218
    static final String nativeLibararyName = "MonitorEnterExecutor";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   219
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   220
    static {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   221
        System.loadLibrary(nativeLibararyName);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   222
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   223
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   224
    // this thread forces MonitorLockingThread to release holding lock
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   225
    static class LockFreeThread extends Thread {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   226
        private Thread blockedThread;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   227
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   228
        private MonitorLockingThread lockingThread;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   229
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   230
        public LockFreeThread(Thread blockedThread,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   231
                MonitorLockingThread lockingThread) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   232
            this.blockedThread = blockedThread;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   233
            this.lockingThread = lockingThread;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   234
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   235
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   236
        public void run() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   237
            // wait when blocked thread switches state to 'BLOCKED'
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   238
            while (blockedThread.getState() != Thread.State.BLOCKED)
59021
cfc7bb9a5a92 8232684: Make switch expressions final
jlahoda
parents: 49934
diff changeset
   239
                Thread.yield();
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   240
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   241
            lockingThread.releaseLock();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   242
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   243
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   244
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   245
    private boolean monitorEnter;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   246
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   247
    private boolean monitorEntered;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   248
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   249
    public MonitorEnterExecutor(boolean monitorEnter, boolean monitorEntered) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   250
        this.monitorEnter = monitorEnter;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   251
        this.monitorEntered = monitorEntered;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   252
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   253
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   254
    protected void monitorEnter() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   255
        // locking thread acquires 'this' lock
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   256
        MonitorLockingThread lockingThread = new MonitorLockingThread(this);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   257
        lockingThread.acquireLock();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   258
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   259
        if (monitorEnter) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   260
            DebuggeeEventData.DebugMonitorEnterEventData eventData = new DebuggeeEventData.DebugMonitorEnterEventData(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   261
                    this, Thread.currentThread(), this);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   262
            addEventData(eventData);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   263
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   264
        if (monitorEntered) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   265
            DebuggeeEventData.DebugMonitorEnteredEventData eventData = new DebuggeeEventData.DebugMonitorEnteredEventData(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   266
                    this, Thread.currentThread(), this);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   267
            addEventData(eventData);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   268
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   269
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   270
        /*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   271
         * This thread forces lockingThread to free 'this' lock when current thread's state will change to 'BLOCKED'
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   272
         *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   273
         * NOTE: this method to provoke MonitorContended events isn't 100% robust
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   274
         * Tests should take in account this issue.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   275
         *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   276
         */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   277
        LockFreeThread lockFreeThread = new LockFreeThread(Thread.currentThread(), lockingThread);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   278
        lockFreeThread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   279
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   280
        // try to acquire 'this' lock
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   281
        eventMethod();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   282
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   283
        while(lockingThread.getState() != Thread.State.TERMINATED)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   284
            Thread.yield();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   285
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   286
        while(lockFreeThread.getState() != Thread.State.TERMINATED)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   287
            Thread.yield();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   288
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   289
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   290
    private MonitorAcquireType monitorAcquireType;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   291
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   292
    // generate events in different ways
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   293
    public void doEventAction() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   294
        for (MonitorAcquireType monitorAcquireType : MonitorAcquireType.values()) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   295
            this.monitorAcquireType = monitorAcquireType;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   296
            monitorEnter();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   297
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   298
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   299
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   300
    protected void eventMethod() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   301
        switch (monitorAcquireType) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   302
        case SYNCHRONIZED_BLOCK:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   303
            synchronizedBlock();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   304
            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   305
        case SYNCHRONIZED_METHOD:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   306
            synchronizedMethod();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   307
            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   308
        case JNI_MONITOR_ENTER:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   309
            nativeJNIMonitorEnter();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   310
            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   311
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   312
        default:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   313
            throw new TestBug("Invalid monitorAcquireType: "
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   314
                    + monitorAcquireType);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   315
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   316
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   317
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   318
    // move event actions to the separate methods to simplify method
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   319
    // redifinition in subclasses:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   320
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   321
    protected void synchronizedBlock() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   322
        // MonitorContendedEnterEvent and MonitorContendedEnteredEvent should occur here
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   323
        synchronized (this) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   324
            // don't expect events for following synchronized block
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   325
            synchronized (this) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   326
            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   327
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   328
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   329
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   330
    // MonitorContendedEnterEvent and MonitorContendedEnteredEvent should occur here
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   331
    synchronized protected void synchronizedMethod() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   332
        // don't expect events for following synchronized block
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   333
        synchronized (this) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   334
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   335
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   336
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   337
    // call JNI methods MonitorEnter and MonitorExit for 'this' object
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   338
    protected native void nativeJNIMonitorEnter();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   339
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   340
}
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   341
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   342
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   343
 * Subclass of MonitorEnterExecutor, defines its own event methods(copy of parent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   344
 * method), intended for event filters test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   345
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   346
class MonitorEnterExecutor_1Subclass extends MonitorEnterExecutor {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   347
    static {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   348
        System.loadLibrary(nativeLibararyName);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   349
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   350
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   351
    public MonitorEnterExecutor_1Subclass(boolean monitorEnter,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   352
            boolean monitorEntered) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   353
        super(monitorEnter, monitorEntered);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   354
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   355
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   356
    protected void synchronizedBlock() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   357
        // MonitorContendedEnterEvent and MonitorContendedEnteredEvent should occur here
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   358
        synchronized (this) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   359
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   360
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   361
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   362
    // MonitorContendedEnterEvent and MonitorContendedEnteredEvent should occur here
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   363
    synchronized protected void synchronizedMethod() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   364
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   365
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   366
    // call JNI methods MonitorEnter and MonitorExit for 'this' object
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   367
    protected native void nativeJNIMonitorEnter();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   368
}
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   369
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   370
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   371
 * Subclass of MonitorEnterExecutor, defines its own event methods(copy of parent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   372
 * method), intended for event filters test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   373
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   374
class MonitorEnterExecutor_2Subclass extends MonitorEnterExecutor_1Subclass {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   375
    static {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   376
        System.loadLibrary(nativeLibararyName);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   377
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   378
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   379
    public MonitorEnterExecutor_2Subclass(boolean monitorEnter,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   380
            boolean monitorEntered) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   381
        super(monitorEnter, monitorEntered);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   382
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   383
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   384
    protected void synchronizedBlock() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   385
        // MonitorContendedEnterEvent and MonitorContendedEnteredEvent should occur here
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   386
        synchronized (this) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   387
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   388
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   389
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   390
    // MonitorContendedEnterEvent and MonitorContendedEnteredEvent should occur here
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   391
    synchronized protected void synchronizedMethod() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   392
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   393
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   394
    // call JNI methods MonitorEnter and MonitorExit for 'this' object
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   395
    protected native void nativeJNIMonitorEnter();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   396
}
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   397
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   398
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   399
 * Class is used as base debuggee in tests for following events and event requests:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   400
 * - MonitorContendedEnterRequest / MonitorContendedEnterEvent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   401
 * - MonitorContendedEnteredRequest / MonitorContendedEnteredEvent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   402
 * - MonitorWaitRequest / MonitorWaitEvent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   403
 * - MonitorWaitedRequest / MonitorWaitedEvent
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   404
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   405
public class MonitorEventsDebuggee extends JDIEventsDebuggee {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   406
    public static void main(String[] args) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   407
        MonitorEventsDebuggee debuggee = new MonitorEventsDebuggee();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   408
        debuggee.doTest(args);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   409
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   410
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   411
    protected void createActionsExecutors(String description, int eventsCount) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   412
        boolean monitorEnter = description
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   413
                .contains(JDIEventsDebugger.EventType.MONITOR_CONTENTED_ENTER
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   414
                        .name());
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   415
        boolean monitorEntered = description
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   416
                .contains(JDIEventsDebugger.EventType.MONITOR_CONTENTED_ENTERED
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   417
                        .name());
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   418
        boolean monitorWait = description
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   419
                .contains(JDIEventsDebugger.EventType.MONITOR_WAIT.name());
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   420
        boolean monitorWaited = description
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   421
                .contains(JDIEventsDebugger.EventType.MONITOR_WAITED.name());
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   422
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   423
        if (monitorEnter || monitorEntered || monitorWait || monitorWaited) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   424
            createActionsExecutors(monitorEnter, monitorEntered, monitorWait,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   425
                    monitorWaited, eventsCount);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   426
        } else
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   427
            throw new TestBug(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   428
                    "Invalid command format (required event not specified)");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   429
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   430
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   431
    private List<DebuggeeEventData.DebugMonitorEventData> eventsData = new ArrayList<DebuggeeEventData.DebugMonitorEventData>();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   432
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   433
    protected void clearResults() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   434
        super.clearResults();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   435
        eventsData.clear();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   436
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   437
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   438
    private void createActionsExecutors(boolean monitorEnter,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   439
            boolean monitorEntered, boolean monitorWait, boolean monitorWaited,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   440
            int actionsCount) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   441
        EventActionsThread thread;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   442
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   443
        // create 3 instances of generating objects of 3 different classes (for
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   444
        // event filters tests)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   445
        if (monitorEnter || monitorEntered) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   446
            thread = new EventActionsThread(new MonitorEnterExecutor(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   447
                    monitorEnter, monitorEntered), actionsCount);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   448
            thread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   449
            eventActionsExecutorsPool.add(thread);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   450
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   451
            thread = new EventActionsThread(new MonitorEnterExecutor_1Subclass(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   452
                    monitorEnter, monitorEntered), actionsCount);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   453
            thread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   454
            eventActionsExecutorsPool.add(thread);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   455
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   456
            thread = new EventActionsThread(new MonitorEnterExecutor_2Subclass(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   457
                    monitorEnter, monitorEntered), actionsCount);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   458
            thread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   459
            eventActionsExecutorsPool.add(thread);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   460
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   461
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   462
        // create 3 instances of generating objects of 3 different classes (for
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   463
        // event filters tests)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   464
        if (monitorWait || monitorWaited) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   465
            thread = new EventActionsThread(new MonitorWaitExecutor(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   466
                    monitorWait, monitorWaited), actionsCount);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   467
            thread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   468
            eventActionsExecutorsPool.add(thread);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   469
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   470
            thread = new EventActionsThread(new MonitorWaitExecutor_1Subclass(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   471
                    monitorWait, monitorWaited), actionsCount);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   472
            thread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   473
            eventActionsExecutorsPool.add(thread);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   474
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   475
            thread = new EventActionsThread(new MonitorWaitExecutor_2Subclass(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   476
                    monitorWait, monitorWaited), actionsCount);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   477
            thread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   478
            eventActionsExecutorsPool.add(thread);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   479
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   480
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   481
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   482
    // start event generating threads and wait when all this threads finish
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   483
    // execution
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   484
    // override parent method because of Thread.join() used in parent method
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   485
    // generates unexpected MonitorWait/MonitorWaited events
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   486
    protected void startExecution() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   487
        if (eventActionsExecutorsPool.size() == 0) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   488
            throw new TestBug("ActionsExecutors were not created");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   489
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   490
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   491
        for (EventActionsThread thread : eventActionsExecutorsPool) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   492
            thread.startExecution();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   493
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   494
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   495
        // wait completion of test threads in separate thread to free thread listening commands
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   496
        executionControllingThread = new Thread(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   497
                new Runnable() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   498
                    public void run() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   499
                        boolean executionCompleted;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   500
                        do {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   501
                            try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   502
                                // give time to event generators
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   503
                                Thread.sleep(500);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   504
                            } catch (InterruptedException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   505
                                unexpectedException(e);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   506
                            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   507
                            executionCompleted = true;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   508
                            for (EventActionsThread thread : eventActionsExecutorsPool) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   509
                                if (thread.isAlive()) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   510
                                    executionCompleted = false;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   511
                                    break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   512
                                }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   513
                            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   514
                        } while (!executionCompleted);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   515
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   516
                        completeExecution();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   517
                    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   518
                });
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   519
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   520
        executionControllingThread.start();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   521
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   522
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   523
}