diff options
author | Sven Gothel <[email protected]> | 2010-03-29 04:24:20 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-03-29 04:24:20 +0200 |
commit | 2138fc787c1e497be7f373aa68b3f751c955008f (patch) | |
tree | d4b1a1dc63602bef8073e70d709faa2821b5dddd /src/java | |
parent | ca2ccb29bd3cd4d9c73ca96ce02402888ac9e9af (diff) |
New Int64Buffer type, which is being used for gluegen 'long *'
Diffstat (limited to 'src/java')
-rwxr-xr-x | src/java/com/jogamp/gluegen/runtime/BufferFactory.java | 13 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/runtime/Int64Buffer.java | 155 | ||||
-rwxr-xr-x | src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java | 94 | ||||
-rwxr-xr-x | src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java | 80 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/runtime/PointerBuffer.java | 6 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/JavaEmitter.java | 22 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/JavaMethodBindingEmitter.java | 2 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/JavaType.java | 14 |
8 files changed, 373 insertions, 13 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/BufferFactory.java b/src/java/com/jogamp/gluegen/runtime/BufferFactory.java index 1f8182c..9b52640 100755 --- a/src/java/com/jogamp/gluegen/runtime/BufferFactory.java +++ b/src/java/com/jogamp/gluegen/runtime/BufferFactory.java @@ -98,6 +98,8 @@ public class BufferFactory { return ((IntBuffer) buf).isDirect(); } else if (buf instanceof ShortBuffer) { return ((ShortBuffer) buf).isDirect(); + } else if (buf instanceof Int64Buffer) { + return ((Int64Buffer) buf).isDirect(); } else if (buf instanceof PointerBuffer) { return ((PointerBuffer) buf).isDirect(); } else if (Platform.isJavaSE()) { @@ -140,6 +142,9 @@ public class BufferFactory { return pos * SIZEOF_CHAR; } } + } else if (buf instanceof Int64Buffer) { + Int64Buffer int64Buffer = (Int64Buffer) buf; + return int64Buffer.position() * Int64Buffer.elementSize(); } else if (buf instanceof PointerBuffer) { PointerBuffer pointerBuffer = (PointerBuffer) buf; return pointerBuffer.position() * PointerBuffer.elementSize(); @@ -165,6 +170,8 @@ public class BufferFactory { return ((IntBuffer) buf).array(); } else if (buf instanceof ShortBuffer) { return ((ShortBuffer) buf).array(); + } else if (buf instanceof Int64Buffer) { + return ((Int64Buffer) buf).array(); } else if (buf instanceof PointerBuffer) { return ((PointerBuffer) buf).array(); }else if(Platform.isJavaSE()) { @@ -210,6 +217,9 @@ public class BufferFactory { return (SIZEOF_CHAR * (((CharBuffer) buf).arrayOffset() + pos)); } } + } else if (buf instanceof Int64Buffer) { + Int64Buffer int64Buffer = (Int64Buffer) buf; + return Int64Buffer.elementSize() * (int64Buffer.arrayOffset() + int64Buffer.position()); } else if (buf instanceof PointerBuffer) { PointerBuffer pointerBuffer = (PointerBuffer) buf; return PointerBuffer.elementSize() * (pointerBuffer.arrayOffset() + pointerBuffer.position()); @@ -323,6 +333,9 @@ public class BufferFactory { bytesRemaining = elementsRemaining * SIZEOF_CHAR; } } + } else if (buffer instanceof Int64Buffer) { + Int64Buffer int64Buffer = (Int64Buffer) buffer; + bytesRemaining = int64Buffer.remaining() * Int64Buffer.elementSize(); } else if (buffer instanceof PointerBuffer) { PointerBuffer pointerBuffer = (PointerBuffer) buffer; bytesRemaining = pointerBuffer.remaining() * PointerBuffer.elementSize(); diff --git a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java new file mode 100644 index 0000000..ad218bc --- /dev/null +++ b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2010, Michael Bien + * 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 Michael Bien 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 Michael Bien 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 com.jogamp.gluegen.runtime; + +import java.nio.ByteBuffer; + +/** + * Hardware independent container for native int64_t arrays. + * + * The native values (NIO direct ByteBuffer) are always 64bit wide. + * + * @author Michael Bien + * @author Sven Gothel + */ +public abstract class Int64Buffer { + + protected final ByteBuffer bb; + protected int capacity; + protected int position; + protected long[] backup; + + protected Int64Buffer(ByteBuffer bb) { + this.bb = bb; + } + + public static Int64Buffer allocate(int size) { + if (Platform.isJavaSE()) { + return new Int64BufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); + } else { + return new Int64BufferME_CDC_FP(ByteBuffer.wrap(new byte[elementSize() * size])); + } + } + + public static Int64Buffer allocateDirect(int size) { + if (Platform.isJavaSE()) { + return new Int64BufferSE(BufferFactory.newDirectByteBuffer(elementSize() * size)); + } else { + return new Int64BufferME_CDC_FP(BufferFactory.newDirectByteBuffer(elementSize() * size)); + } + } + + public static Int64Buffer wrap(ByteBuffer src) { + Int64Buffer res; + if (Platform.isJavaSE()) { + res = new Int64BufferSE(src); + } else { + res = new Int64BufferME_CDC_FP(src); + } + res.updateBackup(); + return res; + + } + + void updateBackup() { + for (int i = 0; i < capacity; i++) { + backup[i] = get(i); + } + } + + int arrayOffset() { + return 0; + } + + public static int elementSize() { + return BufferFactory.SIZEOF_LONG; + } + + public int limit() { + return capacity; + } + + public int capacity() { + return capacity; + } + + public int position() { + return position; + } + + public Int64Buffer position(int newPos) { + if (0 > newPos || newPos >= capacity) { + throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + + "My capacity is "+capacity()+"."); + } + position = newPos; + return this; + } + + public int remaining() { + return capacity - position; + } + + public boolean hasRemaining() { + return position < capacity; + } + + public Int64Buffer rewind() { + position = 0; + return this; + } + + boolean hasArray() { + return true; + } + + public long[] array() { + return backup; + } + + public ByteBuffer getBuffer() { + return bb; + } + + public boolean isDirect() { + return bb.isDirect(); + } + + public long get() { + long r = get(position); + position++; + return r; + } + + public abstract long get(int idx); + + public abstract Int64Buffer put(int index, long value); + + public abstract Int64Buffer put(long value); + +} diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java b/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java new file mode 100755 index 0000000..ec43897 --- /dev/null +++ b/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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 Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package com.jogamp.gluegen.runtime; + +import java.nio.*; + +/** + * @author Sven Gothel + * @author Michael Bien + */ +final class Int64BufferME_CDC_FP extends Int64Buffer { + + private IntBuffer pb; + + Int64BufferME_CDC_FP(ByteBuffer bb) { + super(bb); + this.pb = bb.asIntBuffer(); + + capacity = bb.capacity() / elementSize(); + + position = 0; + backup = new long[capacity]; + } + + public long get(int idx) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + idx = idx << 1; // 8-byte to 4-byte offset + long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx)); + long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1)); + if (BufferFactory.isLittleEndian()) { + return hi << 32 | lo; + } + return lo << 32 | hi; + } + + public Int64Buffer put(int idx, long v) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + backup[idx] = v; + idx = idx << 1; // 8-byte to 4-byte offset + int lo = (int) ((v) & 0x00000000FFFFFFFFL); + int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); + if (BufferFactory.isLittleEndian()) { + pb.put(idx, lo); + pb.put(idx + 1, hi); + } else { + pb.put(idx, hi); + pb.put(idx + 1, lo); + } + return this; + } + + public Int64Buffer put(long v) { + put(position, v); + position++; + return this; + } +} diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java b/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java new file mode 100755 index 0000000..166d0c6 --- /dev/null +++ b/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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 Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package com.jogamp.gluegen.runtime; + +import java.nio.*; + +/** + * @author Sven Gothel + * @author Michael Bien + */ +final class Int64BufferSE extends Int64Buffer { + + private LongBuffer pb; + + Int64BufferSE(ByteBuffer bb) { + super(bb); + + this.pb = bb.asLongBuffer(); + + capacity = bb.capacity() / elementSize(); + + position = 0; + backup = new long[capacity]; + } + + public long get(int idx) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + return pb.get(idx); + } + + public Int64Buffer put(int idx, long v) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + backup[idx] = v; + pb.put(idx, v); + return this; + } + + public Int64Buffer put(long v) { + put(position, v); + position++; + return this; + } +} diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java index 3bff090..8e30ed8 100644 --- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java +++ b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java @@ -33,7 +33,11 @@ package com.jogamp.gluegen.runtime; import java.nio.ByteBuffer; /** - * Hardware independent container for native long- and pointer arrays. + * Hardware independent container for native pointer arrays. + * + * The native values (NIO direct ByteBuffer) might be 32bit or 64bit wide, + * depending of the CPU pointer width. + * * @author Michael Bien * @author Sven Gothel */ diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index 6658a16..e283fcb 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -695,12 +695,12 @@ public class JavaEmitter implements GlueEmitter { // // boolean arg_direct = arg != null && BufferFactory.isDirect(arg); // - // fooMethod0(arg_direct?arg:BufferFactory.getArray(arg), + // fooMethod1(arg_direct?arg:BufferFactory.getArray(arg), // arg_direct?BufferFactory.getDirectBufferByteOffset(arg):BufferFactory.getIndirectBufferByteOffset(arg), // arg_direct, // ... ); // } - // private native void fooMethod0(Object arg, int arg_byte_offset, boolean arg_is_direct, ...); + // private native void fooMethod1(Object arg, int arg_byte_offset, boolean arg_is_direct, ...); // // Method taking primitive array argument: // Interface class: @@ -713,13 +713,15 @@ public class JavaEmitter implements GlueEmitter { // } // public void fooMethod(IntBuffer arg) { // ... bounds checks, etc. ... - // if (arg.isDirect()) { - // fooMethod0(arg, computeDirectBufferByteOffset(arg)); - // } else { - // fooMethod1(getIndirectBufferArray(arg), computeIndirectBufferByteOffset(arg)); - // } + // + // boolean arg_direct = BufferFactory.isDirect(arg); + // + // fooMethod1(arg_direct?arg:BufferFactory.getArray(arg), + // arg_direct?BufferFactory.getDirectBufferByteOffset(arg):BufferFactory.getIndirectBufferByteOffset(arg), + // arg_direct, + // ... ); // } - // private native void fooMethod0(Object arg, int arg_byte_offset, boolean arg_is_direct, ...); + // private native void fooMethod1(Object arg, int arg_byte_offset, boolean arg_is_direct, ...); // // Note in particular that the public entry point taking an // array is merely a special case of the indirect buffer case. @@ -1794,7 +1796,7 @@ public class JavaEmitter implements GlueEmitter { if (convertToArrays) { result = result.replaceJavaArgumentType(i, javaType(ArrayTypes.longArrayClass)); } else { - result = result.replaceJavaArgumentType(i, JavaType.forNIOPointerBufferClass()); + result = result.replaceJavaArgumentType(i, JavaType.forNIOInt64BufferClass()); } } else if (t.isCFloatPointerType()) { arrayPossible = true; @@ -1828,7 +1830,7 @@ public class JavaEmitter implements GlueEmitter { } else if (t.isCInt32PointerType()) { result = result.replaceJavaArgumentType(-1, JavaType.forNIOIntBufferClass()); } else if (t.isCInt64PointerType()) { - result = result.replaceJavaArgumentType(-1, JavaType.forNIOPointerBufferClass()); + result = result.replaceJavaArgumentType(-1, JavaType.forNIOInt64BufferClass()); } else if (t.isCFloatPointerType()) { result = result.replaceJavaArgumentType(-1, JavaType.forNIOFloatBufferClass()); } else if (t.isCDoublePointerType()) { diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java index da5484b..b992fcc 100644 --- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java @@ -589,7 +589,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter } if (type.isNIOBuffer()) { - if(type.isNIOPointerBuffer()) { + if(type.isNIOInt64Buffer() || type.isNIOPointerBuffer()) { if (directNIOOnly) { writer.print( getArgumentName(i)+ " != null ? " + getArgumentName(i) + ".getBuffer() : null"); } else { diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java index 19ac945..23f48b2 100644 --- a/src/java/com/sun/gluegen/JavaType.java +++ b/src/java/com/sun/gluegen/JavaType.java @@ -71,6 +71,7 @@ public class JavaType { private static JavaType nioIntBufferType; private static JavaType nioLongBufferType; private static JavaType nioPointerBufferType; + private static JavaType nioInt64BufferType; private static JavaType nioFloatBufferType; private static JavaType nioDoubleBufferType; private static JavaType nioByteBufferArrayType; @@ -194,6 +195,12 @@ public class JavaType { return nioLongBufferType; } + public static JavaType forNIOInt64BufferClass() { + if(nioInt64BufferType == null) + nioInt64BufferType = createForClass(com.jogamp.gluegen.runtime.Int64Buffer.class); + return nioInt64BufferType; + } + public static JavaType forNIOPointerBufferClass() { if(nioPointerBufferType == null) nioPointerBufferType = createForClass(com.jogamp.gluegen.runtime.PointerBuffer.class); @@ -333,7 +340,8 @@ public class JavaType { public boolean isNIOBuffer() { return clazz != null && ( (java.nio.Buffer.class).isAssignableFrom(clazz) || - (com.jogamp.gluegen.runtime.PointerBuffer.class).isAssignableFrom(clazz) ) ; + (com.jogamp.gluegen.runtime.PointerBuffer.class).isAssignableFrom(clazz) || + (com.jogamp.gluegen.runtime.Int64Buffer.class).isAssignableFrom(clazz) ) ; } public boolean isNIOByteBuffer() { @@ -353,6 +361,10 @@ public class JavaType { return (clazz == java.nio.LongBuffer.class); } + public boolean isNIOInt64Buffer() { + return (clazz == com.jogamp.gluegen.runtime.Int64Buffer.class); + } + public boolean isNIOPointerBuffer() { return (clazz == com.jogamp.gluegen.runtime.PointerBuffer.class); } |