aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp
diff options
context:
space:
mode:
authorsg215889 <[email protected]>2009-07-13 02:54:29 -0700
committersg215889 <[email protected]>2009-07-13 02:54:29 -0700
commit35cad1e103bb30737b4feacf554219b795358eec (patch)
tree5dabd55a164f675d882bfea482fbd568f3c473dd /src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp
parent558389f22d7a257e422ae50385364dcc74c4f106 (diff)
Add missing changes ..
Diffstat (limited to 'src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp')
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp124
1 files changed, 111 insertions, 13 deletions
diff --git a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp
index b2d216e..14a3d34 100755
--- a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp
+++ b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp
@@ -41,38 +41,136 @@ import java.nio.*;
public class PointerBuffer {
private ByteBuffer bb;
private IntBuffer ib;
+ private int capacity, position;
+ private long[] backup;
- public PointerBuffer(ByteBuffer bb) {
+ private PointerBuffer(ByteBuffer bb) {
this.bb = bb;
this.ib = bb.asIntBuffer();
+ capacity = bb.capacity()/BufferFactory.SIZEOF_LONG;
+ position=0;
+ backup = new long[capacity];
+ }
+
+ public final int limit() {
+ return capacity;
+ }
+ public final int capacity() {
+ return capacity;
+ }
+
+ public final int position() {
+ return position;
+ }
+
+ public final int remaining() {
+ return capacity - position;
+ }
+
+ public final boolean hasRemaining() {
+ return position < capacity;
+ }
+
+ public final void rewind() {
+ position=0;
+ }
+
+ int arrayOffset() { return 0; }
+
+ boolean hasArray() { return true; }
+
+ public long[] array() {
+ return backup;
+ }
+
+ public static PointerBuffer allocate(int size) {
+ return new PointerBuffer(ByteBuffer.wrap(new byte[BufferFactory.SIZEOF_LONG * size]));
+ }
+
+ public static PointerBuffer allocateDirect(int size) {
+ return new PointerBuffer(BufferFactory.newDirectByteBuffer(size));
+ }
+
+ public static PointerBuffer wrap(ByteBuffer src) {
+ PointerBuffer res = new PointerBuffer(src);
+ res.updateBackup();
+ 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) {
+ PointerBuffer res;
+ if (CPU.is32Bit()) {
+ // Must convert each pointer from 32-bit to 64-bit
+ IntBuffer buf = src.asIntBuffer();
+ int len = buf.capacity();
+ res = (src.isDirect() && keepDirect) ? PointerBuffer.allocateDirect(len) : PointerBuffer.allocate(len);
+ for (int i = 0; i < len; i++) {
+ res.put(i, buf.get(i));
+ }
+ } else {
+ res = new PointerBuffer(src);
+ res.updateBackup();
+ }
+ return res;
}
public ByteBuffer getBuffer() {
return bb;
}
- /** Retrieves the long at the specified slot (8-byte offset). */
- public long get(int slot) {
- slot = slot << 1 ; // 8-byte to 4-byte offset
- long lo = 0x00000000FFFFFFFFL & ( (long) ib.get(slot) );
- long hi = 0x00000000FFFFFFFFL & ( (long) ib.get(slot+1) );
+ public boolean isDirect() {
+ return bb.isDirect();
+ }
+
+ 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) ib.get(idx) );
+ long hi = 0x00000000FFFFFFFFL & ( (long) ib.get(idx+1) );
if(BufferFactory.isLittleEndian()) {
return hi << 32 | lo ;
}
return lo << 32 | hi ;
}
- /** Puts a long at the specified slot (8-byte offset). */
- public void put(int slot, long v) {
- slot = slot << 1 ; // 8-byte to 4-byte offset
+ public long get() {
+ long r = get(position+1);
+ position++;
+ return r;
+ }
+
+ public PointerBuffer 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()) {
- ib.put(slot, lo);
- ib.put(slot+1, hi);
+ ib.put(idx, lo);
+ ib.put(idx+1, hi);
} else {
- ib.put(slot, hi);
- ib.put(slot+1, lo);
+ ib.put(idx, hi);
+ ib.put(idx+1, lo);
+ }
+ return this;
+ }
+
+ public PointerBuffer put(long v) {
+ put(position+1, v);
+ position++;
+ return this;
+ }
+
+ private void updateBackup() {
+ for (int i = 0; i < capacity; i++) {
+ backup[i] = get(i);
}
}
}