< prev index next >

test/compiler/intrinsics/unsafe/HeapByteBufferTest.java

Print this page

        

*** 1,56 **** ! // ! // Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. ! // Copyright (c) 2015, Red Hat Inc. All rights reserved. ! // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ! // ! // This code is free software; you can redistribute it and/or modify it ! // under the terms of the GNU General Public License version 2 only, as ! // published by the Free Software Foundation. ! // ! // This code is distributed in the hope that it will be useful, but WITHOUT ! // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ! // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ! // version 2 for more details (a copy is included in the LICENSE file that ! // accompanied this code). ! // ! // You should have received a copy of the GNU General Public License version ! // 2 along with this work; if not, write to the Free Software Foundation, ! // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ! // ! // Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ! // or visit www.oracle.com if you need additional information or have any ! // questions. ! // ! // import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; - import static java.nio.ByteOrder.BIG_ENDIAN; - import static java.nio.ByteOrder.LITTLE_ENDIAN; import java.nio.ByteOrder; import java.util.Arrays; import java.util.Random; - import jdk.test.lib.Utils; ! /** ! * @test ! * @bug 8026049 ! * @modules java.base/jdk.internal.misc ! * @library /testlibrary ! * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-UseUnalignedAccesses -Djdk.test.lib.random.seed=0 HeapByteBufferTest ! * @run main/othervm -Djdk.test.lib.random.seed=0 HeapByteBufferTest ! * @summary Verify that byte buffers are correctly accessed. ! */ // A wrapper for a ByteBuffer which maintains a backing array and a // position. Whenever this wrapper is written the backing array and // the wrapped byte buffer are updated together, and whenever it is // read we check that the ByteBuffer and the backing array are identical. ! class MyByteBuffer { final ByteBuffer buf; final byte[] bytes; int pos; ByteOrder byteOrder = BIG_ENDIAN; --- 1,64 ---- ! /* ! * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. ! * Copyright (c) 2015, Red Hat Inc. All rights reserved. ! * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ! * ! * This code is free software; you can redistribute it and/or modify it ! * under the terms of the GNU General Public License version 2 only, as ! * published by the Free Software Foundation. ! * ! * This code is distributed in the hope that it will be useful, but WITHOUT ! * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ! * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ! * version 2 for more details (a copy is included in the LICENSE file that ! * accompanied this code). ! * ! * You should have received a copy of the GNU General Public License version ! * 2 along with this work; if not, write to the Free Software Foundation, ! * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ! * ! * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ! * or visit www.oracle.com if you need additional information or have any ! * questions. ! * ! */ ! ! /** ! * @test ! * @bug 8026049 ! * @summary Verify that byte buffers are correctly accessed. ! * @modules java.base/jdk.internal.misc ! * @library /testlibrary ! * ! * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-UseUnalignedAccesses -Djdk.test.lib.random.seed=0 ! * compiler.intrinsics.unsafe.HeapByteBufferTest ! * @run main/othervm -Djdk.test.lib.random.seed=0 ! * compiler.intrinsics.unsafe.HeapByteBufferTest ! */ ! ! package compiler.intrinsics.unsafe; ! ! import jdk.test.lib.Utils; import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import java.util.Random; ! import static java.nio.ByteOrder.BIG_ENDIAN; ! import static java.nio.ByteOrder.LITTLE_ENDIAN; // A wrapper for a ByteBuffer which maintains a backing array and a // position. Whenever this wrapper is written the backing array and // the wrapped byte buffer are updated together, and whenever it is // read we check that the ByteBuffer and the backing array are identical. ! public class HeapByteBufferTest implements Runnable { ! static class MyByteBuffer { final ByteBuffer buf; final byte[] bytes; int pos; ByteOrder byteOrder = BIG_ENDIAN;
*** 239,251 **** void putChar(char x) { putShortX(pos, (short)x); pos += 2; buf.putChar(x); } void putDouble(double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; buf.putDouble(x); } void putFloat(float x) { putIntX(pos, Float.floatToRawIntBits(x)); pos += 4; buf.putFloat(x); } void rewind() { pos = 0; buf.rewind(); } ! } ! ! public class HeapByteBufferTest implements Runnable { Random random = Utils.getRandomInstance(); MyByteBuffer data = MyByteBuffer.wrap(new byte[1024]); int randomOffset(Random r, MyByteBuffer buf, int size) { --- 247,257 ---- void putChar(char x) { putShortX(pos, (short)x); pos += 2; buf.putChar(x); } void putDouble(double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; buf.putDouble(x); } void putFloat(float x) { putIntX(pos, Float.floatToRawIntBits(x)); pos += 4; buf.putFloat(x); } void rewind() { pos = 0; buf.rewind(); } ! } Random random = Utils.getRandomInstance(); MyByteBuffer data = MyByteBuffer.wrap(new byte[1024]); int randomOffset(Random r, MyByteBuffer buf, int size) {
< prev index next >