hotspot/test/compiler/testlibrary/rtm/AbortProvoker.java
author tpivovarova
Tue, 12 Jul 2016 18:24:48 +0300
changeset 40059 c2304140ed64
parent 39438 206a712f8f16
child 41705 332239c052cc
permissions -rw-r--r--
8132919: Put compiler tests in packages Reviewed-by: vlivanov, dpochepk Contributed-by: igor.ignatyev@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     1
/*
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 28394
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     4
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     8
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    14
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    18
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    21
 * questions.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    22
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    23
 */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    24
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 30604
diff changeset
    25
package compiler.testlibrary.rtm;
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    26
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    27
import jdk.test.lib.Asserts;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    28
import sun.hotspot.WhiteBox;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    29
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    30
import java.util.Objects;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    31
import java.util.concurrent.BrokenBarrierException;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    32
import java.util.concurrent.CyclicBarrier;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    33
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    34
/**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    35
 * Base class for different transactional execution abortion
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    36
 * provokers aimed to force abort due to specified reason.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    37
 */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    38
public abstract class AbortProvoker implements CompilableTest {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    39
    public static final long DEFAULT_ITERATIONS = 10000L;
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    40
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    41
    @SuppressWarnings("unused")
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    42
    private static int sharedState = 0;
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    43
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    44
     * Inflates monitor associated with object {@code monitor}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    45
     * Inflation is forced by entering the same monitor from
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    46
     * two different threads.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    47
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    48
     * @param monitor monitor to be inflated.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    49
     * @return inflated monitor.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    50
     * @throws Exception if something went wrong.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    51
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    52
    public static Object inflateMonitor(Object monitor) throws Exception {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    53
        CyclicBarrier barrier = new CyclicBarrier(2);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    54
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    55
        Runnable inflatingRunnable = () -> {
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    56
            synchronized (monitor) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    57
                try {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    58
                    barrier.await();
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    59
                } catch (BrokenBarrierException  | InterruptedException e) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    60
                    throw new RuntimeException(
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    61
                            "Synchronization issue occurred.", e);
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    62
                }
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    63
                try {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    64
                    monitor.wait();
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    65
                } catch (InterruptedException e) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    66
                    throw new AssertionError("The thread waiting on an"
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    67
                            + " inflated monitor was interrupted, thus test"
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    68
                            + " results may be incorrect.", e);
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    69
                }
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    70
            }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    71
        };
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    72
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    73
        Thread t = new Thread(inflatingRunnable);
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    74
        t.setDaemon(true);
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    75
        t.start();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    76
        // Wait until thread t enters the monitor.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    77
        barrier.await();
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    78
        synchronized (monitor) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    79
            // At this point thread t is already waiting on the monitor.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    80
            // Modifying static field just to avoid lock's elimination.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    81
            sharedState++;
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    82
        }
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    83
        verifyMonitorState(monitor, true /* inflated */);
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    84
        return monitor;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    85
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    86
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    87
    /**
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    88
     * Verifies that {@code monitor} is a stack-lock or inflated lock depending
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    89
     * on {@code shouldBeInflated} value. If {@code monitor} is inflated while
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    90
     * it is expected that it should be a stack-lock, then this method attempts
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    91
     * to deflate it by forcing a safepoint and then verifies the state once
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    92
     * again.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    93
     *
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    94
     * @param monitor monitor to be verified.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    95
     * @param shouldBeInflated flag indicating whether or not monitor is
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    96
     *                         expected to be inflated.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    97
     * @throws RuntimeException if the {@code monitor} in a wrong state.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    98
     */
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    99
    public static void verifyMonitorState(Object monitor,
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   100
            boolean shouldBeInflated) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   101
        if (!shouldBeInflated && WHITE_BOX.isMonitorInflated(monitor)) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   102
            WHITE_BOX.forceSafepoint();
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   103
        }
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   104
        Asserts.assertEQ(WHITE_BOX.isMonitorInflated(monitor), shouldBeInflated,
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   105
                "Monitor in a wrong state.");
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   106
    }
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   107
    /**
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   108
     * Verifies that monitor used by the {@code provoker} is a stack-lock or
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   109
     * inflated lock depending on {@code shouldBeInflated} value. If such
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   110
     * monitor is inflated while it is expected that it should be a stack-lock,
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   111
     * then this method attempts to deflate it by forcing a safepoint and then
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   112
     * verifies the state once again.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   113
     *
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   114
     * @param provoker AbortProvoker whose monitor's state should be verified.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   115
     * @param shouldBeInflated flag indicating whether or not monitor is
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   116
     *                         expected to be inflated.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   117
     * @throws RuntimeException if the {@code monitor} in a wrong state.
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   118
     */
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   119
    public static void verifyMonitorState(AbortProvoker provoker,
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   120
            boolean shouldBeInflated) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   121
        verifyMonitorState(provoker.monitor, shouldBeInflated);
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   122
    }
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   123
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   124
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   125
     * Get instance of specified AbortProvoker, inflate associated monitor
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   126
     * if needed and then invoke forceAbort method in a loop.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   127
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   128
     * Usage:
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   129
     * AbortProvoker <AbortType name> [<inflate monitor&gt
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   130
     * [<iterations> [ <delay>]]]
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   131
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   132
     *  Default parameters are:
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   133
     *  <ul>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   134
     *  <li>inflate monitor = <b>true</b></li>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   135
     *  <li>iterations = {@code AbortProvoker.DEFAULT_ITERATIONS}</li>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   136
     *  <li>delay = <b>0</b></li>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   137
     *  </ul>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   138
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   139
    public static void main(String args[]) throws Throwable {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   140
        Asserts.assertGT(args.length, 0, "At least one argument is required.");
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   141
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   142
        AbortType abortType = AbortType.lookup(Integer.valueOf(args[0]));
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   143
        boolean monitorShouldBeInflated = true;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   144
        long iterations = AbortProvoker.DEFAULT_ITERATIONS;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   145
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   146
        if (args.length > 1) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   147
            monitorShouldBeInflated = Boolean.valueOf(args[1]);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   148
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   149
            if (args.length > 2) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   150
                iterations = Long.valueOf(args[2]);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   151
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   152
                if (args.length > 3) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   153
                    Thread.sleep(Integer.valueOf(args[3]));
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   154
                }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   155
            }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   156
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   157
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   158
        AbortProvoker provoker = abortType.provoker();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   159
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   160
        if (monitorShouldBeInflated) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   161
            provoker.inflateMonitor();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   162
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   163
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   164
        for (long i = 0; i < iterations; i++) {
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   165
            AbortProvoker.verifyMonitorState(provoker, monitorShouldBeInflated);
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   166
            provoker.forceAbort();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   167
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   168
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   169
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   170
    protected final Object monitor;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   171
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   172
    protected AbortProvoker() {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   173
        this(new Object());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   174
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   175
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   176
    protected AbortProvoker(Object monitor) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   177
        this.monitor = Objects.requireNonNull(monitor);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   178
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   179
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   180
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   181
     * Inflates monitor used by this AbortProvoker instance.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   182
     * @throws Exception
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   183
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   184
    public void inflateMonitor() throws Exception {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   185
        AbortProvoker.inflateMonitor(monitor);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   186
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   187
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   188
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   189
     * Forces transactional execution abortion.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   190
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   191
    public abstract void forceAbort();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   192
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   193
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   194
     * Returns names of all methods that have to be compiled
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   195
     * in order to successfully force transactional execution
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   196
     * abortion.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   197
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   198
     * @return array with methods' names that have to be compiled.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   199
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   200
    @Override
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   201
    public String[] getMethodsToCompileNames() {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   202
        return new String[] { getMethodWithLockName() };
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   203
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   204
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   205
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   206
     * Returns name of the method that will contain monitor whose locking
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   207
     * will be elided using transactional execution.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   208
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   209
     * @return name of the method that will contain elided lock.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   210
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   211
    @Override
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   212
    public String getMethodWithLockName() {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   213
        return this.getClass().getName() + "::forceAbort";
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   214
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   215
}