Removed call to Runtime.getRuntime().gc() every 10 frames, added call to Reference.clear() when an object is explicitly deleted.

fix-456
Sebastian Weiß 7 years ago
parent 6785087057
commit 28e4c9848f
  1. 16
      jme3-core/src/main/java/com/jme3/opencl/OpenCLObjectManager.java

@ -45,10 +45,6 @@ public class OpenCLObjectManager {
private static final Logger LOG = Logger.getLogger(OpenCLObjectManager.class.getName()); private static final Logger LOG = Logger.getLogger(OpenCLObjectManager.class.getName());
private static final Level LOG_LEVEL1 = Level.FINER; private static final Level LOG_LEVEL1 = Level.FINER;
private static final Level LOG_LEVEL2 = Level.FINE; private static final Level LOG_LEVEL2 = Level.FINE;
/**
* Call Runtime.getRuntime().gc() every these frames
*/
private static final int GC_FREQUENCY = 10;
private static final OpenCLObjectManager INSTANCE = new OpenCLObjectManager(); private static final OpenCLObjectManager INSTANCE = new OpenCLObjectManager();
private OpenCLObjectManager() {} private OpenCLObjectManager() {}
@ -59,7 +55,6 @@ public class OpenCLObjectManager {
private ReferenceQueue<Object> refQueue = new ReferenceQueue<Object>(); private ReferenceQueue<Object> refQueue = new ReferenceQueue<Object>();
private HashSet<OpenCLObjectRef> activeObjects = new HashSet<OpenCLObjectRef>(); private HashSet<OpenCLObjectRef> activeObjects = new HashSet<OpenCLObjectRef>();
private int gcCounter = 0;
private static class OpenCLObjectRef extends PhantomReference<Object> { private static class OpenCLObjectRef extends PhantomReference<Object> {
@ -80,6 +75,7 @@ public class OpenCLObjectManager {
private void deleteObject(OpenCLObjectRef ref) { private void deleteObject(OpenCLObjectRef ref) {
LOG.log(LOG_LEVEL1, "deleting OpenCL object by: {0}", ref.releaser); LOG.log(LOG_LEVEL1, "deleting OpenCL object by: {0}", ref.releaser);
ref.releaser.release(); ref.releaser.release();
ref.clear();
activeObjects.remove(ref); activeObjects.remove(ref);
} }
@ -89,15 +85,6 @@ public class OpenCLObjectManager {
return; //nothing to do return; //nothing to do
} }
gcCounter++;
if (gcCounter >= GC_FREQUENCY) {
//The program is that the OpenCLObjects are so small that they are
//enqueued for finalization very late. Therefore, without this
//hack, we are running out of host memory on the OpenCL side quickly.
gcCounter = 0;
Runtime.getRuntime().gc();
}
int removed = 0; int removed = 0;
while (true) { while (true) {
// Remove objects reclaimed by GC. // Remove objects reclaimed by GC.
@ -117,6 +104,7 @@ public class OpenCLObjectManager {
for (OpenCLObjectRef ref : activeObjects) { for (OpenCLObjectRef ref : activeObjects) {
LOG.log(LOG_LEVEL1, "deleting OpenCL object by: {0}", ref.releaser); LOG.log(LOG_LEVEL1, "deleting OpenCL object by: {0}", ref.releaser);
ref.releaser.release(); ref.releaser.release();
ref.clear();
} }
activeObjects.clear(); activeObjects.clear();
} }

Loading…
Cancel
Save