# HG changeset patch # User serb # Date 1499381679 25200 # Node ID 627f9ae062502a6ab2305924e920e42403c47287 # Parent b36d9a22240e0d166bb5bc9b4bcc9cae17a22d91 8178403: DirectAudio in JavaSound may hang and leak Reviewed-by: prr, alitvinov diff -r b36d9a22240e -r 627f9ae06250 src/share/classes/com/sun/media/sound/DirectAudioDevice.java --- a/src/share/classes/com/sun/media/sound/DirectAudioDevice.java Wed Jun 26 15:34:13 2019 -0700 +++ b/src/share/classes/com/sun/media/sound/DirectAudioDevice.java Thu Jul 06 15:54:39 2017 -0700 @@ -1379,18 +1379,14 @@ // pre-empted while another thread changes doIO and notifies, // before we wait (so we sleep in wait forever). synchronized(lock) { - if (!doIO) { + while (!doIO && thread == curThread) { try { lock.wait(); - } catch(InterruptedException ie) { - } finally { - if (thread != curThread) { - break; - } + } catch (InterruptedException ignored) { } } } - while (doIO) { + while (doIO && thread == curThread) { if (newFramePosition >= 0) { clipBytePosition = newFramePosition * frameSize; newFramePosition = -1; diff -r b36d9a22240e -r 627f9ae06250 test/javax/sound/sampled/Clip/ClipCloseLoss.java --- a/test/javax/sound/sampled/Clip/ClipCloseLoss.java Wed Jun 26 15:34:13 2019 -0700 +++ b/test/javax/sound/sampled/Clip/ClipCloseLoss.java Thu Jul 06 15:54:39 2017 -0700 @@ -33,7 +33,7 @@ /** * @test - * @bug 4946913 + * @bug 4946913 8178403 * @summary DirectClip doesn't kill the thread correctly, sometimes * @run main/othervm ClipCloseLoss * @key headful @@ -47,7 +47,7 @@ static int success = 0; static boolean failed = false; - public static void run(Mixer m) { + public static void run(Mixer m, long sleep) { Clip clip = null; try { if (m == null) { @@ -69,6 +69,8 @@ clip.open(new AudioInputStream(bais, format, frameCount)); out(" clip.close()"); + // emulates a different delay between open() and close() + Thread.sleep(sleep); //long t = System.currentTimeMillis(); clip.close(); //if (System.currentTimeMillis() - t > 1950) { @@ -107,13 +109,15 @@ public static void main(String[] args) throws Exception { if (isSoundcardInstalled()) { bais.mark(0); - run(null); Mixer.Info[] infos = AudioSystem.getMixerInfo(); - for (int i = 0; i