Monitor_notowner01.java revision 13431:fa2686ded3a7
1264391Snwhitehorn/* 2264391Snwhitehorn * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. 3264391Snwhitehorn * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4264391Snwhitehorn * 5264391Snwhitehorn * This code is free software; you can redistribute it and/or modify it 6264404Snwhitehorn * under the terms of the GNU General Public License version 2 only, as 7264404Snwhitehorn * published by the Free Software Foundation. 8264391Snwhitehorn * 9264391Snwhitehorn * This code is distributed in the hope that it will be useful, but WITHOUT 10264391Snwhitehorn * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11264391Snwhitehorn * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12264391Snwhitehorn * version 2 for more details (a copy is included in the LICENSE file that 13264391Snwhitehorn * accompanied this code). 14264391Snwhitehorn * 15264391Snwhitehorn * You should have received a copy of the GNU General Public License version 16264391Snwhitehorn * 2 along with this work; if not, write to the Free Software Foundation, 17264391Snwhitehorn * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18264391Snwhitehorn * 19264391Snwhitehorn * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20264391Snwhitehorn * or visit www.oracle.com if you need additional information or have any 21264391Snwhitehorn * questions. 22264391Snwhitehorn */ 23264391Snwhitehorn/* 24264391Snwhitehorn */ 25264391Snwhitehornpackage org.graalvm.compiler.jtt.threads; 26264391Snwhitehorn 27264391Snwhitehornimport org.graalvm.compiler.jtt.JTTTest; 28264391Snwhitehornimport org.graalvm.compiler.jtt.hotspot.NotOnDebug; 29271762Semasteimport org.junit.Rule; 30264391Snwhitehornimport org.junit.Test; 31264391Snwhitehornimport org.junit.rules.TestRule; 32264391Snwhitehornimport org.junit.rules.Timeout; 33264391Snwhitehorn 34264391Snwhitehornpublic class Monitor_notowner01 extends JTTTest { 35264391Snwhitehorn 36264391Snwhitehorn @Rule public TestRule timeout = NotOnDebug.create(Timeout.seconds(20)); 37264391Snwhitehorn 38264391Snwhitehorn static Object monitor = new Object(); 39264391Snwhitehorn static Object finished = new Object(); 40264391Snwhitehorn 41264391Snwhitehorn public static boolean test() throws InterruptedException { 42264391Snwhitehorn final BadRunnable badRunnable = new BadRunnable(); 43264391Snwhitehorn synchronized (monitor) { 44264391Snwhitehorn new Thread(badRunnable).start(); 45264391Snwhitehorn synchronized (finished) { 46264391Snwhitehorn finished.wait(1000); 47264391Snwhitehorn } 48264391Snwhitehorn } 49264391Snwhitehorn return badRunnable.caught; 50264391Snwhitehorn } 51264391Snwhitehorn 52264391Snwhitehorn static class BadRunnable implements Runnable { 53264391Snwhitehorn 54264391Snwhitehorn protected boolean caught = false; 55264391Snwhitehorn 56264391Snwhitehorn @Override 57264391Snwhitehorn public void run() { 58264391Snwhitehorn try { 59264391Snwhitehorn // we don't own this! 60264391Snwhitehorn monitor.wait(); 61264391Snwhitehorn } catch (InterruptedException ex) { 62264391Snwhitehorn 63264391Snwhitehorn } catch (IllegalMonitorStateException ex) { 64264391Snwhitehorn caught = true; 65264391Snwhitehorn synchronized (finished) { 66264391Snwhitehorn finished.notifyAll(); 67264391Snwhitehorn } 68264391Snwhitehorn } 69264391Snwhitehorn } 70264391Snwhitehorn } 71264391Snwhitehorn 72264391Snwhitehorn @Test 73264391Snwhitehorn public void run0() throws Throwable { 74264391Snwhitehorn initializeForTimeout(); 75264391Snwhitehorn runTest("test"); 76264391Snwhitehorn } 77264391Snwhitehorn 78264391Snwhitehorn} 79264391Snwhitehorn