Hi, Anton. Probably some other fields in the DirectClip should be marked as volatile? For example loopStartFrame/loopEndFrame/ are used in the run() but assigned in the setLoopPoints () w/o any synchronization?(the same setFramePosition +newFramePosition/clipBytePosition)
> > Hello, > > Could you please review the following fix for the bug. > > Bug: https://bugs.openjdk.java.net/browse/JDK-8168751 > Webrev: http://cr.openjdk.java.net/~alitvinov/8168751/jdk9/webrev.00 > > The bug consists in the fact that after many repetitive sequential calls to > the methods "loop()", "stop()" on the same instance of > "java.applet.AudioClip" at some moment two threads with the name "Direct > Clip", which play this "AudioClip" instance, are created and start existing > in parallel, what makes the being played clip sound as corrupted. > > "Direct Clip" thread is represented by the instance variable > "com.sun.media.sound.DirectAudioDevice.DirectClip.thread", is created in the > method "com.sun.media.sound.DirectAudioDevice.DirectClip.open()" and is > stopped by assigning "null" value to "DirectClip.thread" instance variable in > the method "com.sun.media.sound.DirectAudioDevice.DirectClip.implClose()". > > THE DEFINED ROOT CAUSES OF THE BUG: > > 1. The fact that "DirectClip.thread" instance variable is not thread-safe. > There is a possibility that null value assigned to it in one thread through > the former mentioned "DirectClip.implClose()" method does not become visible > for the running "Direct Clip" thread in the method "DirectClip.run()". > > 2. In the method "DirectClip.run()" not taking into account the fact that a > new "Direct Clip" thread could have already been started and assigned to > "DirectClip.thread" instance variable after the call to > "DirectClip.implClose()", by the moment when "DirectClip.thread" value is > checked for null in "DirectClip.run()" method, or by the moment when the > previous "Direct Clip" thread is awakened and continues execution after the > following code block in "DirectClip.run()" from the file > "jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDevice.java". > > 1354 try { > 1355 lock.wait(); > > 1356 } catch(InterruptedException ie) {} > > THE SOLUTION: > The solution is based on correction of the listed above 2 root causes of the > bug. > > Thank you, > Anton
