Mercurial > hg > openjdk > jdk8u > jdk
changeset 14432:627f9ae06250
8178403: DirectAudio in JavaSound may hang and leak
Reviewed-by: prr, alitvinov
author | serb |
---|---|
date | Thu, 06 Jul 2017 15:54:39 -0700 |
parents | b36d9a22240e |
children | 01352c9f8c07 |
files | src/share/classes/com/sun/media/sound/DirectAudioDevice.java test/javax/sound/sampled/Clip/ClipCloseLoss.java |
diffstat | 2 files changed, 15 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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<infos.length; i++) { - try { - Mixer m = AudioSystem.getMixer(infos[i]); - run(m); - } catch (Exception e) { + for (int sleep = 0; sleep < 100; ++sleep) { + run(null, sleep); + for (int i = 0; i < infos.length; i++) { + try { + Mixer m = AudioSystem.getMixer(infos[i]); + run(m, sleep); + } catch (Exception e) { + } } } out("Waiting 1 second to dispose of all threads");