test/hotspot/jtreg/runtime/handshake/HandshakeWalkExitTest.java
author iignatyev
Wed, 17 Jan 2018 21:44:44 -0800
changeset 48791 6e079ff6c83c
parent 48105 8d15b1369c7a
permissions -rw-r--r--
8186635: ClassFileInstaller should be run as a driver Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     1
/*
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     4
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     8
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    13
 * accompanied this code).
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    14
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    18
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    21
 * questions.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    22
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    23
 */
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    24
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    25
/*
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    26
 * @test HandshakeWalkExitTest
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    27
 * @summary This test tries to stress the handshakes with new and exiting threads
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    28
 * @library /testlibrary /test/lib
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    29
 * @build HandshakeWalkExitTest
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 48105
diff changeset
    30
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    31
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI HandshakeWalkExitTest
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    33
 */
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    34
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    35
import jdk.test.lib.Asserts;
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    36
import sun.hotspot.WhiteBox;
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    37
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    38
public class HandshakeWalkExitTest  implements Runnable {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    39
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    40
    @Override
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    41
    public void run() {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    42
    }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    43
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    44
    static volatile boolean exit_now = false;
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    45
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    46
    public static void main(String... args) throws Exception {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47881
diff changeset
    47
        int testRuns = 20;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47881
diff changeset
    48
        int testThreads = 128;
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    49
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    50
        HandshakeWalkExitTest test = new HandshakeWalkExitTest();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    51
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    52
        Runnable hser = new Runnable(){
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    53
            public void run(){
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    54
                WhiteBox wb = WhiteBox.getWhiteBox();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    55
                while(!exit_now) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    56
                    wb.handshakeWalkStack(null, true);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    57
                }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    58
            }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    59
        };
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    60
        Thread hst = new Thread(hser);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    61
        hst.start();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    62
        for (int k = 0; k<testRuns ; k++) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    63
            Thread[] threads = new Thread[testThreads];
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    64
            for (int i = 0; i<threads.length ; i++) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    65
                threads[i] = new Thread(test);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    66
                threads[i].start();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    67
            }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    68
        }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    69
        exit_now = true;
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    70
        hst.join();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    71
    }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    72
}