# HG changeset patch # User Jaroslav Tulach # Date 1379420730 -7200 # Node ID 456e2909bd5ad680873432b364561d5c11978d72 # Parent 3fc5a6900ecf04878335c0503c027d6820913402 #5368: Provide some implementation of wait and notify diff -r 3fc5a6900ecf -r 456e2909bd5a rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/NotifyWaitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/NotifyWaitTest.java Tue Sep 17 14:25:30 2013 +0200 @@ -0,0 +1,62 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.tck; + +import org.apidesign.bck2brwsr.vmtest.BrwsrTest; +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +/** + * + * @author Jaroslav Tulach + */ +public class NotifyWaitTest { + + @Compare public synchronized String canCallNotify() throws Exception { + notify(); + return "OK"; + } + + @Compare public synchronized String canCallNotifyAll() throws Exception { + notifyAll(); + return "OK"; + } + + @BrwsrTest public synchronized String throwsInterruptedException() { + try { + wait(); + throw new IllegalStateException(); + } catch (InterruptedException ex) { + return "OK"; + } + } + + @BrwsrTest public synchronized String waitMsThrowsInterruptedException() { + try { + wait(32); + throw new IllegalStateException(); + } catch (InterruptedException ex) { + return "OK"; + } + } + + @Factory public static Object[] create() { + return VMTest.create(NotifyWaitTest.class); + } +} diff -r 3fc5a6900ecf -r 456e2909bd5a rt/emul/mini/src/main/java/java/lang/Object.java --- a/rt/emul/mini/src/main/java/java/lang/Object.java Tue Sep 17 14:02:59 2013 +0200 +++ b/rt/emul/mini/src/main/java/java/lang/Object.java Tue Sep 17 14:25:30 2013 +0200 @@ -328,7 +328,8 @@ * @see java.lang.Object#notifyAll() * @see java.lang.Object#wait() */ - public final native void notify(); + public final void notify() { + } /** * Wakes up all threads that are waiting on this object's monitor. A @@ -352,7 +353,8 @@ * @see java.lang.Object#notify() * @see java.lang.Object#wait() */ - public final native void notifyAll(); + public final void notifyAll() { + } /** * Causes the current thread to wait until either another thread invokes the @@ -439,7 +441,9 @@ * @see java.lang.Object#notify() * @see java.lang.Object#notifyAll() */ - public final native void wait(long timeout) throws InterruptedException; + public final void wait(long timeout) throws InterruptedException { + throw new InterruptedException(); + } /** * Causes the current thread to wait until another thread invokes the @@ -504,20 +508,7 @@ * this exception is thrown. */ public final void wait(long timeout, int nanos) throws InterruptedException { - if (timeout < 0) { - throw new IllegalArgumentException("timeout value is negative"); - } - - if (nanos < 0 || nanos > 999999) { - throw new IllegalArgumentException( - "nanosecond timeout value out of range"); - } - - if (nanos >= 500000 || (nanos != 0 && timeout == 0)) { - timeout++; - } - - wait(timeout); + throw new InterruptedException(); } /** @@ -559,7 +550,7 @@ * @see java.lang.Object#notifyAll() */ public final void wait() throws InterruptedException { - wait(0); + throw new InterruptedException(); } /**