Freeze after Termination (OpenGL/CL interoperation)

Started by Jens, January 02, 2012, 14:39:20

Previous topic - Next topic

Jens

My Program shall render the results of an OpenCL-computation using a custom shader.
It works quite well, until the thread terminates.
After thread termination java keeps running. (at 50%CPU on a dual-core !!!)

Here some code, which reproduces the freeze:
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opencl.CL10.*;

import org.lwjgl.opengl.*;
import org.lwjgl.opencl.*;

public class Program {

	public static void main(String[] args) throws Exception {
		Display.create();
		CL.create();
		
		CLPlatform platform = CLPlatform.getPlatforms().get(0);
		Drawable drawable = Display.getDrawable();

		CLContext clContext = CLContext.createFromType(platform, CL_DEVICE_TYPE_GPU, null, drawable, null);
		
		clReleaseContext(clContext);
		
		CL.destroy();
		
		int vshader = glCreateShader(GL_VERTEX_SHADER);
		glCompileShader(vshader);
		
		glDeleteShader(vshader);
		
		Display.destroy();
		System.out.println("The End");
	}
}


"The End" is printed, but the javaw.exe keeps running.
If i comment out the clContext creation or the shader compilation, the Program terminates normally.

I am using:
windows 7 (64bit)
java 7 (64bit)
lwjgl 2.8.2

Intel Pentium Dual-Core CPU
ATI Mobility Radeon HD 4300 Series graphics card

I am clueless, so i hope you can help me.

Matzon

Try to do a thread dump to see which threads are running. But it does indeed sound wrong.

Jens

While frozen i can't do a thread dump.
I added a System.in.read() at the end and did a dump, while waiting for input.
Full thread dump Java HotSpot(TM) 64-Bit Server VM (21.0-b17 mixed mode):

"Service Thread" daemon prio=6 tid=0x0000000005978800 nid=0x1cd8 runnable [0x000
0000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" daemon prio=10 tid=0x000000000596d000 nid=0x251c waiting on
 condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" daemon prio=10 tid=0x0000000005967000 nid=0x2658 waiting on
 condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x000000000595e800 nid=0x26f8 runnable [0x0
000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x000000000595d000 nid=0x2320 waiting on
condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x00000000058db000 nid=0x2848 in Object.wait() [0x
00000000062bf000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000000eaab5628> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x00000000eaab5628> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x00000000058d1000 nid=0x2a50 in Object.w
ait() [0x000000000614f000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000000eaab51a8> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:503)
        at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
        - locked <0x00000000eaab51a8> (a java.lang.ref.Reference$Lock)

"main" prio=6 tid=0x0000000001f9b000 nid=0x2654 runnable [0x000000000237f000]
   java.lang.Thread.State: RUNNABLE
        at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
        at sun.nio.cs.StreamEncoder.flushBuffer(Unknown Source)
        - locked <0x00000000eaabf448> (a java.io.OutputStreamWriter)
        at java.io.OutputStreamWriter.flushBuffer(Unknown Source)
        at java.io.PrintStream.write(Unknown Source)
        - locked <0x00000000eaabf1d8> (a java.io.PrintStream)
        at java.io.PrintStream.print(Unknown Source)
        at java.io.PrintStream.println(Unknown Source)
        - locked <0x00000000eaabf1d8> (a java.io.PrintStream)
        at Program.main(Program.java:30)

"VM Thread" prio=10 tid=0x00000000058c9800 nid=0x2b78 runnable

"GC task thread#0 (ParallelGC)" prio=6 tid=0x0000000001e37000 nid=0x29c0 runnabl
e

"GC task thread#1 (ParallelGC)" prio=6 tid=0x0000000001e38800 nid=0x29a4 runnabl
e

"VM Periodic Task Thread" prio=10 tid=0x0000000005981800 nid=0x1888 waiting on c
ondition

JNI global references: 244

Heap
The End PSYoungGen      total 19136K, used 4515K
 [0x00000000eaab0000, 0x00000000ec000000, 0x0000000100000000)
  eden space 16448K, 27% used [0x00000000eaab0000,0x00000000eaf6b400,0x00000000e
bac0000)
  from space 2688K, 0% used [0x00000000ebd60000,0x00000000ebd60000,0x00000000ec0
00000)
  to   space 2688K, 0% used [0x00000000ebac0000,0x00000000ebac0000,0x00000000ebd
60000)
 PSOldGen        total 43712K, used 0K [0x00000000c0000000, 0x00000000c2ab0000,
0x00000000eaab0000)
  object space 43712K, 0% used [0x00000000c0000000,0x00000000c0000000,0x00000000
c2ab0000)
 PSPermGen       total 21248K, used 4441K [0x00000000bae00000, 0x00000000bc2c000
0, 0x00000000c0000000)
  object space 21248K, 20% used [0x00000000bae00000,0x00000000bb256700,0x0000000
0bc2c0000)


I tried it with the lines commented out, but both look the same.