test/hotspot/jtreg/compiler/c2/InterruptedTest.java
author jiangli
Fri, 02 Nov 2018 19:30:31 -0400
changeset 52397 1322829d1501
parent 47216 71c04702a3d5
permissions -rw-r--r--
8209564: runtime/appcds/CDSandJFR.java timeout on tier6 on sparc Summary: Set timeout 500 in CDSandJFR.java Reviewed-by: dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     1
/*
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
     2
 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     4
 *
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     8
 *
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    13
 * accompanied this code).
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    14
 *
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    22
 */
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    23
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    24
/*
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    25
 * @test
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    26
 * @bug 6772683
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    27
 * @summary Thread.isInterrupted() fails to return true on multiprocessor PC
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35562
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35562
diff changeset
    29
 * @run main/othervm compiler.c2.InterruptedTest 100
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    30
 */
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    31
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35562
diff changeset
    32
package compiler.c2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35562
diff changeset
    33
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    34
public class InterruptedTest {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    35
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    36
    public static void main(String[] args) throws Exception {
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    37
        /* The value of the threshold determines for how many seconds
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    38
         * the main thread must wait for the worker thread. On highly
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    39
         * loaded systems it can take a while until the worker thread
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    40
         * obtains CPU time and is able to check if it was interrupted
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    41
         * by the main thread. The higher the threshold the likelier
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    42
         * the worker thread can check if it was interrupted (that is
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    43
         * required for successul test execution).
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    44
         */
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    45
        int threshold = 100;
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    46
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    47
        if (args.length != 1) {
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    48
            System.out.println("Incorrect number of arguments");
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    49
            System.exit(1);
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    50
        }
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    51
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    52
        try {
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    53
            threshold = Integer.parseInt(args[0]);
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    54
        } catch (NumberFormatException e) {
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    55
            System.out.println("Invalid argument format");
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    56
            System.exit(1);
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    57
        }
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    58
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    59
        if (threshold < 1) {
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    60
            System.out.println("Threshold must be at least 1");
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    61
            System.exit(1);
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    62
        }
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    63
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    64
        Thread workerThread = new Thread("worker") {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    65
            public void run() {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    66
                System.out.println("Worker thread: running...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    67
                while (!Thread.currentThread().isInterrupted()) {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    68
                }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    69
                System.out.println("Worker thread: bye");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    70
            }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    71
        };
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    72
        System.out.println("Main thread: starts a worker thread...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    73
        workerThread.start();
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    74
        System.out.println("Main thread: waits 5 seconds after starting the worker thread");
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    75
        workerThread.join(5000); // Wait 5 sec to let run() method to be compiled
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    76
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    77
        int ntries = 0;
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    78
        while (workerThread.isAlive() && ntries < threshold) {
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    79
            System.out.println("Main thread: interrupts the worker thread...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    80
            workerThread.interrupt();
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    81
            if (workerThread.isInterrupted()) {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    82
                System.out.println("Main thread: worker thread is interrupted");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    83
            }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    84
            ntries++;
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    85
            System.out.println("Main thread: waits 1 second for the worker thread to die...");
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    86
            workerThread.join(1000); // Wait 1 sec and try again
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    87
        }
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    88
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    89
        if (ntries == threshold) {
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    90
          System.out.println("Main thread: the worker thread did not die after " +
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    91
                             ntries + " seconds have elapsed");
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    92
          System.exit(97);
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    93
        }
35562
16a8e33e995c 8071864: compiler/c2/6772683/InterruptedTest.java failed in nightly
zmajo
parents: 27699
diff changeset
    94
2874
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    95
        System.out.println("Main thread: bye");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    96
    }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    97
}