From 75fbdf21fc3d5feffa49d3cca0f3566156b40626 Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Date: Wed, 12 Jun 2024 16:17:53 +0200 Subject: [PATCH] Remove unused bufferutils --- .../pipeline/arrays/ArrayDrawEdgeData.java | 8 +- .../pipeline/arrays/ArrayDrawNodeData.java | 11 +- .../pipeline/common/AbstractNodeData.java | 3 - .../pipeline/indirect/IndirectNodeData.java | 12 +- .../pipeline/instanced/InstancedEdgeData.java | 9 +- .../pipeline/instanced/InstancedNodeData.java | 15 +- .../engine/jogl/util/ManagedDirectBuffer.java | 5 +- .../viz/engine/jogl/util/gl/BufferUtils.java | 337 ------------------ .../jogl/util/gl/GLVertexArrayObject.java | 2 - 9 files changed, 9 insertions(+), 393 deletions(-) delete mode 100644 modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/BufferUtils.java diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawEdgeData.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawEdgeData.java index 9876df3..08de060 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawEdgeData.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawEdgeData.java @@ -7,7 +7,7 @@ import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.util.GLBuffers; import java.nio.FloatBuffer; -import java.nio.IntBuffer; + import org.gephi.graph.api.Edge; import org.gephi.graph.api.Graph; import org.gephi.viz.engine.VizEngine; @@ -17,11 +17,9 @@ import org.gephi.viz.engine.jogl.pipeline.common.AbstractEdgeData; import org.gephi.viz.engine.status.GraphRenderingOptions; import org.gephi.viz.engine.status.GraphSelection; -import org.gephi.viz.engine.structure.GraphIndex; import org.gephi.viz.engine.structure.GraphIndexImpl; import org.gephi.viz.engine.util.ArrayUtils; import org.gephi.viz.engine.jogl.util.ManagedDirectBuffer; -import org.gephi.viz.engine.jogl.util.gl.BufferUtils; import org.gephi.viz.engine.jogl.util.gl.GLBufferMutable; /** @@ -172,8 +170,6 @@ protected void initBuffers(GL gl) { vertexGLBufferUndirected.bind(gl); vertexGLBufferUndirected.init(gl, undirectedVertexData, GLBufferMutable.GL_BUFFER_USAGE_STATIC_DRAW); vertexGLBufferUndirected.unbind(gl); - - //BufferUtils.destroyDirectBuffer(undirectedVertexData); } { @@ -188,8 +184,6 @@ protected void initBuffers(GL gl) { vertexGLBufferDirected.bind(gl); vertexGLBufferDirected.init(gl, directedVertexData, GLBufferMutable.GL_BUFFER_USAGE_STATIC_DRAW); vertexGLBufferDirected.unbind(gl); - - //BufferUtils.destroyDirectBuffer(directedVertexData); } //Initialize for batch edges size: diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawNodeData.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawNodeData.java index 2a41f09..2692e31 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawNodeData.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/arrays/ArrayDrawNodeData.java @@ -1,24 +1,17 @@ package org.gephi.viz.engine.jogl.pipeline.arrays; import com.jogamp.opengl.GL; -import static com.jogamp.opengl.GL.GL_FLOAT; import com.jogamp.opengl.GL2ES2; -import com.jogamp.opengl.util.GLBuffers; + import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import org.gephi.graph.api.Node; + import org.gephi.viz.engine.VizEngine; -import org.gephi.viz.engine.jogl.models.NodeDiskModel; import org.gephi.viz.engine.pipeline.RenderingLayer; import org.gephi.viz.engine.jogl.pipeline.common.AbstractNodeData; -import org.gephi.viz.engine.pipeline.common.InstanceCounter; import org.gephi.viz.engine.status.GraphRenderingOptions; import org.gephi.viz.engine.status.GraphSelection; import org.gephi.viz.engine.structure.GraphIndexImpl; import static org.gephi.viz.engine.util.gl.Constants.*; -import org.gephi.viz.engine.jogl.util.ManagedDirectBuffer; -import org.gephi.viz.engine.jogl.util.gl.BufferUtils; -import org.gephi.viz.engine.jogl.util.gl.GLBufferMutable; /** * diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractNodeData.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractNodeData.java index 0586356..6991065 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractNodeData.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractNodeData.java @@ -13,7 +13,6 @@ import org.gephi.viz.engine.jogl.models.NodeDiskModel; import org.gephi.viz.engine.jogl.models.NodeDiskVertexDataGenerator; import org.gephi.viz.engine.jogl.util.ManagedDirectBuffer; -import org.gephi.viz.engine.jogl.util.gl.BufferUtils; import org.gephi.viz.engine.jogl.util.gl.GLBufferMutable; import org.gephi.viz.engine.pipeline.RenderingLayer; import org.gephi.viz.engine.pipeline.common.InstanceCounter; @@ -152,8 +151,6 @@ protected void initCirclesGLVertexBuffer(GL gl, final int bufferName) { vertexGLBuffer.bind(gl); vertexGLBuffer.init(gl, circleVertexBuffer, GL_BUFFER_USAGE_STATIC_DRAW); vertexGLBuffer.unbind(gl); - - //BufferUtils.destroyDirectBuffer(circleVertexBuffer); } protected int setupShaderProgramForRenderingLayer(final GL2ES2 gl, diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/indirect/IndirectNodeData.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/indirect/IndirectNodeData.java index e01eae7..31c29ad 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/indirect/IndirectNodeData.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/indirect/IndirectNodeData.java @@ -1,25 +1,17 @@ package org.gephi.viz.engine.jogl.pipeline.indirect; import com.jogamp.opengl.GL; -import static com.jogamp.opengl.GL.GL_FLOAT; -import static com.jogamp.opengl.GL.GL_UNSIGNED_INT; import com.jogamp.opengl.GL4; -import com.jogamp.opengl.util.GLBuffers; + import java.nio.FloatBuffer; import java.nio.IntBuffer; -import org.gephi.graph.api.Node; + import org.gephi.viz.engine.VizEngine; -import org.gephi.viz.engine.jogl.models.NodeDiskModel; import org.gephi.viz.engine.pipeline.RenderingLayer; import org.gephi.viz.engine.jogl.pipeline.common.AbstractNodeData; -import org.gephi.viz.engine.pipeline.common.InstanceCounter; import org.gephi.viz.engine.status.GraphRenderingOptions; import org.gephi.viz.engine.status.GraphSelection; import org.gephi.viz.engine.structure.GraphIndexImpl; -import org.gephi.viz.engine.jogl.util.ManagedDirectBuffer; -import org.gephi.viz.engine.jogl.util.gl.BufferUtils; -import org.gephi.viz.engine.jogl.util.gl.GLBuffer; -import org.gephi.viz.engine.jogl.util.gl.GLBufferImmutable; import org.gephi.viz.engine.jogl.util.gl.GLBufferMutable; import static org.gephi.viz.engine.util.gl.GLConstants.INDIRECT_DRAW_COMMAND_BYTES; import static org.gephi.viz.engine.util.gl.GLConstants.INDIRECT_DRAW_COMMAND_INTS_COUNT; diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedEdgeData.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedEdgeData.java index 1d7f068..fef7b3a 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedEdgeData.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedEdgeData.java @@ -1,12 +1,10 @@ package org.gephi.viz.engine.jogl.pipeline.instanced; import com.jogamp.opengl.GL; -import static com.jogamp.opengl.GL.GL_FLOAT; -import com.jogamp.opengl.GL2ES3; import com.jogamp.opengl.GL3ES3; import com.jogamp.opengl.util.GLBuffers; import java.nio.FloatBuffer; -import java.nio.IntBuffer; + import org.gephi.graph.api.Edge; import org.gephi.graph.api.Graph; import org.gephi.viz.engine.VizEngine; @@ -16,10 +14,7 @@ import org.gephi.viz.engine.jogl.pipeline.common.AbstractEdgeData; import org.gephi.viz.engine.status.GraphRenderingOptions; import org.gephi.viz.engine.status.GraphSelection; -import org.gephi.viz.engine.structure.GraphIndex; import org.gephi.viz.engine.structure.GraphIndexImpl; -import org.gephi.viz.engine.jogl.util.ManagedDirectBuffer; -import org.gephi.viz.engine.jogl.util.gl.BufferUtils; import org.gephi.viz.engine.jogl.util.gl.GLBufferMutable; /** @@ -81,14 +76,12 @@ protected void initBuffers(GL gl) { vertexGLBufferUndirected.bind(gl); vertexGLBufferUndirected.init(gl, undirectedVertexData, GLBufferMutable.GL_BUFFER_USAGE_STATIC_DRAW); vertexGLBufferUndirected.unbind(gl); - //BufferUtils.destroyDirectBuffer(undirectedVertexData); final FloatBuffer directedVertexData = GLBuffers.newDirectFloatBuffer(EdgeLineModelDirected.getVertexData()); vertexGLBufferDirected = new GLBufferMutable(bufferName[VERT_BUFFER_DIRECTED], GLBufferMutable.GL_BUFFER_TYPE_ARRAY); vertexGLBufferDirected.bind(gl); vertexGLBufferDirected.init(gl, directedVertexData, GLBufferMutable.GL_BUFFER_USAGE_STATIC_DRAW); vertexGLBufferDirected.unbind(gl); - //BufferUtils.destroyDirectBuffer(directedVertexData); //Initialize for batch edges size: attributesGLBufferDirected = new GLBufferMutable(bufferName[ATTRIBS_BUFFER_DIRECTED], GLBufferMutable.GL_BUFFER_TYPE_ARRAY); diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedNodeData.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedNodeData.java index 32b7232..c191410 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedNodeData.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/instanced/InstancedNodeData.java @@ -1,29 +1,16 @@ package org.gephi.viz.engine.jogl.pipeline.instanced; import com.jogamp.opengl.GL; -import static com.jogamp.opengl.GL.GL_FLOAT; import com.jogamp.opengl.GL2ES3; -import com.jogamp.opengl.GL3ES3; -import com.jogamp.opengl.util.GLBuffers; + import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import org.gephi.graph.api.Edge; -import org.gephi.graph.api.Graph; -import org.gephi.graph.api.Node; import org.gephi.viz.engine.VizEngine; -import org.gephi.viz.engine.jogl.models.EdgeLineModelDirected; -import org.gephi.viz.engine.jogl.models.EdgeLineModelUndirected; -import org.gephi.viz.engine.jogl.models.NodeDiskModel; -import org.gephi.viz.engine.jogl.pipeline.common.AbstractEdgeData; import org.gephi.viz.engine.pipeline.RenderingLayer; import org.gephi.viz.engine.jogl.pipeline.common.AbstractNodeData; -import org.gephi.viz.engine.pipeline.common.InstanceCounter; import org.gephi.viz.engine.status.GraphRenderingOptions; import org.gephi.viz.engine.status.GraphSelection; import org.gephi.viz.engine.structure.GraphIndexImpl; -import org.gephi.viz.engine.jogl.util.ManagedDirectBuffer; -import org.gephi.viz.engine.jogl.util.gl.BufferUtils; import org.gephi.viz.engine.jogl.util.gl.GLBufferMutable; /** diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/ManagedDirectBuffer.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/ManagedDirectBuffer.java index b0574d4..fc3d90e 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/ManagedDirectBuffer.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/ManagedDirectBuffer.java @@ -4,7 +4,7 @@ import java.nio.Buffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; -import org.gephi.viz.engine.jogl.util.gl.BufferUtils; + import static org.gephi.viz.engine.util.ArrayUtils.getNextPowerOf2; /** @@ -44,7 +44,6 @@ public void ensureCapacity(int elements) { buffer.clear(); GLBuffers.put(newBuffer, buffer); - //BufferUtils.destroyDirectBuffer(buffer); this.buffer = newBuffer; this.elementsCapacity = newElementsCapacity; @@ -56,6 +55,6 @@ public int getElementsCapacity() { } public void destroy() { - //BufferUtils.destroyDirectBuffer(buffer); + //NOOP } } diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/BufferUtils.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/BufferUtils.java deleted file mode 100644 index 5fc7ad9..0000000 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/BufferUtils.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.gephi.viz.engine.jogl.util.gl; - -import java.lang.ref.PhantomReference; -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.DoubleBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * BufferUtils is a helper class for generating nio buffers from - * jME data classes such as Vectors and ColorRGBA. - * - * @author Joshua Slack - * @version $Id: BufferUtils.java,v 1.16 2007/10/29 16:56:18 nca Exp $ - */ -public final class BufferUtils { - - private static boolean trackDirectMemory = false; - private static ReferenceQueue removeCollected = new ReferenceQueue(); - private static ConcurrentHashMap trackedBuffers = new ConcurrentHashMap(); - static ClearReferences cleanupthread; - - /** - * Set it to true if you want to enable direct memory tracking for debugging purpose. - * Default is false. - * To print direct memory usage use BufferUtils.printCurrentDirectMemory(StringBuilder store); - * @param enabled - */ - public static void setTrackDirectMemoryEnabled(boolean enabled) { - trackDirectMemory = enabled; - } - - /** - * Creates a clone of the given buffer. The clone's capacity is - * equal to the given buffer's limit. - * - * @param buf The buffer to clone - * @return The cloned buffer - */ - public static Buffer clone(Buffer buf) { - if (buf instanceof FloatBuffer) { - return clone((FloatBuffer) buf); - } else if (buf instanceof ShortBuffer) { - return clone((ShortBuffer) buf); - } else if (buf instanceof ByteBuffer) { - return clone((ByteBuffer) buf); - } else if (buf instanceof IntBuffer) { - return clone((IntBuffer) buf); - } else if (buf instanceof DoubleBuffer) { - return clone((DoubleBuffer) buf); - } else { - throw new UnsupportedOperationException(); - } - } - - private static void onBufferAllocated(Buffer buffer) { - /** - * StackTraceElement[] stackTrace = new Throwable().getStackTrace(); int - * initialIndex = 0; - * - * for (int i = 0; i < stackTrace.length; i++){ if - * (!stackTrace[i].getClassName().equals(BufferUtils.class.getName())){ - * initialIndex = i; break; } } - * - * int allocated = buffer.capacity(); int size = 0; - * - * if (buffer instanceof FloatBuffer){ size = 4; }else if (buffer - * instanceof ShortBuffer){ size = 2; }else if (buffer instanceof - * ByteBuffer){ size = 1; }else if (buffer instanceof IntBuffer){ size = - * 4; }else if (buffer instanceof DoubleBuffer){ size = 8; } - * - * allocated *= size; - * - * for (int i = initialIndex; i < stackTrace.length; i++){ - * StackTraceElement element = stackTrace[i]; if - * (element.getClassName().startsWith("java")){ break; } - * - * try { Class clazz = Class.forName(element.getClassName()); if (i == - * initialIndex){ - * System.out.println(clazz.getSimpleName()+"."+element.getMethodName - * ()+"():" + element.getLineNumber() + " allocated " + allocated); - * }else{ System.out.println(" at " + - * clazz.getSimpleName()+"."+element.getMethodName()+"()"); } } catch - * (ClassNotFoundException ex) { } } - */ - if (BufferUtils.trackDirectMemory) { - - if (BufferUtils.cleanupthread == null) { - BufferUtils.cleanupthread = new ClearReferences(); - BufferUtils.cleanupthread.start(); - } - if (buffer instanceof ByteBuffer) { - BufferInfo info = new BufferInfo(ByteBuffer.class, buffer.capacity(), buffer, BufferUtils.removeCollected); - BufferUtils.trackedBuffers.put(info, info); - } else if (buffer instanceof FloatBuffer) { - BufferInfo info = new BufferInfo(FloatBuffer.class, buffer.capacity() * 4, buffer, BufferUtils.removeCollected); - BufferUtils.trackedBuffers.put(info, info); - } else if (buffer instanceof IntBuffer) { - BufferInfo info = new BufferInfo(IntBuffer.class, buffer.capacity() * 4, buffer, BufferUtils.removeCollected); - BufferUtils.trackedBuffers.put(info, info); - } else if (buffer instanceof ShortBuffer) { - BufferInfo info = new BufferInfo(ShortBuffer.class, buffer.capacity() * 2, buffer, BufferUtils.removeCollected); - BufferUtils.trackedBuffers.put(info, info); - } else if (buffer instanceof DoubleBuffer) { - BufferInfo info = new BufferInfo(DoubleBuffer.class, buffer.capacity() * 8, buffer, BufferUtils.removeCollected); - BufferUtils.trackedBuffers.put(info, info); - } - - } - } - - public static void printCurrentDirectMemory(StringBuilder store) { - long totalHeld = 0; - long heapMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - - boolean printStout = store == null; - if (store == null) { - store = new StringBuilder(); - } - if (trackDirectMemory) { - // make a new set to hold the keys to prevent concurrency issues. - int fBufs = 0, bBufs = 0, iBufs = 0, sBufs = 0, dBufs = 0; - int fBufsM = 0, bBufsM = 0, iBufsM = 0, sBufsM = 0, dBufsM = 0; - for (BufferInfo b : BufferUtils.trackedBuffers.values()) { - if (b.type == ByteBuffer.class) { - totalHeld += b.size; - bBufsM += b.size; - bBufs++; - } else if (b.type == FloatBuffer.class) { - totalHeld += b.size; - fBufsM += b.size; - fBufs++; - } else if (b.type == IntBuffer.class) { - totalHeld += b.size; - iBufsM += b.size; - iBufs++; - } else if (b.type == ShortBuffer.class) { - totalHeld += b.size; - sBufsM += b.size; - sBufs++; - } else if (b.type == DoubleBuffer.class) { - totalHeld += b.size; - dBufsM += b.size; - dBufs++; - } - } - - store.append("Existing buffers: ").append(BufferUtils.trackedBuffers.size()).append("\n"); - store.append("(b: ").append(bBufs).append(" f: ").append(fBufs).append(" i: ").append(iBufs).append(" s: ").append(sBufs).append(" d: ").append(dBufs).append(")").append("\n"); - store.append("Total heap memory held: ").append(heapMem / 1024).append("kb\n"); - store.append("Total direct memory held: ").append(totalHeld / 1024).append("kb\n"); - store.append("(b: ").append(bBufsM / 1024).append("kb f: ").append(fBufsM / 1024).append("kb i: ").append(iBufsM / 1024).append("kb s: ").append(sBufsM / 1024).append("kb d: ").append(dBufsM / 1024).append("kb)").append("\n"); - } else { - store.append("Total heap memory held: ").append(heapMem / 1024).append("kb\n"); - store.append("Only heap memory available, if you want to monitor direct memory use BufferUtils.setTrackDirectMemoryEnabled(true) during initialization.").append("\n"); - } - if (printStout) { - System.out.println(store.toString()); - } - } - private static final AtomicBoolean loadedMethods = new AtomicBoolean(false); - private static Method cleanerMethod = null; - private static Method cleanMethod = null; - private static Method viewedBufferMethod = null; - private static Method freeMethod = null; - - private static Method loadMethod(String className, String methodName) { - try { - Method method = Class.forName(className).getMethod(methodName); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException | SecurityException | ClassNotFoundException ex) { - return null; // the method was not found - } - // setAccessible not allowed by security policy - // the direct buffer implementation was not found - - } - - - //// -- GENERAL BYTE ROUTINES -- //// - /** - * Create a new ByteBuffer of the specified size. - * - * @param size - * required number of ints to store. - * @return the new IntBuffer - */ - public static ByteBuffer createByteBuffer(int size) { - ByteBuffer buf = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()); - buf.clear(); - onBufferAllocated(buf); - return buf; - } - - private static void loadCleanerMethods() { - // If its already true, exit, if not, set it to true. - if (BufferUtils.loadedMethods.getAndSet(true)) { - return; - } - // This could potentially be called many times if used from multiple - // threads - synchronized (BufferUtils.loadedMethods) { - // Oracle JRE / OpenJDK - cleanerMethod = loadMethod("sun.nio.ch.DirectBuffer", "cleaner"); - cleanMethod = loadMethod("sun.misc.Cleaner", "clean"); - viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "viewedBuffer"); - if (viewedBufferMethod == null) { - // They changed the name in Java 7 (???) - viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "attachment"); - } - - // Apache Harmony - ByteBuffer bb = BufferUtils.createByteBuffer(1); - Class clazz = bb.getClass(); - try { - freeMethod = clazz.getMethod("free"); - } catch (NoSuchMethodException | SecurityException ex) { - } - } - } - - /** - * Direct buffers are garbage collected by using a phantom reference and a - * reference queue. Every once a while, the JVM checks the reference queue and - * cleans the direct buffers. However, as this doesn't happen - * immediately after discarding all references to a direct buffer, it's - * easy to OutOfMemoryError yourself using direct buffers. This function - * explicitly calls the Cleaner method of a direct buffer. - * - * @param toBeDestroyed - * The direct buffer that will be "cleaned". Utilizes reflection. - * - */ - public static void destroyDirectBuffer(Buffer toBeDestroyed) { - if (!toBeDestroyed.isDirect()) { - return; - } - - BufferUtils.loadCleanerMethods(); - - try { - if (freeMethod != null) { - freeMethod.invoke(toBeDestroyed); - } else { - Object cleaner = cleanerMethod.invoke(toBeDestroyed); - if (cleaner != null) { - cleanMethod.invoke(cleaner); - } else { - // Try the alternate approach of getting the viewed buffer first - Object viewedBuffer = viewedBufferMethod.invoke(toBeDestroyed); - if (viewedBuffer != null) { - destroyDirectBuffer((Buffer) viewedBuffer); - } else { - Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "Buffer cannot be destroyed: {0}", toBeDestroyed); - } - } - } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException ex) { - Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex); - } - } - - private static class BufferInfo extends PhantomReference { - - private Class type; - private int size; - - public BufferInfo(Class type, int size, Buffer referent, ReferenceQueue q) { - super(referent, q); - this.type = type; - this.size = size; - } - } - - private static class ClearReferences extends Thread { - - ClearReferences() { - this.setDaemon(true); - } - - @Override - public void run() { - try { - while (true) { - Reference toclean = BufferUtils.removeCollected.remove(); - BufferUtils.trackedBuffers.remove(toclean); - } - - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } -} diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/GLVertexArrayObject.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/GLVertexArrayObject.java index 92d2d6e..fe7e624 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/GLVertexArrayObject.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/util/gl/GLVertexArrayObject.java @@ -44,8 +44,6 @@ private void init(GL2ES2 gl) { GLFunctions.glGenVertexArrays(gl, 1, vertexArrayName); arrayId = vertexArrayName.get(0); - //BufferUtils.destroyDirectBuffer(vertexArrayName); - bind(gl); configureAll(gl); unbind(gl);