aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com')
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/BufferFactory.java.javase9
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/PointerBuffer.java.javase48
2 files changed, 39 insertions, 18 deletions
diff --git a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
index cb8c770..60a79c3 100755
--- a/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
+++ b/src/java/com/sun/gluegen/runtime/BufferFactory.java.javase
@@ -130,7 +130,8 @@ public class BufferFactory {
return pos * SIZEOF_CHAR;
}
} else if (buf instanceof PointerBuffer) {
- return (((PointerBuffer)buf).position() * SIZEOF_LONG);
+ PointerBuffer pb = (PointerBuffer)buf;
+ return pb.position() * pb.elementSize();
}
throw new RuntimeException("Disallowed array backing store type in buffer "
@@ -195,7 +196,8 @@ public class BufferFactory {
return (SIZEOF_CHAR*(((CharBuffer)buf).arrayOffset() + pos));
}
} else if(buf instanceof PointerBuffer) {
- return (SIZEOF_LONG*(((PointerBuffer)buf).arrayOffset() + ((PointerBuffer)buf).position()));
+ PointerBuffer pb = (PointerBuffer)buf;
+ return pb.elementSize()*(pb.arrayOffset() + pb.position());
}
throw new RuntimeException("Unknown buffer type " + buf.getClass().getName());
@@ -305,7 +307,8 @@ public class BufferFactory {
bytesRemaining = elementsRemaining * SIZEOF_CHAR;
}
} else if (buffer instanceof PointerBuffer) {
- bytesRemaining = ((PointerBuffer)buffer).remaining() * SIZEOF_LONG;
+ PointerBuffer pb = (PointerBuffer)buffer;
+ bytesRemaining = pb.remaining() * pb.elementSize();
}
if (bytesRemaining < minBytesRemaining) {
throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining);
diff --git a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase
index 6d0029e..57ad05c 100755
--- a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase
+++ b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase
@@ -1,21 +1,21 @@
/*
* 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
@@ -28,7 +28,7 @@
* 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.
@@ -40,14 +40,21 @@ import java.nio.*;
public class PointerBuffer {
private ByteBuffer bb;
- private LongBuffer lb;
+ private Buffer pb;
private int capacity, position;
private long[] backup;
private PointerBuffer(ByteBuffer bb) {
this.bb = bb;
- this.lb = bb.asLongBuffer();
- capacity = bb.capacity()/BufferFactory.SIZEOF_LONG;
+
+ if(CPU.is32Bit()) {
+ this.pb = bb.asIntBuffer();
+ }else{
+ this.pb = bb.asLongBuffer();
+ }
+
+ capacity = bb.capacity() / elementSize();
+
position=0;
backup = new long[capacity];
}
@@ -93,11 +100,11 @@ public class PointerBuffer {
}
public static PointerBuffer allocate(int size) {
- return new PointerBuffer(ByteBuffer.wrap(new byte[BufferFactory.SIZEOF_LONG * size]));
+ return new PointerBuffer(ByteBuffer.wrap(new byte[elementSize()* size]));
}
public static PointerBuffer allocateDirect(int size) {
- return new PointerBuffer(BufferFactory.newDirectByteBuffer(BufferFactory.SIZEOF_LONG * size));
+ return new PointerBuffer(BufferFactory.newDirectByteBuffer(elementSize() * size));
}
public static PointerBuffer wrap(ByteBuffer src) {
@@ -106,7 +113,7 @@ public class PointerBuffer {
return res;
}
- /**
+ /**
* Wraps pointer arrays created by native code.
* Note: In case this is not a 64bit system, each pointer is being converted. */
public static PointerBuffer wrapNative2Java(ByteBuffer src, boolean keepDirect) {
@@ -138,7 +145,10 @@ public class PointerBuffer {
if(0>idx || idx>=capacity) {
throw new IndexOutOfBoundsException();
}
- return lb.get(idx);
+ if(CPU.is32Bit())
+ return ((IntBuffer)pb).get(idx);
+ else
+ return ((LongBuffer)pb).get(idx);
}
public long get() {
@@ -152,7 +162,10 @@ public class PointerBuffer {
throw new IndexOutOfBoundsException();
}
backup[idx] = v;
- lb.put(idx, v);
+ if (CPU.is32Bit())
+ ((IntBuffer)pb).put(idx, (int)v);
+ else
+ ((LongBuffer)pb).put(idx, v);
return this;
}
@@ -167,4 +180,9 @@ public class PointerBuffer {
backup[i] = get(i);
}
}
-}
+
+ public static int elementSize() {
+ return CPU.is32Bit() ? BufferFactory.SIZEOF_INT : BufferFactory.SIZEOF_LONG;
+ }
+
+} \ No newline at end of file