summaryrefslogtreecommitdiffstats
path: root/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase')
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/PointerBuffer.java.javase48
1 files changed, 33 insertions, 15 deletions
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