From 54ad5390d068c49d8ce18ddffa213ccfe3200c37 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Thu, 6 Jul 2017 15:54:39 -0700 Subject: [PATCH] 8178403: DirectAudio in JavaSound may hang and leak Reviewed-by: prr, alitvinov --- .../sun/media/sound/DirectAudioDevice.java | 12 ++++------- jdk/test/ProblemList.txt | 2 -- .../sound/sampled/Clip/ClipCloseLoss.java | 21 +++++++++++-------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDevice.java b/jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDevice.java index 414180e6c7f..c1f6b0099b8 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDevice.java +++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDevice.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1351,18 +1351,14 @@ final class DirectAudioDevice extends AbstractMixer { // 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 --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt index e063fe759ea..35c2f21f907 100644 --- a/jdk/test/ProblemList.txt +++ b/jdk/test/ProblemList.txt @@ -223,8 +223,6 @@ sun/security/ssl/X509KeyManager/PreferredKey.java 8176354 generic- # jdk_sound javax/sound/sampled/AudioInputStream/FrameLengthAfterConversion.java 8178401 windows-all -javax/sound/sampled/Clip/ClipCloseLoss.java 8178403 generic-all - javax/sound/sampled/DirectAudio/bug6372428.java 8055097 generic-all javax/sound/sampled/Clip/bug5070081.java 8055097 generic-all javax/sound/sampled/DataLine/LongFramePosition.java 8055097 generic-all diff --git a/jdk/test/javax/sound/sampled/Clip/ClipCloseLoss.java b/jdk/test/javax/sound/sampled/Clip/ClipCloseLoss.java index 56b046163b0..e0adc55afcc 100644 --- a/jdk/test/javax/sound/sampled/Clip/ClipCloseLoss.java +++ b/jdk/test/javax/sound/sampled/Clip/ClipCloseLoss.java @@ -33,10 +33,9 @@ import javax.sound.sampled.Mixer; /** * @test - * @bug 4946913 + * @bug 4946913 8178403 * @summary DirectClip doesn't kill the thread correctly, sometimes * @run main/othervm ClipCloseLoss - * @key intermittent */ public class ClipCloseLoss { static int frameCount = 441000; // lets say 10 seconds @@ -47,7 +46,7 @@ public class ClipCloseLoss { 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 +68,8 @@ public class ClipCloseLoss { 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 +108,15 @@ public class ClipCloseLoss { 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