6772683: Thread.isInterrupted() fails to return true on multiprocessor PC

Thu, 21 May 2009 10:05:36 -0700

author
kvn
date
Thu, 21 May 2009 10:05:36 -0700
changeset 1222
aabd393cf1ee
parent 1221
27d660246893
child 1223
1851e1fb420e

6772683: Thread.isInterrupted() fails to return true on multiprocessor PC
Summary: Set the control edge for the field _interrupted load in inline_native_isInterrupted().
Reviewed-by: never

src/share/vm/opto/library_call.cpp file | annotate | diff | comparison | revisions
test/compiler/6772683/InterruptedTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/opto/library_call.cpp	Fri May 15 18:14:44 2009 -0700
     1.2 +++ b/src/share/vm/opto/library_call.cpp	Thu May 21 10:05:36 2009 -0700
     1.3 @@ -2593,7 +2593,8 @@
     1.4    Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
     1.5    Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS);
     1.6    p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset()));
     1.7 -  Node* int_bit = make_load(NULL, p, TypeInt::BOOL, T_INT);
     1.8 +  // Set the control input on the field _interrupted read to prevent it floating up.
     1.9 +  Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT);
    1.10    Node* cmp_bit = _gvn.transform( new (C, 3) CmpINode(int_bit, intcon(0)) );
    1.11    Node* bol_bit = _gvn.transform( new (C, 2) BoolNode(cmp_bit, BoolTest::ne) );
    1.12  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/6772683/InterruptedTest.java	Thu May 21 10:05:36 2009 -0700
     2.3 @@ -0,0 +1,65 @@
     2.4 +/*
     2.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + *
    2.26 + */
    2.27 +
    2.28 +/*
    2.29 + * @test
    2.30 + * @bug 6772683
    2.31 + * @summary Thread.isInterrupted() fails to return true on multiprocessor PC
    2.32 + * @run main/othervm InterruptedTest
    2.33 + */
    2.34 +
    2.35 +public class InterruptedTest {
    2.36 +
    2.37 +    public static void main(String[] args) throws Exception {
    2.38 +        Thread workerThread = new Thread("worker") {
    2.39 +            public void run() {
    2.40 +                System.out.println("Worker thread: running...");
    2.41 +                while (!Thread.currentThread().isInterrupted()) {
    2.42 +                }
    2.43 +                System.out.println("Worker thread: bye");
    2.44 +            }
    2.45 +        };
    2.46 +        System.out.println("Main thread: starts a worker thread...");
    2.47 +        workerThread.start();
    2.48 +        System.out.println("Main thread: waits at most 5s for the worker thread to die...");
    2.49 +        workerThread.join(5000); // Wait 5 sec to let run() method to be compiled
    2.50 +        int ntries = 0;
    2.51 +        while (workerThread.isAlive() && ntries < 5) {
    2.52 +            System.out.println("Main thread: interrupts the worker thread...");
    2.53 +            workerThread.interrupt();
    2.54 +            if (workerThread.isInterrupted()) {
    2.55 +                System.out.println("Main thread: worker thread is interrupted");
    2.56 +            }
    2.57 +            ntries++;
    2.58 +            System.out.println("Main thread: waits for the worker thread to die...");
    2.59 +            workerThread.join(1000); // Wait 1 sec and try again
    2.60 +        }
    2.61 +        if (ntries == 5) {
    2.62 +          System.out.println("Main thread: the worker thread dod not die");
    2.63 +          System.exit(97);
    2.64 +        }
    2.65 +        System.out.println("Main thread: bye");
    2.66 +    }
    2.67 +
    2.68 +}

mercurial