hotspot/test/compiler/testlibrary/rtm/MemoryConflictProvoker.java
author fzhinkin
Tue, 30 Dec 2014 11:09:42 +0300
changeset 28394 6d382dc493e5
parent 24005 6841a4be0faa
child 39438 206a712f8f16
permissions -rw-r--r--
8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization Reviewed-by: kvn, iignatyev
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
/*
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    25
package rtm;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    26
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    27
import java.util.concurrent.BrokenBarrierException;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    28
import java.util.concurrent.CyclicBarrier;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    29
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    30
/**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    31
 * To force transactional execution abort due to memory conflict
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    32
 * one thread should access memory region from transactional region
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    33
 * while another thread should modify the same memory region.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    34
 * Since this scenario is based on the race condition between threads
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    35
 * you should not expect some particular amount of aborts.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    36
 */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    37
class MemoryConflictProvoker extends AbortProvoker {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    38
    // Following field have to be static in order to avoid escape analysis.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    39
    @SuppressWarnings("UnsuedDeclaration")
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    40
    private static int field = 0;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    41
    private static final int INNER_ITERATIONS = 10000;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    42
    private final CyclicBarrier barrier;
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
     * This thread will access and modify memory region
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    45
     * from outside of the transaction.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    46
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    47
    private final Runnable conflictingThread;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    48
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    49
    public MemoryConflictProvoker() {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    50
        this(new Object());
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
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    53
    public MemoryConflictProvoker(Object monitor) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    54
        super(monitor);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    55
        barrier = new CyclicBarrier(2);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    56
        conflictingThread = () -> {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    57
            try {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    58
                barrier.await();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    59
            } catch (Exception e) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    60
                throw new RuntimeException(e);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    61
            }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    62
            for (int i = 0; i < MemoryConflictProvoker.INNER_ITERATIONS; i++) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    63
                MemoryConflictProvoker.field++;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    64
            }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    65
        };
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    66
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    67
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    68
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    69
     * Accesses and modifies memory region from within the transaction.
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
    public void transactionalRegion() {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    72
        for (int i = 0; i < MemoryConflictProvoker.INNER_ITERATIONS; i++) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    73
            synchronized(monitor) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    74
                MemoryConflictProvoker.field--;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    75
            }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    76
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    77
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    78
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    79
    @Override
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    80
    public void forceAbort() {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    81
        try {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    82
            Thread t = new Thread(conflictingThread);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    83
            t.start();
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    84
            try {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    85
                barrier.await();
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    86
            } catch (InterruptedException | BrokenBarrierException e) {
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    87
                throw new RuntimeException(e);
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
    88
            }
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    89
            transactionalRegion();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    90
            t.join();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    91
        } catch (Exception e) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    92
            throw new RuntimeException(e);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    93
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    94
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    95
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    96
    @Override
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    97
    public String getMethodWithLockName() {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    98
        return this.getClass().getName() + "::transactionalRegion";
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    99
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   100
}