< prev index next >

test/compiler/intrinsics/unsafe/HeapByteBufferTest.java

Print this page




 229     char getChar() {  ck(buf.getChar(buf.position()), (char)getShortX(pos)); char x = buf.getChar(); pos += 2; return x; }
 230     double getDouble() { ck(buf.getDouble(buf.position()), getDoubleX(pos)); double x = buf.getDouble(); pos += 8; return x; }
 231     float getFloat() { ck(buf.getFloat(buf.position()), getFloatX(pos)); float x = buf.getFloat(); pos += 4; return x; }
 232 
 233     void putLong(long x) { putLongX(pos, x); pos += 8; buf.putLong(x); }
 234     void putInt(int x) { putIntX(pos, x); pos += 4; buf.putInt(x); }
 235     void putShort(short x) { putShortX(pos, x); pos += 2; buf.putShort(x); }
 236     void putChar(char x) { putShortX(pos, (short)x); pos += 2; buf.putChar(x); }
 237     void putDouble(double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; buf.putDouble(x); }
 238     void putFloat(float x) { putIntX(pos, Float.floatToRawIntBits(x)); pos += 4; buf.putFloat(x); }
 239 
 240     void rewind() { pos = 0; buf.rewind(); }
 241 }
 242 
 243 public class HeapByteBufferTest implements Runnable {
 244 
 245     SplittableRandom random = new SplittableRandom();
 246     MyByteBuffer data = MyByteBuffer.wrap(new byte[1024]);
 247 
 248     int randomOffset(SplittableRandom r, MyByteBuffer buf, int size) {
 249         return abs(r.nextInt()) % (buf.capacity() - size);
 250     }
 251 
 252     long iterations;
 253 
 254     HeapByteBufferTest(long iterations) {
 255         this.iterations = iterations;
 256     }
 257 
 258     // The core of the test.  Walk over the buffer reading and writing
 259     // random data, XORing it as we go.  We can detect writes in the
 260     // wrong place, writes which are too long or too short, and reads
 261     // or writes of the wrong data,
 262     void step(SplittableRandom r) {
 263         data.order((r.nextInt() & 1) != 0 ? BIG_ENDIAN : LITTLE_ENDIAN);
 264 
 265         data.rewind();
 266         while (data.position() < data.capacity())
 267             data.putLong(data.getLong() ^ random.nextLong());
 268 
 269         data.rewind();




 229     char getChar() {  ck(buf.getChar(buf.position()), (char)getShortX(pos)); char x = buf.getChar(); pos += 2; return x; }
 230     double getDouble() { ck(buf.getDouble(buf.position()), getDoubleX(pos)); double x = buf.getDouble(); pos += 8; return x; }
 231     float getFloat() { ck(buf.getFloat(buf.position()), getFloatX(pos)); float x = buf.getFloat(); pos += 4; return x; }
 232 
 233     void putLong(long x) { putLongX(pos, x); pos += 8; buf.putLong(x); }
 234     void putInt(int x) { putIntX(pos, x); pos += 4; buf.putInt(x); }
 235     void putShort(short x) { putShortX(pos, x); pos += 2; buf.putShort(x); }
 236     void putChar(char x) { putShortX(pos, (short)x); pos += 2; buf.putChar(x); }
 237     void putDouble(double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; buf.putDouble(x); }
 238     void putFloat(float x) { putIntX(pos, Float.floatToRawIntBits(x)); pos += 4; buf.putFloat(x); }
 239 
 240     void rewind() { pos = 0; buf.rewind(); }
 241 }
 242 
 243 public class HeapByteBufferTest implements Runnable {
 244 
 245     SplittableRandom random = new SplittableRandom();
 246     MyByteBuffer data = MyByteBuffer.wrap(new byte[1024]);
 247 
 248     int randomOffset(SplittableRandom r, MyByteBuffer buf, int size) {
 249         return r.nextInt(buf.capacity() - size);
 250     }
 251 
 252     long iterations;
 253 
 254     HeapByteBufferTest(long iterations) {
 255         this.iterations = iterations;
 256     }
 257 
 258     // The core of the test.  Walk over the buffer reading and writing
 259     // random data, XORing it as we go.  We can detect writes in the
 260     // wrong place, writes which are too long or too short, and reads
 261     // or writes of the wrong data,
 262     void step(SplittableRandom r) {
 263         data.order((r.nextInt() & 1) != 0 ? BIG_ENDIAN : LITTLE_ENDIAN);
 264 
 265         data.rewind();
 266         while (data.position() < data.capacity())
 267             data.putLong(data.getLong() ^ random.nextLong());
 268 
 269         data.rewind();


< prev index next >