SynchronizedLoopExit01.java revision 12651:6ef01bd40ce2
1290001Sglebius/* 2290001Sglebius * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3290001Sglebius * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4290001Sglebius * 5290001Sglebius * This code is free software; you can redistribute it and/or modify it 6290001Sglebius * under the terms of the GNU General Public License version 2 only, as 7290001Sglebius * published by the Free Software Foundation. 8290001Sglebius * 9290001Sglebius * This code is distributed in the hope that it will be useful, but WITHOUT 10290001Sglebius * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11290001Sglebius * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12290001Sglebius * version 2 for more details (a copy is included in the LICENSE file that 13310419Sdelphij * accompanied this code). 14290001Sglebius * 15310419Sdelphij * You should have received a copy of the GNU General Public License version 16290001Sglebius * 2 along with this work; if not, write to the Free Software Foundation, 17310419Sdelphij * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18290001Sglebius * 19290001Sglebius * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20290001Sglebius * or visit www.oracle.com if you need additional information or have any 21290001Sglebius * questions. 22290001Sglebius */ 23290001Sglebius/* 24290001Sglebius */ 25290001Sglebiuspackage org.graalvm.compiler.jtt.threads; 26290001Sglebius 27290001Sglebiusimport org.junit.Test; 28290001Sglebius 29290001Sglebiusimport org.graalvm.compiler.jtt.JTTTest; 30290001Sglebius 31290001Sglebius/** 32290001Sglebius * Inspired by {@code com.sun.media.sound.DirectAudioDevice$DirectDL.drain()}. 33290001Sglebius * 34290001Sglebius * Two loop exits hold a monitor while merging. 35290001Sglebius * 36290001Sglebius */ 37290001Sglebiuspublic final class SynchronizedLoopExit01 extends JTTTest { 38290001Sglebius 39290001Sglebius protected Object object = new Object(); 40290001Sglebius protected volatile boolean drained = false; 41290001Sglebius protected volatile boolean someBoolean = true; 42290001Sglebius 43290001Sglebius public boolean test() { 44290001Sglebius boolean b = true; 45290001Sglebius while (!drained) { 46290001Sglebius synchronized (object) { 47290001Sglebius boolean c = b = someBoolean; 48290001Sglebius if (c || drained) { 49290001Sglebius break; 50290001Sglebius } 51290001Sglebius } 52290001Sglebius } 53290001Sglebius return b; 54290001Sglebius } 55290001Sglebius 56290001Sglebius @Test(timeout = 20000) 57290001Sglebius public void run0() throws Throwable { 58290001Sglebius runTest("test"); 59290001Sglebius } 60290001Sglebius 61290001Sglebius} 62290001Sglebius