hotspot/test/compiler/6772683/InterruptedTest.java
author iveresov
Thu, 18 Sep 2014 08:32:12 +0000
changeset 26800 ed8ab32a293d
parent 5547 f4b087cbb361
permissions -rw-r--r--
Merge
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
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
     2
 * Copyright (c) 2008, 2009, 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
/*
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    26
 * @test
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    27
 * @bug 6772683
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    28
 * @summary Thread.isInterrupted() fails to return true on multiprocessor PC
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    29
 * @run main/othervm InterruptedTest
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
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    32
public class InterruptedTest {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    33
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    34
    public static void main(String[] args) throws Exception {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    35
        Thread workerThread = new Thread("worker") {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    36
            public void run() {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    37
                System.out.println("Worker thread: running...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    38
                while (!Thread.currentThread().isInterrupted()) {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    39
                }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    40
                System.out.println("Worker thread: bye");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    41
            }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    42
        };
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    43
        System.out.println("Main thread: starts a worker thread...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    44
        workerThread.start();
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    45
        System.out.println("Main thread: waits at most 5s for the worker thread to die...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    46
        workerThread.join(5000); // Wait 5 sec to let run() method to be compiled
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    47
        int ntries = 0;
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    48
        while (workerThread.isAlive() && ntries < 5) {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    49
            System.out.println("Main thread: interrupts the worker thread...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    50
            workerThread.interrupt();
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    51
            if (workerThread.isInterrupted()) {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    52
                System.out.println("Main thread: worker thread is interrupted");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    53
            }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    54
            ntries++;
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    55
            System.out.println("Main thread: waits for the worker thread to die...");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    56
            workerThread.join(1000); // Wait 1 sec and try again
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    57
        }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    58
        if (ntries == 5) {
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    59
          System.out.println("Main thread: the worker thread dod not die");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    60
          System.exit(97);
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    61
        }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    62
        System.out.println("Main thread: bye");
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    63
    }
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    64
cb263b90c794 6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
kvn
parents:
diff changeset
    65
}